纸通宝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.
 

102 lines
2.9 KiB

// 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()
const qrUrl = 'https://apicloudprint.qniao.cn/cloud-print-user-center/verify/qrcode'
Scene({
/**
* 页面的初始数据
*/
data: {
type: 0,
id: null,
userId: null,
form: null,
factoryName: null,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.id){
this.data.id = options.id
this.data.userId = options.userId
if(!util.isEmpty(options.type)){
this.data.type = Number(options.type)
}
this.showQrCode(`${qrUrl}?mark=ztb_saas&type=${this.data.type}&factoryId=${app.userInfo.factoryId}&uid=${this.data.id}`)
if(this.data.type == 0){
this.fetchCustomerInfo()
} else if(this.data.type == 1){
let channel = this.getOpenerEventChannel()
let that = this
channel.once('onParam', function (data) {
that.setData({ form: data, type: that.data.type, factoryName: app.userInfo.factoryName })
})
}
}
event.on('EventMessage', this, this.onEvent)
},
onEvent: function(message){
if (message.what == 120) {
wx.navigateBack()
} else if (message.what == 102) {
if(this.data.type == 0){
this.fetchCustomerInfo()
} else if(this.data.type == 1){
wx.navigateBack()
}
}
},
fetchCustomerInfo: function(){
wx.showLoading({ title: '正在获取', mask: true })
getCustomerInfo(this.data.id).then(result => {
this.setData({ form: result.data, type: this.data.type, factoryName: app.userInfo.factoryName })
wx.hideLoading()
}).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] })
}
})
},
lookDetail: function(){
if(this.data.type == 0){
wx.navigateTo({ url: `/pages/home/customer-info/index?id=${this.data.id}&userId=${this.data.userId}` })
} else if(this.data.type == 1){
var that = this
wx.navigateTo({
url: `/pages/home/employee-info/index?id=${this.data.id}`,
success: function(res) {
res.eventChannel.emit('onParam', that.data.form)
}
})
}
},
onUnload: function(){
event.remove('EventMessage', this)
}
})