// packageA/pages/details_serviceCard/details_serviceCard.js const app = getApp(); // const os = app.globalData.setting; let self = null; // 防抖函数用定时器 let timer; const { barcode, qrcode } = require('../../../utils/index.js'); Page({ /** * 页面的初始数据 */ data: { // is_summit_ing: 0, showQr: false, }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { self = this; this.setData({ options, }); // this.data.options = options; app.isLogin().then(function(data) { self.setData({ userInfo: data, }); wx.setNavigationBarTitle({ title: options.title, }); // self.getConfig(); }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { console.log('show~~~'); if (app.globalData.userInfo) { if (!this.data.isLogin) { this.setData({ userInfo: app.globalData.userInfo, imghost: app.globalData.setting.imghost, isLogin: true, }); let url = '/api/weshop/serviceGoods/list' let data = { store_id: app.globalData.setting.stoid, service_id: this.data.options.service_id, }; // 请求数据 app.promiseGet(url, { data: data, }).then(res => { if (res.data.code == 0) { console.log('请求成功', res); this.setData({ details: res.data.data, }); } else { throw (res); }; }).catch(err => { // wx.showToast({ // title: err.data.data, // icon: 'error', // }); }); }; }; }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { }, // 图片异常时加载默认图片 bind_bnerr(e) { var errImg = e.currentTarget.dataset.errorimg; var errObj = {}; errObj[errImg] = 'public/images/default_goods_image_240.gif'; this.setData(errObj); // this.setData({ details.list[0].img_url}); }, createQr() { wx.showLoading({ title:'生成核销码中', }); let store_id = app.globalData.setting.stoid; let id = this.data.options.id; let url = `/api/weshop/rechargeServicelist/update/${store_id}/${id}`; app.request.put(url, { data: {}, success: function(res) { wx.hideLoading(); if(res.data.code == 0) { let verify_code = res.data.data.verify_code; self.qrcode(verify_code); self.setData({ verify_code, showQr: true, }); }; } }); }, showQr() { this.debounce(this.createQr, 300)(); }, closeQr() { this.setData({ showQr: false, }); // 关闭二维码弹窗后,检测核销情况,改变按钮状态 wx.showLoading({ title: '刷新中', mask: true, }); let store_id = app.globalData.setting.stoid; let id = this.data.options.id; let url = `/api/weshop/rechargeServicelist/update/${store_id}/${id}`; app.request.put(url, { data: {}, success: function(res) { wx.hideLoading(); if(res.data.code == 0) { // console.log('xxx000', res.data.data.use_state); self.setData({ ['options.usestate']: res.data.data.use_state, }); }; } }); }, /** * 生成二维码 * by sty */ qrcode:function(val){ barcode('barcode', val, 600,140); qrcode('qrcode', val, 300, 300); }, touchMove() {}, // 函数防抖 debounce(func, wait) { return () => { clearTimeout(timer); timer = setTimeout(func, wait); }; }, })