123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992 |
- /**
- * 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 = '<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>';
- 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 : '<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>',
- 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 : '<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>',
- 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<arr1.length; index++){
- if(!(typeof arr1[index] == "string" && arr1[index]!="undefined" && arr1[index]!="")){
- isLogin1 = false;
- };
- };
- // 子权限
- var loginToken = $api.getStorage('loginToken'),
- pertel = $api.getStorage('pertel');
- var arr2 = [loginToken,pertel,subRoleName];
- var isLogin2 = true;
- for(var index=0; index<arr2.length; index++){
- if(!(typeof arr2[index] == "string" && arr2[index]!="undefined" && arr2[index]!="")){
- isLogin2 = false;
- };
- };
- isLogin = isLogin1 || isLogin2;
- return isLogin;
- };
- // 判断是否已经选择了角色
- Vue.prototype.isHasRoleScene = function(){
- var roleScene = $api.getStorage('roleScene');
- var isHasRoleScene;
- if(typeof roleScene == "string" && roleScene!="undefined"&&roleScene!=""){
- isHasRoleScene = true;
- }else{
- isHasRoleScene = false;
- };
- return isHasRoleScene;
- };
- //登录入口控制
- Vue.prototype.loginEntrance = function(params,urlp){
- var sceneArr = [{
- sceneCode: "10",
- sceneName: "maintbr",
- scenePath: "/main/tbr/main.html",
- openFrameGroupName: "openFrameGroupTbr"
- },{
- sceneCode: "40",
- sceneName: "mainpcr",
- scenePath: "/main/pcr/main.html",
- openFrameGroupName: "openFrameGroupPcr"
- },{//暂定子权限 (订单员是500);
- sceneCode: "500",
- sceneName: "mainsub",
- scenePath: "/main/sub/main.html",
- openFrameGroupName: "openFrameGroupSub"
- }];
- var idx,isHas=false;
- for(var index=0; index<sceneArr.length; index++){
- if(params==sceneArr[index].sceneCode){
- idx = index;
- isHas = true;
- }
- };
- if(isHas){
- this.sendEvent("refushUser");
- this.sendEvent(sceneArr[idx].sceneName,urlp+sceneArr[idx].openFrameGroupName, "");
- this.goWin(sceneArr[idx].sceneName,urlp+sceneArr[idx].scenePath);
- }else{
- $api.toast(langConfig.warning, langConfig.noPermission, 3000);
- }
- };
- // 获取
- /******** ajax请求 ********/
- Vue.prototype.$post = function(url, data, callback, other) {
- var http = new $http();
- http.$post(url, data, function(ret) {
- if (ret.code == 0 || ret.code == "0" || ret.length > 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: '<p class="upwarp-nodata" style="margin-bottom : 1rem;position:relative">-- '+ langConfig.noData +' --</p>',
- htmlLoading: '<p class="upwarp-progress mescroll-rotate"></p><p class="upwarp-tip">'+ langConfig.textLoad +'</p>',
- 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);
- }
- });
- }
|