vue_plugins.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /**
  2. * VUE 注册组件
  3. */
  4. Vue.prototype.getVersion = function() {
  5. return "1.1";
  6. };
  7. var template_shopCar = '<div class="aui-shopCar-bg" v-on:click="goToCar">' + '<div class="aui-shop-badge">{{badge}}</div>' + '<img src="../../image/shopCar.png" class="aui-shop">' + '</div>';
  8. Vue.component('shopcar', {
  9. props : ["badge"],
  10. template : template_shopCar,
  11. methods : {
  12. goToCar : function() {
  13. // 跳转到购物车页面
  14. this.goWin("orderCar_win", "../order/orderCar_win.html", "");
  15. }
  16. }
  17. })
  18. /**
  19. * 弹出层
  20. */
  21. Vue.component('zmqalert', {
  22. props : ["info"],
  23. 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>',
  24. methods : {
  25. clickAlertBtn : function(type) {
  26. this.info.show = false;
  27. if (type == 0) {
  28. this.$emit("donechoose", type);
  29. }
  30. // 0 点击确认 1 点击取消
  31. }
  32. }
  33. })
  34. /******************* 极光推送 *********************/
  35. Vue.prototype.api = {
  36. devices : 5,
  37. }
  38. /*
  39. * 初始化极光
  40. */
  41. Vue.prototype.initApush = function(userid) {
  42. var ajpush = api.require('ajpush');
  43. this.pushObject = ajpush;
  44. var _this = this;
  45. this.pushObject.init(function(ret, err) {
  46. if (ret && ret.status) {
  47. console.log("操作成功");
  48. } else {
  49. console.log("操作失败");
  50. }
  51. });
  52. // 获取deviceToken,成功则继续走,否则gg
  53. this.getTokenAndReid(this.pushObject, function(state) {
  54. if (state == 'success') {
  55. // 开始绑定别名和标签
  56. _this.bindAliasAndTags(ajpush, userid);
  57. // 注册监听接收时间
  58. _this.configListen(ajpush);
  59. }
  60. })
  61. }
  62. /**
  63. * 获取deviceToken和reid
  64. */
  65. Vue.prototype.getTokenAndReid = function(ajpush, callback) {
  66. var _this = this;
  67. this.pushObject.getRegistrationId(function(ret) {
  68. if (api.deviceToken == "" && _this.api.devices > 0) {
  69. _this.api.devices -= 1;
  70. _this.getTokenAndReid(ajpush, callback);
  71. } else {
  72. callback('success');
  73. }
  74. });
  75. }
  76. /**
  77. * 绑定别名和标签
  78. */
  79. Vue.prototype.bindAliasAndTags = function(ajpush, userid) {
  80. var param = {
  81. alias : userid.toString(),
  82. tags : [userid.toString()]
  83. };
  84. //绑定别名
  85. this.pushObject.bindAliasAndTags(param, function(ret) {
  86. var statusCode = ret.statusCode;
  87. });
  88. }
  89. /**
  90. * 注册获取消息
  91. */
  92. Vue.prototype.configListen = function(ajpush) {
  93. var _this = this;
  94. // // 添加消息接受事件
  95. ajpush.setListener(function(ret) {
  96. _this.sendEvent("checkRetailer");
  97. });
  98. api.addEventListener({
  99. name : 'appintent'
  100. }, function(ret, err) {
  101. if (ret && ret.appParam.ajpush) {
  102. api.openWin({
  103. name : 'kehu_win',
  104. url : '../html/kehu/kehu_win.html',
  105. pageParam : ""
  106. });
  107. }
  108. })
  109. }
  110. /******************* 结束推送 *********************/
  111. /**
  112. * 弹出层
  113. */
  114. Vue.component('zmqalert', {
  115. props : ["info"],
  116. 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>',
  117. methods : {
  118. clickAlertBtn : function(type) {
  119. this.info.show = false;
  120. if (type == 0) {
  121. this.$emit("donechoose", type);
  122. }
  123. // 0 点击确认 1 点击取消
  124. }
  125. }
  126. })
  127. /**
  128. * 将两个JSON对象拼接
  129. */
  130. Vue.prototype.extend = function(a, b) {
  131. for (var obj in b) {
  132. a[obj] = b[obj];
  133. }
  134. return a;
  135. }
  136. /**
  137. * 多选控件
  138. * h : 原先已经有的
  139. * d : 需要渲染的数组
  140. * t : 选择框标题
  141. * n : 触发下拉框的id
  142. */
  143. Vue.prototype.checkByDropdown = function(h, d, t, n, c) {
  144. // document.body.style.position = 'fixed';
  145. document.body.style.overflow = 'hidden';
  146. new Dropdown({
  147. dom : n, //点击触发下拉的选择框的id
  148. type : 'multiple', //是单选还是多选 单选 single 多选 multiple
  149. title : t, //选择框title
  150. required : false, //是否必填
  151. dataArr : d,
  152. success : function(resp) {// 回调函数
  153. // document.body.style.position = 'relative';
  154. // var addList = new Array();
  155. // alert(h.length)
  156. // document.body.style.overflow = 'auto';
  157. // resp.map(function(item,index){
  158. // var has = false;
  159. // h.map(function(ir,ids){
  160. // alert(ir.id + ',' + item.id)
  161. // if(item.id == ir.id){
  162. // has = true;
  163. // }
  164. // })
  165. // if(has == false){
  166. // addList.push(item);
  167. // }
  168. // })
  169. c(resp);
  170. }
  171. })
  172. }
  173. // 判断手机号
  174. Vue.prototype.phoneExg = function(phone) {
  175. if (!(/^1[3456789]\d{9}$/.test(phone))) {
  176. return false;
  177. } else {
  178. return true;
  179. }
  180. }
  181. // 判断信息为空
  182. Vue.prototype.checkInfo = function(content) {
  183. if (content == '') {
  184. api.toast({
  185. msg : '必填项不能为空'
  186. });
  187. return false
  188. } else {
  189. return true
  190. }
  191. }
  192. // 判断数组
  193. Vue.prototype.checkArray = function(content) {
  194. if (content.length == 0) {
  195. api.toast({
  196. msg : '必填项不能为空'
  197. });
  198. return false
  199. } else {
  200. return true
  201. }
  202. }
  203. Vue.prototype.checkByDropdown1 = function(h, d, t, n, c) {
  204. // document.body.style.position = 'fixed';
  205. document.body.style.overflow = 'hidden';
  206. new Dropdown({
  207. dom : n, //点击触发下拉的选择框的id
  208. type : 'multiple', //是单选还是多选 单选 single 多选 multiple
  209. title : t, //选择框title
  210. required : false, //是否必填
  211. dataArr : d,
  212. success : function(resp) {// 回调函数
  213. // document.body.style.position = 'relative';
  214. // var addList = new Array();
  215. // alert(h.length)
  216. // document.body.style.overflow = 'auto';
  217. // resp.map(function(item,index){
  218. // var has = false;
  219. // h.map(function(ir,ids){
  220. // alert(ir.id + ',' + item.id)
  221. // if(item.id == ir.id){
  222. // has = true;
  223. // }
  224. // })
  225. // if(has == false){
  226. // addList.push(item);
  227. // }
  228. // })
  229. c(resp);
  230. }
  231. })
  232. }
  233. /**
  234. * VUE 的扩展方法
  235. */
  236. // 获取到的经销商信息
  237. Vue.prototype.userInfo = function() {
  238. this.info = "";
  239. this.loginid = $api.getStorage('loginid');
  240. this.retariler_id = $api.getStorage("retailerid");
  241. this.storeName = $api.getStorage("storeName");
  242. this.carNum = 0;
  243. }
  244. // 使用选择器的时候的数据封装
  245. Vue.prototype.actionSelectorData = function(retlist, c) {
  246. var list = new Array();
  247. retlist.map(function(item, index) {
  248. var option = {
  249. name : eval("item." + c.name),
  250. id : eval("item." + c.id),
  251. }
  252. list.push(option);
  253. })
  254. return list;
  255. }
  256. // 点击查看大图
  257. Vue.prototype.lookBigImage = function(a, srcs) {
  258. a.openImages({
  259. imageUrls : srcs
  260. });
  261. }
  262. // 打开筛选页面
  263. /**
  264. * f - 打开页面名称
  265. * s - 打开选择页面还是关闭
  266. * e - 需要传到筛选页面的值
  267. */
  268. var pageStatus = 'o';
  269. Vue.prototype.configDownChoose = function(o, e) {
  270. if (pageStatus == 'o') {
  271. api.openFrame({
  272. name : 'search',
  273. url : '../search.html',
  274. rect : {
  275. x : 0,
  276. y : e.value.h,
  277. w : api.winWidth,
  278. h : api.frameHeight
  279. },
  280. pageParam : {
  281. e : JSON.stringify(e),
  282. o : JSON.stringify(o),
  283. },
  284. bgColor : 'rgba(0,0,0,0)',
  285. animatin : {
  286. type : "movein", //动画类型(详见动画类型常量)
  287. subType : "from_top", //动画子类型(详见动画子类型常量)
  288. duration : 300 //动画过渡时间,默认300毫秒
  289. }
  290. });
  291. pageStatus = 'c';
  292. } else {
  293. pageStatus = 'o';
  294. api.closeFrame({
  295. name : 'search',
  296. });
  297. }
  298. }
  299. // 使用motive配置下拉刷新
  300. Vue.prototype.configHeaderRefush = function(callback) {
  301. api.setCustomRefreshHeaderInfo({
  302. bgColor : '#f2f8f9',
  303. 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'],
  304. // images : ['widget://image/refush1/try.gif'],
  305. tips : {
  306. pull : '下拉刷新',
  307. threshold : '松开立即刷新',
  308. load : '正在刷新'
  309. }
  310. }, function() {
  311. callback();
  312. // //下拉刷新被触发,自动进入加载状态,使用 api.refreshHeaderLoadDone() 手动结束加载中状态
  313. // //下拉刷新被触发,使用 api.refreshHeaderLoadDone() 结束加载中状态
  314. // alert('开始加载刷新数据,摇一摇停止加载状态');
  315. // api.addEventListener({
  316. // name : 'shake'
  317. // }, function(ret, err) {
  318. // api.refreshHeaderLoadDone()
  319. // });
  320. });
  321. }
  322. // 配置下拉刷新
  323. Vue.prototype.configHeadMotive = function(callback) {
  324. api.setRefreshHeaderInfo({
  325. visible : true,
  326. bgColor : '#ccc',
  327. textColor : '#fff',
  328. textDown : '下拉刷新...',
  329. textUp : '松开刷新...',
  330. showTime : true
  331. }, function(ret, err) {
  332. if (ret) {
  333. callback(ret);
  334. }
  335. });
  336. }
  337. // 配置下拉刷新
  338. Vue.prototype.configBottomRefush = function(callback) {
  339. new auiScroll({
  340. listen : true,
  341. distance : 0 //判断到达底部的距离,isToBottom为true
  342. }, function(ret) {
  343. if (ret.isToBottom) {
  344. callback(true);
  345. }
  346. });
  347. }
  348. // 配置alert提示框
  349. Vue.prototype.showAlert = function(m, c) {
  350. api.alert({
  351. title : '温馨提示',
  352. msg : m,
  353. buttons : ["确定"],
  354. }, function(ret, err) {
  355. //coding...
  356. c();
  357. });
  358. }
  359. // 延时关闭页面发送监听
  360. Vue.prototype.doneSendEvent = function(n, t, e) {
  361. var times = typeof t == 'undefined' ? 200 : t;
  362. this.sendEvent(n, e);
  363. setTimeout(function() {
  364. api.closeWin({
  365. });
  366. }, times);
  367. }
  368. // 提示信息
  369. Vue.prototype.showToast = function(str) {
  370. api.toast({
  371. msg : str
  372. });
  373. }
  374. // 扫码
  375. Vue.prototype.scan = function(f, c) {
  376. api.showProgress({
  377. title : '请稍候',
  378. text : '正在调起摄像头',
  379. modal : false
  380. });
  381. f.open({
  382. autorotation : true,
  383. isDrawQRCodeRect : true,
  384. }, function(ret, err) {
  385. api.hideProgress();
  386. if (ret) {
  387. if (ret.eventType == 'success') {
  388. c(ret.content);
  389. }
  390. } else {
  391. api.toast({
  392. msg : '扫码出错'
  393. });
  394. }
  395. });
  396. }
  397. // 扫码 -- 主要是条形码
  398. Vue.prototype.scant = function(f, c) {
  399. var param = {};
  400. var resultCallback = function(ret, err) {
  401. if (ret.eventType == 'success') {
  402. c(ret.content);
  403. }
  404. };
  405. f.openScanner(param, resultCallback);
  406. }
  407. // 输入框类型
  408. Vue.prototype.showPromt = function(title, msg, buttons, callback) {
  409. api.prompt({
  410. title : title,
  411. msg : msg,
  412. buttons : buttons
  413. }, function(ret, err) {
  414. //coding...
  415. callback(ret);
  416. });
  417. }
  418. // 注册监听
  419. Vue.prototype.addEvent = function(eventName, callback) {
  420. api.addEventListener({
  421. name : eventName,
  422. }, function(ret, err) {
  423. //coding...
  424. callback(ret);
  425. });
  426. }
  427. // 提示信息
  428. Vue.prototype.showModal = function(title, msg, buttons, callback) {
  429. api.confirm({
  430. title : title,
  431. msg : msg,
  432. buttons : buttons,
  433. }, function(ret, err) {
  434. //coding...
  435. callback(ret.buttonIndex);
  436. });
  437. }
  438. // 过滤掉数组中的对象
  439. Vue.prototype.filterArrNotNull = function(s, a) {
  440. return s.filter(a == null)
  441. }
  442. // 发送监听
  443. Vue.prototype.sendEvent = function(eventName, params) {
  444. api.sendEvent({
  445. name : eventName,
  446. extra : params
  447. });
  448. }
  449. // 跳转页面
  450. Vue.prototype.goWin = function(winName, winUrl, params) {
  451. setTimeout(function() {
  452. api.openWin({
  453. name : winName,
  454. url : winUrl,
  455. pageParam : params,
  456. bounces : false,
  457. animation : {
  458. type : "push", //动画类型(详见动画类型常量)
  459. subType : "from_right", //动画子类型(详见动画子类型常量)
  460. duration : 300 //动画过渡时间,默认300毫秒
  461. }
  462. });
  463. }, 200);
  464. }
  465. // 点击查看大图
  466. Vue.prototype.lookBigImage = function(a, srcs) {
  467. a.openImages({
  468. imageUrls : srcs
  469. });
  470. }
  471. // 选择图片
  472. Vue.prototype.chooseImage = function(c) {
  473. var _this = this;
  474. // 判断是相机还是图片库
  475. api.actionSheet({
  476. title : '选择附件',
  477. cancelTitle : '这里是取消按钮',
  478. buttons : ['相机', '相册']
  479. }, function(ret, err) {
  480. if (ret.buttonIndex == 3) {
  481. return;
  482. }
  483. var imageT = _this.imageType[ret.buttonIndex];
  484. _this.startChooseImage(imageT, function(path) {
  485. c(path);
  486. });
  487. });
  488. }
  489. // 开始选择图片
  490. Vue.prototype.startChooseImage = function(imageT, callback) {
  491. var _this = this;
  492. api.getPicture({
  493. sourceType : imageT,
  494. encodingType : 'png',
  495. mediaValue : 'pic',
  496. destinationType : 'url',
  497. allowEdit : true,
  498. quality : 100,
  499. // targetWidth : 100,
  500. // targetHeight : 100,
  501. saveToPhotoAlbum : false
  502. }, function(ret, err) {
  503. if (ret) {
  504. if (ret.data != "") {
  505. // 有选择的相片了
  506. // _this.imgs = ret.data;
  507. callback(ret.data);
  508. }
  509. } else {
  510. alert(JSON.stringify(err));
  511. }
  512. });
  513. }
  514. // 关闭页面
  515. Vue.prototype.closeWin = function() {
  516. setTimeout(function() {
  517. api.closeWin({
  518. });
  519. }, 200);
  520. }
  521. // 点击选择省市区
  522. Vue.prototype.chooseRegion = function(UIActionSelector, col, datasUrl, callback) {
  523. UIActionSelector.open({
  524. datas : datasUrl,
  525. layout : {
  526. row : 5,
  527. col : col,
  528. height : 30,
  529. size : 12,
  530. sizeActive : 14,
  531. rowSpacing : 5,
  532. colSpacing : 10,
  533. maskBg : 'rgba(0,0,0,0.2)',
  534. bg : '#fff',
  535. color : '#ddd',
  536. colorActive : '#f00',
  537. colorSelected : '#000'
  538. },
  539. animation : true,
  540. cancel : {
  541. text : '取消',
  542. size : 12,
  543. w : 90,
  544. h : 35,
  545. bg : '#fff',
  546. bgActive : '#ccc',
  547. color : '#888',
  548. colorActive : '#fff'
  549. },
  550. ok : {
  551. text : '确定',
  552. size : 12,
  553. w : 90,
  554. h : 35,
  555. bg : '#fff',
  556. bgActive : '#ccc',
  557. color : '#888',
  558. colorActive : '#fff'
  559. },
  560. title : {
  561. text : '请选择',
  562. size : 12,
  563. h : 44,
  564. bg : '#eee',
  565. color : '#888',
  566. },
  567. fixedOn : api.frameName
  568. }, function(ret, err) {
  569. if (ret) {
  570. if (ret.eventType == 'ok') {
  571. callback(ret);
  572. }
  573. } else {
  574. api.toast({
  575. msg : '事件错误'
  576. });
  577. }
  578. });
  579. }
  580. // 显示加载框
  581. Vue.prototype.showProcess = function() {
  582. api.showProgress({
  583. title : '请稍候...',
  584. text : '加载中...'
  585. });
  586. }
  587. // 隐藏加载框
  588. Vue.prototype.hideProcess = function() {
  589. api.hideProgress();
  590. }
  591. // 获取用户信息
  592. Vue.prototype.getUserInfo = function(callback) {
  593. var url = "getUserInfoUrl", loginid = $api.getStorage('agentCode'), _this = this;
  594. var data = {
  595. agentCode : loginid,
  596. url : 'json',
  597. type : 'body',
  598. };
  599. this.$post(url, data, function(ret) {
  600. if ( typeof callback != 'undefined' && callback != "undefined" && callback != "") {
  601. callback(ret);
  602. }
  603. if (ret.agentDto != null) {
  604. // 将retariler_id和username保存起来
  605. $api.setStorage('agentid', ret.agentDto.id);
  606. // $api.setStorage('storeName', ret.retailerDto.storeName);
  607. }
  608. });
  609. }
  610. // 获取购物车数量
  611. Vue.prototype.getCarNum = function(id, callback) {
  612. var data = {
  613. retailer_id : id,
  614. }, url = "shopCarListUrl", _this = this;
  615. this.$post(url, data, function(ret) {
  616. if (ret.code == 0) {
  617. _this.userInfo.carNum = ret.list.length;
  618. callback(ret.list);
  619. }
  620. })
  621. }
  622. // 获取新版本,然后下载安装
  623. Vue.prototype.getNewVersionUrl = function() {
  624. var data = {
  625. paramKey : 'agent_url',
  626. url : 'json',
  627. type : 'body'
  628. }, url = "getVersionUrl", _this = this;
  629. this.$post(url, data, function(ret) {
  630. if (ret.code == 0) {
  631. _this.downLoadApp(ret.version);
  632. }
  633. })
  634. }
  635. // 下载版本
  636. Vue.prototype.downLoadApp = function(url) {
  637. var _this = this;
  638. api.showProgress({
  639. title : "更新提示",
  640. text : "正在更新",
  641. modal : false
  642. });
  643. // if (app.uav_type == 'IOS') {
  644. // api.installApp({
  645. // appUri : app.uav_filepath
  646. // });
  647. // } else {
  648. api.download({
  649. url : url,
  650. savePath : '',
  651. report : true,
  652. cache : true,
  653. allowResume : true
  654. }, function(re, err) {
  655. if (re.state == 1) {
  656. api.hideProgress();
  657. api.installApp({
  658. appUri : re.savePath
  659. });
  660. } else if (re.state == 2) {
  661. callback('fail')
  662. }
  663. })
  664. //}
  665. }
  666. // 获取
  667. /******** ajax请求 ********/
  668. Vue.prototype.$post = function(url, data, callback, other) {
  669. var http = new $http();
  670. http.$post(url, data, function(ret) {
  671. if (ret.code == 0) {
  672. callback(ret);
  673. } else {
  674. api.toast({
  675. msg : ret.msg
  676. });
  677. }
  678. }, other)
  679. }
  680. Vue.prototype.$get = function(url, data, callback, other) {
  681. var http = new $http();
  682. http.$get(url, data, function(ret) {
  683. if (ret.code == 0) {
  684. callback(ret);
  685. } else {
  686. api.toast({
  687. msg : ret.msg
  688. });
  689. }
  690. }, other)
  691. }