vue_plugins.js 34 KB

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