纸通宝SAAS仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

94 lines
2.6 KiB

// pages/home/customer-info/index.js
import Scene from '../../index/scene'
import { getCustomerInfo } from "../../../api/saas"
import { getEmplyeeInfo } from "../../../api/user"
const util = require('../../../utils/util')
const event = require('../../../utils/event')
const qrCode = require('../../../utils/weapp-qrcode')
const app = getApp()
Scene({
/**
* 页面的初始数据
*/
data: {
type: 0,
id: null,
userId: null,
form: null,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(!util.isEmpty(options.id)){
this.data.id = options.id
this.data.userId = options.userId
if(!util.isEmpty(options.type)){
this.data.type = Number(options.type)
}
if(this.data.type == 0){
this.fetchCustomerInfo()
} else if(this.data.type == 1){
this.fetchEmplyeeInfo()
}
}
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, type: this.data.type })
this.showQrCode(`?mark=ztb_saas&QrCodeRecordId=${this.data.id}` )
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
fetchEmplyeeInfo: function(){
wx.showLoading({ title: '正在获取', mask: true })
getEmplyeeInfo(this.data.id).then(result => {
wx.hideLoading()
this.setData({ form: result.data, type: this.data.type })
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)
}
})