| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693 |
- /**
- * VUE 注册组件
- */
- Vue.prototype.getVersion = function() {
- return "1.1";
- };
- 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;
- this.pushObject.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 && ret.appParam.ajpush) {
- api.openWin({
- name : 'kehu_win',
- url : '../html/kehu/kehu_win.html',
- pageParam : ""
- });
- }
- })
- }
- /******************* 结束推送 *********************/
- /**
- * 弹出层
- */
- 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 : '必填项不能为空'
- });
- return false
- } else {
- return true
- }
- }
- // 判断数组
- Vue.prototype.checkArray = function(content) {
- if (content.length == 0) {
- api.toast({
- msg : '必填项不能为空'
- });
- 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',
- });
- }
- }
- // 使用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 : '下拉刷新',
- threshold : '松开立即刷新',
- load : '正在刷新'
- }
- }, function() {
- callback();
- // //下拉刷新被触发,自动进入加载状态,使用 api.refreshHeaderLoadDone() 手动结束加载中状态
- // //下拉刷新被触发,使用 api.refreshHeaderLoadDone() 结束加载中状态
- // alert('开始加载刷新数据,摇一摇停止加载状态');
- // api.addEventListener({
- // name : 'shake'
- // }, function(ret, err) {
- // api.refreshHeaderLoadDone()
- // });
- });
- }
- // 配置下拉刷新
- Vue.prototype.configHeadMotive = function(callback) {
- api.setRefreshHeaderInfo({
- visible : true,
- bgColor : '#ccc',
- textColor : '#fff',
- textDown : '下拉刷新...',
- textUp : '松开刷新...',
- showTime : true
- }, 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 : '温馨提示',
- msg : m,
- buttons : ["确定"],
- }, function(ret, err) {
- //coding...
- c();
- });
- }
- // 延时关闭页面发送监听
- 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 : '请稍候',
- text : '正在调起摄像头',
- 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 : '扫码出错'
- });
- }
- });
- }
- // 扫码 -- 主要是条形码
- 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);
- });
- }
- // 过滤掉数组中的对象
- 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 : '选择附件',
- cancelTitle : '这里是取消按钮',
- buttons : ['相机', '相册']
- }, function(ret, err) {
- if (ret.buttonIndex == 3) {
- return;
- }
- var imageT = _this.imageType[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 : '#ddd',
- colorActive : '#f00',
- colorSelected : '#000'
- },
- animation : true,
- cancel : {
- text : '取消',
- size : 12,
- w : 90,
- h : 35,
- bg : '#fff',
- bgActive : '#ccc',
- color : '#888',
- colorActive : '#fff'
- },
- ok : {
- text : '确定',
- size : 12,
- w : 90,
- h : 35,
- bg : '#fff',
- bgActive : '#ccc',
- color : '#888',
- colorActive : '#fff'
- },
- title : {
- text : '请选择',
- 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 : '事件错误'
- });
- }
- });
- }
- // 显示加载框
- Vue.prototype.showProcess = function() {
- api.showProgress({
- title : '请稍候...',
- text : '加载中...'
- });
- }
- // 隐藏加载框
- 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);
- }
- })
- }
- // 获取新版本,然后下载安装
- Vue.prototype.getNewVersionUrl = function() {
- var data = {
- paramKey : 'agent_url',
- url : 'json',
- type : 'body'
- }, url = "getVersionUrl", _this = this;
- this.$post(url, data, function(ret) {
- if (ret.code == 0) {
- _this.downLoadApp(ret.version);
- }
- })
- }
- // 下载版本
- Vue.prototype.downLoadApp = function(url) {
- var _this = this;
- api.showProgress({
- title : "更新提示",
- text : "正在更新",
- 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')
- }
- })
- //}
- }
- // 获取
- /******** ajax请求 ********/
- Vue.prototype.$post = function(url, data, callback, other) {
- var http = new $http();
- http.$post(url, data, function(ret) {
- if (ret.code == 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)
- }
|