workbench.js 5.4 KB

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