// pages/home/customer-info/index.js import Scene from '../../index/scene' import { getCustomerInfo } from "../../../api/saas" const util = require('../../../utils/util') const event = require('../../../utils/event') const qrCode = require('../../../utils/weapp-qrcode') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { id: null, userId: null, form: null, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(!util.isEmpty(options.id)){ this.data.id = options.id this.data.userId = options.userId this.fetchCustomerInfo() } event.on('EventMessage', this, this.onEvent) }, onEvent: function(message){ if (message.what == 101) { wx.navigateBack() } else if (message.what == 102) { this.fetchCustomerInfo() } }, fetchCustomerInfo: function(){ wx.showLoading({ title: '正在获取', mask: true }) getCustomerInfo(this.data.id).then(result => { wx.hideLoading() this.setData({ form: result.data }) this.showQrCode(`?mark=ztb_saas&QrCodeRecordId=${this.data.id}` ) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, rpx2px: function(rpx) { return rpx / 750 * app.globalData.windowWidth }, showQrCode: function(text){ new qrCode('van-qrcode', { text: text, width: this.rpx2px(600), height: this.rpx2px(600), colorDark: "#333333", colorLight: "#FFFFFF", correctLevel: qrCode.CorrectLevel.H }) }, previewImage: function(){ wx.canvasToTempFilePath({ canvasId: 'van-qrcode', success: (res) => { wx.previewImage({ urls: [res.tempFilePath] }) } }) }, customerInfo: function(){ wx.navigateTo({ url: `/pages/home/customer-info/index?id=${this.data.id}&userId=${this.data.userId}` }) }, onUnload: function(){ event.remove('EventMessage', this) } })