workbench.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. that.setData({
  98. orderNo: response.orderNo,
  99. orderId: response.orderId,
  100. personName: response.personName,
  101. personSex: response.personSex,
  102. birthday: response.birthday,
  103. age: response.age,
  104. useNum: response.useNum,
  105. overlayShow: true
  106. })
  107. }).catch(e => {
  108. wx.hideLoading()
  109. wx.showModal({
  110. content: e.msg,
  111. confirmColor: '#333',
  112. showCancel: false
  113. })
  114. })
  115. },
  116. // 取消用户扫描结果
  117. handlecancel() {
  118. this.setData({
  119. overlayShow: false
  120. })
  121. },
  122. // 提交用户扫描结果
  123. handlesubmit() {
  124. var that =this
  125. var data = {
  126. orderId: this.data.orderId
  127. }
  128. wx.showLoading({
  129. title: '加载中...',
  130. mask: true
  131. })
  132. confirmOrder(data).then(res => {
  133. wx.hideLoading()
  134. wx.showToast({
  135. title: res.msg,
  136. icon: 'success'
  137. })
  138. that.setData({
  139. overlayShow: false
  140. })
  141. }).catch(e => {
  142. wx.hideLoading()
  143. wx.showModal({
  144. content: e.msg,
  145. confirmColor: '#333',
  146. showCancel: false
  147. })
  148. })
  149. },
  150. // 拉起微信扫一扫,扫车辆 获取新车权限
  151. handleWXScanDevice () {
  152. wx.redirectTo({
  153. url: '/pages/permissions/permissions'
  154. })
  155. /* var that = this
  156. wx.scanCode({
  157. onlyFromCamera: true,
  158. success (scanRes) {
  159. that.handleScanDevice(scanRes.result)
  160. }
  161. }) */
  162. },
  163. // 处理扫描的设备二维码
  164. handleScanDevice (response) {
  165. var that = this
  166. var scodeType = response.split('|')[0] == 'DEVICE' ? true : false
  167. if (!scodeType) {
  168. wx.showModal({
  169. content: '请扫描正确的设备二维码',
  170. confirmColor: '#333',
  171. showCancel: false
  172. })
  173. } else {
  174. // DEVICE|deviceCode|nonceCode|timeStamp
  175. var deviceTimer = setTimeout(() => {
  176. var deviceCode = response.split('|')[1]
  177. var nonceCode = response.split('|')[2]
  178. var timeStamp = response.split('|')[3]
  179. that.bindCarFn(deviceCode, nonceCode, timeStamp)
  180. clearTimeout(deviceTimer)
  181. }, 500);
  182. }
  183. },
  184. // 绑定设备
  185. bindCarFn (deviceCode = '', nonceCode = '', timeStamp = '') {
  186. var that = this
  187. var data = {
  188. deviceCode: deviceCode,
  189. nonceCode: nonceCode,
  190. timeStamp: timeStamp
  191. }
  192. wx.showLoading({
  193. title: '绑定中...',
  194. mask: true
  195. })
  196. bindCar(data).then(scanres => {
  197. // 绑定成功到扫描档案页面
  198. wx.hideLoading()
  199. wx.showModal({
  200. content: '权限登录成功',
  201. confirmColor: '#333',
  202. showCancel: false,
  203. success (pres) {
  204. if (pres.confirm) {
  205. that.setData({
  206. deviceName: scanres.data.deviceName
  207. })
  208. }
  209. }
  210. })
  211. }).catch(e => {
  212. wx.hideLoading()
  213. wx.showModal({
  214. content: e.msg,
  215. confirmColor: '#333',
  216. showCancel: false
  217. })
  218. })
  219. },
  220. })