| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- // 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() {
- }
- })
|