scanCode.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import tool from "../../utils/tool"
  2. import {
  3. get,
  4. post
  5. } from '../../utils/http.js'
  6. // 移动动画
  7. let animation = wx.createAnimation({});
  8. Page({
  9. data: {
  10. codeList: [], //手机
  11. qrCodeList: [], //耳机
  12. userName: '',
  13. remarks: '',
  14. nowCode: '',
  15. type: '',
  16. popupShow: false,
  17. againDelete: false,
  18. deleteOverData: false
  19. },
  20. onLoad: function () {
  21. },
  22. onShow() {
  23. this.donghua()
  24. },
  25. donghua() {
  26. var that = this;
  27. // 控制向上还是向下移动
  28. let m = true
  29. setInterval(function () {
  30. if (m) {
  31. animation.translateY(230).step({
  32. duration: 3000
  33. })
  34. m = !m;
  35. } else {
  36. animation.translateY(0).step({
  37. duration: 3000
  38. })
  39. m = !m;
  40. }
  41. that.setData({
  42. animation: animation.export()
  43. })
  44. }.bind(this), 3000)
  45. },
  46. /**
  47. * 扫码,延时器
  48. */
  49. scancode: tool.debounce(function (e) {
  50. // 校验扫描结果,并处理
  51. let code = e[0].detail.result
  52. // 提示音
  53. let innerAudioContext = wx.createInnerAudioContext()
  54. innerAudioContext.src = '/audio/scanCode.mp3'
  55. innerAudioContext.play()
  56. console.log(e[0].detail);
  57. if (this.data.codeList.length == 0 && this.data.qrCodeList.length == 0) {
  58. this.setData({
  59. type: e[0].detail.type
  60. })
  61. } else {
  62. if (e[0].detail.type != this.data.type) {
  63. wx.showToast({
  64. title: '同一批次只能入库相同的设备',
  65. icon: 'none'
  66. })
  67. return
  68. }
  69. }
  70. console.log('code',code);
  71. if (e[0].detail.type == "barcode") {
  72. console.log('code2',code);
  73. var result = this.data.codeList.some(item => item.imei == code)
  74. if (!result) {
  75. console.log('code1',code);
  76. post('get_phone_info', {
  77. imei: code
  78. }, res => {
  79. console.log(res,'resres');
  80. if (res.code == 200) {
  81. let arr = this.data.codeList
  82. arr.unshift(res.data)
  83. this.setData({
  84. codeList: arr
  85. })
  86. }else{
  87. console.log('tanchuang ');
  88. wx.showToast({
  89. title: '没有找到该设备',
  90. icon: 'none'
  91. })
  92. }
  93. })
  94. } else {
  95. wx.showToast({
  96. title: '重复扫码。',
  97. icon: 'error'
  98. })
  99. }
  100. } else {
  101. if (JSON.stringify(this.data.qrCodeList).indexOf(code) == -1) {
  102. let arr = this.data.qrCodeList
  103. arr.unshift(code)
  104. this.setData({
  105. qrCodeList: arr
  106. })
  107. } else {
  108. wx.showToast({
  109. title: '重复扫码。',
  110. icon: 'error'
  111. })
  112. }
  113. }
  114. }, 500),
  115. warehousing() {
  116. this.setData({
  117. popupShow: true
  118. })
  119. },
  120. onOpenShow() {
  121. this.setData({
  122. popupShow: true
  123. })
  124. },
  125. /**
  126. * 入库
  127. */
  128. onAddCode() {
  129. if (this.data.userName.length == 0) {
  130. wx.showToast({
  131. title: '请输入客户名',
  132. icon: 'error'
  133. })
  134. return
  135. }
  136. let imeiList = []
  137. this.data.codeList.forEach(item => {
  138. imeiList.push(item.imei)
  139. })
  140. wx.showLoading({
  141. title: '入库中...',
  142. })
  143. let that = this
  144. post('save_box_info', {
  145. ids: this.data.type == 'barcode' ? imeiList : this.data.qrCodeList,
  146. name: this.data.userName,
  147. comment: this.data.remarks,
  148. type:this.data.type
  149. }, res => {
  150. if (res.code == 200) {
  151. setTimeout(function () {
  152. wx.hideLoading()
  153. wx.showToast({
  154. title: `成功入库${res.cnt}台设备`,
  155. icon: 'error'
  156. })
  157. that.setData({
  158. popupShow:false
  159. })
  160. that.clearData()
  161. }, 2000)
  162. }
  163. })
  164. },
  165. onCloseShow() {
  166. this.setData({
  167. popupShow: false,
  168. codeInfo: ''
  169. })
  170. },
  171. onDelete(e) {
  172. this.setData({
  173. nowCode: e.currentTarget.dataset.index,
  174. againDelete: true
  175. })
  176. },
  177. /**
  178. * 删除单条录入数据
  179. * @param {} e
  180. */
  181. onDeleteCode(e) {
  182. let index, _codeList
  183. index = this.data.nowCode
  184. if (this.data.type == 'barcode') {
  185. _codeList = this.data.codeList
  186. _codeList.splice(index, 1)
  187. this.setData({
  188. codeList: _codeList,
  189. againDelete: false
  190. })
  191. } else {
  192. _codeList = this.data.qrCodeList
  193. _codeList.splice(index, 1)
  194. this.setData({
  195. qrCodeList: _codeList,
  196. againDelete: false
  197. })
  198. }
  199. },
  200. clearData() {
  201. this.setData({
  202. codeList: [], //手机
  203. qrCodeList: [], //耳机
  204. userName: '',
  205. remarks: '',
  206. nowCode: '',
  207. type: '',
  208. })
  209. },
  210. /**
  211. * 清空数据
  212. */
  213. onCodeInput() {
  214. this.setData({
  215. deleteOverData: true
  216. })
  217. },
  218. onDeleteOverData() {
  219. this.clearData()
  220. this.setData({
  221. deleteOverData: false
  222. })
  223. }
  224. })