workbench.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // pages/workbench/workbench.js
  2. import { writeOffOrder, confirmOrder } from '../../api/workbench'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. scanFlag: true,
  10. overlayShow: false,
  11. deviceName: '',
  12. userName: '',
  13. headImg: '',
  14. workerId: '',
  15. personName: '',
  16. personSex: true,
  17. birthday: '',
  18. orderId: '',
  19. orderNo: ''
  20. },
  21. onLoad (options) {
  22. this.getInitData(options)
  23. },
  24. getInitData (data) {
  25. this.setData({
  26. deviceName: data.deviceName ? data.deviceName : '',
  27. userName: app.globalData.userName,
  28. headImg: app.globalData.headImg,
  29. workerId: app.globalData.workerId
  30. })
  31. },
  32. handlecancel() {
  33. this.setData({
  34. overlayShow: false
  35. })
  36. },
  37. handlesubmit() {
  38. var data = {
  39. orderId: this.data.orderId
  40. }
  41. wx.showLoading({
  42. title: '加载中...',
  43. mask: true
  44. })
  45. confirmOrder(data).then(res => {
  46. wx.hideLoading()
  47. wx.showToast({
  48. title: res.msg,
  49. icon: 'success'
  50. })
  51. }).catch(e => {
  52. wx.hideLoading()
  53. wx.showModal({
  54. content: e.msg,
  55. confirmColor: '#333',
  56. showCancel: false
  57. })
  58. })
  59. },
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow() {
  64. if (!app.globalData.accessToken) {
  65. wx.showModal({
  66. content: '请先登录',
  67. confirmColor: '#333',
  68. showCancel: false,
  69. success (scanres) {
  70. if (scanres.confirm) {
  71. wx.redirectTo({
  72. url: '/pages/login/login'
  73. })
  74. }
  75. }
  76. })
  77. }
  78. },
  79. bindscancode (e) {
  80. var that = this
  81. if (that.data.scanFlag) {
  82. var response = e.detail.result
  83. console.log(response, 'response');
  84. var scodeType = response.split('|')[0] == 'DOCUMENT' ? true : false
  85. if (!scodeType) {
  86. that.setData({
  87. scanFlag: false
  88. })
  89. wx.showModal({
  90. content: '请扫描正确的二维码',
  91. confirmColor: '#333',
  92. showCancel: false,
  93. success (scanres) {
  94. if (scanres.confirm) {
  95. that.setData({
  96. scanFlag: true
  97. })
  98. }
  99. }
  100. })
  101. } else {
  102. // DOCUMENT|documentId|uuid
  103. var documentId = response.split('|')[1]
  104. var uuid = response.split('|')[2]
  105. that.writeOffOrderFn(documentId, uuid)
  106. }
  107. }
  108. },
  109. writeOffOrderFn (documentId = '', uuid = '') {
  110. var that = this
  111. var data = {
  112. documentId: documentId,
  113. uuid: uuid
  114. }
  115. wx.showLoading({
  116. title: '加载中...',
  117. mask: true
  118. })
  119. writeOffOrder(data).then(res => {
  120. console.log(res, 'writeOffOrder');
  121. that.setData({
  122. scanFlag: true,
  123. orderNo: res.data.orderNo,
  124. orderId: res.data.orderId,
  125. personName: res.data.personName,
  126. personSex: res.data.personSex,
  127. birthday: res.data.birthday,
  128. overlayShow: true
  129. })
  130. }).catch(e => {
  131. that.setData({
  132. scanFlag: false
  133. })
  134. wx.hideLoading()
  135. wx.showModal({
  136. content: e.msg,
  137. confirmColor: '#333',
  138. showCancel: false,
  139. confirmText: '重新扫描',
  140. success (res) {
  141. if (res.confirm) {
  142. var timer = setTimeout(() => {
  143. that.setData({
  144. scanFlag: true
  145. })
  146. clearTimeout(timer)
  147. }, 400);
  148. }
  149. }
  150. })
  151. })
  152. },
  153. bindscanerror () {
  154. wx.showModal({
  155. content: '请打开相机权限',
  156. confirmColor: '#333',
  157. showCancel: false,
  158. success (auth) {
  159. if (auth.confirm) {
  160. wx.openSetting({
  161. success (res) {
  162. console.log(res.authSetting)
  163. }
  164. })
  165. }
  166. }
  167. })
  168. }
  169. })