Showing
2 changed files
with
1014 additions
and
0 deletions
pages/book/b_addnew.js
0 → 100644
| 1 | +// pages/book/b_addnew.js | ||
| 2 | +import util from '../../utils/util'; | ||
| 3 | +import comm from '../../utils/bookCommon'; | ||
| 4 | +import App from '../../utils/api'; | ||
| 5 | +const {regeneratorRuntime} = global | ||
| 6 | +Page({ | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * 页面的初始数据 | ||
| 10 | + */ | ||
| 11 | + data: { | ||
| 12 | + dateStr:[], | ||
| 13 | + form:{ | ||
| 14 | + | ||
| 15 | + date:0, | ||
| 16 | + time:0, | ||
| 17 | + pnum_str:'1-4', | ||
| 18 | + tabid:0, | ||
| 19 | + | ||
| 20 | + rname:'', | ||
| 21 | + phone:'', | ||
| 22 | + sex:1, | ||
| 23 | + cusdem:'', | ||
| 24 | + | ||
| 25 | + tid:[], | ||
| 26 | + | ||
| 27 | + }, | ||
| 28 | + tables:[], | ||
| 29 | + grand:[ | ||
| 30 | + { | ||
| 31 | + sex:1, | ||
| 32 | + grand_title:'先生', | ||
| 33 | + isselect:true | ||
| 34 | + }, | ||
| 35 | + { | ||
| 36 | + sex:2, | ||
| 37 | + grand_title:'女士', | ||
| 38 | + isselect:false | ||
| 39 | + } | ||
| 40 | + ], | ||
| 41 | + buttonhide:true, | ||
| 42 | + }, | ||
| 43 | + tablesAll:[], | ||
| 44 | + /** | ||
| 45 | + * 生命周期函数--监听页面加载 | ||
| 46 | + */ | ||
| 47 | + onLoad: function (options) { | ||
| 48 | + let d=new Date()/1000; | ||
| 49 | + let dateStr=[ | ||
| 50 | + util.unixtoTime(d,'MM-DD'), | ||
| 51 | + util.unixtoTime(d+86400,'MM-DD'), | ||
| 52 | + ]; | ||
| 53 | + this.setData({ | ||
| 54 | + dateStr:dateStr, | ||
| 55 | + }) | ||
| 56 | + this.sellerid=util.cache('sellerid'); | ||
| 57 | + this.getTables() | ||
| 58 | + }, | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 生命周期函数--监听页面初次渲染完成 | ||
| 62 | + */ | ||
| 63 | + onReady: function () { | ||
| 64 | + | ||
| 65 | + }, | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 生命周期函数--监听页面显示 | ||
| 69 | + */ | ||
| 70 | + onShow: function () { | ||
| 71 | + | ||
| 72 | + }, | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * 生命周期函数--监听页面隐藏 | ||
| 76 | + */ | ||
| 77 | + onHide: function () { | ||
| 78 | + | ||
| 79 | + }, | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * 生命周期函数--监听页面卸载 | ||
| 83 | + */ | ||
| 84 | + onUnload: function () { | ||
| 85 | + | ||
| 86 | + }, | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * 页面相关事件处理函数--监听用户下拉动作 | ||
| 90 | + */ | ||
| 91 | + onPullDownRefresh: function () { | ||
| 92 | + | ||
| 93 | + }, | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 页面上拉触底事件的处理函数 | ||
| 97 | + */ | ||
| 98 | + onReachBottom: function () { | ||
| 99 | + | ||
| 100 | + }, | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * 用户点击右上角分享 | ||
| 104 | + */ | ||
| 105 | + onShareAppMessage: function () { | ||
| 106 | + | ||
| 107 | + }, | ||
| 108 | + selectedValue(e){ | ||
| 109 | + //console.log(e); | ||
| 110 | + let key=util.attr(e,'key'); | ||
| 111 | + let val; | ||
| 112 | + if(e.type=='input'){ | ||
| 113 | + val=util.val(e); | ||
| 114 | + if(e.currentTarget.dataset.key=='phone'){ | ||
| 115 | + var that=this; | ||
| 116 | + if(e.detail.value!='' && e.detail.value.length>=3) { | ||
| 117 | + App.Reserve.GetReserveUser({keywords:e.detail.value}).then(function(json){ | ||
| 118 | + if(json.ret==200 && json.data.length>0){ | ||
| 119 | + that.setData({ | ||
| 120 | + searchlist:json.data | ||
| 121 | + }) | ||
| 122 | + }else{ | ||
| 123 | + that.setData({ | ||
| 124 | + searchlist:null | ||
| 125 | + }) | ||
| 126 | + } | ||
| 127 | + }) | ||
| 128 | + }else{ | ||
| 129 | + this.setData({ | ||
| 130 | + searchlist:null | ||
| 131 | + }) | ||
| 132 | + } | ||
| 133 | + } | ||
| 134 | + }else{ | ||
| 135 | + val=util.attr(e,'value'); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + let form=this.data.form; | ||
| 139 | + let sobj={}; | ||
| 140 | + if(key=='tid'){ | ||
| 141 | + let ts=this.data.tables; | ||
| 142 | + if(ts[val].isselect){ | ||
| 143 | + ts[val].isselect=false; | ||
| 144 | + form.tid.remove(ts[val].id); | ||
| 145 | + }else{ | ||
| 146 | + ts[val].isselect=true; | ||
| 147 | + form.tid.push(ts[val].id); | ||
| 148 | + } | ||
| 149 | + sobj.tables=ts; | ||
| 150 | + }else{ | ||
| 151 | + form[key]=val; | ||
| 152 | + } | ||
| 153 | + //console.log(e.type,key,val,form); | ||
| 154 | + sobj.form=form; | ||
| 155 | + sobj.buttonhide=true; | ||
| 156 | + if(form.tid.length>0 && form.rname.length>0){ | ||
| 157 | + sobj.buttonhide=false; | ||
| 158 | + } | ||
| 159 | + this.setData(sobj) | ||
| 160 | + | ||
| 161 | + if('date,time,pnum_str,tabid'.indexOf(key)>-1){ | ||
| 162 | + this.getTables(); | ||
| 163 | + } | ||
| 164 | + }, | ||
| 165 | + async getTables(){ | ||
| 166 | + let form=this.data.form; | ||
| 167 | + try{ | ||
| 168 | + let rdate=await comm.getTimeSpace(this.data.dateStr[this.data.form.date],this.data.form.time); | ||
| 169 | + console.log('rdate',rdate); | ||
| 170 | + App.Reserve.GetTableList({ | ||
| 171 | + sid:this.sellerid, | ||
| 172 | + pnum_str:form.pnum_str, | ||
| 173 | + rdate:rdate, | ||
| 174 | + tid:form.tabid, | ||
| 175 | + }).then(res=>{ | ||
| 176 | + let tables=[]; | ||
| 177 | + res.data.forEach(p=>{ | ||
| 178 | + if(tables.length>=3) return true; | ||
| 179 | + p.list.forEach(t=>{ | ||
| 180 | + if(tables.length>=3) return true; | ||
| 181 | + tables.push(t); | ||
| 182 | + }) | ||
| 183 | + }) | ||
| 184 | + this.tablesAll=res.data; | ||
| 185 | + this.setData({ | ||
| 186 | + tables:tables | ||
| 187 | + }) | ||
| 188 | + }) | ||
| 189 | + }catch (e){ | ||
| 190 | + this.setData({ | ||
| 191 | + tables:[] | ||
| 192 | + }) | ||
| 193 | + } | ||
| 194 | +}, | ||
| 195 | +async formsubmit(){ | ||
| 196 | + if(this.data.buttonhide) return; | ||
| 197 | + try { | ||
| 198 | + let rdate = await comm.getTimeSpace(this.data.dateStr[this.data.form.date], this.data.form.time); | ||
| 199 | + console.log('rdate', rdate); | ||
| 200 | + this.setData({ | ||
| 201 | + buttonhide: true, | ||
| 202 | + }) | ||
| 203 | + let form = this.data.form; | ||
| 204 | + form.tid = form.tid.toString(); | ||
| 205 | + form.sid = this.sellerid; | ||
| 206 | + form.rdate =rdate | ||
| 207 | + App.Reserve.SetReserveInfo(form).then(res => { | ||
| 208 | + if(res.ret==200){ | ||
| 209 | + wx.navigateTo({ | ||
| 210 | + url:'b_detail?id='+res.data.id, | ||
| 211 | + }); | ||
| 212 | + }else{ | ||
| 213 | + util.toast(res.msg,'none') | ||
| 214 | + } | ||
| 215 | + }) | ||
| 216 | + }catch (e){} | ||
| 217 | +}, | ||
| 218 | +selectphone:function(e){ | ||
| 219 | + this.data.form.phone=e.detail.phone; | ||
| 220 | + this.data.form.rname=e.detail.rname; | ||
| 221 | + this.data.form.cusdem=e.detail.cusdem; | ||
| 222 | + this.data.form.sex=e.detail.sex; | ||
| 223 | + this.setData({ | ||
| 224 | + form:this.data.form, | ||
| 225 | + searchlist:null | ||
| 226 | + }) | ||
| 227 | +}, | ||
| 228 | +async selectdesk(){ | ||
| 229 | + let rdate=await comm.getTimeSpace(this.data.dateStr[this.data.form.date],this.data.form.time); | ||
| 230 | + console.log(this.data.form) | ||
| 231 | + wx.navigateTo({ | ||
| 232 | + url:'b_desk?rdate='+rdate+'&tid='+this.data.form.tabid+'&pnum_str='+this.data.form.pnum_str | ||
| 233 | + }) | ||
| 234 | +} | ||
| 235 | +}) |
utils/util.js
0 → 100644
| 1 | +var uri=require('uri.js') | ||
| 2 | + | ||
| 3 | +function formatTime(date,type,connect) { | ||
| 4 | + var year = date.getFullYear() | ||
| 5 | + var month = date.getMonth() + 1 | ||
| 6 | + var day = date.getDate() | ||
| 7 | + | ||
| 8 | + var hour = date.getHours() | ||
| 9 | + var minute = date.getMinutes() | ||
| 10 | + var second = date.getSeconds() | ||
| 11 | + if(type==1){ | ||
| 12 | + if(connect){ | ||
| 13 | + return [year, month, day].map(formatNumber).join(connect) | ||
| 14 | + }else{ | ||
| 15 | + return [year, month, day].map(formatNumber).join('/') | ||
| 16 | + } | ||
| 17 | + }else if(type==2){ | ||
| 18 | + return [month, day].map(formatNumber).join('/') | ||
| 19 | + }else{ | ||
| 20 | + return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | +} | ||
| 24 | +function formatNumber(n) { | ||
| 25 | + n = n.toString() | ||
| 26 | + return n[1] ? n : '0' + n | ||
| 27 | +} | ||
| 28 | +//时间戳转为时间 | ||
| 29 | +function unixtoTime(ns,format) { | ||
| 30 | + var result; | ||
| 31 | + var time = new Date(ns*1000); | ||
| 32 | + //result=format || 'YYYY年MM月DD日 HH时II分SS秒 WW'; | ||
| 33 | + result=format || 'YYYY年MM月DD日'; | ||
| 34 | + //console.log(format); | ||
| 35 | + result=result.toUpperCase(); | ||
| 36 | + result=result.replace('YYYY',time.getFullYear()); | ||
| 37 | + var m=time.getMonth()+1; | ||
| 38 | + result=result.replace('MM',m>9?m:"0"+m); | ||
| 39 | + var d=time.getDate(); | ||
| 40 | + result=result.replace('DD',d>9?d:'0'+d); | ||
| 41 | + var hh=time.getHours(); | ||
| 42 | + result=result.replace('HH',hh>9?hh:'0'+hh); | ||
| 43 | + var ii=time.getMinutes(); | ||
| 44 | + result=result.replace('II',ii>9?ii:'0'+ii); | ||
| 45 | + var ss=time.getSeconds(); | ||
| 46 | + result=result.replace('SS',ss>9?ss:'0'+ss); | ||
| 47 | + var week; | ||
| 48 | + switch (time.getDay()) { | ||
| 49 | + case 0:week="日";break | ||
| 50 | + case 1:week="一";break | ||
| 51 | + case 2:week="二";break | ||
| 52 | + case 3:week="三";break | ||
| 53 | + case 4:week="四";break | ||
| 54 | + case 5:week="五";break | ||
| 55 | + case 6:week="六";break | ||
| 56 | + } | ||
| 57 | + result=result.replace('WW',week); | ||
| 58 | + if(format.indexOf('DAY')>0){ | ||
| 59 | + // 获取当天 0 点的时间戳 | ||
| 60 | + var timeStamp = new Date(new Date().setHours(0, 0, 0, 0)) / 1000; | ||
| 61 | + | ||
| 62 | + var day1 = timeStamp+86400//今天结束 | ||
| 63 | + var day2 = day1+86400//明天结束 | ||
| 64 | + | ||
| 65 | + //console.log('ns<day.getTime()',ns,day1,day2) | ||
| 66 | + | ||
| 67 | + if(ns<day1){ | ||
| 68 | + result=result.replace('DAY','今天'); | ||
| 69 | + }else{ | ||
| 70 | + if(ns<day2){ | ||
| 71 | + result=result.replace('DAY','明天'); | ||
| 72 | + }else{ | ||
| 73 | + result=result.replace('DAY',''); | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + return result; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +//时间转为时间戳 | ||
| 81 | +function timetouUnix(dasr,connect) | ||
| 82 | +{ | ||
| 83 | + if(connect){ | ||
| 84 | + var newstr = dasr.replace(/-/g,connect); | ||
| 85 | + }else{ | ||
| 86 | + var newstr = dasr.replace(/-/g,'/'); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + var date = new Date(newstr); | ||
| 90 | + var time_str = date.getTime().toString(); | ||
| 91 | + return time_str.substr(0, 10); | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +//支付 | ||
| 95 | +function orderPay(charge){ | ||
| 96 | + var that=this; | ||
| 97 | + console.log(charge); | ||
| 98 | + var obj = JSON.parse(charge) | ||
| 99 | + console.log('obj:',obj); | ||
| 100 | + wx.requestPayment({ | ||
| 101 | + 'timeStamp': obj.timeStamp, | ||
| 102 | + 'nonceStr': obj.nonceStr, | ||
| 103 | + 'package': obj.package, | ||
| 104 | + 'signType': 'MD5', | ||
| 105 | + 'paySign': obj.paySign, | ||
| 106 | + 'success':function(res){ | ||
| 107 | + console.log('success:',res); | ||
| 108 | + }, | ||
| 109 | + 'fail':function(res){ | ||
| 110 | + console.log('fail:',res); | ||
| 111 | + }, | ||
| 112 | + 'complete':function(res){ | ||
| 113 | + | ||
| 114 | + } | ||
| 115 | + }) | ||
| 116 | +} | ||
| 117 | +module.exports = { | ||
| 118 | + formatTime: formatTime, | ||
| 119 | + unixtoTime:unixtoTime, | ||
| 120 | + timetouUnix:timetouUnix, | ||
| 121 | + orderPay:orderPay, | ||
| 122 | + cgi:function(act){ | ||
| 123 | + return uri.HOST__LINE+act //正式 | ||
| 124 | + //return uri.HOST__TEST+act //测试 | ||
| 125 | + }, | ||
| 126 | + wxApiIsUse:function(api){ | ||
| 127 | + if(wx.canIUse(api)){ | ||
| 128 | + return true; | ||
| 129 | + }else{ | ||
| 130 | + this.alert('当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'); | ||
| 131 | + } | ||
| 132 | + }, | ||
| 133 | + openXcx:function(data){ | ||
| 134 | + if(this.wxApiIsUse('navigateToMiniProgram')){ | ||
| 135 | + wx.navigateToMiniProgram({ | ||
| 136 | + appId: data.appId, | ||
| 137 | + path: data.path, | ||
| 138 | + extraData: { | ||
| 139 | + foo: 'bar' | ||
| 140 | + }, | ||
| 141 | + envVersion: 'trial', | ||
| 142 | + //envVersion: '', | ||
| 143 | + success(res) { | ||
| 144 | + // 打开成功 | ||
| 145 | + } | ||
| 146 | + }) | ||
| 147 | + } | ||
| 148 | + }, | ||
| 149 | + loading:function(flag){ | ||
| 150 | + if(flag=='clear' || flag=="clean"){ | ||
| 151 | + wx.hideNavigationBarLoading(); | ||
| 152 | + return; | ||
| 153 | + } | ||
| 154 | + wx.showNavigationBarLoading(); | ||
| 155 | + }, | ||
| 156 | + postSuccessFun:function(json,uri_code){ | ||
| 157 | + console.log("APP::postSuccessFun",uri_code,json); | ||
| 158 | + }, | ||
| 159 | + postFailFun:function(json,uri_code){ | ||
| 160 | + console.log(json,uri_code); | ||
| 161 | + }, | ||
| 162 | + getToken:function(n_function){ | ||
| 163 | + var token=this.cache(uri.CACHE__TOKEN); | ||
| 164 | + console.log("token:",token); | ||
| 165 | + if(!token) { | ||
| 166 | + this.loginStart(n_function); | ||
| 167 | + return; | ||
| 168 | + } | ||
| 169 | + return token; | ||
| 170 | + }, | ||
| 171 | + asyn:function(act,data,uri_code,n_function){//静默方式,不带loading | ||
| 172 | + data=data||{}; | ||
| 173 | + var that=this; | ||
| 174 | + data.token=that.cache(uri.CACHE__TOKEN); | ||
| 175 | + wx.request({ | ||
| 176 | + url: that.cgi(act), | ||
| 177 | + method:'POST', | ||
| 178 | + data: data, | ||
| 179 | + header: { | ||
| 180 | + 'content-type': 'application/x-www-form-urlencoded' | ||
| 181 | + }, | ||
| 182 | + success: function(res) { | ||
| 183 | + console.log('request==>',that.http_build_query(data,that.cgi(act))+'\nrequest.success',res.data); | ||
| 184 | + that.loading('clear'); | ||
| 185 | + if(n_function){ | ||
| 186 | + that.loginStart(n_function); | ||
| 187 | + } | ||
| 188 | + /*if(typeof res.data!='string'){ | ||
| 189 | + if(res.data.code!=200&&res.data.code!=1000){ | ||
| 190 | + console.log(res.data.code==-1,res.data.code); | ||
| 191 | + if(res.data.code==-1) { | ||
| 192 | + that.loginStart(n_function); | ||
| 193 | + return; | ||
| 194 | + }else{ | ||
| 195 | + that.alert(res.data.message); | ||
| 196 | + return; | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | + }*/ | ||
| 200 | + that.postSuccessFun(res.data,uri_code); | ||
| 201 | + }, | ||
| 202 | + fail: function(res) { | ||
| 203 | + console.log('request==>',that.http_build_query(data,that.cgi(act))+'\nrequest.fail',res); | ||
| 204 | + that.loading('clear'); | ||
| 205 | + that.toast(res.errMsg); | ||
| 206 | + that.postFailFun(res.data,uri_code); | ||
| 207 | + } | ||
| 208 | + }) | ||
| 209 | + }, | ||
| 210 | + post:function(act,data,uri_code,is_load,n_function,header={'Content-Type': 'application/x-www-form-urlencoded'}){ | ||
| 211 | + console.log('act:',act) | ||
| 212 | + if(is_load!='0'){ | ||
| 213 | + this.loading(); | ||
| 214 | + } | ||
| 215 | + this.asyn(act,data,uri_code,n_function,header); | ||
| 216 | + }, | ||
| 217 | + upload:function(filePath,fileIndex,uri_code,sellerid,type,file){ | ||
| 218 | + var that=this; | ||
| 219 | + this.loading(); | ||
| 220 | + if(this.wxApiIsUse('uploadFile')){ | ||
| 221 | + wx.uploadFile({ | ||
| 222 | + url: that.cgi('Seller/Index/UploadImages'), | ||
| 223 | + filePath: filePath, | ||
| 224 | + name: 'file', | ||
| 225 | + formData:{ | ||
| 226 | + sellerid:sellerid, | ||
| 227 | + type:type | ||
| 228 | + }, | ||
| 229 | + success: function(res){ | ||
| 230 | + that.loading('clear'); | ||
| 231 | + that.postSuccessFun(res.data,uri_code,fileIndex); | ||
| 232 | + }, | ||
| 233 | + fail: function(res) { | ||
| 234 | + that.loading('clear'); | ||
| 235 | + that.toast("上传失败,请重试"); | ||
| 236 | + that.postFailFun(res.data,uri_code,fileIndex); | ||
| 237 | + } | ||
| 238 | + }); | ||
| 239 | + } | ||
| 240 | + }, | ||
| 241 | + | ||
| 242 | + uploading:function(filePath,fileIndex,dir,uri_code,file){ | ||
| 243 | + var that=this; | ||
| 244 | + this.loading(); | ||
| 245 | + | ||
| 246 | + console.log(filePath,fileIndex,dir,uri_code); | ||
| 247 | + | ||
| 248 | + if(this.wxApiIsUse('uploadFile')){ | ||
| 249 | + wx.uploadFile({ | ||
| 250 | + url: 'https://xt05.colorcun.com/?s=App.Cookbook.UpLoadFile', | ||
| 251 | + filePath: filePath, | ||
| 252 | + name: 'file', | ||
| 253 | + formData:{ | ||
| 254 | + dir:dir | ||
| 255 | + }, | ||
| 256 | + success: function(res){ | ||
| 257 | + console.log('上传成功') | ||
| 258 | + console.log(res) | ||
| 259 | + that.loading('clear'); | ||
| 260 | + that.postSuccessFun(res.data,uri_code,fileIndex); | ||
| 261 | + }, | ||
| 262 | + fail: function(res) { | ||
| 263 | + | ||
| 264 | + that.toast("上传失败,请重试"); | ||
| 265 | + that.postFailFun(res.data,uri_code,fileIndex); | ||
| 266 | + } | ||
| 267 | + }); | ||
| 268 | + } | ||
| 269 | + }, | ||
| 270 | + | ||
| 271 | + uploadImg:function(filePath,fileIndex,uri_code){ | ||
| 272 | + var that=this; | ||
| 273 | + if(this.wxApiIsUse('uploadFile')){ | ||
| 274 | + wx.uploadFile({ | ||
| 275 | + url: that.cgi('bargainimage'), | ||
| 276 | + filePath: filePath, | ||
| 277 | + name: 'path', | ||
| 278 | + formData:{ | ||
| 279 | + 'token': that.getToken() | ||
| 280 | + }, | ||
| 281 | + success: function(res){ | ||
| 282 | + console.log(res); | ||
| 283 | + res.data=JSON.parse(res.data); | ||
| 284 | + if(res.data.code!=200){ | ||
| 285 | + if(res.data.code==-1) { | ||
| 286 | + wx.navigateTo({url:'/pages/login/index'}); | ||
| 287 | + return; | ||
| 288 | + }else{ | ||
| 289 | + that.alert(res.data.message); | ||
| 290 | + } | ||
| 291 | + } | ||
| 292 | + console.log("res-code-data",uri_code,res.data); | ||
| 293 | + that.postSuccessFun(res.data,uri_code,fileIndex); | ||
| 294 | + }, | ||
| 295 | + fail:function(res){ | ||
| 296 | + console.log(res); | ||
| 297 | + } | ||
| 298 | + }); | ||
| 299 | + } | ||
| 300 | + }, | ||
| 301 | + download:function(id,uri_code,width){ | ||
| 302 | + var that=this; | ||
| 303 | + this.loading(); | ||
| 304 | + if(this.wxApiIsUse('downloadFile')){ | ||
| 305 | + wx.downloadFile({ | ||
| 306 | + url: that.cgi('download'), | ||
| 307 | + success: function(res) { | ||
| 308 | + console.log("res-code-data",uri_code,res); | ||
| 309 | + wx.playVoice({ | ||
| 310 | + filePath: res.tempFilePath | ||
| 311 | + }) | ||
| 312 | + that.postSuccessFun(id,uri_code,width,res.data); | ||
| 313 | + } | ||
| 314 | + }); | ||
| 315 | + } | ||
| 316 | + }, | ||
| 317 | + alert:function(msg,success,cancel,title){ | ||
| 318 | + wx.showModal({ | ||
| 319 | + title:title?title:"提示信息", | ||
| 320 | + content:msg, | ||
| 321 | + showCancel:typeof cancel=='undefined'?false:true, | ||
| 322 | + success:function(res){ | ||
| 323 | + if(res.confirm){ | ||
| 324 | + if(success) success(); | ||
| 325 | + }else{ | ||
| 326 | + if(cancel) cancel(); | ||
| 327 | + } | ||
| 328 | + } | ||
| 329 | + }); | ||
| 330 | + }, | ||
| 331 | + toast:function(title,icon='success'){ | ||
| 332 | + wx.showToast({ | ||
| 333 | + title:title, | ||
| 334 | + icon:icon | ||
| 335 | + }) | ||
| 336 | + }, | ||
| 337 | + showLoading:function(title){ | ||
| 338 | + wx.showLoading({ | ||
| 339 | + title: '加载中', | ||
| 340 | + }) | ||
| 341 | + | ||
| 342 | + }, | ||
| 343 | + getCommonType:function(key){ | ||
| 344 | + var that=this; | ||
| 345 | + var common = that.cache(uri.CACHE__COMMON) || {time:0}; | ||
| 346 | + var time=Date.now(); | ||
| 347 | + if(common.time<time-600000){ | ||
| 348 | + wx.request({ | ||
| 349 | + url: that.cgi('commontype'), | ||
| 350 | + header: { | ||
| 351 | + 'Content-Type': 'application/json' | ||
| 352 | + }, | ||
| 353 | + success: function(res) { | ||
| 354 | + if(res.data.code==200){ | ||
| 355 | + common={data:res.data.data,time:time}; | ||
| 356 | + //wx.setStorageSync(uri.CACHE__COMMON,common); | ||
| 357 | + that.cache(uri.CACHE__COMMON,common) | ||
| 358 | + } | ||
| 359 | + } | ||
| 360 | + }) | ||
| 361 | + } | ||
| 362 | + if(!key) return common.data; | ||
| 363 | + common = that.cache(uri.CACHE__COMMON) || {time:0}; | ||
| 364 | + return common.data[key]; | ||
| 365 | + }, | ||
| 366 | + getCommonTag:function(key,v_id){ | ||
| 367 | + var that=this; | ||
| 368 | + var tagsdata=this.cache(uri.CACHE__COMMONTAG); | ||
| 369 | + if(!tagsdata){ | ||
| 370 | + | ||
| 371 | + wx.request({ | ||
| 372 | + url: that.cgi(uri.CGI__USER_TCOMMONTAG), | ||
| 373 | + data:{ | ||
| 374 | + 'token': that.getToken() | ||
| 375 | + }, | ||
| 376 | + header: { | ||
| 377 | + 'Content-Type': 'application/json' | ||
| 378 | + }, | ||
| 379 | + success: function(res) { | ||
| 380 | + if(res.data.code==200){ | ||
| 381 | + that.cache(uri.CACHE__COMMONTAG,res.data.data); | ||
| 382 | + } | ||
| 383 | + } | ||
| 384 | + }) | ||
| 385 | + } | ||
| 386 | + tagsdata=this.cache(uri.CACHE__COMMONTAG); | ||
| 387 | + var result; | ||
| 388 | + if(v_id){ | ||
| 389 | + tagsdata[key].map(function(v){ | ||
| 390 | + if(v.id==v_id){ | ||
| 391 | + result=v.tag_name; | ||
| 392 | + } | ||
| 393 | + }) | ||
| 394 | + }else{ | ||
| 395 | + result=tagsdata[key]; | ||
| 396 | + } | ||
| 397 | + return result; | ||
| 398 | + }, | ||
| 399 | + cache:function(key,value){ | ||
| 400 | + if(value){ | ||
| 401 | + wx.setStorageSync(key,value); | ||
| 402 | + } | ||
| 403 | + return wx.getStorageSync(key); | ||
| 404 | + }, | ||
| 405 | + remove:function(key){ | ||
| 406 | + if(key){ | ||
| 407 | + wx.removeStorage({key: key}) | ||
| 408 | + } | ||
| 409 | + }, | ||
| 410 | + image:function(id,width=""){ | ||
| 411 | + var url=this.cgi(uri.CGI__DOWNLOAD+'/id/'+id); | ||
| 412 | + if(width){ | ||
| 413 | + url+='/width/'+width; | ||
| 414 | + } | ||
| 415 | + return url; | ||
| 416 | + }, | ||
| 417 | + | ||
| 418 | + avatar:function(id,t='pu'){ | ||
| 419 | + return this.cgi(uri.CGI__AVATAR +'/'+t+'/'+id); | ||
| 420 | + }, | ||
| 421 | + trim:function(str){ | ||
| 422 | + return str.replace(/^([ ]+)/,"").replace(/([ ]+)$/,""); | ||
| 423 | + }, | ||
| 424 | + clear:function(str){//去除html标签 | ||
| 425 | + return this.trim(str.replace(/<[^>]+>/ig,"")); | ||
| 426 | + }, | ||
| 427 | + clearHtml:function(html){//去除html中特殊字符 | ||
| 428 | + html=html.replace(/[\n\r\t]+/ig,''); | ||
| 429 | + html=html.replace(/<html[^>]*>(.*)<body[^>]*>/ig,''); | ||
| 430 | + html=html.replace(/<div[^>]*>(.*)<article[^>]*>/ig,''); | ||
| 431 | + html=html.replace(/<\/article[^>]*>(.*)<\/div[^>]*>/ig,''); | ||
| 432 | + html=html.replace(/<style[^>]*>(.*)<\/style>/ig,''); | ||
| 433 | + html=html.replace(/<\/body.*/ig,''); | ||
| 434 | + html=html.replace(/<!--[^>]+>/ig,''); | ||
| 435 | + html=html.replace(/"/ig,''); | ||
| 436 | + return html; | ||
| 437 | + }, | ||
| 438 | + val:function(e){ | ||
| 439 | + return e.detail.value; | ||
| 440 | + }, | ||
| 441 | + attr:function(e,key){ | ||
| 442 | + return e.currentTarget.dataset[key]; | ||
| 443 | + }, | ||
| 444 | + extend:function(destination, source) { | ||
| 445 | + for (var property in source) { | ||
| 446 | + destination[property] = source[property]; | ||
| 447 | + } | ||
| 448 | + return destination; | ||
| 449 | + }, | ||
| 450 | + getToken:function(n_function){ | ||
| 451 | + var token=this.cache(uri.CACHE__TOKEN); | ||
| 452 | + console.log("token:",token); | ||
| 453 | + if(!token) { | ||
| 454 | + this.loginStart(n_function); | ||
| 455 | + return; | ||
| 456 | + } | ||
| 457 | + return token; | ||
| 458 | + }, | ||
| 459 | + loginStart:function(n_function){ | ||
| 460 | + console.log("n_function:",n_function,1111); | ||
| 461 | + var that=this; | ||
| 462 | + wx.login({ | ||
| 463 | + success: function(login_res) { | ||
| 464 | + if (login_res.code) { | ||
| 465 | + console.log('success'); | ||
| 466 | + console.log('wx.login.res' , login_res); | ||
| 467 | + that.cache(uri.CACHE__LOGINCODE,login_res.code); | ||
| 468 | + wx.getUserInfo({ | ||
| 469 | + success: function(res) { | ||
| 470 | + res.code=login_res.code; | ||
| 471 | + console.log('wx.getProviderInfo.res' , res); | ||
| 472 | + var data={ | ||
| 473 | + code:login_res.code, | ||
| 474 | + encryptData:res.encryptData, | ||
| 475 | + encryptedData:res.encryptedData, | ||
| 476 | + iv:res.iv, | ||
| 477 | + rawData:res.rawData, | ||
| 478 | + signature:res.signature, | ||
| 479 | + appid:'wxc359908817c7bdd9', | ||
| 480 | + secret:'a14a8415a501ade9542968d8a6504820', | ||
| 481 | + } | ||
| 482 | + wx.request({ | ||
| 483 | + url: that.cgi(uri.CGI__USER_XCXLOGIN), | ||
| 484 | + data: data, | ||
| 485 | + header: { | ||
| 486 | + 'content-type': 'application/json' | ||
| 487 | + }, | ||
| 488 | + success: function(res) { | ||
| 489 | + that.cache('setting','success'); | ||
| 490 | + that.cache(uri.CACHE__LOGINCODE,login_res.code); | ||
| 491 | + /*if(n_function){ | ||
| 492 | + var pagelength=getCurrentPages().length; | ||
| 493 | + console.log("pagelength:",pagelength); | ||
| 494 | + console.log("getCurrentPages:",getCurrentPages()); | ||
| 495 | + if(typeof getCurrentPages()[pagelength-1][n_function]()!='undefined'){ | ||
| 496 | + getCurrentPages()[pagelength-1][n_function](); | ||
| 497 | + } | ||
| 498 | + }*/ | ||
| 499 | + return; | ||
| 500 | + } | ||
| 501 | + }) | ||
| 502 | + }, | ||
| 503 | + fail:function(){ | ||
| 504 | + that.cache('loginfail','fail'); | ||
| 505 | + if(n_function){ | ||
| 506 | + var pagelength=getCurrentPages().length; | ||
| 507 | + console.log('hahahah'); | ||
| 508 | + getCurrentPages()[pagelength-1].onShow(); | ||
| 509 | + } | ||
| 510 | + } | ||
| 511 | + }); | ||
| 512 | + } else { | ||
| 513 | + console.log('获取用户登录态失败!' + res.errMsg) | ||
| 514 | + } | ||
| 515 | + } | ||
| 516 | + }); | ||
| 517 | + }, | ||
| 518 | + //重新调起授权 | ||
| 519 | + userInfoHandler:function(etarget){ | ||
| 520 | + if(this.wxApiIsUse('button.open-type.getUserInfo')){ | ||
| 521 | + if(etarget.detail&& etarget.detail.errMsg=='getUserInfo:ok'){ | ||
| 522 | + return true | ||
| 523 | + //this.dc_loginStart() | ||
| 524 | + } | ||
| 525 | + } | ||
| 526 | + }, | ||
| 527 | + | ||
| 528 | + getAccess_token: function (a, s, n_tempmessage) { | ||
| 529 | + var that = this; | ||
| 530 | + wx.request({ | ||
| 531 | + url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + a + '&secret=' + s, //仅为示例,并非真实的接口地址 | ||
| 532 | + header: { | ||
| 533 | + 'content-type': 'application/json' | ||
| 534 | + }, | ||
| 535 | + success: function (res) { | ||
| 536 | + console.log('access_token!!!!console:', res) | ||
| 537 | + console.log('access_token:', res.data.access_token) | ||
| 538 | + that.sendMessage(res.data.access_token, n_tempmessage); | ||
| 539 | + } | ||
| 540 | + }) | ||
| 541 | + }, | ||
| 542 | + //模板消息 | ||
| 543 | + sendMessage: function (a_t, dd) { | ||
| 544 | + var that = this; | ||
| 545 | + wx.request({ | ||
| 546 | + url: 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=' + a_t, //仅为示例,并非真实的接口地址 | ||
| 547 | + data: dd, | ||
| 548 | + method: 'POST', | ||
| 549 | + header: { | ||
| 550 | + 'content-type': 'application/json' | ||
| 551 | + }, | ||
| 552 | + success: function (res) { | ||
| 553 | + console.log('发送模板消息:',res) | ||
| 554 | + //that.sendMessuc(res); | ||
| 555 | + } | ||
| 556 | + }) | ||
| 557 | + }, | ||
| 558 | + //获取当前网络状态 | ||
| 559 | + getNetwork:function(){ | ||
| 560 | + var that=this; | ||
| 561 | + if(this.wxApiIsUse('getNetworkType')){ | ||
| 562 | + wx.getNetworkType({ | ||
| 563 | + success: function(res) { | ||
| 564 | + that.getNetworkSuccess(res.networkType); | ||
| 565 | + }, | ||
| 566 | + fail:function(res){ | ||
| 567 | + that.toast('获取网络状况失败!'); | ||
| 568 | + } | ||
| 569 | + }) | ||
| 570 | + } | ||
| 571 | + }, | ||
| 572 | + getNetworkSuccess:function(network){ | ||
| 573 | + return network; | ||
| 574 | + }, | ||
| 575 | + compare:function(property){ | ||
| 576 | + return function(a,b){ | ||
| 577 | + var value1 = a[property]; | ||
| 578 | + var value2 = b[property]; | ||
| 579 | + return value1 - value2; | ||
| 580 | + } | ||
| 581 | + }, | ||
| 582 | + getJsonLength:function(jsonData){ | ||
| 583 | + var jsonLength = 0; | ||
| 584 | + for(var item in jsonData){ | ||
| 585 | + jsonLength++; | ||
| 586 | + } | ||
| 587 | + return jsonLength; | ||
| 588 | + }, | ||
| 589 | + testPhone:function(phone){ | ||
| 590 | + if(!/^1[3-9][0-9]{9}$/.test(phone)){ | ||
| 591 | + this.alert("请输入正确的电话号码"); | ||
| 592 | + return false; | ||
| 593 | + } | ||
| 594 | + }, | ||
| 595 | + //加入卡包 | ||
| 596 | + addInCard:function(sellerid){ | ||
| 597 | + var that = this; | ||
| 598 | + wx.request({ | ||
| 599 | + url: that.cgi(uri.CGI__USER_GETSIGNOPENCARD), | ||
| 600 | + method:'GET', | ||
| 601 | + header: { | ||
| 602 | + 'content-type': 'application/x-www-form-urlencoded' | ||
| 603 | + }, | ||
| 604 | + data:{ | ||
| 605 | + sellerid:1, | ||
| 606 | + }, | ||
| 607 | + success: function(res) { | ||
| 608 | + console.log(res) | ||
| 609 | + var cardExtstr = res.data.data.cardExt | ||
| 610 | + var cardId = res.data.data.cardid | ||
| 611 | + console.log('cardExtstr:',cardExtstr); | ||
| 612 | + wx.addCard({ | ||
| 613 | + cardList: [ | ||
| 614 | + { | ||
| 615 | + cardId: cardId, | ||
| 616 | + cardExt: cardExtstr, | ||
| 617 | + } | ||
| 618 | + ], | ||
| 619 | + success: function(res) { | ||
| 620 | + console.log('success:',res) | ||
| 621 | + that.cache('cardList',res.cardList); | ||
| 622 | + }, | ||
| 623 | + fail:function(res) { | ||
| 624 | + console.log('fail:',res) | ||
| 625 | + }, | ||
| 626 | + }) | ||
| 627 | + } | ||
| 628 | + }) | ||
| 629 | + }, | ||
| 630 | + //保存图片 | ||
| 631 | + saveImage: function(url){ | ||
| 632 | + var that = this; | ||
| 633 | + wx.downloadFile({ | ||
| 634 | + url:url, | ||
| 635 | + success:function(res){ | ||
| 636 | + var path = res.tempFilePath | ||
| 637 | + wx.saveImageToPhotosAlbum({ | ||
| 638 | + filePath: path, | ||
| 639 | + success(res) { | ||
| 640 | + | ||
| 641 | + }, | ||
| 642 | + //保存图片重新授权 | ||
| 643 | + fail(res) { | ||
| 644 | + wx.openSetting({ | ||
| 645 | + success: (res) => { | ||
| 646 | + res.authSetting = { | ||
| 647 | + "scope.writePhotosAlbum": true | ||
| 648 | + } | ||
| 649 | + } | ||
| 650 | + }) | ||
| 651 | + }, | ||
| 652 | + }) | ||
| 653 | + }, | ||
| 654 | + fail:function(res){ | ||
| 655 | + | ||
| 656 | + } | ||
| 657 | + }) | ||
| 658 | + }, | ||
| 659 | + //根据source判断会员卡1 或优惠券2 | ||
| 660 | + sourceFrom:function(){ | ||
| 661 | + var source = this.cache('source') | ||
| 662 | + console.log('source:',source) | ||
| 663 | + var title = '' | ||
| 664 | + if(source==1){ | ||
| 665 | + title = '会员卡' | ||
| 666 | + }else{ | ||
| 667 | + title = '优惠券' | ||
| 668 | + } | ||
| 669 | + wx.setNavigationBarTitle({ | ||
| 670 | + title:title | ||
| 671 | + }) | ||
| 672 | + return source | ||
| 673 | + }, | ||
| 674 | + //返回会员卡 优惠券的开通进度 | ||
| 675 | + stepSetting:function(stepnum){ | ||
| 676 | + var source = this.cache('source') | ||
| 677 | + var step = { | ||
| 678 | + content:['会员卡开通','会员卡设置','发放确认','发放完成'], | ||
| 679 | + step:[{id:'0'},{id:'1'},{id:'2'},{id:'3'}], | ||
| 680 | + stepnum:stepnum | ||
| 681 | + } | ||
| 682 | + if(step&&source==2){ | ||
| 683 | + step.content[0] = '优惠券开通' | ||
| 684 | + step.content[1] = '优惠券设置' | ||
| 685 | + } | ||
| 686 | + return step | ||
| 687 | + }, | ||
| 688 | + setBarTitle:function(title){ | ||
| 689 | + wx.setNavigationBarTitle({ | ||
| 690 | + title:title | ||
| 691 | + }) | ||
| 692 | + }, | ||
| 693 | + //小数规则:小数只能存在一个小数点并且至多保留两位小数 数字首位可以为0 第二位不能为0 | ||
| 694 | + limitDigit:function(value,firsezero){ | ||
| 695 | + if(value.length==1&value=='.'){ | ||
| 696 | + value = '0'+'.' | ||
| 697 | + } | ||
| 698 | + if(value=='00'){ | ||
| 699 | + value = '0' | ||
| 700 | + } | ||
| 701 | + value = value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的 | ||
| 702 | + value = value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); | ||
| 703 | + value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数 | ||
| 704 | + //firsezero存在 首位不能为0 | ||
| 705 | + if(firsezero){ | ||
| 706 | + if(value.indexOf(".")< 0 && value !=""){//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额 | ||
| 707 | + value= parseFloat(value); | ||
| 708 | + } | ||
| 709 | + } | ||
| 710 | + return value | ||
| 711 | + }, | ||
| 712 | + | ||
| 713 | + // | ||
| 714 | + isEOne : function(arr,value){ | ||
| 715 | + for(var i = 0,vlen = arr.length; i < vlen; i++){ | ||
| 716 | + if(arr[i] == value){ | ||
| 717 | + return i; | ||
| 718 | + } | ||
| 719 | + } | ||
| 720 | + return -1; | ||
| 721 | + }, | ||
| 722 | + linkTo:function(url,sellerid,code){ | ||
| 723 | + var path='pages/menu/'+url; | ||
| 724 | + if(code!=''){ | ||
| 725 | + path+='?sellerid='+sellerid+'&code='+code | ||
| 726 | + } | ||
| 727 | + if(sellerid!=''){ | ||
| 728 | + path+='?sellerid='+sellerid | ||
| 729 | + } | ||
| 730 | + console.log(path) | ||
| 731 | + wx.navigateToMiniProgram({ | ||
| 732 | + appId: 'wx52646daaa3f42a4f', | ||
| 733 | + path: path, | ||
| 734 | + envVersion: 'release', | ||
| 735 | + success:function(res) { | ||
| 736 | + console.log(path) | ||
| 737 | + } | ||
| 738 | + }) | ||
| 739 | + }, | ||
| 740 | + setting:function(){ | ||
| 741 | + if(wx.canIUse('openSetting')==true){ | ||
| 742 | + wx.openSetting({ | ||
| 743 | + success:function(res){ | ||
| 744 | + console.log(res.authSetting) | ||
| 745 | + return res.authSetting | ||
| 746 | + } | ||
| 747 | + }) | ||
| 748 | + } | ||
| 749 | + }, | ||
| 750 | + //获取设备信息 | ||
| 751 | + getsystem:function(){ | ||
| 752 | + try { | ||
| 753 | + var res = wx.getSystemInfoSync() | ||
| 754 | + return res; | ||
| 755 | + } catch (e) { | ||
| 756 | + return false | ||
| 757 | + } | ||
| 758 | + }, | ||
| 759 | + http_build_query(obj,url=''){ | ||
| 760 | + let ps=[] | ||
| 761 | + for(let i in obj){ | ||
| 762 | + if(typeof obj[i]=='undefined' || obj[i]==null) continue; | ||
| 763 | + ps.push(i+'='+obj[i].toString()) | ||
| 764 | + } | ||
| 765 | + ps=ps.join('&'); | ||
| 766 | + if(!url){ | ||
| 767 | + return ps; | ||
| 768 | + } | ||
| 769 | + url+=(url.indexOf('?')>-1?'&':'?')+ps; | ||
| 770 | + return url; | ||
| 771 | + } | ||
| 772 | +} | ||
| 773 | + | ||
| 774 | + | ||
| 775 | + | ||
| 776 | + | ||
| 777 | + | ||
| 778 | + | ||
| 779 | + |
-
Please register or login to post a comment