/** * VUE 注册组件 */ /** * * 多语言配置 */ var lang = $api.getStorage('lang') var chineseConfig = { versionTitle: '新版本提示', versionConfirm: '立即更新', versionCancel: '暂不更新', versionStatus: '已是最新版本', warning: '警告', noPermission: '您没有权限,请联系系统关系员分配权限', textOut: '释放更新', textIn: '下拉刷新', textLoad: '加载中...', noData: '无更多数据', noEmpty: '必填项不能为空', selectTime: '请选择日期', refreshNow: '松开立即刷新', refreshing: '正在刷新', reminder: '温馨提示', confirm: '确定', cancel: '取消', select: '请选择', pleaseWait: '请稍候', pickUpCamera: '正在调起摄像头', scanError: '扫码出错', selectFile: '选择附件', thisCancelBtn: '这里是取消按钮', camera: '相机', photo: '相册', eventError: '事件错误', updateTips: '更新提示', updating: '正在更新', remind: '提醒', noGet: '没有获得', permission: '权限', goOnSet: '是否前往设置?', setting: '设置' } var engLishConfig = { versionTitle: 'New Version Tips', versionConfirm: 'right now update', versionCancel: 'no update', versionStatus: "It's the latest version", warning: "warning", noPermission: "You don't have permission. Please contact the system relation officer to assign permission", textOut: 'Push Refresh', textIn: 'Pull Refresh', textLoad: 'Loading...', noData: 'No more data', noEmpty: 'no Empty', selectTime: 'select Time', refreshNow: 'refres Now', refreshing: 'refreshing', reminder: 'reminder', confirm: 'confirm', cancel: 'Cancel', select: 'Please Select', pleaseWait: 'Please wait', pickUpCamera: 'Turn up the camera', scanError: 'scan coding error', selectFile: 'Select attachment', thisCancelBtn: 'this is a Cancel button', camera: 'camera', photo: 'photo', eventError: 'Event Error', updateTips: 'Update Tips', updating: 'updating', remind: 'Remind', noGet: 'noGet', permission: 'permission', goOnSet: 'go On Set?', setting: 'Setting' } var langConfig = lang == 'en'? engLishConfig : chineseConfig Vue.prototype.getVersion = function() { var appVersion = api.appVersion; return appVersion.match(/^[0-9]\d*\.\d*|0\.\d*[1-9]\d*$/)[0]; }; var template_shopCar = '
' + '
{{badge}}
' + '' + '
'; Vue.component('shopcar', { props : ["badge"], template : template_shopCar, methods : { goToCar : function() { // 跳转到购物车页面 this.goWin("orderCar_win", "../order/orderCar_win.html", ""); } } }) /** * 弹出层 */ Vue.component('zmqalert', { props : ["info"], template : '
{{info.title}}
{{info.msg}}
取消
确认
', methods : { clickAlertBtn : function(type) { this.info.show = false; if (type == 0) { this.$emit("donechoose", type); } // 0 点击确认 1 点击取消 } } }) /******************* 极光推送 *********************/ Vue.prototype.api = { devices : 5, } /* * 初始化极光 */ Vue.prototype.initApush = function(userid) { var ajpush = api.require('ajpush'); this.pushObject = ajpush; var _this = this; this.pushObject.init(function(ret, err) { if (ret && ret.status) { console.log("操作成功"); } else { console.log("操作失败"); } }); // 获取deviceToken,成功则继续走,否则gg this.getTokenAndReid(this.pushObject, function(state) { if (state == 'success') { // 开始绑定别名和标签 _this.bindAliasAndTags(ajpush, userid); // 注册监听接收时间 _this.configListen(ajpush); } }) } /** * 获取deviceToken和reid */ Vue.prototype.getTokenAndReid = function(ajpush, callback) { var _this = this; ajpush.getRegistrationId(function(ret) { if (api.deviceToken == "" && _this.api.devices > 0) { _this.api.devices -= 1; _this.getTokenAndReid(ajpush, callback); } else { callback('success'); } }); } /** * 绑定别名和标签 */ Vue.prototype.bindAliasAndTags = function(ajpush, userid) { var param = { alias : userid.toString(), tags : [userid.toString()] }; //绑定别名 this.pushObject.bindAliasAndTags(param, function(ret) { var statusCode = ret.statusCode; }); } /** * 注册获取消息 */ Vue.prototype.configListen = function(ajpush) { var _this = this; // // 添加消息接受事件 ajpush.setListener(function(ret) { _this.sendEvent("checkRetailer"); }); api.addEventListener({ name : 'appintent' }, function(ret, err) { if (ret.appParam.ajpush) { if(ret.appParam.ajpush.extra.env == 2 || ret.appParam.ajpush.extra.env == '2'){ // 订单详情 api.openWin({ name : 'orderInfo_win', url : './orderInfo/orderInfo_win.html', pageParam : { id : ret.appParam.extra.id } }); } if(ret.appParam.ajpush.extra.env == 3 || ret.appParam.ajpush.extra.env == '3'){ // 订单详情 api.openWin({ name : 'agentList_win', url : '../home/agentList/agentList_win.html', pageParam : { active:2 } }); } } }) } /******************* 结束推送 *********************/ /** * 弹出层 */ Vue.component('zmqalert', { props : ["info"], template : '
{{info.title}}
{{info.msg}}
取消
确认
', methods : { clickAlertBtn : function(type) { this.info.show = false; if (type == 0) { this.$emit("donechoose", type); } // 0 点击确认 1 点击取消 } } }) /** * 将两个JSON对象拼接 */ Vue.prototype.extend = function(a, b) { for (var obj in b) { a[obj] = b[obj]; } return a; } /** * 多选控件 * h : 原先已经有的 * d : 需要渲染的数组 * t : 选择框标题 * n : 触发下拉框的id */ Vue.prototype.checkByDropdown = function(h, d, t, n, c) { // document.body.style.position = 'fixed'; document.body.style.overflow = 'hidden'; new Dropdown({ dom : n, //点击触发下拉的选择框的id type : 'multiple', //是单选还是多选 单选 single 多选 multiple title : t, //选择框title required : false, //是否必填 dataArr : d, success : function(resp) {// 回调函数 // document.body.style.position = 'relative'; // var addList = new Array(); // alert(h.length) // document.body.style.overflow = 'auto'; // resp.map(function(item,index){ // var has = false; // h.map(function(ir,ids){ // alert(ir.id + ',' + item.id) // if(item.id == ir.id){ // has = true; // } // }) // if(has == false){ // addList.push(item); // } // }) c(resp); } }) } // 判断手机号 Vue.prototype.phoneExg = function(phone) { if (!(/^1[3456789]\d{9}$/.test(phone))) { return false; } else { return true; } } // 判断信息为空 Vue.prototype.checkInfo = function(content) { if (content == '') { api.toast({ msg : langConfig.noEmpty }); return false } else { return true } } // 判断数组 Vue.prototype.checkArray = function(content) { if (content.length == 0) { api.toast({ msg : langConfig.noEmpty }); return false } else { return true } } Vue.prototype.checkByDropdown1 = function(h, d, t, n, c) { // document.body.style.position = 'fixed'; document.body.style.overflow = 'hidden'; new Dropdown({ dom : n, //点击触发下拉的选择框的id type : 'multiple', //是单选还是多选 单选 single 多选 multiple title : t, //选择框title required : false, //是否必填 dataArr : d, success : function(resp) {// 回调函数 // document.body.style.position = 'relative'; // var addList = new Array(); // alert(h.length) // document.body.style.overflow = 'auto'; // resp.map(function(item,index){ // var has = false; // h.map(function(ir,ids){ // alert(ir.id + ',' + item.id) // if(item.id == ir.id){ // has = true; // } // }) // if(has == false){ // addList.push(item); // } // }) c(resp); } }) } /** * VUE 的扩展方法 */ // 获取到的经销商信息 Vue.prototype.userInfo = function() { this.info = ""; this.loginid = $api.getStorage('loginid'); this.retariler_id = $api.getStorage("retailerid"); this.storeName = $api.getStorage("storeName"); this.carNum = 0; } // 使用选择器的时候的数据封装 Vue.prototype.actionSelectorData = function(retlist, c) { var list = new Array(); retlist.map(function(item, index) { var option = { name : eval("item." + c.name), id : eval("item." + c.id), } list.push(option); }) return list; } // 点击查看大图 Vue.prototype.lookBigImage = function(a, srcs) { a.openImages({ imageUrls : srcs }); } // 打开筛选页面 /** * f - 打开页面名称 * s - 打开选择页面还是关闭 * e - 需要传到筛选页面的值 */ var pageStatus = 'o'; Vue.prototype.configDownChoose = function(o, e) { if (pageStatus == 'o') { api.openFrame({ name : 'search', url : '../search.html', rect : { x : 0, y : e.value.h, w : api.winWidth, h : api.frameHeight }, pageParam : { e : JSON.stringify(e), o : JSON.stringify(o), }, bgColor : 'rgba(0,0,0,0)', animatin : { type : "movein", //动画类型(详见动画类型常量) subType : "from_top", //动画子类型(详见动画子类型常量) duration : 300 //动画过渡时间,默认300毫秒 } }); pageStatus = 'c'; } else { pageStatus = 'o'; api.closeFrame({ name : 'search', }); } } Vue.prototype.getNowTime = function(type) { var myDate = new Date(); //获取系统当前时间 var YY = myDate.getFullYear(); // 获取年月日 var MM = myDate.getMonth() > 8 ? (myDate.getMonth() + 1) : ('0' + (myDate.getMonth() + 1)); var DD = myDate.getDate() > 9 ? myDate.getDate() : '0' + myDate.getDate(); var T = myDate.getHours() > 9 ? myDate.getHours() : '0' + myDate.getHours(); var M = myDate.getMinutes() > 9 ? myDate.getMinutes() : '0' + myDate.getMinutes(); var S = myDate.getSeconds() > 9 ? myDate.getSeconds() : '0' + myDate.getSeconds(); if (type == 'data') { return YY + '-' + MM + '-' + DD; } else { return YY + ' - ' + MM + ' - ' + DD + ' ' + T + ':' + M + ':' + S; } } // 选择时间 Vue.prototype.getTime = function(c) { var date = this.getNowTime('date'); api.openPicker({ type: 'date', date: date, title: langConfig.selectTime }, function(ret, err) { if (ret) { var ct = ret.year + '-' + (ret.month < 10 ? '0' + ret.month : ret.month) + '-' + (ret.day < 10 ? '0' + ret.day : ret.day); c(ct); } }); } // 使用motive配置下拉刷新 Vue.prototype.configHeaderRefush = function(callback) { api.setCustomRefreshHeaderInfo({ bgColor : '#f2f8f9', 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'], // images : ['widget://image/refush1/try.gif'], tips : { pull : langConfig.textIn, threshold : langConfig.refreshNow, load : langConfig.refreshing } }, function() { callback(); // //下拉刷新被触发,自动进入加载状态,使用 api.refreshHeaderLoadDone() 手动结束加载中状态 // //下拉刷新被触发,使用 api.refreshHeaderLoadDone() 结束加载中状态 // alert('开始加载刷新数据,摇一摇停止加载状态'); // api.addEventListener({ // name : 'shake' // }, function(ret, err) { // api.refreshHeaderLoadDone() // }); }); } // 配置下拉刷新 Vue.prototype.configHeadMotive = function(callback, swtichLang) { api.setRefreshHeaderInfo({ visible : true, bgColor : '#fff', textColor : '#000', textDown : langConfig.textIn, textUp : langConfig.refreshNow, textLoading: langConfig.refreshing, showTime : false }, function(ret, err) { if (ret) { callback(ret); } }); } // 配置下拉刷新 Vue.prototype.configBottomRefush = function(callback) { new auiScroll({ listen : true, distance : 0 //判断到达底部的距离,isToBottom为true }, function(ret) { if (ret.isToBottom) { callback(true); } }); } // 配置alert提示框 Vue.prototype.showAlert = function(m, c) { api.alert({ title : langConfig.reminder, msg : m, buttons : [langConfig.confirm], }, function(ret, err) { //coding... }); } // 延时关闭页面发送监听 Vue.prototype.doneSendEvent = function(n, t, e) { var times = typeof t == 'undefined' ? 200 : t; this.sendEvent(n, e); setTimeout(function() { api.closeWin({ }); }, times); } // 提示信息 Vue.prototype.showToast = function(str) { api.toast({ msg : str }); } // 扫码 Vue.prototype.scan = function(f, c) { api.showProgress({ title : langConfig.pleaseWait, text : langConfig.pickUpCamera, modal : false }); f.open({ autorotation : true, isDrawQRCodeRect : true, }, function(ret, err) { api.hideProgress(); if (ret) { if (ret.eventType == 'success') { c(ret.content); } } else { api.toast({ msg : langConfig.scanError }); } }); } // 扫码 -- 主要是条形码 Vue.prototype.scant = function(f, c) { var param = {}; var resultCallback = function(ret, err) { if (ret.eventType == 'success') { c(ret.content); } }; f.openScanner(param, resultCallback); } // 输入框类型 Vue.prototype.showPromt = function(title, msg, buttons, callback) { api.prompt({ title : title, msg : msg, buttons : buttons }, function(ret, err) { //coding... callback(ret); }); } // 注册监听 Vue.prototype.addEvent = function(eventName, callback) { api.addEventListener({ name : eventName, }, function(ret, err) { //coding... callback(ret); }); } // 提示信息 Vue.prototype.showModal = function(title, msg, buttons, callback) { api.confirm({ title : title, msg : msg, buttons : buttons, }, function(ret, err) { //coding... // callback(ret.buttonIndex); callback(ret.buttonIndex == 2 ? 1 : 2); }); } // 过滤掉数组中的对象 Vue.prototype.filterArrNotNull = function(s, a) { return s.filter(a == null) } // 发送监听 Vue.prototype.sendEvent = function(eventName, params) { api.sendEvent({ name : eventName, extra : params }); } // 跳转页面 Vue.prototype.goWin = function(winName, winUrl, params) { setTimeout(function() { api.openWin({ name : winName, url : winUrl, pageParam : params, bounces : false, animation : { type : "push", //动画类型(详见动画类型常量) subType : "from_right", //动画子类型(详见动画子类型常量) duration : 300 //动画过渡时间,默认300毫秒 } }); }, 200); } // 点击查看大图 Vue.prototype.lookBigImage = function(a, srcs) { a.openImages({ imageUrls : srcs }); } // 选择图片 Vue.prototype.chooseImage = function(c) { var _this = this; // 判断是相机还是图片库 api.actionSheet({ title : langConfig.selectFile, cancelTitle : langConfig.thisCancelBtn, buttons : [langConfig.camera, langConfig.photo] }, function(ret, err) { if (ret.buttonIndex == 3) { return; } console.log(JSON.stringify(ret)); var imageT = ["", "camera", "album"][ret.buttonIndex]; _this.startChooseImage(imageT, function(path) { c(path); }); }); } // 开始选择图片 Vue.prototype.startChooseImage = function(imageT, callback) { var _this = this; api.getPicture({ sourceType : imageT, encodingType : 'png', mediaValue : 'pic', destinationType : 'url', allowEdit : true, quality : 100, // targetWidth : 100, // targetHeight : 100, saveToPhotoAlbum : false }, function(ret, err) { if (ret) { if (ret.data != "") { // 有选择的相片了 // _this.imgs = ret.data; callback(ret.data); } } else { alert(JSON.stringify(err)); } }); } // 关闭页面 Vue.prototype.closeWin = function() { setTimeout(function() { api.closeWin({ }); }, 200); } // 点击选择省市区 Vue.prototype.chooseRegion = function(UIActionSelector, col, datasUrl, callback) { UIActionSelector.open({ datas : datasUrl, layout : { row : 5, col : col, height : 30, size : 12, sizeActive : 14, rowSpacing : 5, colSpacing : 10, maskBg : 'rgba(0,0,0,0.2)', bg : '#fff', color : '#a5a5a5', colorActive : '#f00', colorSelected : '#000' }, animation : true, cancel : { text : langConfig.cancel, size : 12, w : 90, h : 35, bg : '#fff', bgActive : '#ccc', color : '#888', colorActive : '#fff' }, ok : { text : langConfig.confirm, size : 12, w : 90, h : 35, bg : '#fff', bgActive : '#ccc', color : '#888', colorActive : '#fff' }, title : { text : langConfig.select, size : 12, h : 44, bg : '#eee', color : '#888', }, fixedOn : api.frameName }, function(ret, err) { if (ret) { if (ret.eventType == 'ok') { callback(ret); } } else { api.toast({ msg : langConfig.eventError }); } }); } // 显示加载框 Vue.prototype.showProcess = function() { api.showProgress({ title : langConfig.pleaseWait, text : langConfig.textLoad }); } // 隐藏加载框 Vue.prototype.hideProcess = function() { api.hideProgress(); } // 获取用户信息 Vue.prototype.getUserInfo = function(callback) { var url = "getUserInfoUrl", loginid = $api.getStorage('agentCode'), _this = this; var data = { agentCode : loginid, url : 'json', type : 'body', }; this.$post(url, data, function(ret) { if ( typeof callback != 'undefined' && callback != "undefined" && callback != "") { callback(ret); } if (ret.agentDto != null) { // 将retariler_id和username保存起来 $api.setStorage('agentid', ret.agentDto.id); // $api.setStorage('storeName', ret.retailerDto.storeName); } }); } // 获取购物车数量 Vue.prototype.getCarNum = function(id, callback) { var data = { retailer_id : id, }, url = "shopCarListUrl", _this = this; this.$post(url, data, function(ret) { if (ret.code == 0) { _this.userInfo.carNum = ret.list.length; callback(ret.list); } }) } // pcr 获取新版本,然后下载安装, Vue.prototype.getNewVersionUrl = function(c) { var data ='', url = "checkVersionU", _this = this; this.$get(url, data, function(ret) { if (ret.code == 0 || ret.code == '0') { if(ret.version != _this.getVersion()){ _this.showModal(langConfig.versionTitle, ret.plus_msg,[langConfig.versionConfirm, langConfig.versionCancel],function(res){ if(res == 2){ _this.downLoadApp(ret.url,c); } }) }else{ api.toast({ msg : langConfig.versionStatus }) } } },'formdata') }; // tbr 获取新版本,然后下载安装, Vue.prototype.getNewVersionUrlTbr = function(c) { var data = { "url": "json", "type": "body", "text": "1" }, url = "checkVersionU", _this = this; this.$post(url, data, function(ret) { if (ret.code == 0 || ret.code == '0') { if(ret.version != _this.getVersion()){ _this.showModal(langConfig.versionTitle , ret.plus_msg,[langConfig.versionConfirm, langConfig.versionCancel],function(res){ if(res == 2){ _this.downLoadApp(ret.url,c); } }) }else{ api.toast({ msg : langConfig.versionStatus }) } } }) }; // 下载版本 Vue.prototype.downLoadApp = function(url,callback) { var _this = this; api.showProgress({ title : langConfig.updateTips, text : langConfig.updating, modal : false }); // if (app.uav_type == 'IOS') { // api.installApp({ // appUri : app.uav_filepath // }); // } else { api.download({ url: url, savePath : '', report : true, cache : true, allowResume : true }, function(re, err) { if (re.state == 1) { api.hideProgress(); api.installApp({ appUri : re.savePath }); } else if (re.state == 2) { callback('fail') } }) //} } /**********************************************登录信息*************************************************/ // 判断是否已经登录:loginid token kunnr subRoleName roleScene Vue.prototype.isLogin = function(){ // 经销商 var loginid = $api.getStorage('kunnr'), token = $api.getStorage('token'), kunnr = $api.getStorage('kunnr'), subRoleName = $api.getStorage('subRoleName'); var arr1 = [loginid,token,kunnr,subRoleName]; var isLogin1=true; for(var index=0; index 0) { callback(ret); } else { api.toast({ msg : ret.msg }); } }, other) } Vue.prototype.$get = function(url, data, callback, other) { var http = new $http(); http.$get(url, data, function(ret) { if (ret.code == 0) { callback(ret); } else { api.toast({ msg : ret.msg }); } }, other) } // 配置上拉加载和下拉刷新 Vue.prototype.configDownAndPull = function(id, pullDown, down, useUp) { var mescroll = new MeScroll(id, { down: { auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true textOutOffset: langConfig.textOut, textInOffset: langConfig.textIn, textLoading: langConfig.textLoad, callback: function(){ pullDown(mescroll); }, //下拉刷新的回调 }, up: { use : useUp == false ? false : true, // 是否开启上拉加载 auto: false, //初始化完毕,是否自动触发上拉加载的回调 isBoth: true, //上拉加载时,如果滑动到列表顶部是否可以同时触发下拉刷新;默认false,两者不可同时触发; 这里为了演示改为true,不必等列表加载完毕才可下拉; isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10 offset: 0, htmlNodata: '

-- '+ langConfig.noData +' --

', htmlLoading: '

'+ langConfig.textLoad +'

', callback: function(){ down(mescroll); }, //上拉加载的回调 } }); } // 判断是否有权限 Vue.prototype.ifHasPrme = function(perm, c) { var has = this.hasPermission(perm),_this = this; if (!has || !has[0] || !has[0].granted) { api.confirm({ title: langConfig.remind, msg: langConfig.noGet + perm + langConfig.permission + "\n" + langConfig.goOnSet, buttons: [langConfig.setting, langConfig.cancel] }, function(ret, err) { if (1 == ret.buttonIndex) { _this.reqPermission(perm,function(){ c(true); }); } }); c(false); }else{ c(true); } } Vue.prototype.hasPermission = function(perm) { var perms = new Array(); perms.push(perm); var rets = api.hasPermission({ list: perms }); return rets; } Vue.prototype.reqPermission = function(perm,callback) { var perms = new Array(); perms.push(perm); api.requestPermission({ list: perms, }, function(ret, err) { if (ret && ret.list.length > 0) { callback(ret); } }); }