vue_plugins_sub.js 24 KB

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