You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
8.0 KiB

1 year ago
  1. // pages/changeLock/changeLock.js
  2. import ICINLockerMethods from '../../utils/equipment'
  3. import utils from '../../utils/index'
  4. import moment from "../../utils/moment"
  5. const WXAPI = require('../../utils/request')
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. oldLock:'',
  12. newLock:''
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. },
  19. // 确认换锁
  20. confirmChange(){
  21. var _this=this
  22. if(this.data.oldLock == "" || this.data.newLock == ""){
  23. wx.showToast({
  24. title: '请输入旧锁和新锁设备号',
  25. duration:2000,
  26. icon:'none'
  27. })
  28. }else{
  29. wx.showModal({
  30. title: "提示",
  31. content: "请确认是否进行此操作!",
  32. showCancel: false,
  33. confirmText: "确定",
  34. success(res) {
  35. var data={
  36. q: JSON.stringify({
  37. deviceNum:_this.data.oldLock
  38. }),
  39. pageNum: 0,
  40. pageSize: 0,
  41. }
  42. WXAPI.getDeviceItems(data).then(res=>{
  43. if(res.success && res.data.list.length>0){
  44. var oldlock=res.data.list[0]
  45. var data1={
  46. q: JSON.stringify({
  47. deviceNum:_this.data.newLock
  48. }),
  49. pageNum: 0,
  50. pageSize: 0,
  51. }
  52. WXAPI.getDeviceItems(data1).then(res1=>{
  53. if(res1.success && res1.data.list.length>0){
  54. var newlock=res1.data.list[0]
  55. _this.orderDeviceData(oldlock,newlock)
  56. }
  57. })
  58. }
  59. })
  60. }
  61. });
  62. }
  63. },
  64. orderDeviceData(row,newlock) {
  65. if (row.roomId) {
  66. var data1 = {
  67. pageNum: 0,
  68. pageSize: 0,
  69. q: {
  70. id: row.roomId
  71. }
  72. }
  73. WXAPI.getSiteTenant(data1).then(res => {
  74. if (res.success) {
  75. var person = res.data.list
  76. var data = {
  77. imei: row.imei
  78. }
  79. WXAPI.orderDeviceData(data).then(res1 => {
  80. if (res1.success) {
  81. var alllist = res1.data
  82. ICINLockerMethods.getPersonCallback(person, alllist, (callback) => {
  83. var personlist = callback
  84. ICINLockerMethods.resetInitialization(newlock, (callback) => {
  85. console.log(personlist,'personlist')
  86. if (newlock.manufactureId == 101) {
  87. personlist.map(lt => {
  88. var endTime = new Date(lt.person.endTime).getTime()
  89. var startTime = new Date(lt.person.startTime).getTime()
  90. var passwordEndTime = moment(endTime).format("YYYYMMDDHHmmss");
  91. var passwordStartTime = moment(startTime).format("YYYYMMDDHHmmss");
  92. var userTelephone = JSON.parse(lt.person.info).userTelephone;
  93. var userPassword = JSON.parse(lt.person.info).userPassword;
  94. var data = {
  95. deviceNum: newlock.deviceNum,
  96. imei: newlock.imei,
  97. userTelephone: userTelephone,
  98. userPassword: userPassword,
  99. password: userPassword,
  100. operateMode: 26,
  101. order: 6226,
  102. passwordStartTime: passwordStartTime,
  103. passwordEndTime: passwordEndTime,
  104. cardName: lt.person.name,
  105. roomName: row.roomName
  106. }
  107. ICINLockerMethods.LDAddUser(data.deviceNum, data.imei, data.userTelephone, data
  108. .userPassword,
  109. data
  110. .password, passwordStartTime, passwordEndTime, data.operateMode, data
  111. .order,
  112. data
  113. .cardName,
  114. data.roomName, (callback) => {
  115. lt.data.map(ll => {
  116. utils.putCarfidAdd(newlock, ll)
  117. })
  118. })
  119. })
  120. } else if (newlock.manufactureId == 201||newlock.manufactureId == 221) {
  121. personlist.map(lt => {
  122. var endTime = new Date(lt.person.endTime).getTime()
  123. var startTime = new Date(lt.person.startTime).getTime()
  124. var passwordEndTime = moment(endTime).format("YYYYMMDDHHmmss");
  125. var passwordStartTime = moment(startTime).format("YYYYMMDDHHmmss");
  126. var userTelephone = JSON.parse(lt.person.info).userTelephone;
  127. var userPassword = JSON.parse(lt.person.info).userPassword;
  128. var data = {
  129. lockerId: newlock.deviceNum,
  130. imei: newlock.imei,
  131. lockerUserId: userPassword,
  132. keyId: userPassword,
  133. role: 0,
  134. action: 1,
  135. order: 6226,
  136. cardName: lt.person.name,
  137. roomName: row.roomName
  138. };
  139. ICINLockerMethods.addUserToLock(data.lockerId, data.imei, data
  140. .lockerUserId, data.role, data.action, data.order, data.cardName, data
  141. .roomName, (
  142. callback) => {
  143. if (callback.success) {
  144. lt.data.map(ll => {
  145. utils.putCarfidzgAdd(lt,newlock, ll)
  146. })
  147. }
  148. })
  149. })
  150. }
  151. })
  152. })
  153. } else {
  154. this.$message.error(res1.msg)
  155. }
  156. })
  157. } else {
  158. this.$message.error(res.msg)
  159. }
  160. })
  161. } else {
  162. this.$message.error("暂无数据")
  163. }
  164. },
  165. onChange(event) {
  166. // event.detail 为当前输入的值
  167. console.log(event.detail);
  168. this.setData({
  169. oldLock:event.detail
  170. })
  171. },
  172. onChange1(event) {
  173. // event.detail 为当前输入的值
  174. console.log(event.detail);
  175. this.setData({
  176. newLock:event.detail
  177. })
  178. },
  179. // 扫描
  180. scanning() {
  181. var that = this
  182. wx.showLoading({
  183. title: '加载中',
  184. mask: true
  185. });
  186. wx.scanCode({
  187. success(res) {
  188. var deviceNum = ''
  189. if (res.result.indexOf('&') != -1) {
  190. deviceNum = res.result.split('&')[0]
  191. } else if (res.result.indexOf('_')) {
  192. deviceNum = "ICIN_" + res.result.split('_')[0]
  193. }
  194. that.setData({
  195. oldLock: deviceNum
  196. })
  197. wx.hideLoading()
  198. },
  199. fail(res) {
  200. wx.hideLoading()
  201. }
  202. })
  203. },
  204. // 扫描
  205. scanning1() {
  206. var that = this
  207. wx.showLoading({
  208. title: '加载中',
  209. mask: true
  210. });
  211. wx.scanCode({
  212. success(res) {
  213. var deviceNum = ''
  214. if (res.result.indexOf('&') != -1) {
  215. deviceNum = res.result.split('&')[0]
  216. } else if (res.result.indexOf('_')) {
  217. deviceNum = "ICIN_" + res.result.split('_')[0]
  218. }
  219. that.setData({
  220. newLock: deviceNum
  221. })
  222. wx.hideLoading()
  223. },
  224. fail(res) {
  225. wx.hideLoading()
  226. }
  227. })
  228. },
  229. /**
  230. * 生命周期函数--监听页面初次渲染完成
  231. */
  232. onReady: function () {
  233. },
  234. /**
  235. * 生命周期函数--监听页面显示
  236. */
  237. onShow: function () {
  238. },
  239. /**
  240. * 生命周期函数--监听页面隐藏
  241. */
  242. onHide: function () {
  243. },
  244. /**
  245. * 生命周期函数--监听页面卸载
  246. */
  247. onUnload: function () {
  248. },
  249. /**
  250. * 页面相关事件处理函数--监听用户下拉动作
  251. */
  252. onPullDownRefresh: function () {
  253. },
  254. /**
  255. * 页面上拉触底事件的处理函数
  256. */
  257. onReachBottom: function () {
  258. },
  259. /**
  260. * 用户点击右上角分享
  261. */
  262. onShareAppMessage: function () {
  263. }
  264. })