// StepPage/pages/qrCode/qrCode.js var qrcode = require('./weapp.qrcode.min'); Page({ /** * 页面的初始数据 */ data: { ishow:false, show:false, mobile:'', searchList:[], searchValue:'', title:'', shopList:[], chooseList:[{four_shop_id:'',expires_time:''}], chooseIndex:0, state:true }, handleChoose(item){ let arr = JSON.parse(JSON.stringify(this.data.chooseList)); arr[this.data.chooseIndex].title = item.target.dataset.item.title; arr[this.data.chooseIndex].four_shop_id = item.target.dataset.item.id; this.setData({ ishow:false, chooseList:arr }) }, handleCancel(){ this.setData({ ishow:false }) }, handleSearch(e){ this.setData({ ishow:true, chooseIndex:e.target.dataset.index, searchList:this.data.shopList }) }, handleAdd(data){ let arr = this.data.chooseList; arr.splice(data.target.dataset.index+1,0,{title:'',four_shop_id:'',expires_time:''}); this.setData({ chooseList:arr }) }, handleDelete(data){ let arr = this.data.chooseList; if(arr.length==1){ arr = [{title:'',four_shop_id:'',expires_time:''}] }else{ arr.splice(data.target.dataset.index,1); } this.setData({ chooseList:arr }) }, onSearch(event){ let arr = this.data.shopList.filter(v=>v.title.indexOf(event.detail)!=-1); this.setData({ searchList:arr }) }, bindDateChange(e){ let arr = JSON.parse(JSON.stringify(this.data.chooseList)); arr[e.target.dataset.index].expires_time = e.detail.value; this.setData({ chooseList:arr }) }, onClose() { this.setData({ show: false }); }, handleBack(){ wx.redirectTo({ url: '../../../pages/zero/zero', }) }, handleChangeMobile(e){ this.setData({ mobile:e.detail }) }, handleNext(){ if(!this.data.mobile||this.data.chooseList.length==0){ return wx.showToast({ icon:'error', title: '请填写信息', }) } if (!/^1[3456789]\d{9}$/.test(this.data.mobile)) { return wx.showToast({ icon:'error', title: '手机格式不对', }) } if(this.data.state){ this.setData({ state:false }) let app = getApp(); let openid = app.globalData.openID; let arr =[] this.data.chooseList.forEach(ele => { let obj = {}; obj.four_shop_id = ele.four_shop_id; obj.expires_time = ele.expires_time?(new Date(new Date(ele.expires_time).toLocaleDateString()).getTime()+86400000-1).toString().slice(0,10):'' arr.push(obj); }); wx.p.request({ url: `${app.globalData.url}wx/createTemporaryJs`, method:'POST', data:{ openid, mobile:this.data.mobile, four_shop:arr } }).then(res=>{ if(res.data.code==200){ this.setData({ show:true }) qrcode({ width:200, height:200, canvasId:'myQrcode', text:`https://zhapi.qingyaokeji.com`, callback:function(){ } }) }else{ wx.showToast({ icon:'none', title: res.data.msg, }) } setTimeout(()=>{ this.setData({ state:true }) },2000) }) } }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let app = getApp(); let openid = app.globalData.openID; wx.p.request({ url: `${app.globalData.url}wx/fourShop`, method:'POST', data:{ openid } }).then(res=>{ if(res.data.code==200){ let shopList = res.data.data this.setData({ shopList:shopList }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })