vue_plugins.js 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  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.replace(/\\n/g, "\n"),
  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.replace(/\\n/g, "\n"),
  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. duration: 2000,
  835. });
  836. }
  837. }
  838. }
  839. }, other)
  840. }
  841. Vue.prototype.$postuser = function (url, data, callback, other) {
  842. var http = new $http();
  843. http.$postuser(url, data, function (ret) {
  844. callback(ret);
  845. }, other)
  846. }
  847. Vue.prototype.$get = function (url, data, callback, other) {
  848. var http = new $http();
  849. http.$get(url, data, function (ret) {
  850. if (ret.code == 0) {
  851. callback(ret);
  852. } else {
  853. api.toast({
  854. msg: ret.msg,
  855. duration: 2000,
  856. });
  857. }
  858. }, other)
  859. }
  860. Vue.prototype.$getadd = function (url, data, callback, other) {
  861. var http = new $http();
  862. http.$getadd(url, data, function (ret) {
  863. if (ret.code == 0) {
  864. callback(ret);
  865. } else {
  866. api.toast({
  867. msg: ret.msg
  868. });
  869. }
  870. }, other)
  871. }
  872. Vue.prototype.$getOption = function (url, data, callback) {
  873. var http = new $http();
  874. http.$getOption(url, data, function (ret) {
  875. if (ret.code == 0) {
  876. callback(ret);
  877. } else {
  878. api.toast({
  879. msg: ret.msg
  880. });
  881. }
  882. })
  883. }
  884. Vue.prototype.$uploadfile = function (url, data, callback) {
  885. var http = new $http();
  886. http.uploadfile(url, data, function (ret) {
  887. if (ret.code == 0 || ret.code == '0') {
  888. callback(ret);
  889. } else {
  890. api.toast({
  891. msg: ret.msg
  892. });
  893. }
  894. })
  895. }
  896. // 选择图片
  897. Vue.prototype.addPhoto = function (c) {
  898. var _this = this;
  899. // 判断是相机还是图片库
  900. api.actionSheet({
  901. title: '选择附件',
  902. cancelTitle: '这里是取消按钮',
  903. buttons: ['相机', '相册']
  904. }, function (ret, err) {
  905. if (ret.buttonIndex == 3) {
  906. return;
  907. }
  908. var imageT = ['album', 'camera'][ret.buttonIndex];
  909. _this.startChooseImage(imageT, c);
  910. });
  911. }
  912. // Vue.prototype.startChooseImage = function(imageT, c) {
  913. // api.getPicture({
  914. // sourceType: imageT,
  915. // encodingType: 'png',
  916. // mediaValue: 'pic',
  917. // destinationType: 'url',
  918. // allowEdit: true,
  919. // quality: 100,
  920. // saveToPhotoAlbum: false
  921. // }, function(ret, err) {
  922. // alertJson(ret);
  923. // if (ret) {
  924. // if (ret.data != "") {
  925. // // 有选择的相片了
  926. // c(ret.data, ret.base64Data);
  927. // }
  928. // } else {
  929. // alert(JSON.stringify(err));
  930. // }
  931. // });
  932. // }
  933. Vue.prototype.getNowTime = function (type) {
  934. var myDate = new Date();
  935. //获取系统当前时间
  936. var YY = myDate.getFullYear();
  937. // 获取年月日
  938. var MM = myDate.getMonth() > 8 ? (myDate.getMonth() + 1) : ('0' + (myDate.getMonth() + 1));
  939. var DD = myDate.getDate() > 9 ? myDate.getDate() : '0' + myDate.getDate();
  940. var T = myDate.getHours() > 9 ? myDate.getHours() : '0' + myDate.getHours();
  941. var M = myDate.getMinutes() > 9 ? myDate.getMinutes() : '0' + myDate.getMinutes();
  942. var S = myDate.getSeconds() > 9 ? myDate.getSeconds() : '0' + myDate.getSeconds();
  943. if (type == 'data') {
  944. return YY + '-' + MM + '-' + DD;
  945. } else {
  946. return YY + ' - ' + MM + ' - ' + DD + ' ' + T + ':' + M + ':' + S;
  947. }
  948. }
  949. // 选择时间
  950. Vue.prototype.getTime = function (c) {
  951. var date = this.getNowTime('date');
  952. api.openPicker({
  953. type: 'date',
  954. date: date,
  955. title: '请选择日期'
  956. }, function (ret, err) {
  957. if (ret) {
  958. var ct = ret.year + '-' + (ret.month < 10 ? '0' + ret.month : ret.month) + '-' + (ret.day < 10 ? '0' + ret.day : ret.day);
  959. c(ct);
  960. }
  961. });
  962. }
  963. // // 月份的最后一天
  964. Vue.prototype.formatMonthLastDay = function (v) {
  965. // 计算二月份的最后一天
  966. var dateStr = v + "-1"; //需要获取此月最后一天的日期
  967. var dateObj = new Date(dateStr);
  968. var nextMonth = dateObj.getMonth() + 1; //0-11,下一个月
  969. //设置当前日期为下个月的1号
  970. dateObj.setMonth(nextMonth);
  971. dateObj.setDate(1); //1-31
  972. var nextMonthFirstDayTime = dateObj.getTime(); //下个月一号对应毫秒
  973. var theMonthLastDayTime = nextMonthFirstDayTime - 24 * 60 * 60 * 1000; //下个月一号减去一天,正好是这个月最后一天
  974. var theMonthDay = (new Date(theMonthLastDayTime)).getDate();
  975. var val = theMonthDay;
  976. return val;
  977. }
  978. // 配置上拉加载和下拉刷新
  979. Vue.prototype.configDownAndPull = function (id, pullDown, down, useUp) {
  980. var mescroll = new MeScroll(id, {
  981. down: {
  982. auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
  983. callback: function () {
  984. pullDown(mescroll);
  985. }, //下拉刷新的回调
  986. },
  987. up: {
  988. use: useUp == false ? false : true, // 是否开启上拉加载
  989. auto: false, //初始化完毕,是否自动触发上拉加载的回调
  990. isBoth: true, //上拉加载时,如果滑动到列表顶部是否可以同时触发下拉刷新;默认false,两者不可同时触发; 这里为了演示改为true,不必等列表加载完毕才可下拉;
  991. isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
  992. htmlNodata: '',
  993. callback: function () {
  994. down(mescroll);
  995. }, //上拉加载的回调
  996. }
  997. });
  998. }
  999. // 判断是否有权限
  1000. Vue.prototype.ifHasPrme = function (perm, c) {
  1001. var has = this.hasPermission(perm),
  1002. _this = this;
  1003. if (!has || !has[0] || !has[0].granted) {
  1004. api.confirm({
  1005. title: '温馨提示',
  1006. msg: '需要您同意才能获取到' + perm + " 权限\n是否同意前往设置?",
  1007. buttons: ['不同意', '同意']
  1008. }, function (ret, err) {
  1009. if (2 == ret.buttonIndex) {
  1010. _this.reqPermission(perm, function () {
  1011. c(true);
  1012. });
  1013. } else if (1 == ret.buttonIndex) {
  1014. c(false);
  1015. }
  1016. });
  1017. } else {
  1018. c(true);
  1019. }
  1020. }
  1021. Vue.prototype.hasPermission = function (perm) {
  1022. var perms = new Array();
  1023. perms.push(perm);
  1024. var rets = api.hasPermission({
  1025. list: perms
  1026. });
  1027. return rets;
  1028. }
  1029. Vue.prototype.reqPermission = function (perm, callback) {
  1030. var perms = new Array();
  1031. perms.push(perm);
  1032. api.requestPermission({
  1033. list: perms,
  1034. }, function (ret, err) {
  1035. if (ret && ret.list.length > 0) {
  1036. callback(ret);
  1037. }
  1038. });
  1039. }