workbench.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // pages/workbench/workbench.js
  2. import { writeOffOrder, confirmOrder } from '../../api/workbench'
  3. import { bindCar } from '../../api/permission'
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. scanFlag: true,
  11. overlayShow: false,
  12. deviceName: 'XX',
  13. userName: '',
  14. headImg: '',
  15. workerId: '',
  16. personName: '',
  17. personSex: true,
  18. birthday: '',
  19. orderId: '',
  20. orderNo: '',
  21. age: '',
  22. useNum: ''
  23. },
  24. onLoad (options) {
  25. this.getInitData(options)
  26. },
  27. getInitData (data) {
  28. this.setData({
  29. deviceName: data.deviceName ? data.deviceName : '',
  30. userName: app.globalData.userName,
  31. headImg: app.globalData.headImg,
  32. workerId: app.globalData.workerId
  33. })
  34. },
  35. /**
  36. * 生命周期函数--监听页面显示
  37. */
  38. onShow() {
  39. if (!app.globalData.accessToken) {
  40. wx.showModal({
  41. content: '请先登录',
  42. confirmColor: '#333',
  43. showCancel: false,
  44. success (scanres) {
  45. if (scanres.confirm) {
  46. wx.redirectTo({
  47. url: '/pages/login/login'
  48. })
  49. }
  50. }
  51. })
  52. }
  53. },
  54. // 拉起微信扫一扫,扫描用户档案二维码
  55. handleWxScanUser () {
  56. var that = this
  57. wx.scanCode({
  58. onlyFromCamera: true,
  59. success (scanRes) {
  60. that.handleScanUser(scanRes.result)
  61. }
  62. })
  63. },
  64. // 处理扫描用户二维码
  65. handleScanUser (response) {
  66. var scodeType = response.split('|')[0] == 'DOCUMENT' ? true : false
  67. if (!scodeType) {
  68. wx.showModal({
  69. content: '请扫描正确的二维码',
  70. confirmColor: '#333',
  71. showCancel: false
  72. })
  73. } else {
  74. // DOCUMENT|documentId|uuid
  75. var successScanTimer = setTimeout(() => {
  76. var documentId = response.split('|')[1]
  77. var uuid = response.split('|')[2]
  78. this.writeOffOrderFn(documentId, uuid)
  79. clearTimeout(successScanTimer)
  80. }, 500);
  81. }
  82. },
  83. // 核销用户检测次数
  84. writeOffOrderFn (documentId = '', uuid = '') {
  85. var that = this
  86. var data = {
  87. documentId: documentId,
  88. uuid: uuid
  89. }
  90. wx.showLoading({
  91. title: '加载中...',
  92. })
  93. writeOffOrder(data).then(res => {
  94. wx.hideLoading()
  95. const response = res.data
  96. if (response.useNum == 0) {
  97. wx.showModal({
  98. content: '该用户检测次数为0,提示充值',
  99. confirmColor: '#333',
  100. showCancel: false
  101. })
  102. } else {
  103. that.setData({
  104. orderNo: response.orderNo,
  105. orderId: response.orderId,
  106. personName: response.personName,
  107. personSex: response.personSex,
  108. birthday: response.birthday,
  109. age: response.age,
  110. useNum: response.useNum,
  111. overlayShow: true
  112. })
  113. }
  114. }).catch(e => {
  115. wx.hideLoading()
  116. wx.showModal({
  117. content: e.msg,
  118. confirmColor: '#333',
  119. showCancel: false
  120. })
  121. })
  122. },
  123. // 取消用户扫描结果
  124. handlecancel() {
  125. this.setData({
  126. overlayShow: false
  127. })
  128. },
  129. // 提交用户扫描结果
  130. handlesubmit() {
  131. var that =this
  132. var data = {
  133. orderId: this.data.orderId
  134. }
  135. wx.showLoading({
  136. title: '加载中...',
  137. mask: true
  138. })
  139. confirmOrder(data).then(res => {
  140. wx.hideLoading()
  141. wx.showToast({
  142. title: res.msg,
  143. icon: 'success'
  144. })
  145. that.setData({
  146. overlayShow: false
  147. })
  148. }).catch(e => {
  149. wx.hideLoading()
  150. wx.showModal({
  151. content: e.msg,
  152. confirmColor: '#333',
  153. showCancel: false
  154. })
  155. })
  156. },
  157. // 拉起微信扫一扫,扫车辆 获取新车权限
  158. handleWXScanDevice () {
  159. var that = this
  160. wx.scanCode({
  161. onlyFromCamera: true,
  162. success (scanRes) {
  163. that.handleScanDevice(scanRes.result)
  164. }
  165. })
  166. },
  167. // 处理扫描的设备二维码
  168. handleScanDevice (response) {
  169. var that = this
  170. var scodeType = response.split('|')[0] == 'DEVICE' ? true : false
  171. if (!scodeType) {
  172. wx.showModal({
  173. content: '请扫描正确的设备二维码',
  174. confirmColor: '#333',
  175. showCancel: false
  176. })
  177. } else {
  178. // DEVICE|deviceCode|nonceCode|timeStamp
  179. var deviceTimer = setTimeout(() => {
  180. var deviceCode = response.split('|')[1]
  181. var nonceCode = response.split('|')[2]
  182. var timeStamp = response.split('|')[3]
  183. that.bindCarFn(deviceCode, nonceCode, timeStamp)
  184. clearTimeout(deviceTimer)
  185. }, 500);
  186. }
  187. },
  188. // 绑定设备
  189. bindCarFn (deviceCode = '', nonceCode = '', timeStamp = '') {
  190. var that = this
  191. var data = {
  192. deviceCode: deviceCode,
  193. nonceCode: nonceCode,
  194. timeStamp: timeStamp
  195. }
  196. wx.showLoading({
  197. title: '绑定中...',
  198. mask: true
  199. })
  200. bindCar(data).then(scanres => {
  201. // 绑定成功到扫描档案页面
  202. wx.hideLoading()
  203. wx.showModal({
  204. content: '权限登录成功',
  205. confirmColor: '#333',
  206. showCancel: false,
  207. success (pres) {
  208. if (pres.confirm) {
  209. that.setData({
  210. deviceName: scanres.data.deviceName
  211. })
  212. }
  213. }
  214. })
  215. }).catch(e => {
  216. wx.hideLoading()
  217. wx.showModal({
  218. content: e.msg,
  219. confirmColor: '#333',
  220. showCancel: false
  221. })
  222. })
  223. },
  224. })