vue_plugins.js 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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. url = "checkVersionU",
  716. _this = this;
  717. this.$get(url, data, function(ret) {
  718. if (ret.code == 0 || ret.code == '0') {
  719. if (ret.version != _this.getVersion()) {
  720. if (api.systemType == 'ios') {
  721. api.alert({
  722. title: '新版本提示',
  723. msg: '检测到有新版本,请及时到APP Store 更新!',
  724. buttons:'我知道了!'
  725. }, function(ret, err) {
  726. if(ret){
  727. $api.clearStorage();
  728. _this.goWin("login ", "login.html", "");
  729. }
  730. });
  731. } else {
  732. api.alert({
  733. title: '新版本提示',
  734. msg:ret.plus_msg,
  735. buttons:'立即更新'
  736. }, function(res) {
  737. if(res){
  738. _this.downLoadApp(ret.url, c);
  739. }
  740. });
  741. }
  742. } else {
  743. api.toast({
  744. msg: '已是最新版本'
  745. })
  746. }
  747. }
  748. })
  749. }
  750. // 下载版本
  751. Vue.prototype.downLoadApp = function(url, callback) {
  752. var _this = this;
  753. api.showProgress({
  754. title: "更新提示",
  755. text: "正在更新",
  756. modal: true
  757. });
  758. // if (app.uav_type == 'IOS') {
  759. // api.installApp({
  760. // appUri : app.uav_filepath
  761. // });
  762. // } else {
  763. api.download({
  764. url: url,
  765. savePath: '',
  766. report: true,
  767. cache: true,
  768. allowResume: true
  769. }, function(ret, err) {
  770. // if (ret.state == 1) {
  771. // api.hideProgress();
  772. // api.installApp({
  773. // appUri: ret.savePath
  774. // });
  775. // } else if (ret.state == 2) {
  776. // callback('fail')
  777. // }
  778. if (ret && 0 == ret.state) { /* 下载进度 */
  779. api.showProgress({
  780. title: '正在下载...',
  781. text: ret.percent + "%",
  782. modal: true
  783. });
  784. }
  785. if (ret && 1 == ret.state) { /* 下载完成 */
  786. var savePath = ret.savePath;
  787. api.installApp({
  788. appUri: savePath
  789. });
  790. _this.showModal('温馨提示', '请安装程序,否则程序无法正常使用', ["", "确定"], function(res) {
  791. if (res == 2) {
  792. _this.getNewVersionUrl()
  793. }
  794. })
  795. }
  796. })
  797. //}
  798. }
  799. // 获取
  800. /******** ajax请求 ********/
  801. Vue.prototype.$webIp = {
  802. ip: new $http().ip
  803. }
  804. Vue.prototype.$post = function(url, data, callback, other) {
  805. var http = new $http();
  806. http.$post(url, data, function(ret) {
  807. if (ret.code == 0 || ret.code == '0') {
  808. callback(ret);
  809. } else {
  810. if (ret.records && ret.records.length > 0) {
  811. callback({
  812. code: 0,
  813. data: ret
  814. })
  815. } else {
  816. if (url == 'getLipeiInfoU') {
  817. callback({
  818. code: 500,
  819. msg: ret.msg
  820. })
  821. } else {
  822. api.toast({
  823. msg: ret.msg
  824. });
  825. }
  826. }
  827. }
  828. }, other)
  829. }
  830. Vue.prototype.$postuser = function(url, data, callback, other) {
  831. var http = new $http();
  832. http.$postuser(url, data, function(ret) {
  833. callback(ret);
  834. }, other)
  835. }
  836. Vue.prototype.$get = function(url, data, callback, other) {
  837. var http = new $http();
  838. http.$get(url, data, function(ret) {
  839. if (ret.code == 0) {
  840. callback(ret);
  841. } else {
  842. api.toast({
  843. msg: ret.msg
  844. });
  845. }
  846. }, other)
  847. }
  848. Vue.prototype.$getadd = function(url, data, callback, other) {
  849. var http = new $http();
  850. http.$getadd(url, data, function(ret) {
  851. if (ret.code == 0) {
  852. callback(ret);
  853. } else {
  854. api.toast({
  855. msg: ret.msg
  856. });
  857. }
  858. }, other)
  859. }
  860. Vue.prototype.$getOption = function(url, data, callback) {
  861. var http = new $http();
  862. http.$getOption(url, data, function(ret) {
  863. if (ret.code == 0) {
  864. callback(ret);
  865. } else {
  866. api.toast({
  867. msg: ret.msg
  868. });
  869. }
  870. })
  871. }
  872. Vue.prototype.$uploadfile = function(url, data, callback) {
  873. var http = new $http();
  874. http.uploadfile(url, data, function(ret) {
  875. if (ret.code == 0 || ret.code == '0') {
  876. callback(ret);
  877. } else {
  878. api.toast({
  879. msg: ret.msg
  880. });
  881. }
  882. })
  883. }
  884. // 选择图片
  885. Vue.prototype.addPhoto = function(c) {
  886. var _this = this;
  887. // 判断是相机还是图片库
  888. api.actionSheet({
  889. title: '选择附件',
  890. cancelTitle: '这里是取消按钮',
  891. buttons: ['相机', '相册']
  892. }, function(ret, err) {
  893. if (ret.buttonIndex == 3) {
  894. return;
  895. }
  896. var imageT = ['album', 'camera'][ret.buttonIndex];
  897. _this.startChooseImage(imageT, c);
  898. });
  899. }
  900. // Vue.prototype.startChooseImage = function(imageT, c) {
  901. // api.getPicture({
  902. // sourceType: imageT,
  903. // encodingType: 'png',
  904. // mediaValue: 'pic',
  905. // destinationType: 'url',
  906. // allowEdit: true,
  907. // quality: 100,
  908. // saveToPhotoAlbum: false
  909. // }, function(ret, err) {
  910. // alertJson(ret);
  911. // if (ret) {
  912. // if (ret.data != "") {
  913. // // 有选择的相片了
  914. // c(ret.data, ret.base64Data);
  915. // }
  916. // } else {
  917. // alert(JSON.stringify(err));
  918. // }
  919. // });
  920. // }
  921. Vue.prototype.getNowTime = function(type) {
  922. var myDate = new Date();
  923. //获取系统当前时间
  924. var YY = myDate.getFullYear();
  925. // 获取年月日
  926. var MM = myDate.getMonth() > 8 ? (myDate.getMonth() + 1) : ('0' + (myDate.getMonth() + 1));
  927. var DD = myDate.getDate() > 9 ? myDate.getDate() : '0' + myDate.getDate();
  928. var T = myDate.getHours() > 9 ? myDate.getHours() : '0' + myDate.getHours();
  929. var M = myDate.getMinutes() > 9 ? myDate.getMinutes() : '0' + myDate.getMinutes();
  930. var S = myDate.getSeconds() > 9 ? myDate.getSeconds() : '0' + myDate.getSeconds();
  931. if (type == 'data') {
  932. return YY + '-' + MM + '-' + DD;
  933. } else {
  934. return YY + ' - ' + MM + ' - ' + DD + ' ' + T + ':' + M + ':' + S;
  935. }
  936. }
  937. // 选择时间
  938. Vue.prototype.getTime = function(c) {
  939. var date = this.getNowTime('date');
  940. api.openPicker({
  941. type: 'date',
  942. date: date,
  943. title: '请选择日期'
  944. }, function(ret, err) {
  945. if (ret) {
  946. var ct = ret.year + '-' + (ret.month < 10 ? '0' + ret.month : ret.month) + '-' + (ret.day < 10 ? '0' + ret.day : ret.day);
  947. c(ct);
  948. }
  949. });
  950. }
  951. // // 月份的最后一天
  952. Vue.prototype.formatMonthLastDay = function(v){
  953. // 计算二月份的最后一天
  954. var dateStr = v +"-1"; //需要获取此月最后一天的日期
  955. var dateObj = new Date(dateStr);
  956. var nextMonth = dateObj.getMonth()+1; //0-11,下一个月
  957. //设置当前日期为下个月的1号
  958. dateObj.setMonth(nextMonth);
  959. dateObj.setDate(1); //1-31
  960. var nextMonthFirstDayTime = dateObj.getTime(); //下个月一号对应毫秒
  961. var theMonthLastDayTime = nextMonthFirstDayTime-24*60*60*1000; //下个月一号减去一天,正好是这个月最后一天
  962. var theMonthDay = (new Date(theMonthLastDayTime)).getDate();
  963. var val = theMonthDay;
  964. return val;
  965. }
  966. // 配置上拉加载和下拉刷新
  967. Vue.prototype.configDownAndPull = function(id, pullDown, down, useUp) {
  968. var mescroll = new MeScroll(id, {
  969. down: {
  970. auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
  971. callback: function() {
  972. pullDown(mescroll);
  973. }, //下拉刷新的回调
  974. },
  975. up: {
  976. use: useUp == false ? false : true, // 是否开启上拉加载
  977. auto: false, //初始化完毕,是否自动触发上拉加载的回调
  978. isBoth: true, //上拉加载时,如果滑动到列表顶部是否可以同时触发下拉刷新;默认false,两者不可同时触发; 这里为了演示改为true,不必等列表加载完毕才可下拉;
  979. isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
  980. htmlNodata: '',
  981. callback: function() {
  982. down(mescroll);
  983. }, //上拉加载的回调
  984. }
  985. });
  986. }
  987. // 判断是否有权限
  988. Vue.prototype.ifHasPrme = function(perm, c) {
  989. var has = this.hasPermission(perm),
  990. _this = this;
  991. if (!has || !has[0] || !has[0].granted) {
  992. api.confirm({
  993. title: '温馨提示',
  994. msg: '需要您同意才能获取到' + perm + " 权限\n是否同意前往设置?",
  995. buttons: ['不同意', '同意']
  996. }, function(ret, err) {
  997. if (2 == ret.buttonIndex) {
  998. _this.reqPermission(perm, function() {
  999. c(true);
  1000. });
  1001. } else if (1 == ret.buttonIndex) {
  1002. c(false);
  1003. }
  1004. });
  1005. } else {
  1006. c(true);
  1007. }
  1008. }
  1009. Vue.prototype.hasPermission = function(perm) {
  1010. var perms = new Array();
  1011. perms.push(perm);
  1012. var rets = api.hasPermission({
  1013. list: perms
  1014. });
  1015. return rets;
  1016. }
  1017. Vue.prototype.reqPermission = function(perm, callback) {
  1018. var perms = new Array();
  1019. perms.push(perm);
  1020. api.requestPermission({
  1021. list: perms,
  1022. }, function(ret, err) {
  1023. if (ret && ret.list.length > 0) {
  1024. callback(ret);
  1025. }
  1026. });
  1027. }