vue_plugins.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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. 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>';
  9. Vue.component('shopcar', {
  10. props : ["badge"],
  11. template : template_shopCar,
  12. methods : {
  13. goToCar : function() {
  14. // 跳转到购物车页面
  15. this.goWin("orderCar_win", "../order/orderCar_win.html", "");
  16. }
  17. }
  18. })
  19. /**
  20. * 弹出层
  21. */
  22. Vue.component('zmqalert', {
  23. props : ["info"],
  24. 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>',
  25. methods : {
  26. clickAlertBtn : function(type) {
  27. this.info.show = false;
  28. if (type == 0) {
  29. this.$emit("donechoose", type);
  30. }
  31. // 0 点击确认 1 点击取消
  32. }
  33. }
  34. })
  35. /******************* 极光推送 *********************/
  36. Vue.prototype.api = {
  37. devices : 5,
  38. }
  39. /*
  40. * 初始化极光
  41. */
  42. Vue.prototype.initApush = function(userid) {
  43. var ajpush = api.require('ajpush');
  44. this.pushObject = ajpush;
  45. var _this = this;
  46. this.pushObject.init(function(ret, err) {
  47. if (ret && ret.status) {
  48. console.log("操作成功");
  49. } else {
  50. console.log("操作失败");
  51. }
  52. });
  53. // 获取deviceToken,成功则继续走,否则gg
  54. this.getTokenAndReid(this.pushObject, function(state) {
  55. if (state == 'success') {
  56. // 开始绑定别名和标签
  57. _this.bindAliasAndTags(ajpush, userid);
  58. // 注册监听接收时间
  59. _this.configListen(ajpush);
  60. }
  61. })
  62. }
  63. /**
  64. * 获取deviceToken和reid
  65. */
  66. Vue.prototype.getTokenAndReid = function(ajpush, callback) {
  67. var _this = this;
  68. ajpush.getRegistrationId(function(ret) {
  69. if (api.deviceToken == "" && _this.api.devices > 0) {
  70. _this.api.devices -= 1;
  71. _this.getTokenAndReid(ajpush, callback);
  72. } else {
  73. callback('success');
  74. }
  75. });
  76. }
  77. /**
  78. * 绑定别名和标签
  79. */
  80. Vue.prototype.bindAliasAndTags = function(ajpush, userid) {
  81. var param = {
  82. alias : userid.toString(),
  83. tags : [userid.toString()]
  84. };
  85. //绑定别名
  86. this.pushObject.bindAliasAndTags(param, function(ret) {
  87. var statusCode = ret.statusCode;
  88. });
  89. }
  90. /**
  91. * 注册获取消息
  92. */
  93. Vue.prototype.configListen = function(ajpush) {
  94. var _this = this;
  95. // // 添加消息接受事件
  96. ajpush.setListener(function(ret) {
  97. _this.sendEvent("checkRetailer");
  98. });
  99. api.addEventListener({
  100. name : 'appintent'
  101. }, function(ret, err) {
  102. if (ret.appParam.ajpush) {
  103. if(ret.appParam.ajpush.extra.env == 2 || ret.appParam.ajpush.extra.env == '2'){ // 订单详情
  104. api.openWin({
  105. name : 'orderInfo_win',
  106. url : './orderInfo/orderInfo_win.html',
  107. pageParam : {
  108. id : ret.appParam.extra.id
  109. }
  110. });
  111. }
  112. if(ret.appParam.ajpush.extra.env == 3 || ret.appParam.ajpush.extra.env == '3'){ // 订单详情
  113. api.openWin({
  114. name : 'agentList_win',
  115. url : '../home/agentList/agentList_win.html',
  116. pageParam : {
  117. active:2
  118. }
  119. });
  120. }
  121. }
  122. })
  123. }
  124. /******************* 结束推送 *********************/
  125. /**
  126. * 弹出层
  127. */
  128. Vue.component('zmqalert', {
  129. props : ["info"],
  130. 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>',
  131. methods : {
  132. clickAlertBtn : function(type) {
  133. this.info.show = false;
  134. if (type == 0) {
  135. this.$emit("donechoose", type);
  136. }
  137. // 0 点击确认 1 点击取消
  138. }
  139. }
  140. })
  141. /**
  142. * 将两个JSON对象拼接
  143. */
  144. Vue.prototype.extend = function(a, b) {
  145. for (var obj in b) {
  146. a[obj] = b[obj];
  147. }
  148. return a;
  149. }
  150. /**
  151. * 多选控件
  152. * h : 原先已经有的
  153. * d : 需要渲染的数组
  154. * t : 选择框标题
  155. * n : 触发下拉框的id
  156. */
  157. Vue.prototype.checkByDropdown = function(h, d, t, n, c) {
  158. // document.body.style.position = 'fixed';
  159. document.body.style.overflow = 'hidden';
  160. new Dropdown({
  161. dom : n, //点击触发下拉的选择框的id
  162. type : 'multiple', //是单选还是多选 单选 single 多选 multiple
  163. title : t, //选择框title
  164. required : false, //是否必填
  165. dataArr : d,
  166. success : function(resp) {// 回调函数
  167. // document.body.style.position = 'relative';
  168. // var addList = new Array();
  169. // alert(h.length)
  170. // document.body.style.overflow = 'auto';
  171. // resp.map(function(item,index){
  172. // var has = false;
  173. // h.map(function(ir,ids){
  174. // alert(ir.id + ',' + item.id)
  175. // if(item.id == ir.id){
  176. // has = true;
  177. // }
  178. // })
  179. // if(has == false){
  180. // addList.push(item);
  181. // }
  182. // })
  183. c(resp);
  184. }
  185. })
  186. }
  187. // 判断手机号
  188. Vue.prototype.phoneExg = function(phone) {
  189. if (!(/^1[3456789]\d{9}$/.test(phone))) {
  190. return false;
  191. } else {
  192. return true;
  193. }
  194. }
  195. // 判断信息为空
  196. Vue.prototype.checkInfo = function(content) {
  197. if (content == '') {
  198. api.toast({
  199. msg : '必填项不能为空'
  200. });
  201. return false
  202. } else {
  203. return true
  204. }
  205. }
  206. // 判断数组
  207. Vue.prototype.checkArray = function(content) {
  208. if (content.length == 0) {
  209. api.toast({
  210. msg : '必填项不能为空'
  211. });
  212. return false
  213. } else {
  214. return true
  215. }
  216. }
  217. Vue.prototype.checkByDropdown1 = function(h, d, t, n, c) {
  218. // document.body.style.position = 'fixed';
  219. document.body.style.overflow = 'hidden';
  220. new Dropdown({
  221. dom : n, //点击触发下拉的选择框的id
  222. type : 'multiple', //是单选还是多选 单选 single 多选 multiple
  223. title : t, //选择框title
  224. required : false, //是否必填
  225. dataArr : d,
  226. success : function(resp) {// 回调函数
  227. // document.body.style.position = 'relative';
  228. // var addList = new Array();
  229. // alert(h.length)
  230. // document.body.style.overflow = 'auto';
  231. // resp.map(function(item,index){
  232. // var has = false;
  233. // h.map(function(ir,ids){
  234. // alert(ir.id + ',' + item.id)
  235. // if(item.id == ir.id){
  236. // has = true;
  237. // }
  238. // })
  239. // if(has == false){
  240. // addList.push(item);
  241. // }
  242. // })
  243. c(resp);
  244. }
  245. })
  246. }
  247. /**
  248. * VUE 的扩展方法
  249. */
  250. // 获取到的经销商信息
  251. Vue.prototype.userInfo = function() {
  252. this.info = "";
  253. this.loginid = $api.getStorage('loginid');
  254. this.retariler_id = $api.getStorage("retailerid");
  255. this.storeName = $api.getStorage("storeName");
  256. this.carNum = 0;
  257. }
  258. // 使用选择器的时候的数据封装
  259. Vue.prototype.actionSelectorData = function(retlist, c) {
  260. var list = new Array();
  261. retlist.map(function(item, index) {
  262. var option = {
  263. name : eval("item." + c.name),
  264. id : eval("item." + c.id),
  265. }
  266. list.push(option);
  267. })
  268. return list;
  269. }
  270. // 点击查看大图
  271. Vue.prototype.lookBigImage = function(a, srcs) {
  272. a.openImages({
  273. imageUrls : srcs
  274. });
  275. }
  276. // 打开筛选页面
  277. /**
  278. * f - 打开页面名称
  279. * s - 打开选择页面还是关闭
  280. * e - 需要传到筛选页面的值
  281. */
  282. var pageStatus = 'o';
  283. Vue.prototype.configDownChoose = function(o, e) {
  284. if (pageStatus == 'o') {
  285. api.openFrame({
  286. name : 'search',
  287. url : '../search.html',
  288. rect : {
  289. x : 0,
  290. y : e.value.h,
  291. w : api.winWidth,
  292. h : api.frameHeight
  293. },
  294. pageParam : {
  295. e : JSON.stringify(e),
  296. o : JSON.stringify(o),
  297. },
  298. bgColor : 'rgba(0,0,0,0)',
  299. animatin : {
  300. type : "movein", //动画类型(详见动画类型常量)
  301. subType : "from_top", //动画子类型(详见动画子类型常量)
  302. duration : 300 //动画过渡时间,默认300毫秒
  303. }
  304. });
  305. pageStatus = 'c';
  306. } else {
  307. pageStatus = 'o';
  308. api.closeFrame({
  309. name : 'search',
  310. });
  311. }
  312. }
  313. Vue.prototype.getNowTime = function(type) {
  314. var myDate = new Date();
  315. //获取系统当前时间
  316. var YY = myDate.getFullYear();
  317. // 获取年月日
  318. var MM = myDate.getMonth() > 8 ? (myDate.getMonth() + 1) : ('0' + (myDate.getMonth() + 1));
  319. var DD = myDate.getDate() > 9 ? myDate.getDate() : '0' + myDate.getDate();
  320. var T = myDate.getHours() > 9 ? myDate.getHours() : '0' + myDate.getHours();
  321. var M = myDate.getMinutes() > 9 ? myDate.getMinutes() : '0' + myDate.getMinutes();
  322. var S = myDate.getSeconds() > 9 ? myDate.getSeconds() : '0' + myDate.getSeconds();
  323. if (type == 'data') {
  324. return YY + '-' + MM + '-' + DD;
  325. } else {
  326. return YY + ' - ' + MM + ' - ' + DD + ' ' + T + ':' + M + ':' + S;
  327. }
  328. }
  329. // 选择时间
  330. Vue.prototype.getTime = function(c) {
  331. var date = this.getNowTime('date');
  332. api.openPicker({
  333. type: 'date',
  334. date: date,
  335. title: '请选择日期'
  336. }, function(ret, err) {
  337. if (ret) {
  338. var ct = ret.year + '-' + (ret.month < 10 ? '0' + ret.month : ret.month) + '-' + (ret.day < 10 ? '0' + ret.day : ret.day);
  339. c(ct);
  340. }
  341. });
  342. }
  343. // 使用motive配置下拉刷新
  344. Vue.prototype.configHeaderRefush = function(callback) {
  345. api.setCustomRefreshHeaderInfo({
  346. bgColor : '#f2f8f9',
  347. 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'],
  348. // images : ['widget://image/refush1/try.gif'],
  349. tips : {
  350. pull : '下拉刷新',
  351. threshold : '松开立即刷新',
  352. load : '正在刷新'
  353. }
  354. }, function() {
  355. callback();
  356. // //下拉刷新被触发,自动进入加载状态,使用 api.refreshHeaderLoadDone() 手动结束加载中状态
  357. // //下拉刷新被触发,使用 api.refreshHeaderLoadDone() 结束加载中状态
  358. // alert('开始加载刷新数据,摇一摇停止加载状态');
  359. // api.addEventListener({
  360. // name : 'shake'
  361. // }, function(ret, err) {
  362. // api.refreshHeaderLoadDone()
  363. // });
  364. });
  365. }
  366. // 配置下拉刷新
  367. Vue.prototype.configHeadMotive = function(callback) {
  368. api.setRefreshHeaderInfo({
  369. visible : true,
  370. bgColor : '#fff',
  371. textColor : '#000',
  372. textDown : '下拉刷新...',
  373. textUp : '松开刷新...',
  374. showTime : true
  375. }, function(ret, err) {
  376. if (ret) {
  377. callback(ret);
  378. }
  379. });
  380. }
  381. // 配置下拉刷新
  382. Vue.prototype.configBottomRefush = function(callback) {
  383. new auiScroll({
  384. listen : true,
  385. distance : 0 //判断到达底部的距离,isToBottom为true
  386. }, function(ret) {
  387. if (ret.isToBottom) {
  388. callback(true);
  389. }
  390. });
  391. }
  392. // 配置alert提示框
  393. Vue.prototype.showAlert = function(m, c) {
  394. api.alert({
  395. title : '温馨提示',
  396. msg : m,
  397. buttons : ["确定"],
  398. }, function(ret, err) {
  399. //coding...
  400. });
  401. }
  402. // 延时关闭页面发送监听
  403. Vue.prototype.doneSendEvent = function(n, t, e) {
  404. var times = typeof t == 'undefined' ? 200 : t;
  405. this.sendEvent(n, e);
  406. setTimeout(function() {
  407. api.closeWin({
  408. });
  409. }, times);
  410. }
  411. // 提示信息
  412. Vue.prototype.showToast = function(str) {
  413. api.toast({
  414. msg : str
  415. });
  416. }
  417. // 扫码
  418. Vue.prototype.scan = function(f, c) {
  419. api.showProgress({
  420. title : '请稍候',
  421. text : '正在调起摄像头',
  422. modal : false
  423. });
  424. f.open({
  425. autorotation : true,
  426. isDrawQRCodeRect : true,
  427. }, function(ret, err) {
  428. api.hideProgress();
  429. if (ret) {
  430. if (ret.eventType == 'success') {
  431. c(ret.content);
  432. }
  433. } else {
  434. api.toast({
  435. msg : '扫码出错'
  436. });
  437. }
  438. });
  439. }
  440. // 扫码 -- 主要是条形码
  441. Vue.prototype.scant = function(f, c) {
  442. var param = {};
  443. var resultCallback = function(ret, err) {
  444. if (ret.eventType == 'success') {
  445. c(ret.content);
  446. }
  447. };
  448. f.openScanner(param, resultCallback);
  449. }
  450. // 输入框类型
  451. Vue.prototype.showPromt = function(title, msg, buttons, callback) {
  452. api.prompt({
  453. title : title,
  454. msg : msg,
  455. buttons : buttons
  456. }, function(ret, err) {
  457. //coding...
  458. callback(ret);
  459. });
  460. }
  461. // 注册监听
  462. Vue.prototype.addEvent = function(eventName, callback) {
  463. api.addEventListener({
  464. name : eventName,
  465. }, function(ret, err) {
  466. //coding...
  467. callback(ret);
  468. });
  469. }
  470. // 提示信息
  471. Vue.prototype.showModal = function(title, msg, buttons, callback) {
  472. api.confirm({
  473. title : title,
  474. msg : msg,
  475. buttons : buttons,
  476. }, function(ret, err) {
  477. //coding...
  478. // callback(ret.buttonIndex);
  479. callback(ret.buttonIndex == 2 ? 1 : 2);
  480. });
  481. }
  482. // 过滤掉数组中的对象
  483. Vue.prototype.filterArrNotNull = function(s, a) {
  484. return s.filter(a == null)
  485. }
  486. // 发送监听
  487. Vue.prototype.sendEvent = function(eventName, params) {
  488. api.sendEvent({
  489. name : eventName,
  490. extra : params
  491. });
  492. }
  493. // 跳转页面
  494. Vue.prototype.goWin = function(winName, winUrl, params) {
  495. setTimeout(function() {
  496. api.openWin({
  497. name : winName,
  498. url : winUrl,
  499. pageParam : params,
  500. bounces : false,
  501. animation : {
  502. type : "push", //动画类型(详见动画类型常量)
  503. subType : "from_right", //动画子类型(详见动画子类型常量)
  504. duration : 300 //动画过渡时间,默认300毫秒
  505. }
  506. });
  507. }, 200);
  508. }
  509. // 点击查看大图
  510. Vue.prototype.lookBigImage = function(a, srcs) {
  511. a.openImages({
  512. imageUrls : srcs
  513. });
  514. }
  515. // 选择图片
  516. Vue.prototype.chooseImage = function(c) {
  517. var _this = this;
  518. // 判断是相机还是图片库
  519. api.actionSheet({
  520. title : '选择附件',
  521. cancelTitle : '这里是取消按钮',
  522. buttons : ['相机', '相册']
  523. }, function(ret, err) {
  524. if (ret.buttonIndex == 3) {
  525. return;
  526. }
  527. console.log(JSON.stringify(ret));
  528. var imageT = ["", "camera", "album"][ret.buttonIndex];
  529. _this.startChooseImage(imageT, function(path) {
  530. c(path);
  531. });
  532. });
  533. }
  534. // 开始选择图片
  535. Vue.prototype.startChooseImage = function(imageT, callback) {
  536. var _this = this;
  537. api.getPicture({
  538. sourceType : imageT,
  539. encodingType : 'png',
  540. mediaValue : 'pic',
  541. destinationType : 'url',
  542. allowEdit : true,
  543. quality : 100,
  544. // targetWidth : 100,
  545. // targetHeight : 100,
  546. saveToPhotoAlbum : false
  547. }, function(ret, err) {
  548. if (ret) {
  549. if (ret.data != "") {
  550. // 有选择的相片了
  551. // _this.imgs = ret.data;
  552. callback(ret.data);
  553. }
  554. } else {
  555. alert(JSON.stringify(err));
  556. }
  557. });
  558. }
  559. // 关闭页面
  560. Vue.prototype.closeWin = function() {
  561. setTimeout(function() {
  562. api.closeWin({
  563. });
  564. }, 200);
  565. }
  566. // 点击选择省市区
  567. Vue.prototype.chooseRegion = function(UIActionSelector, col, datasUrl, callback) {
  568. UIActionSelector.open({
  569. datas : datasUrl,
  570. layout : {
  571. row : 5,
  572. col : col,
  573. height : 30,
  574. size : 12,
  575. sizeActive : 14,
  576. rowSpacing : 5,
  577. colSpacing : 10,
  578. maskBg : 'rgba(0,0,0,0.2)',
  579. bg : '#fff',
  580. color : '#a5a5a5',
  581. colorActive : '#f00',
  582. colorSelected : '#000'
  583. },
  584. animation : true,
  585. cancel : {
  586. text : '取消',
  587. size : 12,
  588. w : 90,
  589. h : 35,
  590. bg : '#fff',
  591. bgActive : '#ccc',
  592. color : '#888',
  593. colorActive : '#fff'
  594. },
  595. ok : {
  596. text : '确定',
  597. size : 12,
  598. w : 90,
  599. h : 35,
  600. bg : '#fff',
  601. bgActive : '#ccc',
  602. color : '#888',
  603. colorActive : '#fff'
  604. },
  605. title : {
  606. text : '请选择',
  607. size : 12,
  608. h : 44,
  609. bg : '#eee',
  610. color : '#888',
  611. },
  612. fixedOn : api.frameName
  613. }, function(ret, err) {
  614. if (ret) {
  615. if (ret.eventType == 'ok') {
  616. callback(ret);
  617. }
  618. } else {
  619. api.toast({
  620. msg : '事件错误'
  621. });
  622. }
  623. });
  624. }
  625. // 显示加载框
  626. Vue.prototype.showProcess = function() {
  627. api.showProgress({
  628. title : '请稍候...',
  629. text : '加载中...'
  630. });
  631. }
  632. // 隐藏加载框
  633. Vue.prototype.hideProcess = function() {
  634. api.hideProgress();
  635. }
  636. // 获取用户信息
  637. Vue.prototype.getUserInfo = function(callback) {
  638. var url = "getUserInfoUrl", loginid = $api.getStorage('agentCode'), _this = this;
  639. var data = {
  640. agentCode : loginid,
  641. url : 'json',
  642. type : 'body',
  643. };
  644. this.$post(url, data, function(ret) {
  645. if ( typeof callback != 'undefined' && callback != "undefined" && callback != "") {
  646. callback(ret);
  647. }
  648. if (ret.agentDto != null) {
  649. // 将retariler_id和username保存起来
  650. $api.setStorage('agentid', ret.agentDto.id);
  651. // $api.setStorage('storeName', ret.retailerDto.storeName);
  652. }
  653. });
  654. }
  655. // 获取购物车数量
  656. Vue.prototype.getCarNum = function(id, callback) {
  657. var data = {
  658. retailer_id : id,
  659. }, url = "shopCarListUrl", _this = this;
  660. this.$post(url, data, function(ret) {
  661. if (ret.code == 0) {
  662. _this.userInfo.carNum = ret.list.length;
  663. callback(ret.list);
  664. }
  665. })
  666. }
  667. // pcr 获取新版本,然后下载安装,
  668. Vue.prototype.getNewVersionUrl = function(c) {
  669. var data ='',
  670. url = "checkVersionU",
  671. _this = this;
  672. this.$get(url, data, function(ret) {
  673. if (ret.code == 0 || ret.code == '0') {
  674. if(ret.version != _this.getVersion()){
  675. _this.showModal('新版本提示',ret.plus_msg,["立即更新","暂不更新"],function(res){
  676. if(res == 2){
  677. _this.downLoadApp(ret.url,c);
  678. }
  679. })
  680. }else{
  681. api.toast({ msg : '已是最新版本' })
  682. }
  683. }
  684. },'formdata')
  685. };
  686. // tbr 获取新版本,然后下载安装,
  687. Vue.prototype.getNewVersionUrlTbr = function(c) {
  688. var data = {
  689. "url": "json",
  690. "type": "body",
  691. "text": "1"
  692. },
  693. url = "checkVersionU",
  694. _this = this;
  695. this.$post(url, data, function(ret) {
  696. if (ret.code == 0 || ret.code == '0') {
  697. if(ret.version != _this.getVersion()){
  698. _this.showModal('新版本提示',ret.plus_msg,["立即更新","暂不更新"],function(res){
  699. if(res == 2){
  700. _this.downLoadApp(ret.url,c);
  701. }
  702. })
  703. }else{
  704. api.toast({ msg : '已是最新版本' })
  705. }
  706. }
  707. })
  708. };
  709. // 下载版本
  710. Vue.prototype.downLoadApp = function(url,callback) {
  711. var _this = this;
  712. api.showProgress({
  713. title : "更新提示",
  714. text : "正在更新",
  715. modal : false
  716. });
  717. // if (app.uav_type == 'IOS') {
  718. // api.installApp({
  719. // appUri : app.uav_filepath
  720. // });
  721. // } else {
  722. api.download({
  723. url: url,
  724. savePath : '',
  725. report : true,
  726. cache : true,
  727. allowResume : true
  728. }, function(re, err) {
  729. if (re.state == 1) {
  730. api.hideProgress();
  731. api.installApp({
  732. appUri : re.savePath
  733. });
  734. } else if (re.state == 2) {
  735. callback('fail')
  736. }
  737. })
  738. //}
  739. }
  740. /**********************************************登录信息*************************************************/
  741. // 判断是否已经登录:loginid token kunnr subRoleName roleScene
  742. Vue.prototype.isLogin = function(){
  743. // 经销商
  744. var loginid = $api.getStorage('kunnr'),
  745. token = $api.getStorage('token'),
  746. kunnr = $api.getStorage('kunnr'),
  747. subRoleName = $api.getStorage('subRoleName');
  748. var arr1 = [loginid,token,kunnr,subRoleName];
  749. var isLogin1=true;
  750. for(var index=0; index<arr1.length; index++){
  751. if(!(typeof arr1[index] == "string" && arr1[index]!="undefined" && arr1[index]!="")){
  752. isLogin1 = false;
  753. };
  754. };
  755. // 子权限
  756. var loginToken = $api.getStorage('loginToken'),
  757. pertel = $api.getStorage('pertel');
  758. var arr2 = [loginToken,pertel,subRoleName];
  759. var isLogin2 = true;
  760. for(var index=0; index<arr2.length; index++){
  761. if(!(typeof arr2[index] == "string" && arr2[index]!="undefined" && arr2[index]!="")){
  762. isLogin2 = false;
  763. };
  764. };
  765. isLogin = isLogin1 || isLogin2;
  766. return isLogin;
  767. };
  768. // 判断是否已经选择了角色
  769. Vue.prototype.isHasRoleScene = function(){
  770. var roleScene = $api.getStorage('roleScene');
  771. var isHasRoleScene;
  772. if(typeof roleScene == "string" && roleScene!="undefined"&&roleScene!=""){
  773. isHasRoleScene = true;
  774. }else{
  775. isHasRoleScene = false;
  776. };
  777. return isHasRoleScene;
  778. };
  779. //登录入口控制
  780. Vue.prototype.loginEntrance = function(params,urlp){
  781. var sceneArr = [{
  782. sceneCode: "10",
  783. sceneName: "maintbr",
  784. scenePath: "/main/tbr/main.html",
  785. openFrameGroupName: "openFrameGroupTbr"
  786. },{
  787. sceneCode: "40",
  788. sceneName: "mainpcr",
  789. scenePath: "/main/pcr/main.html",
  790. openFrameGroupName: "openFrameGroupPcr"
  791. },{//暂定子权限 (订单员是500);
  792. sceneCode: "500",
  793. sceneName: "mainsub",
  794. scenePath: "/main/sub/main.html",
  795. openFrameGroupName: "openFrameGroupSub"
  796. }];
  797. var idx,isHas=false;
  798. for(var index=0; index<sceneArr.length; index++){
  799. if(params==sceneArr[index].sceneCode){
  800. idx = index;
  801. isHas = true;
  802. }
  803. };
  804. if(isHas){
  805. this.sendEvent("refushUser");
  806. this.sendEvent(sceneArr[idx].sceneName,urlp+sceneArr[idx].openFrameGroupName, "");
  807. this.goWin(sceneArr[idx].sceneName,urlp+sceneArr[idx].scenePath);
  808. }else{
  809. $api.toast('提醒', '您没有权限,请联系系统关系员分配权限', 3000);
  810. }
  811. };
  812. // 获取
  813. /******** ajax请求 ********/
  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" || ret.length > 0) {
  818. callback(ret);
  819. } else {
  820. api.toast({
  821. msg : ret.msg
  822. });
  823. }
  824. }, other)
  825. }
  826. Vue.prototype.$get = function(url, data, callback, other) {
  827. var http = new $http();
  828. http.$get(url, data, function(ret) {
  829. if (ret.code == 0) {
  830. callback(ret);
  831. } else {
  832. api.toast({
  833. msg : ret.msg
  834. });
  835. }
  836. }, other)
  837. }
  838. // 配置上拉加载和下拉刷新
  839. Vue.prototype.configDownAndPull = function(id, pullDown, down, useUp) {
  840. var mescroll = new MeScroll(id, {
  841. down: {
  842. auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
  843. callback: function(){
  844. pullDown(mescroll);
  845. }, //下拉刷新的回调
  846. },
  847. up: {
  848. use : useUp == false ? false : true, // 是否开启上拉加载
  849. auto: false, //初始化完毕,是否自动触发上拉加载的回调
  850. isBoth: true, //上拉加载时,如果滑动到列表顶部是否可以同时触发下拉刷新;默认false,两者不可同时触发; 这里为了演示改为true,不必等列表加载完毕才可下拉;
  851. isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
  852. htmlNodata: '<p class="upwarp-nodata" style="margin-bottom : 1rem;position:relative">-- 无更多数据 --</p>',
  853. callback: function(){
  854. down(mescroll);
  855. }, //上拉加载的回调
  856. }
  857. });
  858. }
  859. // 判断是否有权限
  860. Vue.prototype.ifHasPrme = function(perm, c) {
  861. var has = this.hasPermission(perm),_this = this;
  862. if (!has || !has[0] || !has[0].granted) {
  863. api.confirm({
  864. title: '提醒',
  865. msg: '没有获得 ' + perm + " 权限\n是否前往设置?",
  866. buttons: ['去设置', '取消']
  867. }, function(ret, err) {
  868. if (1 == ret.buttonIndex) {
  869. _this.reqPermission(perm,function(){
  870. c(true);
  871. });
  872. }
  873. });
  874. c(false);
  875. }else{
  876. c(true);
  877. }
  878. }
  879. Vue.prototype.hasPermission = function(perm) {
  880. var perms = new Array();
  881. perms.push(perm);
  882. var rets = api.hasPermission({
  883. list: perms
  884. });
  885. return rets;
  886. }
  887. Vue.prototype.reqPermission = function(perm,callback) {
  888. var perms = new Array();
  889. perms.push(perm);
  890. api.requestPermission({
  891. list: perms,
  892. }, function(ret, err) {
  893. if (ret && ret.list.length > 0) {
  894. callback(ret);
  895. }
  896. });
  897. }