vue_plugins.js 26 KB

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