// pages/workbench/workbench.js import { writeOffOrder, confirmOrder } from '../../api/workbench' const app = getApp() Page({ /** * 页面的初始数据 */ data: { scanFlag: true, overlayShow: false, deviceName: '', userName: '', headImg: '', workerId: '', personName: '', personSex: true, birthday: '', orderId: '', orderNo: '' }, onLoad (options) { this.getInitData(options) }, getInitData (data) { this.setData({ deviceName: data.deviceName ? data.deviceName : '', userName: app.globalData.userName, headImg: app.globalData.headImg, workerId: app.globalData.workerId }) }, handlecancel() { this.setData({ overlayShow: false }) }, handlesubmit() { var data = { orderId: this.data.orderId } wx.showLoading({ title: '加载中...', mask: true }) confirmOrder(data).then(res => { wx.hideLoading() wx.showToast({ title: res.msg, icon: 'success' }) }).catch(e => { wx.hideLoading() wx.showModal({ content: e.msg, confirmColor: '#333', showCancel: false }) }) }, /** * 生命周期函数--监听页面显示 */ onShow() { if (!app.globalData.accessToken) { wx.showModal({ content: '请先登录', confirmColor: '#333', showCancel: false, success (scanres) { if (scanres.confirm) { wx.redirectTo({ url: '/pages/login/login' }) } } }) } }, bindscancode (e) { var that = this if (that.data.scanFlag) { var response = e.detail.result console.log(response, 'response'); var scodeType = response.split('|')[0] == 'DOCUMENT' ? true : false if (!scodeType) { that.setData({ scanFlag: false }) wx.showModal({ content: '请扫描正确的二维码', confirmColor: '#333', showCancel: false, success (scanres) { if (scanres.confirm) { that.setData({ scanFlag: true }) } } }) } else { // DOCUMENT|documentId|uuid var documentId = response.split('|')[1] var uuid = response.split('|')[2] that.writeOffOrderFn(documentId, uuid) } } }, writeOffOrderFn (documentId = '', uuid = '') { var that = this var data = { documentId: documentId, uuid: uuid } wx.showLoading({ title: '加载中...', mask: true }) writeOffOrder(data).then(res => { console.log(res, 'writeOffOrder'); that.setData({ scanFlag: true, orderNo: res.data.orderNo, orderId: res.data.orderId, personName: res.data.personName, personSex: res.data.personSex, birthday: res.data.birthday, overlayShow: true }) }).catch(e => { that.setData({ scanFlag: false }) wx.hideLoading() wx.showModal({ content: e.msg, confirmColor: '#333', showCancel: false, confirmText: '重新扫描', success (res) { if (res.confirm) { var timer = setTimeout(() => { that.setData({ scanFlag: true }) clearTimeout(timer) }, 400); } } }) }) }, bindscanerror () { wx.showModal({ content: '请打开相机权限', confirmColor: '#333', showCancel: false, success (auth) { if (auth.confirm) { wx.openSetting({ success (res) { console.log(res.authSetting) } }) } } }) } })