vue_plugins.js 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. /**
  2. * VUE 注册组件
  3. */
  4. Vue.prototype.getVersion = function() {
  5. var appVersion = api.appVersion;
  6. return appVersion.match(/^[0-9]\d*\.\d*|0\.\d*[1-9]\d*$/)[0];
  7. };
  8. // Vue.prototype.Language=function(ludata,callback){
  9. // var ludata="ZH"
  10. // if (ludata=="ZH"){
  11. // api.readFile({
  12. // path: 'widget://res/zh.json'
  13. // }, function(ret, err) {
  14. // if (ret.status) {
  15. // var a =ret.data;
  16. // var ret=JSON.parse(a)
  17. // callback(ret)
  18. // } else {
  19. // // alertJson(err)
  20. // }
  21. // });
  22. // }else if(ludata="EN"){
  23. // api.readFile({
  24. // path: 'widget://res/en.json'
  25. // }, function(ret, err) {
  26. // if (ret.status) {
  27. // // alertJson(ret)
  28. // } else {
  29. // // alertJson(err)
  30. // }
  31. // });
  32. // }
  33. // }
  34. var template_shopCar = '<div class="aui-shopCar-bg" v-on:click="goToCar">' + '<div class="aui-shop-badge">{{badge}}</div>' + '<div class="zmq-car-text">订单<br />确认</div>' + '</div>';
  35. Vue.component('shopcar', {
  36. props: ["badge"],
  37. template: template_shopCar,
  38. methods: {
  39. goToCar: function() {
  40. // 跳转到购物车页面
  41. this.goWin("orderCar_win", "../order/orderCar_win.html", "");
  42. }
  43. }
  44. })
  45. /**
  46. * 弹出层
  47. */
  48. Vue.component('zmqalert', {
  49. props: ["info"],
  50. template: '<div v-show="info.show"><div class="zmq-model-bg"></div><div class="zmq-prome zmq-bg-white zmq-alert zmq-radius-5"><div class="zmq-alert-title zmq-text-font-09 zmq-text-value zmq-font-weight">{{info.title}}</div><div v-show="info.showMsg" class="zmq-alert-msg zmq-text-value zmq-text-font-06">{{info.msg}}</div><div class="zmq-alert-input zmq-bg-input"><input type="text" placeholder="请按要求填写" v-model = "info.content"/></div><div class="zmq-alert-btn zmq-flex"><div class="zmq-alert-btn-item zmq-flex-1 zmq-textAlign-center" v-on:click="clickAlertBtn(1)">取消</div><div class="zmq-alert-btn-item zmq-flex-1 zmq-textAlign-center" v-on:click="clickAlertBtn(0)">确认</div></div></div></div>',
  51. methods: {
  52. clickAlertBtn: function(type) {
  53. this.info.show = false;
  54. if (type == 0) {
  55. this.$emit("donechoose", type);
  56. }
  57. // 0 点击确认 1 点击取消
  58. }
  59. }
  60. })
  61. /******************* 极光推送 *********************/
  62. Vue.prototype.api = {
  63. devices: 5,
  64. }
  65. /*
  66. * 初始化极光
  67. */
  68. Vue.prototype.initApush = function(userid) {
  69. var ajpush = api.require('ajpush');
  70. this.pushObject = ajpush;
  71. var _this = this;
  72. this.pushObject.init(function(ret, err) {
  73. if (ret && ret.status) {
  74. console.log("操作成功");
  75. } else {
  76. console.log("操作失败");
  77. }
  78. });
  79. // 获取deviceToken,成功则继续走,否则gg
  80. this.getTokenAndReid(this.pushObject, function(state) {
  81. if (state == 'success') {
  82. // 开始绑定别名和标签
  83. _this.bindAliasAndTags(ajpush, userid);
  84. // 注册监听接收时间
  85. _this.configListen(ajpush);
  86. }
  87. })
  88. }
  89. /**
  90. * 获取deviceToken和reid
  91. */
  92. Vue.prototype.getTokenAndReid = function(ajpush, callback) {
  93. var _this = this;
  94. ajpush.getRegistrationId(function(ret) {
  95. if (api.deviceToken == "" && _this.api.devices > 0) {
  96. _this.api.devices -= 1;
  97. _this.getTokenAndReid(ajpush, callback);
  98. } else {
  99. callback('success');
  100. }
  101. });
  102. }
  103. /**
  104. * 绑定别名和标签
  105. */
  106. Vue.prototype.bindAliasAndTags = function(ajpush, userid) {
  107. var param = {
  108. alias: userid.toString(),
  109. tags: [userid.toString()]
  110. };
  111. //绑定别名
  112. this.pushObject.bindAliasAndTags(param, function(ret) {
  113. var statusCode = ret.statusCode;
  114. });
  115. }
  116. /**
  117. * 注册获取消息
  118. */
  119. Vue.prototype.configListen = function(ajpush) {
  120. var _this = this;
  121. // // 添加消息接受事件
  122. ajpush.setListener(function(ret) {
  123. _this.sendEvent("checkRetailer");
  124. });
  125. api.addEventListener({
  126. name: 'appintent'
  127. }, function (ret, err) {
  128. if (ret && ret.appParam.ajpush) {
  129. if (ret.appParam.ajpush.extra.env == 4 || ret.appParam.ajpush.extra.env == '4') { // 消息中心
  130. api.openWin({
  131. name: 'msg',
  132. url: '../luntai/msgDetails.html',
  133. pageParam : {
  134. sendUserId: ret.appParam.ajpush.extra.sendUserId
  135. }
  136. });
  137. }
  138. if (ret.appParam.ajpush.extra.env == 5 || ret.appParam.ajpush.extra.env == '5') { // 消息中心
  139. api.openWin({
  140. name: 'msg',
  141. url: '../luntai/msgDetails.html',
  142. });
  143. }
  144. }
  145. })
  146. }
  147. /******************* 结束推送 *********************/
  148. /**
  149. * 多选控件
  150. * h : 原先已经有的
  151. * d : 需要渲染的数组
  152. * t : 选择框标题
  153. * n : 触发下拉框的id
  154. */
  155. Vue.prototype.checkByDropdown = function(h, d, t, n, c) {
  156. // document.body.style.position = 'fixed';
  157. document.body.style.overflow = 'hidden';
  158. new Dropdown({
  159. dom: n, //点击触发下拉的选择框的id
  160. type: 'multiple', //是单选还是多选 单选 single 多选 multiple
  161. title: t, //选择框title
  162. required: false, //是否必填
  163. dataArr: d,
  164. success: function(resp) { // 回调函数
  165. // document.body.style.position = 'relative';
  166. // var addList = new Array();
  167. // alert(h.length)
  168. // document.body.style.overflow = 'auto';
  169. // resp.map(function(item,index){
  170. // var has = false;
  171. // h.map(function(ir,ids){
  172. // alert(ir.id + ',' + item.id)
  173. // if(item.id == ir.id){
  174. // has = true;
  175. // }
  176. // })
  177. // if(has == false){
  178. // addList.push(item);
  179. // }
  180. // })
  181. c(resp);
  182. }
  183. })
  184. }
  185. /**
  186. * 将两个JSON对象拼接
  187. */
  188. Vue.prototype.extend = function(a, b) {
  189. for (var obj in b) {
  190. a[obj] = b[obj];
  191. }
  192. return a;
  193. }
  194. // 判断手机号
  195. Vue.prototype.phoneExg = function(phone) {
  196. if (!(/^1[3456789]\d{9}$/.test(phone))) {
  197. return false;
  198. } else {
  199. return true;
  200. }
  201. }
  202. // 判断信息为空
  203. Vue.prototype.checkInfo = function(content) {
  204. if (content == '') {
  205. api.toast({
  206. msg: '必填项不能为空'
  207. });
  208. return false
  209. } else {
  210. return true
  211. }
  212. }
  213. // 判断数组
  214. Vue.prototype.checkArray = function(content) {
  215. if (content.length == 0) {
  216. api.toast({
  217. msg: '必填项不能为空'
  218. });
  219. return false
  220. } else {
  221. return true
  222. }
  223. }
  224. Vue.prototype.checkByDropdown1 = function(h, d, t, n, c) {
  225. // document.body.style.position = 'fixed';
  226. document.body.style.overflow = 'hidden';
  227. new Dropdown({
  228. dom: n, //点击触发下拉的选择框的id
  229. type: 'multiple', //是单选还是多选 单选 single 多选 multiple
  230. title: t, //选择框title
  231. required: false, //是否必填
  232. dataArr: d,
  233. success: function(resp) { // 回调函数
  234. // document.body.style.position = 'relative';
  235. // var addList = new Array();
  236. // alert(h.length)
  237. // document.body.style.overflow = 'auto';
  238. // resp.map(function(item,index){
  239. // var has = false;
  240. // h.map(function(ir,ids){
  241. // alert(ir.id + ',' + item.id)
  242. // if(item.id == ir.id){
  243. // has = true;
  244. // }
  245. // })
  246. // if(has == false){
  247. // addList.push(item);
  248. // }
  249. // })
  250. c(resp);
  251. }
  252. })
  253. }
  254. /**
  255. * 将文字放到图片中生成img
  256. */
  257. Vue.prototype.createImg = function(c) {
  258. var canvas2 = document.createElement("canvas");
  259. var _canvas = document.querySelector('div');
  260. var w = parseInt(window.getComputedStyle(_canvas).width);
  261. var h = parseInt(window.getComputedStyle(_canvas).height);
  262. //将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了
  263. canvas2.width = w * 2;
  264. canvas2.height = h * 2;
  265. canvas2.style.width = w + "px";
  266. canvas2.style.height = h + "px";
  267. //可以按照自己的需求,对context的参数修改,translate指的是偏移量
  268. // var context = canvas.getContext("2d");
  269. // context.translate(0,0);
  270. var context = canvas2.getContext("2d");
  271. context.scale(2, 2);
  272. html2canvas(document.querySelector('div'), {
  273. canvas: canvas2
  274. }).then(function(canvas) {
  275. //document.body.appendChild(canvas);
  276. //canvas转换成url,然后利用a标签的download属性,直接下载,绕过上传服务器再下载
  277. c(canvas.toDataURL());
  278. })
  279. }
  280. /**
  281. * VUE 的扩展方法
  282. */
  283. // 获取到的经销商信息
  284. Vue.prototype.userInfo = function() {
  285. this.info = "";
  286. this.loginid = $api.getStorage('loginid');
  287. this.retariler_id = $api.getStorage("retailerid");
  288. this.storeName = $api.getStorage("storeName");
  289. this.carNum = 0;
  290. }
  291. // 使用选择器的时候的数据封装
  292. Vue.prototype.actionSelectorData = function(retlist, c) {
  293. var list = new Array();
  294. retlist.map(function(item, index) {
  295. var option = {
  296. name: eval("item." + c.name),
  297. id: eval("item." + c.id),
  298. }
  299. list.push(option);
  300. })
  301. return list;
  302. }
  303. // 打开筛选页面
  304. /**
  305. * f - 打开页面名称
  306. * s - 打开选择页面还是关闭
  307. * e - 需要传到筛选页面的值
  308. */
  309. var pageStatus = 'o';
  310. Vue.prototype.configDownChoose = function(o, e) {
  311. if (pageStatus == 'o') {
  312. api.openFrame({
  313. name: 'search',
  314. url: '../search.html',
  315. rect: {
  316. x: 0,
  317. y: e.value.h,
  318. w: api.winWidth,
  319. h: api.frameHeight
  320. },
  321. pageParam: {
  322. e: JSON.stringify(e),
  323. o: JSON.stringify(o),
  324. },
  325. bgColor: 'rgba(0,0,0,0)',
  326. animatin: {
  327. type: "movein", //动画类型(详见动画类型常量)
  328. subType: "from_top", //动画子类型(详见动画子类型常量)
  329. duration: 300 //动画过渡时间,默认300毫秒
  330. }
  331. });
  332. pageStatus = 'c';
  333. } else {
  334. pageStatus = 'o';
  335. api.closeFrame({
  336. name: 'search',
  337. });
  338. }
  339. }
  340. // 使用motive配置下拉刷新
  341. Vue.prototype.configHeaderRefush = function(callback) {
  342. api.setCustomRefreshHeaderInfo({
  343. bgColor: '#f2f8f9',
  344. images: ['widget://image/refush1/ru0.png', 'widget://image/refush1/ru1.png', 'widget://image/refush1/ru2.png', 'widget://image/refush1/ru3.png', 'widget://image/refush1/ru4.png', 'widget://image/refush1/ru5.png', 'widget://image/refush1/ru6.png', 'widget://image/refush1/ru7.png'],
  345. // images : ['widget://image/refush1/try.gif'],
  346. tips: {
  347. pull: '下拉刷新',
  348. threshold: '松开立即刷新',
  349. load: '正在刷新'
  350. }
  351. }, function() {
  352. callback();
  353. // //下拉刷新被触发,自动进入加载状态,使用 api.refreshHeaderLoadDone() 手动结束加载中状态
  354. // //下拉刷新被触发,使用 api.refreshHeaderLoadDone() 结束加载中状态
  355. // alert('开始加载刷新数据,摇一摇停止加载状态');
  356. // api.addEventListener({
  357. // name : 'shake'
  358. // }, function(ret, err) {
  359. // api.refreshHeaderLoadDone()
  360. // });
  361. });
  362. }
  363. // 配置下拉刷新
  364. Vue.prototype.configHeadMotive = function(callback) {
  365. api.setRefreshHeaderInfo({
  366. visible: true,
  367. bgColor: '#fff',
  368. textColor: '#ccc',
  369. textDown: '下拉刷新...',
  370. textUp: '松开刷新...',
  371. showTime: true
  372. }, function(ret, err) {
  373. if (ret) {
  374. callback(ret);
  375. }
  376. });
  377. }
  378. // 配置下拉刷新
  379. Vue.prototype.configBottomRefush = function(callback) {
  380. new auiScroll({
  381. listen: true,
  382. distance: 0 //判断到达底部的距离,isToBottom为true
  383. }, function(ret) {
  384. if (ret.isToBottom) {
  385. callback(true);
  386. }
  387. });
  388. }
  389. // 配置alert提示框
  390. Vue.prototype.showAlert = function(m, c) {
  391. api.alert({
  392. title: '温馨提示',
  393. msg: m,
  394. buttons: ["确定"],
  395. }, function(ret, err) {
  396. //coding...
  397. c();
  398. });
  399. }
  400. // 延时关闭页面发送监听
  401. Vue.prototype.doneSendEvent = function(n, t, e) {
  402. var times = typeof t == 'undefined' ? 200 : t;
  403. this.sendEvent(n, e);
  404. setTimeout(function() {
  405. api.closeWin({});
  406. }, times);
  407. }
  408. // 提示信息
  409. Vue.prototype.showToast = function(str) {
  410. api.toast({
  411. msg: str
  412. });
  413. }
  414. // 扫码
  415. Vue.prototype.scan = function(f, c) {
  416. api.showProgress({
  417. title: '请稍候',
  418. text: '正在调起摄像头',
  419. modal: false
  420. });
  421. f.open({
  422. autorotation: true,
  423. isDrawQRCodeRect: true,
  424. }, function(ret, err) {
  425. api.hideProgress();
  426. if (ret) {
  427. if (ret.eventType == 'success') {
  428. c(ret.content);
  429. }
  430. } else {
  431. api.toast({
  432. msg: '扫码出错'
  433. });
  434. }
  435. });
  436. }
  437. // 查看大图
  438. Vue.prototype.lookBigImg = function(f, i) {
  439. f.openImages({
  440. imageUrls: i
  441. });
  442. }
  443. // 扫码 -- 主要是条形码
  444. Vue.prototype.scant = function(f, c) {
  445. var param = {};
  446. var resultCallback = function(ret, err) {
  447. if (ret.eventType == 'success') {
  448. c(ret.content);
  449. }
  450. };
  451. f.openScanner(param, resultCallback);
  452. }
  453. // 输入框类型
  454. Vue.prototype.showPromt = function(title, msg, buttons, callback) {
  455. api.prompt({
  456. title: title,
  457. msg: msg,
  458. buttons: buttons
  459. }, function(ret, err) {
  460. //coding...
  461. callback(ret);
  462. });
  463. }
  464. // 注册监听
  465. Vue.prototype.addEvent = function(eventName, callback) {
  466. api.addEventListener({
  467. name: eventName,
  468. }, function(ret, err) {
  469. //coding...
  470. callback(ret);
  471. });
  472. }
  473. // 提示信息
  474. Vue.prototype.showModal = function(title, msg, buttons, callback) {
  475. api.confirm({
  476. title: title,
  477. msg: msg,
  478. buttons: buttons.reverse(),
  479. }, function(ret, err) {
  480. //coding...
  481. callback(ret.buttonIndex == 2 ? 1 : 2);
  482. });
  483. }
  484. // 过滤掉数组中的对象
  485. Vue.prototype.filterArrNotNull = function(s, a) {
  486. return s.filter(a == null)
  487. }
  488. // 发送监听
  489. Vue.prototype.sendEvent = function(eventName, params) {
  490. api.sendEvent({
  491. name: eventName,
  492. extra: params
  493. });
  494. }
  495. // 跳转页面
  496. Vue.prototype.goWin = function(winName, winUrl, params) {
  497. setTimeout(function() {
  498. api.openWin({
  499. name: winName,
  500. url: winUrl,
  501. pageParam: params,
  502. bounces: false,
  503. animation: {
  504. type: "push", //动画类型(详见动画类型常量)
  505. subType: "from_right", //动画子类型(详见动画子类型常量)
  506. duration: 300 //动画过渡时间,默认300毫秒
  507. }
  508. });
  509. }, 200);
  510. }
  511. // 点击查看大图
  512. Vue.prototype.lookBigImage = function(a, srcs) {
  513. a.openImages({
  514. imageUrls: srcs
  515. });
  516. }
  517. // 选择图片
  518. Vue.prototype.chooseImage_onlycamer = function(c) {
  519. var _this = this;
  520. // 判断是相机还是图片库
  521. api.actionSheet({
  522. title: '选择附件',
  523. cancelTitle: '这里是取消按钮',
  524. buttons: ['相机']
  525. }, function(ret, err) {
  526. if (ret.buttonIndex == 2) {
  527. return;
  528. }
  529. var imageT = ["", "camera"][ret.buttonIndex];
  530. _this.startChooseImage(imageT, function(path) {
  531. c(path);
  532. });
  533. });
  534. }
  535. // 选择图片
  536. Vue.prototype.chooseImage = function(c) {
  537. var _this = this;
  538. // 判断是相机还是图片库
  539. api.actionSheet({
  540. title: '选择附件',
  541. cancelTitle: '这里是取消按钮',
  542. buttons: ['相机', '相册']
  543. }, function(ret, err) {
  544. if (ret.buttonIndex == 3) {
  545. return;
  546. }
  547. var imageT = ["", "camera", "album"][ret.buttonIndex];
  548. _this.startChooseImage(imageT, function(path) {
  549. c(path);
  550. });
  551. });
  552. }
  553. // 开始选择图片
  554. Vue.prototype.startChooseImage = function(imageT, callback) {
  555. var _this = this;
  556. api.getPicture({
  557. sourceType: imageT,
  558. encodingType: 'png',
  559. mediaValue: 'pic',
  560. destinationType: 'base64',
  561. allowEdit: true,
  562. quality: 50,
  563. // targetWidth : 1000,
  564. saveToPhotoAlbum: false
  565. }, function(ret, err) {
  566. if (ret) {
  567. if (ret.data != "") {
  568. _this.compreseImg(ret.data, function(img) {
  569. callback(img)
  570. });
  571. _this.localImage = ret.data
  572. }
  573. } else {
  574. // alert(JSON.stringify(err));
  575. }
  576. });
  577. }
  578. // 压缩图片
  579. Vue.prototype.compreseImg = function(src, c) {
  580. var _this = this;
  581. auiCompress(src, {
  582. width: 1080,
  583. quantity: 50,
  584. // 压缩成功
  585. success: function(retimg) {
  586. _this.getBlobBy64(retimg.base64, c);
  587. }
  588. })
  589. }
  590. // base64 To blob
  591. Vue.prototype.getBlobBy64 = function(dataurl, c) {
  592. var filename = 'file';
  593. var arr = dataurl.split(',')
  594. var mime = arr[0].match(/:(.*?);/)[1]
  595. var suffix = mime.split('/')[1]
  596. var bstr = atob(arr[1])
  597. var n = bstr.length
  598. var u8arr = new Uint8Array(n)
  599. while (n--) {
  600. u8arr[n] = bstr.charCodeAt(n)
  601. }
  602. c(new File([u8arr], `${filename}.${suffix}`, {
  603. type: mime
  604. }))
  605. }
  606. // 关闭页面
  607. Vue.prototype.closeWin = function() {
  608. setTimeout(function() {
  609. api.closeWin({});
  610. }, 200);
  611. }
  612. // 点击选择省市区
  613. Vue.prototype.chooseRegion = function(UIActionSelector, col, datasUrl, callback) {
  614. UIActionSelector.open({
  615. datas: datasUrl,
  616. layout: {
  617. row: 5,
  618. col: col,
  619. height: 30,
  620. size: 12,
  621. sizeActive: 14,
  622. rowSpacing: 5,
  623. colSpacing: 10,
  624. maskBg: 'rgba(0,0,0,0.2)',
  625. bg: '#fff',
  626. color: '#ddd',
  627. colorActive: '#f00',
  628. colorSelected: '#000'
  629. },
  630. animation: true,
  631. cancel: {
  632. text: '取消',
  633. size: 12,
  634. w: 90,
  635. h: 35,
  636. bg: '#fff',
  637. bgActive: '#ccc',
  638. color: '#888',
  639. colorActive: '#fff'
  640. },
  641. ok: {
  642. text: '确定',
  643. size: 12,
  644. w: 90,
  645. h: 35,
  646. bg: '#fff',
  647. bgActive: '#ccc',
  648. color: '#888',
  649. colorActive: '#fff'
  650. },
  651. title: {
  652. text: '请选择',
  653. size: 12,
  654. h: 44,
  655. bg: '#eee',
  656. color: '#888',
  657. },
  658. fixedOn: api.frameName
  659. }, function(ret, err) {
  660. if (ret) {
  661. if (ret.eventType == 'ok') {
  662. callback(ret);
  663. }
  664. } else {
  665. api.toast({
  666. msg: '事件错误'
  667. });
  668. }
  669. });
  670. }
  671. // 显示加载框
  672. Vue.prototype.showProcess = function() {
  673. api.showProgress({
  674. title: '请稍候...',
  675. text: '加载中...'
  676. });
  677. }
  678. // 隐藏加载框
  679. Vue.prototype.hideProcess = function() {
  680. api.hideProgress();
  681. }
  682. // 获取用户信息
  683. Vue.prototype.getUserInfo = function(callback) {
  684. return;
  685. var url = "getUserInfoUrl",
  686. loginid = $api.getStorage('loginid'),
  687. _this = this;
  688. var data = {
  689. loginId: loginid,
  690. url: 'json',
  691. type: 'body',
  692. };
  693. this.$post(url, data, function(ret) {
  694. if (typeof callback != 'undefined' && callback != "undefined" && callback != "") {
  695. callback(ret);
  696. }
  697. if (ret.retailerDto != null) {
  698. // 将retariler_id和username保存起来
  699. $api.setStorage('retailerid', ret.retailerDto.id);
  700. $api.setStorage('storeName', ret.retailerDto.storeName);
  701. }
  702. });
  703. }
  704. // 获取购物车数量
  705. Vue.prototype.getCarNum = function(id, callback) {
  706. var data = {
  707. retailer_id: id,
  708. },
  709. url = "shopCarListUrl",
  710. _this = this;
  711. this.$post(url, data, function(ret) {
  712. if (ret.code == 0) {
  713. _this.userInfo.carNum = ret.list.length;
  714. callback(ret.list);
  715. }
  716. })
  717. }
  718. // 获取新版本,然后下载安装
  719. Vue.prototype.getNewVersionUrl = function(c) {
  720. var data = '',
  721. _this = this;
  722. if(api.systemType == 'ios'){
  723. var url = "ioscheckVersionU"
  724. }else{
  725. var url = "checkVersionU"
  726. }
  727. this.$get(url, data, function(ret) {
  728. if (ret.code == 0 || ret.code == '0') {
  729. if (ret.version != _this.getVersion()) {
  730. if (api.systemType == 'ios') {
  731. api.alert({
  732. title: '新版本提示',
  733. msg: '检测到有新版本,请及时到APP Store 更新!\n'+ret.plus_msg,
  734. buttons:'我知道了!'
  735. }, function(ret, err) {
  736. if(ret){
  737. $api.clearStorage();
  738. _this.goWin("login ", "login.html", "");
  739. }
  740. });
  741. } else {
  742. api.alert({
  743. title: '新版本提示',
  744. msg:ret.plus_msg,
  745. buttons:'立即更新'
  746. }, function(res) {
  747. if(res){
  748. _this.downLoadApp(ret.url, c);
  749. }
  750. });
  751. }
  752. } else {
  753. api.toast({
  754. msg: '已是最新版本'
  755. })
  756. }
  757. }
  758. })
  759. }
  760. // 下载版本
  761. Vue.prototype.downLoadApp = function(url, callback) {
  762. var _this = this;
  763. api.showProgress({
  764. title: "更新提示",
  765. text: "正在更新",
  766. modal: true
  767. });
  768. // if (app.uav_type == 'IOS') {
  769. // api.installApp({
  770. // appUri : app.uav_filepath
  771. // });
  772. // } else {
  773. api.download({
  774. url: url,
  775. savePath: '',
  776. report: true,
  777. cache: true,
  778. allowResume: true
  779. }, function(ret, err) {
  780. // if (ret.state == 1) {
  781. // api.hideProgress();
  782. // api.installApp({
  783. // appUri: ret.savePath
  784. // });
  785. // } else if (ret.state == 2) {
  786. // callback('fail')
  787. // }
  788. if (ret && 0 == ret.state) { /* 下载进度 */
  789. api.showProgress({
  790. title: '正在下载...',
  791. text: ret.percent + "%",
  792. modal: true
  793. });
  794. }
  795. if (ret && 1 == ret.state) { /* 下载完成 */
  796. var savePath = ret.savePath;
  797. api.installApp({
  798. appUri: savePath
  799. });
  800. _this.showModal('温馨提示', '请安装程序,否则程序无法正常使用', ["", "确定"], function(res) {
  801. if (res == 2) {
  802. _this.getNewVersionUrl()
  803. }
  804. })
  805. }
  806. })
  807. //}
  808. }
  809. // 获取
  810. /******** ajax请求 ********/
  811. Vue.prototype.$webIp = {
  812. ip: new $http().ip
  813. }
  814. Vue.prototype.$post = function(url, data, callback, other) {
  815. var http = new $http();
  816. http.$post(url, data, function(ret) {
  817. if (ret.code == 0 || ret.code == '0') {
  818. callback(ret);
  819. } else {
  820. if (ret.records && ret.records.length > 0) {
  821. callback({
  822. code: 0,
  823. data: ret
  824. })
  825. } else {
  826. if (url == 'getLipeiInfoU') {
  827. callback({
  828. code: 500,
  829. msg: ret.msg
  830. })
  831. } else {
  832. api.toast({
  833. msg: ret.msg
  834. });
  835. }
  836. }
  837. }
  838. }, other)
  839. }
  840. Vue.prototype.$postuser = function(url, data, callback, other) {
  841. var http = new $http();
  842. http.$postuser(url, data, function(ret) {
  843. callback(ret);
  844. }, other)
  845. }
  846. Vue.prototype.$get = function(url, data, callback, other) {
  847. var http = new $http();
  848. http.$get(url, data, function(ret) {
  849. if (ret.code == 0) {
  850. callback(ret);
  851. } else {
  852. api.toast({
  853. msg: ret.msg
  854. });
  855. }
  856. }, other)
  857. }
  858. Vue.prototype.$getadd = function(url, data, callback, other) {
  859. var http = new $http();
  860. http.$getadd(url, data, function(ret) {
  861. if (ret.code == 0) {
  862. callback(ret);
  863. } else {
  864. api.toast({
  865. msg: ret.msg
  866. });
  867. }
  868. }, other)
  869. }
  870. Vue.prototype.$getOption = function(url, data, callback) {
  871. var http = new $http();
  872. http.$getOption(url, data, function(ret) {
  873. if (ret.code == 0) {
  874. callback(ret);
  875. } else {
  876. api.toast({
  877. msg: ret.msg
  878. });
  879. }
  880. })
  881. }
  882. Vue.prototype.$uploadfile = function(url, data, callback) {
  883. var http = new $http();
  884. http.uploadfile(url, data, function(ret) {
  885. if (ret.code == 0 || ret.code == '0') {
  886. callback(ret);
  887. } else {
  888. api.toast({
  889. msg: ret.msg
  890. });
  891. }
  892. })
  893. }
  894. // 选择图片
  895. Vue.prototype.addPhoto = function(c) {
  896. var _this = this;
  897. // 判断是相机还是图片库
  898. api.actionSheet({
  899. title: '选择附件',
  900. cancelTitle: '这里是取消按钮',
  901. buttons: ['相机', '相册']
  902. }, function(ret, err) {
  903. if (ret.buttonIndex == 3) {
  904. return;
  905. }
  906. var imageT = ['album', 'camera'][ret.buttonIndex];
  907. _this.startChooseImage(imageT, c);
  908. });
  909. }
  910. // Vue.prototype.startChooseImage = function(imageT, c) {
  911. // api.getPicture({
  912. // sourceType: imageT,
  913. // encodingType: 'png',
  914. // mediaValue: 'pic',
  915. // destinationType: 'url',
  916. // allowEdit: true,
  917. // quality: 100,
  918. // saveToPhotoAlbum: false
  919. // }, function(ret, err) {
  920. // alertJson(ret);
  921. // if (ret) {
  922. // if (ret.data != "") {
  923. // // 有选择的相片了
  924. // c(ret.data, ret.base64Data);
  925. // }
  926. // } else {
  927. // alert(JSON.stringify(err));
  928. // }
  929. // });
  930. // }
  931. Vue.prototype.getNowTime = function(type) {
  932. var myDate = new Date();
  933. //获取系统当前时间
  934. var YY = myDate.getFullYear();
  935. // 获取年月日
  936. var MM = myDate.getMonth() > 8 ? (myDate.getMonth() + 1) : ('0' + (myDate.getMonth() + 1));
  937. var DD = myDate.getDate() > 9 ? myDate.getDate() : '0' + myDate.getDate();
  938. var T = myDate.getHours() > 9 ? myDate.getHours() : '0' + myDate.getHours();
  939. var M = myDate.getMinutes() > 9 ? myDate.getMinutes() : '0' + myDate.getMinutes();
  940. var S = myDate.getSeconds() > 9 ? myDate.getSeconds() : '0' + myDate.getSeconds();
  941. if (type == 'data') {
  942. return YY + '-' + MM + '-' + DD;
  943. } else {
  944. return YY + ' - ' + MM + ' - ' + DD + ' ' + T + ':' + M + ':' + S;
  945. }
  946. }
  947. // 选择时间
  948. Vue.prototype.getTime = function(c) {
  949. var date = this.getNowTime('date');
  950. api.openPicker({
  951. type: 'date',
  952. date: date,
  953. title: '请选择日期'
  954. }, function(ret, err) {
  955. if (ret) {
  956. var ct = ret.year + '-' + (ret.month < 10 ? '0' + ret.month : ret.month) + '-' + (ret.day < 10 ? '0' + ret.day : ret.day);
  957. c(ct);
  958. }
  959. });
  960. }
  961. // // 月份的最后一天
  962. Vue.prototype.formatMonthLastDay = function(v){
  963. // 计算二月份的最后一天
  964. var dateStr = v +"-1"; //需要获取此月最后一天的日期
  965. var dateObj = new Date(dateStr);
  966. var nextMonth = dateObj.getMonth()+1; //0-11,下一个月
  967. //设置当前日期为下个月的1号
  968. dateObj.setMonth(nextMonth);
  969. dateObj.setDate(1); //1-31
  970. var nextMonthFirstDayTime = dateObj.getTime(); //下个月一号对应毫秒
  971. var theMonthLastDayTime = nextMonthFirstDayTime-24*60*60*1000; //下个月一号减去一天,正好是这个月最后一天
  972. var theMonthDay = (new Date(theMonthLastDayTime)).getDate();
  973. var val = theMonthDay;
  974. return val;
  975. }
  976. // 配置上拉加载和下拉刷新
  977. Vue.prototype.configDownAndPull = function(id, pullDown, down, useUp) {
  978. var mescroll = new MeScroll(id, {
  979. down: {
  980. auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
  981. callback: function() {
  982. pullDown(mescroll);
  983. }, //下拉刷新的回调
  984. },
  985. up: {
  986. use: useUp == false ? false : true, // 是否开启上拉加载
  987. auto: false, //初始化完毕,是否自动触发上拉加载的回调
  988. isBoth: true, //上拉加载时,如果滑动到列表顶部是否可以同时触发下拉刷新;默认false,两者不可同时触发; 这里为了演示改为true,不必等列表加载完毕才可下拉;
  989. isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
  990. htmlNodata: '',
  991. callback: function() {
  992. down(mescroll);
  993. }, //上拉加载的回调
  994. }
  995. });
  996. }
  997. // 判断是否有权限
  998. Vue.prototype.ifHasPrme = function(perm, c) {
  999. var has = this.hasPermission(perm),
  1000. _this = this;
  1001. if (!has || !has[0] || !has[0].granted) {
  1002. api.confirm({
  1003. title: '温馨提示',
  1004. msg: '需要您同意才能获取到' + perm + " 权限\n是否同意前往设置?",
  1005. buttons: ['不同意', '同意']
  1006. }, function(ret, err) {
  1007. if (2 == ret.buttonIndex) {
  1008. _this.reqPermission(perm, function() {
  1009. c(true);
  1010. });
  1011. } else if (1 == ret.buttonIndex) {
  1012. c(false);
  1013. }
  1014. });
  1015. } else {
  1016. c(true);
  1017. }
  1018. }
  1019. Vue.prototype.hasPermission = function(perm) {
  1020. var perms = new Array();
  1021. perms.push(perm);
  1022. var rets = api.hasPermission({
  1023. list: perms
  1024. });
  1025. return rets;
  1026. }
  1027. Vue.prototype.reqPermission = function(perm, callback) {
  1028. var perms = new Array();
  1029. perms.push(perm);
  1030. api.requestPermission({
  1031. list: perms,
  1032. }, function(ret, err) {
  1033. if (ret && ret.list.length > 0) {
  1034. callback(ret);
  1035. }
  1036. });
  1037. }