123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- // 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) {
- setTimeout(() => {
- that.setData({
- scanFlag: true
- })
- }, 400);
- }
- }
- })
- })
- },
- bindscanerror () {
- wx.showModal({
- content: '请打开相机权限',
- confirmColor: '#333',
- showCancel: false,
- success (auth) {
- if (auth.confirm) {
- wx.openSetting({
- success (res) {
- console.log(res.authSetting)
- }
- })
- }
- }
- })
- }
- })
|