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.

3624 lines
110 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. // pages/Bluetooth/Bluetooth.js
  2. const config = require('../../config')
  3. const util1 = require('../../utils/util1.js')
  4. const plugin = requirePlugin("myPlugin")
  5. var util = require('../../utils/util');
  6. var md5 = require('../../utils/md5.js');
  7. // import {
  8. // BLE
  9. // } from "../../utils/btls/ble";
  10. const app = getApp();
  11. function RandNum() {
  12. var rand = ''
  13. for (var i = 0; i < 8; i++) {
  14. rand += Math.floor(Math.random() * 10)
  15. }
  16. return rand
  17. }
  18. var connectedDeviceId
  19. var basecode = 29283991 //RandNum()//
  20. var lockId = 1
  21. var lockManagerId = 1
  22. var lockMac = ''
  23. var isInitReady = false
  24. var isConnected = false
  25. var lockModel
  26. var lockDevice
  27. var taskId = 0
  28. var pincode = -1
  29. var pincodeIndex = -1
  30. var rfCardId = -1
  31. var rfCardIndex = -1
  32. var fingerprintIndex = -1
  33. var isLockLogin = false
  34. const WXAPI = require('../../utils/request')
  35. import ICINLocker from '../../utils/ICINPakage/ICINLocker'
  36. import moment from '../../utils/moment';
  37. // const emitter = app.globalData.emitter
  38. // ArrayBuffer转16进度字符串示例
  39. function ab2hex(buffer) {
  40. var hexArr = Array.prototype.map.call(
  41. new Uint8Array(buffer),
  42. function (bit) {
  43. return ('00' + bit.toString(16)).slice(-2)
  44. }
  45. )
  46. return hexArr.join(',');
  47. }
  48. Page({
  49. /**
  50. * 页面的初始数据
  51. */
  52. data: {
  53. platformId: 0, // 运营商
  54. platformname: "",
  55. sheetshow: false,
  56. actions1: [{
  57. name: '电信',
  58. id: 1
  59. },
  60. {
  61. name: '移动',
  62. id: 2
  63. },
  64. {
  65. name: '联通',
  66. id: 3
  67. },
  68. {
  69. name: "直连UDP平台",
  70. id: 8
  71. },
  72. {
  73. name: "直连TCP平台",
  74. id: 9
  75. },
  76. {
  77. name: "消息服务器",
  78. id: 98
  79. },
  80. {
  81. name: "本地缓存",
  82. id: 99
  83. }
  84. ],
  85. selectRadio1: '1201',
  86. showreg: false, // 注册到平台的弹出层
  87. show2: false,
  88. WifiName: '',
  89. WifiPwd: "",
  90. isBindLock: false,
  91. isPincodeAdd: false,
  92. isRfCardAdd: false,
  93. isRegister: false,
  94. isFingerprintAdd: false,
  95. isUnloked: false,
  96. isMuted: false,
  97. isNbEnable: true,
  98. lockModel: 0,
  99. lock: {
  100. imei: '',
  101. roomName: '',
  102. roomId: '',
  103. mac: '',
  104. lockType: '',
  105. id: ''
  106. },
  107. showWifi: false,
  108. showIP: false,
  109. deviceInfo: {
  110. roomId: '',
  111. deviceNum: ''
  112. },
  113. dataTree: [],
  114. selectKey: '', //选中的节点id
  115. dataList: [],
  116. array: [],
  117. show: false,
  118. deviceNum: '',
  119. type: '1',
  120. cgInfo: '',
  121. lockStatus: "",
  122. userInfo: '',
  123. show1: false,
  124. actions: [{
  125. name: '静音',
  126. color: '#ee0a24'
  127. },
  128. {
  129. name: '低音',
  130. color: '#333'
  131. },
  132. {
  133. name: '高音',
  134. color: '#333'
  135. },
  136. ],
  137. resgiterdevice: true,
  138. volume: '',
  139. adminuserinfo: {
  140. enterpriseId: ''
  141. },
  142. wifiName: '',
  143. wifiPassword: '',
  144. IPName: '',
  145. IPport: '',
  146. privateKey: "",
  147. showRoom: false,
  148. firstAuthList: [],
  149. secondAuthList: [],
  150. threeAuthList: [],
  151. fourAuthList: [],
  152. romeLockerList: [],
  153. firstAuthListInfo: [],
  154. secondAuthListInfo: [],
  155. threeAuthListInfo: [],
  156. fourAuthListInfo: [],
  157. romeLockerListInfo: [],
  158. selectRoomList: ["", "", "", "", ""],
  159. index: 0,
  160. indexSecond: 0,
  161. indexThree: 0,
  162. indexFour: 0,
  163. indexFive: 0,
  164. FiveAuthList: {},
  165. selectindex: '',
  166. selectRadio: '1',
  167. onlyResgiter: false,
  168. selectRoomName: ''
  169. },
  170. /**
  171. * 生命周期函数--监听页面加载
  172. */
  173. onLoad: function (options) {
  174. if (options.selectKey) {
  175. this.setData({
  176. selectKey: options.selectKey,
  177. selectRoomName: options.selectRoomName
  178. })
  179. }
  180. if (options.selectindex == 4) {
  181. var data = {
  182. q: JSON.stringify({
  183. deviceNum: options.deviceNum
  184. })
  185. }
  186. this.data.deviceInfo.deviceNum = options.deviceNum
  187. WXAPI.getDeviceItems(data).then(res => {
  188. console.log(res);
  189. if (res.data.list.length > 0) {
  190. let lock = this.data.lock
  191. lock.roomName = res.data.list[0].roomName || ''
  192. lock.roomId = res.data.list[0].roomId || ''
  193. lock.id = res.data.list[0].id || ''
  194. lock.deviceNum = res.data.list[0].deviceNum || ''
  195. lock.cardName = wx.getStorageSync('userInfo').username
  196. // var data = {
  197. // code: "zg/bleRegisterInfo",
  198. // data: {
  199. // lockerId: options.deviceNum
  200. // }
  201. // }
  202. // WXAPI.sendCommand(data).then(res1 => {
  203. // if (res1.success) {
  204. // this.setData({
  205. // cgInfo: res1.data
  206. // })
  207. // } else {
  208. // }
  209. // })
  210. let superAdmin = []
  211. var superAdminIdlist = lock.mac.slice(lock.mac.length - 11, lock.mac.length).split(":").join("")
  212. for (let i = 0; i < superAdminIdlist.length; i++) {
  213. if (superAdminIdlist[i] >= 0 && superAdminIdlist[i] <= 9) {
  214. superAdmin.push(superAdminIdlist[i])
  215. } else {
  216. let adminid = superAdminIdlist.charCodeAt(i)
  217. superAdmin.push(adminid)
  218. }
  219. }
  220. let superAdminId = superAdmin.join('').slice(superAdmin.length - 8, superAdmin.length)
  221. basecode = superAdminId
  222. console.log("超管", basecode, superAdminId, this.data.lock);
  223. this.setData({
  224. deviceInfo: res.data.list[0],
  225. lock: lock,
  226. resgiterdevice: false
  227. })
  228. } else {
  229. this.setData({
  230. resgiterdevice: true
  231. })
  232. }
  233. })
  234. var that = this
  235. connectedDeviceId = options.connectedDeviceId
  236. lockMac = options.mac
  237. console.log('onLoad', 'mac = ' + lockMac, connectedDeviceId)
  238. lockModel = util1.getLockModel(options.name)
  239. console.log('onLoad', 'model = ' + lockModel)
  240. var lockType = util1.getLockType(lockModel)
  241. var lock = this.data.lock
  242. lock.mac = lockMac
  243. lock.lockType = lockType
  244. lock.deviceNum = options.deviceNum
  245. lockDevice = app.getDeviceByDevName(options.name)
  246. wx.setNavigationBarTitle({
  247. title: options.name,
  248. })
  249. that.setData({
  250. lock: lock,
  251. lockModel: lockModel,
  252. isNbLock: lockModel > 30 && lockModel < 49 || lockModel > 80 && lockModel < 89 || lockModel > 100 && lockModel < 109,
  253. isFpLock: lockModel > 70 && lockModel < 89,
  254. isJack: lockModel > 10000 && lockModel < 10009
  255. })
  256. var adminuserinfo = wx.getStorageSync('userInfo')
  257. this.setData({
  258. deviceNum: options.deviceNum,
  259. type: options.type,
  260. adminuserinfo: adminuserinfo,
  261. selectindex: options.selectindex
  262. })
  263. } else {
  264. var adminuserinfo = wx.getStorageSync('userInfo')
  265. this.setData({
  266. deviceNum: options.deviceNum,
  267. type: options.type,
  268. adminuserinfo: adminuserinfo,
  269. selectindex: options.selectindex
  270. })
  271. var datathree = {
  272. code: "zg/auth/firstAuthList",
  273. data: {}
  274. }
  275. WXAPI.sendCommand(datathree).then(res1 => {
  276. if (res1.success) {
  277. var firstAuthList = []
  278. res1.data.map(li => {
  279. firstAuthList.push(li.value)
  280. })
  281. this.setData({
  282. firstAuthListInfo: res1.data,
  283. firstAuthList: firstAuthList
  284. })
  285. }
  286. })
  287. if (options.deviceNum.indexOf('yxwl') != -1) {
  288. } else if (options.deviceNum.indexOf('ICIN')) {
  289. this.concatFun(options.deviceNum)
  290. this.readLockStatus()
  291. }
  292. var data = {
  293. q: JSON.stringify({
  294. deviceNum: options.deviceNum
  295. })
  296. }
  297. WXAPI.getDeviceItems(data).then(res => {
  298. console.log(res, '设备列表')
  299. if (res.data.list.length == 0) {
  300. this.setData({
  301. deviceInfo: '',
  302. resgiterdevice: false
  303. })
  304. } else {
  305. if (res.data.list[0].roomId) {
  306. this.getuser(res.data.list[0].roomId)
  307. var selectRoomList = res.data.list[0].roomName.split('/')
  308. this.setData({
  309. selectRoomList
  310. })
  311. }
  312. var data = {
  313. code: "zg/bleRegisterInfo",
  314. data: {
  315. lockerId: options.deviceNum
  316. }
  317. }
  318. WXAPI.sendCommand(data).then(res1 => {
  319. if (res1.success) {
  320. this.setData({
  321. cgInfo: res1.data,
  322. deviceInfo: res.data.list[0]
  323. })
  324. } else {
  325. }
  326. })
  327. }
  328. })
  329. }
  330. this.getRoom()
  331. },
  332. onSelect(event) {
  333. console.log(event.detail);
  334. this.setData({
  335. platformId: event.detail.id,
  336. platformname: event.detail.name
  337. })
  338. },
  339. changesheetshow() {
  340. this.setData({
  341. sheetshow: true
  342. })
  343. },
  344. //
  345. onChangeSelectRaio(event) {
  346. this.setData({
  347. selectRadio: event.detail,
  348. });
  349. },
  350. onChangeSelectRaio1(event) {
  351. this.setData({
  352. selectRadio1: event.detail
  353. })
  354. },
  355. bindPickerChange: function (e) {
  356. console.log('picker发送选择改变,携带值为', e.detail.value)
  357. var selectRoomList = this.data.selectRoomList
  358. selectRoomList[0].name = this.data.firstAuthListInfo[e.detail.value].value
  359. selectRoomList[0].code = this.data.firstAuthListInfo[e.detail.value].code
  360. this.setData({
  361. index: e.detail.value,
  362. selectRoomList
  363. })
  364. var datathree = {
  365. code: "zg/auth/secondAuthList",
  366. data: {
  367. parentId: selectRoomList[0].code
  368. }
  369. }
  370. WXAPI.sendCommand(datathree).then(res1 => {
  371. if (res1.success) {
  372. var secondAuthList = []
  373. res1.data.map(li => {
  374. secondAuthList.push(li.value)
  375. })
  376. this.setData({
  377. secondAuthListInfo: res1.data,
  378. secondAuthList: secondAuthList
  379. })
  380. }
  381. })
  382. },
  383. bindPickerChangeSecond: function (e) {
  384. console.log('picker发送选择改变,携带值为', e.detail.value)
  385. var selectRoomList = this.data.selectRoomList
  386. selectRoomList[1].name = this.data.secondAuthListInfo[e.detail.value].value
  387. selectRoomList[1].code = this.data.secondAuthListInfo[e.detail.value].code
  388. this.setData({
  389. indexSecond: e.detail.value,
  390. selectRoomList
  391. })
  392. var datathree = {
  393. code: "zg/auth/threeAuthList",
  394. data: {
  395. parentId: selectRoomList[1].code
  396. }
  397. }
  398. WXAPI.sendCommand(datathree).then(res1 => {
  399. if (res1.success) {
  400. var threeAuthList = []
  401. res1.data.map(li => {
  402. threeAuthList.push(li.value)
  403. })
  404. this.setData({
  405. threeAuthListInfo: res1.data,
  406. threeAuthList: threeAuthList
  407. })
  408. }
  409. })
  410. },
  411. bindPickerChangeThree: function (e) {
  412. console.log('picker发送选择改变,携带值为', e.detail.value)
  413. var selectRoomList = this.data.selectRoomList
  414. selectRoomList[2].name = this.data.threeAuthListInfo[e.detail.value].value
  415. selectRoomList[2].code = this.data.threeAuthListInfo[e.detail.value].code
  416. this.setData({
  417. indexThree: e.detail.value,
  418. selectRoomList
  419. })
  420. var datathree = {
  421. code: "zg/auth/fourAuthList",
  422. data: {
  423. parentId: selectRoomList[2].code
  424. }
  425. }
  426. WXAPI.sendCommand(datathree).then(res1 => {
  427. if (res1.success) {
  428. var fourAuthList = []
  429. res1.data.map(li => {
  430. fourAuthList.push(li.value)
  431. })
  432. this.setData({
  433. fourAuthListInfo: res1.data,
  434. fourAuthList: fourAuthList
  435. })
  436. }
  437. })
  438. },
  439. bindPickerChangeFour: function (e) {
  440. console.log('picker发送选择改变,携带值为', e.detail.value)
  441. var selectRoomList = this.data.selectRoomList
  442. selectRoomList[3].name = this.data.fourAuthListInfo[e.detail.value].value
  443. selectRoomList[3].code = this.data.fourAuthListInfo[e.detail.value].code
  444. this.setData({
  445. indexFour: e.detail.value,
  446. selectRoomList
  447. })
  448. var datathree = {
  449. code: "zg/auth/getRomeUnLockerList",
  450. data: {
  451. parentId: selectRoomList[3].code
  452. }
  453. }
  454. WXAPI.sendCommand(datathree).then(res1 => {
  455. if (res1.success) {
  456. var romeLockerList = []
  457. res1.data.map(li => {
  458. romeLockerList.push(li.value)
  459. })
  460. this.setData({
  461. romeLockerListInfo: res1.data,
  462. romeLockerList: romeLockerList
  463. })
  464. }
  465. })
  466. },
  467. bindPickerChangeFive: function (e) {
  468. console.log('picker发送选择改变,携带值为', e.detail.value)
  469. var selectRoomList = this.data.selectRoomList
  470. selectRoomList[4].name = this.data.romeLockerListInfo[e.detail.value].value
  471. selectRoomList[4].code = this.data.romeLockerListInfo[e.detail.value].code
  472. this.setData({
  473. indexFive: e.detail.value,
  474. selectRoomList
  475. })
  476. // var datathreeOne = {
  477. // code: "zg/auth/romeFiveAuthByName",
  478. // data: {
  479. // "firstAuthName": selectRoomList[0].name,
  480. //     "secondAuthName": selectRoomList[1].name,
  481. //     "threeAuthName": selectRoomList[2].name,
  482. //     "fourAuthName": selectRoomList[3].name,
  483. //     "roomAuth": selectRoomList[4].name
  484. // }
  485. // }
  486. // WXAPI.sendCommand(datathreeOne).then(res1 => {
  487. // if (res1.code==200) {
  488. // this.setData({
  489. // FiveAuthList:res1.data
  490. // })
  491. // }
  492. // })
  493. },
  494. // 获取锁端私钥
  495. getPirvateKey() {
  496. wx.showLoading({
  497. title: '读取中',
  498. mask: true
  499. })
  500. var that = this
  501. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  502. (callback) => {
  503. var signKey = callback.signKey
  504. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, signKey, (callback1) => {
  505. ICINLocker.getPirvateKey(this.data.cgInfo.lockerId, callback1.commonKey, (callback2) => {
  506. if (callback2.status == '00') {
  507. console.log(callback2, 'sdsiy')
  508. var privateKey = callback2.privateKey
  509. if (privateKey) {
  510. that.setData({
  511. privateKey: privateKey
  512. })
  513. }
  514. wx.hideLoading()
  515. console.log(that.data.privateKey, 'sdsiy')
  516. }
  517. })
  518. })
  519. })
  520. setTimeout(() => {
  521. wx.hideLoading()
  522. }, 5000)
  523. },
  524. synchronizationTime() {
  525. var time = parseInt(new Date().getTime() / 1000)
  526. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  527. (callback) => {
  528. var signKey = callback.signKey
  529. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, signKey, (callback1) => {
  530. var _commonKey = callback1.commonKey
  531. ICINLocker.updateTime(this.data.cgInfo.lockerId, this.data.cgInfo.superId, time, '', _commonKey, callback2 => {
  532. if (callback2.status == '00') {
  533. wx.showToast({
  534. title: '同步时间成功',
  535. duration: 2000,
  536. icon: 'none'
  537. })
  538. this.setData({
  539. showIP: false
  540. })
  541. } else {
  542. wx.showToast({
  543. title: '同步时间失败,错误码:' + callback2.status,
  544. duration: 2000,
  545. icon: 'none'
  546. })
  547. }
  548. });
  549. })
  550. })
  551. },
  552. confirmSetIP() {
  553. if (this.data.IPName == '' || this.data.IPport == '') {
  554. wx.showToast({
  555. title: '请填写完整信息',
  556. duration: 2000,
  557. icon: 'none'
  558. })
  559. } else {
  560. var NbGwIp = this.data.IPName
  561. var NbGwPort = this.data.IPport
  562. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  563. (callback) => {
  564. console.log(callback)
  565. var signKey = callback.signKey
  566. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, signKey, (callback1) => {
  567. console.log(callback1)
  568. var _commonKey = callback1.commonKey
  569. ICINLocker.setWifiApInfo(NbGwIp, NbGwPort, _commonKey, callback2 => {
  570. if (callback2.status == '00') {
  571. wx.showToast({
  572. title: '设置成功',
  573. duration: 2000,
  574. icon: 'none'
  575. })
  576. this.setData({
  577. showIP: false
  578. })
  579. } else {
  580. wx.showToast({
  581. title: '设置失败,错误码:' + callback2.status,
  582. duration: 2000,
  583. icon: 'none'
  584. })
  585. }
  586. });
  587. })
  588. })
  589. }
  590. },
  591. confirmSetWifi() {
  592. if (this.data.wifiName == '' || this.data.wifiPassword == '') {
  593. wx.showToast({
  594. title: '请填写完整信息',
  595. duration: 2000,
  596. icon: 'none'
  597. })
  598. } else {
  599. var _wifiApSsid = this.data.wifiName
  600. var _wifiApPwd = this.data.wifiPassword
  601. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  602. (callback) => {
  603. console.log(callback)
  604. var signKey = callback.signKey
  605. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, signKey, (callback1) => {
  606. console.log(callback1)
  607. var _commonKey = callback1.commonKey
  608. ICINLocker.setWifiApInfo(_wifiApSsid, _wifiApPwd, _commonKey, callback2 => {
  609. if (callback2.status == '00') {
  610. wx.showToast({
  611. title: '设置成功',
  612. duration: 2000,
  613. icon: 'none'
  614. })
  615. this.setData({
  616. showWifi: false
  617. })
  618. } else {
  619. wx.showToast({
  620. title: '设置失败,错误码:' + callback2.status,
  621. duration: 2000,
  622. icon: 'none'
  623. })
  624. }
  625. });
  626. })
  627. })
  628. }
  629. },
  630. onChangeWifi(event) {
  631. // event.detail 为当前输入的值
  632. this.setData({
  633. wifiName: event.detail
  634. })
  635. },
  636. onChangeWifi1(event) {
  637. // event.detail 为当前输入的值
  638. this.setData({
  639. wifiPassword: event.detail
  640. })
  641. },
  642. setWifi() {
  643. this.setData({
  644. showWifi: true
  645. });
  646. },
  647. onCloseWifi() {
  648. this.setData({
  649. showWifi: false
  650. });
  651. },
  652. onChangeIP(event) {
  653. // event.detail 为当前输入的值
  654. this.setData({
  655. IPName: event.detail
  656. })
  657. },
  658. onChangeIP1(event) {
  659. // event.detail 为当前输入的值
  660. this.setData({
  661. IPport: event.detail
  662. })
  663. },
  664. setIP() {
  665. this.setData({
  666. showIP: true
  667. });
  668. },
  669. onCloseIP() {
  670. this.setData({
  671. showIP: false
  672. });
  673. },
  674. onCloseRoom() {
  675. this.setData({
  676. showRoom: false
  677. });
  678. },
  679. // 获取用户
  680. getuser(roomId) {
  681. var data = {
  682. q: JSON.stringify({
  683. id: roomId
  684. }),
  685. orderBy: "createTime",
  686. orderType: 'desc'
  687. }
  688. WXAPI.getSiteTenant(data).then(res => {
  689. if (res.success) {
  690. this.setData({
  691. userInfo: res.data.list[0]
  692. })
  693. }
  694. })
  695. },
  696. // 删除用户
  697. deleteUser() {
  698. },
  699. // 添加指纹
  700. addFingerPrints() {
  701. if (this.userInfo == '') {
  702. wx.showToast({
  703. title: '请添加用户',
  704. duration: 2000,
  705. icon: 'none'
  706. })
  707. } else {
  708. var userInfo = JSON.parse(this.data.userInfo.info)
  709. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, this.data.cgInfo.authKey, (callback) => {
  710. ICINLocker.addFingerPrints(this.data.cgInfo.lockerId, this.data.cgInfo.superId, userInfo.userPassword, this.data.cgInfo.superId, '', this.data.cgInfo.authKey, '00000000', 'FFFFFFFF', '00', callback.commonKey, (callback) => {
  711. console.log(callback)
  712. })
  713. })
  714. }
  715. },
  716. ShowRoomMathods() {
  717. this.setData({
  718. showRoom: true
  719. })
  720. },
  721. sendSetKey() {
  722. wx.showModal({
  723. title: '下发五组密钥前,请先获取锁端私钥,是否下发五组密钥',
  724. success: (result) => {
  725. if (result.confirm) {
  726. var selectRoomList = this.data.selectRoomList
  727. if (this.data.privateKey == '') {
  728. wx.showModal({
  729. title: '请获取锁端私钥,才能下发五组密钥',
  730. })
  731. return
  732. }
  733. wx.showLoading({
  734. title: '下发中',
  735. mask: true
  736. })
  737. var that = this
  738. var dataOne = {
  739. code: "zg/auth/romeFiveAuthByName",
  740. data: {
  741. "firstAuthName": selectRoomList[0],
  742. "secondAuthName": selectRoomList[1],
  743. "threeAuthName": selectRoomList[2],
  744. "fourAuthName": selectRoomList[3],
  745. "roomAuth": selectRoomList[4],
  746. }
  747. }
  748. WXAPI.sendCommand(dataOne).then(resOne => {
  749. if (resOne.code == 200) {
  750. let FiveAuthList = resOne.data
  751. var currtime = moment().format("X")
  752. var writeTime = parseInt(currtime).toString(16).toUpperCase()
  753. ICINLocker.getSignKey(that.data.cgInfo.lockerId, that.data.cgInfo.superId, that.data.cgInfo.superId, (callbackSignKey) => {
  754. ICINLocker.getCommonKey(that.data.cgInfo.lockerId, that.data.cgInfo.superId, that.data.cgInfo.superId, callbackSignKey.signKey, (callback) => {
  755. console.log(callback)
  756. if (callback.status == "00") {
  757. ICINLocker.addFiveKeys(that.data.cgInfo.lockerId, writeTime, "01", that.data.privateKey, "01", FiveAuthList.firstAuth, "01", FiveAuthList.secondAuth, "01", FiveAuthList.threeAuth, "01", FiveAuthList.fourAuth, callback.commonKey, (callback1) => {
  758. console.log(callback1, '下发五组密钥返回')
  759. if (callback1.completeFlag == "01" && callback1.status == "00") {
  760. wx.showModal({
  761. title: '下发成功',
  762. })
  763. var datathreeTwo = {
  764. code: "zg/auth/reportOfflineCardPrivateKey",
  765. data: {
  766. roomId: resOne.data.homeId,
  767. privateKey: that.data.privateKey,
  768. }
  769. }
  770. WXAPI.sendCommand(datathreeTwo).then(res1 => {
  771. if (res1.code == 200) {}
  772. })
  773. this.setData({
  774. showRoom: false
  775. })
  776. } else {
  777. wx.showModal({
  778. title: '下发失败',
  779. })
  780. // wx.showToast({
  781. // title: '下发失败',
  782. // duration:2000,
  783. // icon:"none"
  784. // })
  785. }
  786. });
  787. }
  788. })
  789. })
  790. }
  791. })
  792. }
  793. }
  794. })
  795. setTimeout(() => {
  796. wx.hideLoading()
  797. }, 10000)
  798. },
  799. // 蓝牙开门
  800. openTheDoor() {
  801. if (this.userInfo == '') {
  802. wx.showToast({
  803. title: '请添加用户',
  804. duration: 2000,
  805. icon: 'none'
  806. })
  807. } else {
  808. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  809. (callback) => {
  810. console.log(callback)
  811. var signKey = callback.signKey
  812. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, signKey, (callback1) => {
  813. console.log(callback1)
  814. var commonKey = callback1.commonKey
  815. ICINLocker.openTheDoor(this.data.cgInfo.lockerId, this.data.cgInfo.superId, signKey, this.data.cgInfo.superId, '', '01', commonKey, (callback2) => {
  816. console.log(callback2.status)
  817. var data = {
  818. code: "zg/bleUnlockRecord",
  819. data: {
  820. lockerId: this.data.cgInfo.lockerId,
  821. lockerUserId: this.data.cgInfo.superId
  822. }
  823. }
  824. WXAPI.sendCommand(data).then(res => {
  825. console.log(res)
  826. })
  827. setTimeout(() => {
  828. this.synchronizationTime()
  829. }, 1000)
  830. })
  831. })
  832. })
  833. }
  834. },
  835. //连接蓝牙
  836. concatFun() {
  837. var deviceNum = this.data.deviceNum
  838. var that = this
  839. wx.showLoading({
  840. title: '连接中',
  841. mask: true
  842. })
  843. wx.removeStorageSync("connectedDeviceId")
  844. ICINLocker.scanDevices(deviceNum)
  845. .then((res) => {
  846. if (res.status == 0) {
  847. //成功找到蓝牙情况下进行锁连接
  848. ICINLocker.connect(res.deviceId, false) // 此处 deviceId 存起来,当断开连接时使用
  849. .then((res) => {
  850. if (res.status == 0) {
  851. wx.showToast({
  852. title: res.statusReason,
  853. duration: 2000,
  854. icon: "none"
  855. })
  856. wx.hideLoading()
  857. } else {
  858. wx.showToast({
  859. title: res.statusReason,
  860. duration: 2000,
  861. icon: "none"
  862. })
  863. console.log(222, res)
  864. wx.hideLoading()
  865. //此处处理返回值不为成功(0)的情况
  866. }
  867. }).catch((res) => {
  868. this.concatFun()
  869. // 此处处理未能连接成功问题
  870. })
  871. }
  872. })
  873. .catch((res) => {
  874. //此处处理未能连接到蓝牙的问题
  875. })
  876. },
  877. resetLock1() {
  878. wx.showModal({
  879. title: '是否确认重置锁',
  880. success: (result) => {
  881. if (result.confirm) {
  882. ICINLocker.getSignKey('ICIN_16b017e8f6cc', 'AE822FD', 'AE822FD',
  883. (callback) => {
  884. console.log(callback, '111')
  885. var signKey = callback.signKey
  886. ICINLocker.getCommonKey('ICIN_16b017e8f6cc', 'AE822FD', 'AE822FD', signKey, (callback1) => {
  887. console.log(callback1)
  888. ICINLocker.resetLock('ICIN_16b017e8f6cc', 'AE822FD', '', signKey, callback1.commonKey, (callback2) => {
  889. console.log(callback2)
  890. if (callback2.status = '00') {
  891. var data1 = {
  892. device: this.data.deviceNum
  893. }
  894. // WXAPI.deleteZGDevice(data1).then(res => {
  895. // })
  896. this.unbindRoom()
  897. }
  898. });
  899. })
  900. })
  901. }
  902. },
  903. fail: (res) => {
  904. },
  905. })
  906. },
  907. // 重置
  908. resetLock() {
  909. wx.showModal({
  910. title: '是否确认重置锁',
  911. success: (result) => {
  912. if (result.confirm) {
  913. wx.showLoading({
  914. title: '重置中',
  915. mask: true
  916. })
  917. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  918. (callback) => {
  919. if (callback.status == '00') {
  920. var signKey = callback.signKey
  921. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, signKey, (callback1) => {
  922. ICINLocker.resetLock(this.data.cgInfo.lockerId, this.data.cgInfo.superId, '', signKey, callback1.commonKey, (callback2) => {
  923. if (callback2.status = '00') {
  924. wx.showToast({
  925. title: '重置成功',
  926. duration: 2000,
  927. icon: 'none'
  928. })
  929. this.unbindRoom()
  930. } else {
  931. wx.hideLoading()
  932. wx.showToast({
  933. title: '重置失败',
  934. duration: 2000,
  935. icon: 'none'
  936. })
  937. }
  938. });
  939. })
  940. } else {
  941. wx.hideLoading()
  942. wx.showToast({
  943. title: '重置失败',
  944. duration: 2000,
  945. icon: 'none'
  946. })
  947. }
  948. })
  949. }
  950. },
  951. fail: (res) => {
  952. },
  953. })
  954. },
  955. // 解绑房间
  956. unbindRoomMethods() {
  957. wx.showModal({
  958. title: '是否确认解绑',
  959. success: (result) => {
  960. if (result.confirm) {
  961. var data = [{
  962. siteId: this.data.deviceInfo.roomId,
  963. deviceId: this.data.deviceInfo.id,
  964. }]
  965. WXAPI.unbindDeviceSite(data).then(res => {
  966. var data2 = {
  967. code: "zg/bleResetDevice",
  968. data: {
  969. lockerId: this.data.deviceInfo.deviceNum
  970. }
  971. }
  972. WXAPI.sendCommand(data2).then(res1 => {
  973. console.log(res1, 'res1------')
  974. if (res1.success) {
  975. var data1 = {
  976. lockerId: this.data.deviceInfo.deviceNum,
  977. imei: this.data.deviceInfo.imei,
  978. order: 5102,
  979. cardName: this.data.adminuserinfo.username,
  980. roomName: this.data.deviceInfo.roomName
  981. }
  982. WXAPI.deleteZGDevice(data1).then(res => {
  983. // console.log(res, '删除设备')
  984. if (res.success) {
  985. wx.showToast({
  986. title: '解绑成功',
  987. duration: 2000,
  988. icon: 'none'
  989. })
  990. var deviceInfo = this.data.deviceInfo
  991. deviceInfo['roomId'] = ''
  992. deviceInfo['roomName'] = ''
  993. this.setData({
  994. deviceInfo,
  995. resgiterdevice: false
  996. })
  997. }
  998. })
  999. } else {
  1000. wx.showToast({
  1001. title: '删除失败',
  1002. icon: "none",
  1003. duration: 2000
  1004. })
  1005. }
  1006. })
  1007. var data3 = {
  1008. q: JSON.stringify({
  1009. id: this.data.deviceInfo.roomId
  1010. })
  1011. }
  1012. WXAPI.getSiteTenant(data3).then(res2 => {
  1013. console.log(res2, 'res22222')
  1014. if (res2.success) {
  1015. var ids = []
  1016. res2.data.list.map(li => {
  1017. var obj = {
  1018. siteId: this.data.deviceInfo.roomId,
  1019. cardId: li.cardId,
  1020. }
  1021. ids.push(obj)
  1022. })
  1023. WXAPI.unbindCard(ids).then(res3 => {
  1024. if (res3.success) {
  1025. wx.showToast({
  1026. title: '退租成功',
  1027. duration: 2000,
  1028. icon: 'none'
  1029. })
  1030. } else {
  1031. wx.showToast({
  1032. title: '退租失败',
  1033. duration: 2000,
  1034. icon: 'none'
  1035. })
  1036. }
  1037. })
  1038. } else {
  1039. wx.showToast({
  1040. title: '退租失败',
  1041. duration: 2000,
  1042. icon: 'none'
  1043. })
  1044. }
  1045. })
  1046. })
  1047. }
  1048. }
  1049. })
  1050. },
  1051. // 解绑房间
  1052. unbindRoom() {
  1053. var data = [{
  1054. siteId: this.data.deviceInfo.roomId,
  1055. deviceId: this.data.deviceInfo.id,
  1056. }]
  1057. WXAPI.unbindDeviceSite(data).then(res => {
  1058. var data2 = {
  1059. code: "zg/bleResetDevice",
  1060. data: {
  1061. lockerId: this.data.deviceInfo.deviceNum
  1062. }
  1063. }
  1064. WXAPI.sendCommand(data2).then(res1 => {
  1065. console.log(res1, 'res1------')
  1066. if (res1.success) {
  1067. var data1 = {
  1068. lockerId: this.data.deviceInfo.deviceNum,
  1069. imei: this.data.deviceInfo.imei,
  1070. order: 5102,
  1071. cardName: this.data.adminuserinfo.username,
  1072. roomName: this.data.deviceInfo.roomName,
  1073. result: 1
  1074. }
  1075. WXAPI.deleteZGDevice(data1).then(res => {
  1076. // console.log(res, '删除设备')
  1077. if (res.success) {
  1078. wx.showToast({
  1079. title: '解绑成功',
  1080. duration: 2000,
  1081. icon: 'none'
  1082. })
  1083. var deviceInfo = this.data.deviceInfo
  1084. deviceInfo['roomId'] = ''
  1085. deviceInfo['roomName'] = ''
  1086. this.setData({
  1087. deviceInfo,
  1088. resgiterdevice: false
  1089. })
  1090. }
  1091. })
  1092. } else {
  1093. wx.showToast({
  1094. title: '删除失败',
  1095. icon: "none",
  1096. duration: 2000
  1097. })
  1098. }
  1099. })
  1100. var data3 = {
  1101. q: JSON.stringify({
  1102. id: this.data.deviceInfo.roomId
  1103. })
  1104. }
  1105. WXAPI.getSiteTenant(data3).then(res2 => {
  1106. console.log(res2, 'res22222')
  1107. if (res2.success) {
  1108. var ids = []
  1109. res2.data.list.map(li => {
  1110. var obj = {
  1111. siteId: this.data.deviceInfo.roomId,
  1112. cardId: li.cardId,
  1113. }
  1114. ids.push(obj)
  1115. })
  1116. WXAPI.unbindCard(ids).then(res3 => {
  1117. if (res3.success) {
  1118. wx.showToast({
  1119. title: '退租成功',
  1120. duration: 2000,
  1121. icon: 'none'
  1122. })
  1123. } else {
  1124. wx.showToast({
  1125. title: '退租失败',
  1126. duration: 2000,
  1127. icon: 'none'
  1128. })
  1129. }
  1130. })
  1131. } else {
  1132. wx.showToast({
  1133. title: '退租失败',
  1134. duration: 2000,
  1135. icon: 'none'
  1136. })
  1137. }
  1138. })
  1139. })
  1140. },
  1141. randomString(len, charSet) {
  1142. charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  1143. var randomString = '';
  1144. for (var i = 0; i < len; i++) {
  1145. var randomPoz = Math.floor(Math.random() * charSet.length);
  1146. randomString += charSet.substring(randomPoz, randomPoz + 1);
  1147. }
  1148. return randomString;
  1149. },
  1150. // 设置声音
  1151. setVoice() {
  1152. this.setData({
  1153. show1: true
  1154. });
  1155. },
  1156. // 关闭设置音量
  1157. onClose1() {
  1158. this.setData({
  1159. show2: false
  1160. });
  1161. },
  1162. // 选择设置音量
  1163. onSelect1(event) {
  1164. var volume = ''
  1165. if (event.detail.name == '静音') {
  1166. volume = '00'
  1167. } else if (event.detail.name == '低音') {
  1168. volume = '01'
  1169. } else if (event.detail.name == '高音') {
  1170. volume = '02'
  1171. }
  1172. this.setData({
  1173. volume: volume
  1174. })
  1175. wx.showLoading({
  1176. title: "正在设置...",
  1177. mask: true
  1178. });
  1179. this.setVolume(volume)
  1180. },
  1181. // 设置音量
  1182. setVolume(volume) {
  1183. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  1184. (callback) => {
  1185. console.log(callback, '-----')
  1186. if (callback.status == '00') {
  1187. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, callback.signKey, (callback1) => {
  1188. console.log(callback1, '2222222')
  1189. if (callback1.status == '00') {
  1190. ICINLocker.setVolume(this.data.cgInfo.lockerId, this.data.cgInfo.superId, volume, callback1.commonKey, (callback2) => {
  1191. console.log(callback2, '333333333')
  1192. if (callback2.status == '00') {
  1193. wx.hideLoading()
  1194. wx.showToast({
  1195. title: '设置成功',
  1196. duration: 2000,
  1197. icon: 'none'
  1198. })
  1199. } else {
  1200. wx.hideLoading()
  1201. wx.showToast({
  1202. title: '设置失败',
  1203. duration: 2000,
  1204. icon: 'none'
  1205. })
  1206. }
  1207. })
  1208. } else {
  1209. wx.hideLoading()
  1210. wx.showToast({
  1211. title: '设置失败',
  1212. duration: 2000,
  1213. icon: 'none'
  1214. })
  1215. }
  1216. })
  1217. } else {
  1218. wx.hideLoading()
  1219. wx.showToast({
  1220. title: '设置失败',
  1221. duration: 2000,
  1222. icon: 'none'
  1223. })
  1224. }
  1225. });
  1226. },
  1227. reportOfflineCardPrivateKeyMethods(str, signKey, commonKey, IMEI, IMSI) {
  1228. var that = this
  1229. var dataTwo = {
  1230. code: "zg/auth/romeFiveAuthByName",
  1231. data: {
  1232. "firstAuthName": that.data.selectRoomList[0],
  1233. "secondAuthName": that.data.selectRoomList[1],
  1234. "threeAuthName": that.data.selectRoomList[2],
  1235. "fourAuthName": that.data.selectRoomList[3],
  1236. "roomAuth": that.data.selectRoomList[4],
  1237. }
  1238. }
  1239. WXAPI.sendCommand(dataTwo).then(resTwo => {
  1240. var datathreeOne = {
  1241. code: "zg/customer/compleateLocker",
  1242. data: {
  1243. romeId: resTwo.data.homeId,
  1244. lockerId: this.data.deviceNum,
  1245. superAdminId: str,
  1246. superAdminKey: str,
  1247. authCode: signKey,
  1248. communicationKey: commonKey,
  1249. commentType: that.data.type,
  1250. imei: IMEI,
  1251. imsi: IMSI
  1252. }
  1253. }
  1254. WXAPI.sendCommand(datathreeOne).then(resOne => {
  1255. })
  1256. })
  1257. },
  1258. // 添加管理员
  1259. addAdmin() {
  1260. var that = this
  1261. var str1 = JSON.stringify(util.gettimestamp1())
  1262. var devicenum = this.data.deviceNum
  1263. var md51 = md5(devicenum);
  1264. console.log(md51)
  1265. // var sjnum=this.randomString(7,md51)
  1266. // var str = sjnum.toUpperCase()
  1267. wx.showLoading({
  1268. title: '注册中',
  1269. mask: true
  1270. })
  1271. var str = md51.substr(md51.length - 7, md51.length).toUpperCase()
  1272. console.log(str, this.data.deviceNum)
  1273. ICINLocker.getSignKey(this.data.deviceNum, str, str,
  1274. (callback) => {
  1275. this.data.signKey = callback.signKey
  1276. var signKey = callback.signKey
  1277. console.log(signKey)
  1278. ICINLocker.getCommonKey(this.data.deviceNum, str, str, callback.signKey, (callback) => {
  1279. this.data.commonKey = callback.commonKey
  1280. var commonKey = callback.commonKey
  1281. ICINLocker.readLockerInfo(this.data.deviceNum, str, (callback) => {
  1282. if (that.data.type == '0') {
  1283. ICINLocker.setIpOfNb("103.120.227.76", "9090", commonKey, callback2 => {
  1284. ICINLocker.addUserToLock(this.data.deviceNum, str, str, str, 'FF', signKey, '', commonKey, '00000000', 'FFFFFFFF', (callback1) => {
  1285. if (callback1.status == '00') {
  1286. var IMEI = callback.nbIMEI.substr(0, 15);
  1287. var IMSI = callback.nvIMSI.substr(0, 15);
  1288. var data = {
  1289. lockerId: this.data.deviceNum,
  1290. imei: IMEI,
  1291. imsi: IMSI,
  1292. // customerCode: "d39eaa7fc1f34190869608259133d2fb",
  1293. lockerSuperAdminId: str,
  1294. authKey: this.data.signKey.toUpperCase(),
  1295. commonKey: this.data.commonKey,
  1296. type: this.data.type,
  1297. enterpriseId: this.data.adminuserinfo.enterpriseId,
  1298. order: 5101,
  1299. status: 1,
  1300. cardName: this.data.adminuserinfo.username + '-蓝牙注册锁',
  1301. roomName: this.data.selectRoomList.join("/")
  1302. };
  1303. if (that.data.selectRadio == 1 || that.data.selectRadio == 3) {
  1304. that.reportOfflineCardPrivateKeyMethods(str, signKey, commonKey, IMEI, IMSI)
  1305. }
  1306. setTimeout(() => {
  1307. if (!that.data.resgiterdevice) {
  1308. var datastr = {
  1309. data: {
  1310. manufactureId: that.data.selectindex == 2 ? 201 : that.data.selectindex == 3 ? 221 : '',
  1311. lockerId: data.lockerId,
  1312. imei: data.imei,
  1313. imsi: data.imsi,
  1314. // customerCode:data.customerCode,
  1315. lockerSuperAdminId: data.lockerSuperAdminId,
  1316. authKey: data.authKey,
  1317. commonKey: data.commonKey,
  1318. type: data.type,
  1319. order: 5101,
  1320. status: 1,
  1321. cardName: data.cardName,
  1322. roomName: data.roomName
  1323. },
  1324. code: "/v1/zg/registerDevice",
  1325. enterpriseId: data.enterpriseId,
  1326. key: data.lockerId
  1327. }
  1328. WXAPI.registerDeviceAll(datastr).then(res => {
  1329. console.log(res, '注册设备')
  1330. if (res.success) {
  1331. that.setData({
  1332. onlyResgiter: true
  1333. })
  1334. wx.showToast({
  1335. title: res.message,
  1336. icon: 'none',
  1337. duration: 2000
  1338. })
  1339. var data1 = {
  1340. pageNum: 1,
  1341. pageSize: 10,
  1342. q: JSON.stringify({
  1343. deviceNum: this.data.deviceNum,
  1344. // lockType:1,
  1345. types: [1, 21],
  1346. })
  1347. }
  1348. var data2 = [{
  1349. siteId: that.data.selectKey,
  1350. deviceId: res.data.id,
  1351. }]
  1352. var data3 = {
  1353. code: "zg/bleRegisterInfo",
  1354. data: {
  1355. lockerId: this.data.deviceNum
  1356. }
  1357. }
  1358. WXAPI.sendCommand(data3).then(res1 => {
  1359. console.log(res1, '蓝牙设备')
  1360. if (res1.success) {
  1361. this.setData({
  1362. cgInfo: res1.data
  1363. })
  1364. } else {
  1365. }
  1366. })
  1367. if (that.data.selectRadio == 1 || that.data.selectRadio == 3) {
  1368. WXAPI.bindDeviceSite(data2).then(res2 => {
  1369. console.log(res2, '绑定设备数据')
  1370. if (res2.success) {
  1371. wx.showToast({
  1372. title: '操作成功',
  1373. duration: 2000,
  1374. icon: "none"
  1375. })
  1376. this.getuser(that.data.selectKey)
  1377. WXAPI.getDeviceItems(data1).then(res3 => {
  1378. console.log(res, '获取设备')
  1379. wx.hideLoading()
  1380. this.setData({
  1381. deviceInfo: res3.data.list[0],
  1382. show: false,
  1383. })
  1384. })
  1385. }
  1386. })
  1387. }
  1388. } else {
  1389. wx.showToast({
  1390. title: '平台注册失败',
  1391. icon: 'none',
  1392. duration: 2000
  1393. })
  1394. }
  1395. })
  1396. } else {
  1397. var data1 = {
  1398. pageNum: 1,
  1399. pageSize: 10,
  1400. q: JSON.stringify({
  1401. deviceNum: this.data.deviceNum,
  1402. // lockType:1,
  1403. types: [1, 21],
  1404. })
  1405. }
  1406. var data2 = [{
  1407. siteId: that.data.selectKey,
  1408. deviceId: that.data.deviceInfo.id,
  1409. }]
  1410. var data3 = {
  1411. code: "zg/bleRegisterInfo",
  1412. data: {
  1413. lockerId: this.data.deviceNum
  1414. }
  1415. }
  1416. WXAPI.sendCommand(data3).then(res1 => {
  1417. if (res1.success) {
  1418. this.setData({
  1419. cgInfo: res1.data
  1420. })
  1421. } else {
  1422. }
  1423. })
  1424. if (that.data.selectRadio == 1 || that.data.selectRadio == 3) {
  1425. WXAPI.bindDeviceSite(data2).then(res2 => {
  1426. console.log(res2, '绑定设备数据')
  1427. if (res2.success) {
  1428. wx.showToast({
  1429. title: '操作成功',
  1430. duration: 2000,
  1431. icon: "none"
  1432. })
  1433. this.getuser(that.data.selectKey)
  1434. WXAPI.getDeviceItems(data1).then(res3 => {
  1435. wx.hideLoading()
  1436. this.setData({
  1437. deviceInfo: res3.data.list[0],
  1438. show: false
  1439. })
  1440. })
  1441. }
  1442. })
  1443. }
  1444. }
  1445. }, 1000)
  1446. } else {
  1447. wx.showToast({
  1448. title: '门锁注册失败',
  1449. icon: 'none',
  1450. duration: 2000
  1451. })
  1452. }
  1453. })
  1454. })
  1455. } else {
  1456. ICINLocker.addUserToLock(this.data.deviceNum, str, str, str, 'FF', signKey, '', commonKey, '00000000', 'FFFFFFFF', (callback1) => {
  1457. if (callback1.status == '00') {
  1458. console.log(callback, '锁信息')
  1459. var IMEI = callback.nbIMEI.substr(0, 15);
  1460. var IMSI = callback.nvIMSI.substr(0, 15);
  1461. var data = {
  1462. lockerId: this.data.deviceNum,
  1463. imei: IMEI,
  1464. imsi: IMSI,
  1465. // customerCode: "d39eaa7fc1f34190869608259133d2fb",
  1466. lockerSuperAdminId: str,
  1467. authKey: this.data.signKey.toUpperCase(),
  1468. commonKey: this.data.commonKey,
  1469. enterpriseId: this.data.adminuserinfo.enterpriseId,
  1470. type: this.data.type,
  1471. order: 5101,
  1472. roomName: this.data.selectRoomList.join("/")
  1473. };
  1474. if (that.data.selectRadio == 1 || that.data.selectRadio == 3) {
  1475. that.reportOfflineCardPrivateKeyMethods(str, signKey, commonKey, IMEI, IMSI)
  1476. }
  1477. setTimeout(() => {
  1478. if (!that.data.resgiterdevice) {
  1479. var datastr = {
  1480. data: {
  1481. manufactureId: that.data.selectindex == 2 ? 201 : that.data.selectindex == 3 ? 221 : '',
  1482. lockerId: data.lockerId,
  1483. imei: data.imei,
  1484. imsi: data.imsi,
  1485. // customerCode:data.customerCode,
  1486. lockerSuperAdminId: data.lockerSuperAdminId,
  1487. authKey: data.authKey,
  1488. commonKey: data.commonKey,
  1489. type: data.type,
  1490. order: 5101,
  1491. cardName: data.cardName,
  1492. roomName: data.roomName
  1493. },
  1494. code: "/v1/zg/registerDevice",
  1495. enterpriseId: data.enterpriseId,
  1496. key: data.lockerId
  1497. }
  1498. console.log(datastr, 'datastrdatastr631')
  1499. WXAPI.registerDeviceAll(datastr).then(res => {
  1500. console.log(res, '注册设备')
  1501. if (res.success) {
  1502. that.setData({
  1503. onlyResgiter: true
  1504. })
  1505. wx.showToast({
  1506. title: res.message,
  1507. icon: 'none',
  1508. duration: 2000
  1509. })
  1510. var data1 = {
  1511. pageNum: 1,
  1512. pageSize: 10,
  1513. q: JSON.stringify({
  1514. deviceNum: this.data.deviceNum,
  1515. // lockType:1,
  1516. types: [1, 21],
  1517. })
  1518. }
  1519. var data2 = [{
  1520. siteId: that.data.selectKey,
  1521. deviceId: res.data.id,
  1522. }]
  1523. var data3 = {
  1524. code: "zg/bleRegisterInfo",
  1525. data: {
  1526. lockerId: this.data.deviceNum
  1527. }
  1528. }
  1529. WXAPI.sendCommand(data3).then(res1 => {
  1530. if (res1.success) {
  1531. this.setData({
  1532. cgInfo: res1.data
  1533. })
  1534. } else {
  1535. }
  1536. })
  1537. if (that.data.selectRadio == 1 || that.data.selectRadio == 3) {
  1538. WXAPI.bindDeviceSite(data2).then(res2 => {
  1539. console.log(res2, '绑定设备数据')
  1540. if (res2.success) {
  1541. wx.showToast({
  1542. title: '操作成功',
  1543. duration: 2000,
  1544. icon: "none"
  1545. })
  1546. this.getuser(that.data.selectKey)
  1547. WXAPI.getDeviceItems(data1).then(res3 => {
  1548. wx.hideLoading()
  1549. this.setData({
  1550. deviceInfo: res3.data.list[0],
  1551. show: false
  1552. })
  1553. })
  1554. }
  1555. })
  1556. }
  1557. } else {
  1558. wx.showToast({
  1559. title: '平台注册失败',
  1560. icon: 'none',
  1561. duration: 2000
  1562. })
  1563. }
  1564. })
  1565. } else {
  1566. var data1 = {
  1567. pageNum: 1,
  1568. pageSize: 10,
  1569. q: JSON.stringify({
  1570. deviceNum: this.data.deviceNum,
  1571. // lockType:1,
  1572. types: [1, 21],
  1573. })
  1574. }
  1575. var data2 = [{
  1576. siteId: that.data.selectKey,
  1577. deviceId: that.data.deviceInfo.id,
  1578. }]
  1579. var data3 = {
  1580. code: "zg/bleRegisterInfo",
  1581. data: {
  1582. lockerId: this.data.deviceNum
  1583. }
  1584. }
  1585. WXAPI.sendCommand(data3).then(res1 => {
  1586. if (res1.success) {
  1587. this.setData({
  1588. cgInfo: res1.data
  1589. })
  1590. } else {
  1591. }
  1592. })
  1593. if (that.data.selectRadio == 1 || that.data.selectRadio == 3) {
  1594. WXAPI.bindDeviceSite(data2).then(res2 => {
  1595. console.log(res2, '绑定设备数据')
  1596. if (res2.success) {
  1597. wx.showToast({
  1598. title: '操作成功',
  1599. duration: 2000,
  1600. icon: "none"
  1601. })
  1602. this.getuser(that.data.selectKey)
  1603. WXAPI.getDeviceItems(data1).then(res3 => {
  1604. wx.hideLoading()
  1605. this.setData({
  1606. deviceInfo: res3.data.list[0],
  1607. show: false
  1608. })
  1609. })
  1610. }
  1611. })
  1612. }
  1613. }
  1614. }, 1000)
  1615. } else {
  1616. wx.showToast({
  1617. title: '门锁注册失败',
  1618. icon: 'none',
  1619. duration: 2000
  1620. })
  1621. }
  1622. })
  1623. }
  1624. })
  1625. })
  1626. })
  1627. },
  1628. // 绑定房间
  1629. bindRoomMethods() {
  1630. this.setData({
  1631. show: true
  1632. })
  1633. },
  1634. // resgiterDeviceMethods(){
  1635. // let deviceInfo = this.data.deviceInfo
  1636. // let userInfo = wx.getStorageSync('userInfo')
  1637. // if(deviceInfo.imei){
  1638. // var datastr={
  1639. // data: {
  1640. // deviceNum: deviceInfo.deviceNum,
  1641. // imei: deviceInfo.imei,
  1642. // imsi: deviceInfo.imei,
  1643. // order: 5101,
  1644. // platformId: 1,
  1645. // manufactureId: 1201,
  1646. // },
  1647. // code: "/v1/isp/registerDevice",
  1648. // enterpriseId: userInfo.enterpriseId,
  1649. // key: deviceInfo.deviceNum
  1650. // }
  1651. // WXAPI.registerDeviceAll(datastr).then(res => {
  1652. // if(res.success && res.data.success){
  1653. // this.getdevice()
  1654. // wx.showToast({
  1655. // title: '注册成功',
  1656. // duration:2000,
  1657. // icon:'none'
  1658. // })
  1659. // }else{
  1660. // if(res.success){
  1661. // wx.showToast({
  1662. // title: `注册失败:${res.data.msg}`,
  1663. // duration:2000,
  1664. // icon:'none'
  1665. // })
  1666. // }else{
  1667. // wx.showToast({
  1668. // title: `注册失败:${res.message}`,
  1669. // duration:2000,
  1670. // icon:'none'
  1671. // })
  1672. // }
  1673. // }
  1674. // })
  1675. // }else if(this.data.selectindex == 4) {
  1676. // let data = {
  1677. // code: 'lwj/registerDevice',
  1678. // }
  1679. // WXAPI.sendCommand(data).then(res => {
  1680. // })
  1681. // }else{
  1682. // wx.showToast({
  1683. // title: '请先查询IMEI',
  1684. // duration:2000,
  1685. // icon:'none'
  1686. // })
  1687. // }
  1688. // },
  1689. // 注册到平台
  1690. resgiterDeviceMethods1() {
  1691. if (this.data.platformId == 0) {
  1692. return wx.showToast({
  1693. title: '请先选择运营商',
  1694. icon: "none",
  1695. duration: 2000
  1696. })
  1697. }
  1698. if (this.data.selectRadio1 == '1201') {
  1699. this.resgWfiDevice()
  1700. } else if (this.data.selectRadio1 == '1221') {
  1701. } else if (this.data.selectRadio1 == '1231') {
  1702. } else if (this.data.selectRadio1 == '1241') {
  1703. this.resgWfiDevice()
  1704. }
  1705. },
  1706. // Wifi人脸锁注册
  1707. resgWfiDevice() {
  1708. wx.showLoading({
  1709. title: '注册中...',
  1710. icon: 'none'
  1711. })
  1712. var that = this
  1713. var lockMac = this.data.lock.mac
  1714. // var superAdminIdlist = this.data.lock.mac.slice(this.data.lock.mac.length - 11, this.data.lock.mac.length).split(":").join("")
  1715. // var superAdmin = []
  1716. var superAdminId
  1717. var deviceimei
  1718. console.log(that.data.lock);
  1719. if (that.data.selectRadio1 == 1201) {
  1720. deviceimei = that.data.lock.imei
  1721. } else if (that.data.selectRadio1 == 1241) {
  1722. if (that.data.deviceNum.length <= 15) {
  1723. deviceimei = that.data.deviceNum
  1724. } else {
  1725. deviceimei = that.data.deviceNum.slice(that.data.deviceNum.length - 15, that.data.deviceNum.length)
  1726. }
  1727. }
  1728. // for (let i = 0; i < superAdminIdlist.length; i++) {
  1729. // if (superAdminIdlist[i] >= 0 && superAdminIdlist[i] <= 9) {
  1730. // superAdmin.push(superAdminIdlist[i])
  1731. // } else {
  1732. // let adminid = superAdminIdlist.charCodeAt(i)
  1733. // superAdmin.push(adminid)
  1734. // }
  1735. // }
  1736. // superAdminId = superAdmin.join('').slice(superAdmin.length - 8, superAdmin.length)
  1737. // console.log(lockMac, superAdminIdlist, superAdminId);
  1738. // let superAdmin = []
  1739. // var superAdminIdlist = lock.mac.slice(lock.mac.length - 11, lock.mac.length).split(":").join("")
  1740. // for (let i = 0; i < superAdminIdlist.length; i++) {
  1741. // if (superAdminIdlist[i] >= 0 && superAdminIdlist[i] <= 9) {
  1742. // superAdmin.push(superAdminIdlist[i])
  1743. // } else {
  1744. // let adminid = superAdminIdlist.charCodeAt(i)
  1745. // superAdmin.push(adminid)
  1746. // }
  1747. // }
  1748. // let superAdminId = superAdmin.join('').slice(superAdmin.length - 8, superAdmin.length)
  1749. // basecode = superAdminId
  1750. console.log("123123123123", basecode, superAdminId, deviceimei);
  1751. let data = {
  1752. code: 'lwj/registerDevice',
  1753. data: {
  1754. deviceNum: this.data.deviceNum,
  1755. imei: deviceimei,
  1756. imsi: deviceimei,
  1757. platformId: this.data.platformId,
  1758. manufactureId: this.data.selectRadio1
  1759. }
  1760. }
  1761. console.log(data);
  1762. WXAPI.sendCommand(data).then(res => {
  1763. console.log(res, data, basecode);
  1764. if (res.success) {
  1765. let data1 = {
  1766. code: 'lwj/registerSupperAdmin',
  1767. data: {
  1768. lockerId: that.data.deviceNum,
  1769. lockerSuperAdminId: basecode,
  1770. bluetoothMac: lockMac
  1771. }
  1772. }
  1773. WXAPI.sendCommand(data1).then(res1 => {
  1774. console.log(res1);
  1775. if (res1.success) {
  1776. wx.hideLoading()
  1777. wx.showToast({
  1778. title: '注册成功',
  1779. icon: 'none',
  1780. duration: 2000
  1781. })
  1782. this.setData({
  1783. showreg: false,
  1784. resgiterdevice: true
  1785. })
  1786. } else {
  1787. wx.hideLoading()
  1788. wx.showToast({
  1789. title: '注册失败',
  1790. icon: 'none',
  1791. duration: 2000
  1792. })
  1793. this.setData({
  1794. showreg: false
  1795. })
  1796. }
  1797. })
  1798. } else {
  1799. wx.hideLoading()
  1800. wx.showToast({
  1801. title: '注册失败',
  1802. icon: 'none',
  1803. duration: 2000
  1804. })
  1805. }
  1806. })
  1807. },
  1808. changemanId() {
  1809. // var data = {
  1810. // q: JSON.stringify({
  1811. // // lockType:1,
  1812. // types: [41],
  1813. // })
  1814. // }
  1815. // WXAPI.getDeviceItems(data).then(res => {
  1816. // console.log(res);
  1817. // let deviceNumlist = res.data.list.filter(li => {
  1818. // return li.deviceNum == this.data.deviceNum
  1819. // })
  1820. // console.log(deviceNumlist);
  1821. // if (deviceNumlist[0]) {
  1822. // wx.showToast({
  1823. // title: '该设备已注册在平台上',
  1824. // icon: 'none',
  1825. // duration: 2000
  1826. // })
  1827. // } else {
  1828. this.setData({
  1829. showreg: true
  1830. })
  1831. // }
  1832. // })
  1833. },
  1834. onClosereg() {
  1835. this.setData({
  1836. showreg: false
  1837. })
  1838. },
  1839. registerSelectRoom() {
  1840. var _this = this
  1841. if (this.data.selectKey) {
  1842. wx.showModal({
  1843. title: '',
  1844. content: '是否绑定',
  1845. success(res) {
  1846. if (res.confirm) {
  1847. if (_this.data.selectindex == 4) {
  1848. var data2 = [{
  1849. siteId: _this.data.selectKey,
  1850. deviceId: _this.data.deviceInfo.id,
  1851. }]
  1852. WXAPI.bindDeviceSite(data2).then(res2 => {
  1853. if (res2.success) {
  1854. _this.getdevice()
  1855. }
  1856. })
  1857. } else {
  1858. var name = util.findIndexArray(_this.data.dataList, _this.data.selectKey, [])
  1859. _this.setData({
  1860. selectKey: _this.data.selectKey,
  1861. show: false,
  1862. selectRoomList: name
  1863. })
  1864. var data = {
  1865. pageNum: 1,
  1866. pageSize: 1,
  1867. q: JSON.stringify({
  1868. roomIds: [_this.data.selectKey],
  1869. // lockType:1,
  1870. types: [1, 21],
  1871. })
  1872. }
  1873. WXAPI.getDeviceItems(data).then(res => {
  1874. if (res.data.list.length == 0) {
  1875. _this.addAdmin()
  1876. } else {
  1877. wx.showToast({
  1878. title: '该房间已绑定',
  1879. icon: 'none'
  1880. })
  1881. }
  1882. })
  1883. }
  1884. } else if (res.cancel) {
  1885. _this.setData({
  1886. selectKey: _this.data.selectKey,
  1887. show: false
  1888. })
  1889. }
  1890. }
  1891. })
  1892. } else {
  1893. wx.showToast({
  1894. title: '请选择房间',
  1895. icon: 'none'
  1896. })
  1897. }
  1898. },
  1899. handleSelect(e) {
  1900. var _this = this
  1901. if (e.detail.tips) {
  1902. wx.showToast({
  1903. title: '请选择房间',
  1904. icon: 'none'
  1905. })
  1906. } else {
  1907. wx.showModal({
  1908. title: '',
  1909. content: '是否绑定',
  1910. success(res) {
  1911. if (res.confirm) {
  1912. if (_this.data.selectindex == 4) {
  1913. var data2 = [{
  1914. siteId: e.detail.item.id,
  1915. deviceId: _this.data.deviceInfo.id,
  1916. }]
  1917. WXAPI.bindDeviceSite(data2).then(res2 => {
  1918. console.log(res2);
  1919. if (res2.success) {
  1920. _this.getdevice()
  1921. wx.showToast({
  1922. title: '绑定成功',
  1923. icon: 'none',
  1924. duration: 2000
  1925. })
  1926. } else {
  1927. wx.showToast({
  1928. title: '绑定失败',
  1929. icon: 'none',
  1930. duration: 2000
  1931. })
  1932. }
  1933. })
  1934. } else {
  1935. var name = util.findIndexArray(_this.data.dataList, e.detail.item.id, [])
  1936. _this.setData({
  1937. selectKey: e.detail.item.id,
  1938. show: false,
  1939. selectRoomList: name
  1940. })
  1941. var data = {
  1942. pageNum: 1,
  1943. pageSize: 1,
  1944. q: JSON.stringify({
  1945. roomIds: [e.detail.item.id],
  1946. // lockType:1,
  1947. types: [1, 21],
  1948. })
  1949. }
  1950. WXAPI.getDeviceItems(data).then(res => {
  1951. if (res.data.list.length == 0) {
  1952. _this.addAdmin()
  1953. } else {
  1954. wx.showToast({
  1955. title: '该房间已绑定',
  1956. icon: 'none'
  1957. })
  1958. }
  1959. })
  1960. }
  1961. } else if (res.cancel) {
  1962. _this.setData({
  1963. selectKey: e.detail.item.id,
  1964. show: false
  1965. })
  1966. }
  1967. }
  1968. })
  1969. }
  1970. },
  1971. // 配网
  1972. changeshow2() {
  1973. this.setData({
  1974. show2: true
  1975. })
  1976. },
  1977. onChange(event) {
  1978. this.setData({
  1979. WifiName: event.detail
  1980. })
  1981. },
  1982. onChange1(event) {
  1983. this.setData({
  1984. WifiPwd: event.detail
  1985. })
  1986. },
  1987. onConfigurewifi() {
  1988. // if (isConnected) {
  1989. var that = this
  1990. // that.wifitimer = setTimeout(() => {
  1991. // wx.closeBLEConnection({
  1992. // deviceId: lockDevice.deviceId,
  1993. // success(res) {
  1994. // },
  1995. // fail: res => {
  1996. // console.log("1", res);
  1997. // }
  1998. // })
  1999. // wx.showToast({
  2000. // title: '配网失败,请重试',
  2001. // duration: 2000
  2002. // })
  2003. // }, 6000)
  2004. // wx.showLoading({
  2005. // title: '配置网络中...',
  2006. // })
  2007. var bytes = plugin.configureWifi(lockDevice.name, lockMac, that.data.WifiName, that.data.WifiPwd)
  2008. that.sendBytes(bytes)
  2009. this.setData({
  2010. show2: false
  2011. })
  2012. // }else{
  2013. // this.initBluetooth()
  2014. // }
  2015. },
  2016. // 添加人脸
  2017. addFaceprint() {
  2018. wx.navigateTo({
  2019. url: '/pagesA/selectFace/selectFace',
  2020. })
  2021. },
  2022. // 删除人脸
  2023. delFaceprint() {
  2024. },
  2025. // 获取设备
  2026. getdevice() {
  2027. var q = {
  2028. deviceNum: this.data.deviceInfo.deviceNum,
  2029. // lockType:1,
  2030. types: [1, 21],
  2031. };
  2032. var data = {
  2033. q: JSON.stringify(q),
  2034. pageNum: 1,
  2035. pageSize: 10,
  2036. };
  2037. WXAPI.getDeviceItems(data).then(res => {
  2038. var data = res.data.list
  2039. this.setData({
  2040. deviceInfo: data[0],
  2041. show: false
  2042. })
  2043. })
  2044. },
  2045. bindroom() {
  2046. if (this.data.selectKey) {
  2047. this.registerSelectRoom()
  2048. } else {
  2049. this.setData({
  2050. show: true
  2051. });
  2052. }
  2053. },
  2054. // 添加用户
  2055. adduser() {
  2056. var userInfo = wx.getStorageSync('userInfo')
  2057. var str = md5(userInfo.phone)
  2058. var usrID = str.substr(str.length - 7, str.length).toUpperCase()
  2059. console.log(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, this.data.cgInfo.authKey, '----')
  2060. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, (callback) => {
  2061. var signKey = callback.signKey
  2062. console.log(signKey, 'signKey', callback)
  2063. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, callback.signKey, (callback1) => {
  2064. var commonKey = callback1.commonKey
  2065. console.log(commonKey, 'commonKey', callback1)
  2066. ICINLocker.addUserToLock(this.data.cgInfo.lockerId, this.data.cgInfo.superId, usrID, this.data.cgInfo.superId, '00', signKey, '', commonKey, '00000000', 'FFFFFFFF', (callback) => {
  2067. if (callback.status == '00') {
  2068. var infostr = {
  2069. userTelephone: userInfo.phone,
  2070. userPassword: usrID,
  2071. };
  2072. var data1 = {
  2073. cardId: userInfo.phone,
  2074. cardState: 1,
  2075. info: JSON.stringify(infostr),
  2076. name: '施工用户',
  2077. number: userInfo.phone,
  2078. phone: userInfo.phone,
  2079. sex: 1,
  2080. type: 0
  2081. }
  2082. WXAPI.addCard(data1).then(res => {
  2083. if (res.success) {
  2084. wx.showToast({
  2085. title: '添加成功',
  2086. icon: 'none'
  2087. })
  2088. var data2 = [{
  2089. cardId: res.data,
  2090. siteId: this.data.deviceInfo.roomId,
  2091. }]
  2092. WXAPI.bindCard(data2).then(res2 => {
  2093. if (res2.success) {
  2094. wx.showToast({
  2095. title: '绑定成功',
  2096. icon: 'none'
  2097. })
  2098. }
  2099. })
  2100. }
  2101. })
  2102. }
  2103. })
  2104. })
  2105. })
  2106. },
  2107. // 读取门锁状态
  2108. readLockStatus() {
  2109. wx.showLoading({
  2110. title: '读取中',
  2111. mask: true
  2112. })
  2113. var cgInfo = this.data.cgInfo
  2114. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, (callback) => {
  2115. var signKey = callback.signKey
  2116. console.log(signKey, 'signKey')
  2117. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, signKey, (callback1) => {
  2118. ICINLocker.readLockerInfo(cgInfo.lockerId, cgInfo.superId, (callback) => {
  2119. console.log(callback)
  2120. this.setData({
  2121. lockStatus: callback
  2122. })
  2123. wx.hideLoading()
  2124. })
  2125. })
  2126. })
  2127. setTimeout(() => {
  2128. wx.hideLoading()
  2129. }, 5000)
  2130. // ICINLocker.readLockerInfo(this.data.cgInfo.lockerId, this.data.cgInfo.superId, (callback) => {
  2131. // this.setData({
  2132. // lockStatus: callback
  2133. // })
  2134. // })
  2135. },
  2136. onClose() {
  2137. this.setData({
  2138. show: false,
  2139. show2: false
  2140. });
  2141. },
  2142. onClose1() {
  2143. this.setData({
  2144. sheetshow: false
  2145. })
  2146. },
  2147. // 获取房间
  2148. getRoom() {
  2149. var _this = this
  2150. WXAPI.getTree('').then(res => {
  2151. var list = (res.data.sort((pre, cur) => pre.id - cur.id))
  2152. var newArr = util.uniqueArray(list, "id");
  2153. this.list = newArr
  2154. var setting = {
  2155. data: {
  2156. simpleData: {
  2157. idKey: 'id',
  2158. pIdKey: 'pid'
  2159. },
  2160. key: {
  2161. children: 'children'
  2162. }
  2163. }
  2164. }
  2165. var dataList = this.transformTozTreeFormat(setting, newArr)
  2166. this.setData({
  2167. dataList: dataList
  2168. })
  2169. })
  2170. },
  2171. transformTozTreeFormat(setting, sNodes) {
  2172. var i, l,
  2173. key = setting.data.simpleData.idKey,
  2174. parentKey = setting.data.simpleData.pIdKey,
  2175. childKey = setting.data.key.children
  2176. if (!key || key == "" || !sNodes) return [];
  2177. var r = [];
  2178. var tmpMap = [];
  2179. for (i = 0, l = sNodes.length; i < l; i++) {
  2180. tmpMap[sNodes[i][key]] = sNodes[i];
  2181. }
  2182. for (i = 0, l = sNodes.length; i < l; i++) {
  2183. if (tmpMap[sNodes[i][parentKey]] && sNodes[i][key] != sNodes[i][parentKey]) {
  2184. if (!tmpMap[sNodes[i][parentKey]][childKey])
  2185. tmpMap[sNodes[i][parentKey]][childKey] = [];
  2186. tmpMap[sNodes[i][parentKey]][childKey].push(sNodes[i]);
  2187. } else {
  2188. r.push(sNodes[i]);
  2189. }
  2190. }
  2191. return r;
  2192. },
  2193. /**
  2194. * 生命周期函数--监听页面初次渲染完成
  2195. */
  2196. onReady: function () {
  2197. var that = this
  2198. if (that.data.selectindex == 4) {
  2199. that.initBluetooth()
  2200. }
  2201. },
  2202. /**
  2203. * 生命周期函数--监听页面显示
  2204. */
  2205. onShow: function () {
  2206. },
  2207. /**
  2208. * 生命周期函数--监听页面隐藏
  2209. */
  2210. onHide: function () {},
  2211. /**
  2212. * 生命周期函数--监听页面卸载
  2213. */
  2214. onUnload: function () {
  2215. if (this.data.selectindex == 4) {
  2216. if (isConnected) {
  2217. wx.closeBLEConnection({
  2218. deviceId: connectedDeviceId,
  2219. success: function (res) {
  2220. isConnected = false
  2221. },
  2222. })
  2223. }
  2224. } else {
  2225. ICINLocker.disConnect(app.globalData.blueDeviceId);
  2226. app.globalData.zgBlueStatus = false
  2227. }
  2228. },
  2229. /**
  2230. * 页面相关事件处理函数--监听用户下拉动作
  2231. */
  2232. onPullDownRefresh: function () {
  2233. wx.stopPullDownRefresh()
  2234. },
  2235. bindLock: function () {
  2236. var that = this
  2237. taskId = 11
  2238. that.initBluetooth()
  2239. },
  2240. configurewifj() {
  2241. var that = this
  2242. taskId = 121
  2243. that.initBluetooth()
  2244. },
  2245. unbindLock: function () {
  2246. var that = this
  2247. taskId = 12
  2248. that.initBluetooth()
  2249. },
  2250. queryBindState: function () {
  2251. var that = this
  2252. taskId = 21
  2253. that.initBluetooth()
  2254. },
  2255. queryBattery: function () {
  2256. var that = this
  2257. taskId = 22
  2258. that.initBluetooth()
  2259. },
  2260. queryNbImei: function () {
  2261. var that = this
  2262. taskId = 31
  2263. that.initBluetooth()
  2264. },
  2265. login: function () {
  2266. var that = this
  2267. taskId = 32
  2268. that.initBluetooth()
  2269. },
  2270. openLock: function () {
  2271. var that = this
  2272. taskId = 41
  2273. that.initBluetooth()
  2274. },
  2275. syncClock: function () {
  2276. var that = this
  2277. taskId = 42
  2278. that.initBluetooth()
  2279. },
  2280. addPincode: function () {
  2281. var that = this
  2282. taskId = 51
  2283. that.initBluetooth()
  2284. },
  2285. delPincode: function () {
  2286. var that = this
  2287. taskId = 52
  2288. that.initBluetooth()
  2289. },
  2290. addRfCard: function () {
  2291. var that = this
  2292. taskId = 61
  2293. that.initBluetooth()
  2294. },
  2295. delRfCard: function () {
  2296. var that = this
  2297. taskId = 62
  2298. that.initBluetooth()
  2299. },
  2300. addFingerprint: function () {
  2301. var that = this
  2302. taskId = 71
  2303. that.initBluetooth()
  2304. },
  2305. delFingerprint: function () {
  2306. var that = this
  2307. taskId = 72
  2308. that.initBluetooth()
  2309. },
  2310. changeAdminPincode: function () {
  2311. var that = this
  2312. taskId = 81
  2313. that.initBluetooth()
  2314. },
  2315. queryLockSlotState: function () {
  2316. var that = this
  2317. taskId = 91
  2318. that.initBluetooth()
  2319. },
  2320. queryLockUnlockState: function () {
  2321. var that = this
  2322. taskId = 92
  2323. that.initBluetooth()
  2324. },
  2325. changeLockUnlockState: function () {
  2326. var that = this
  2327. taskId = 101
  2328. that.initBluetooth()
  2329. },
  2330. changeLockMutedState: function () {
  2331. var that = this
  2332. taskId = 102
  2333. that.initBluetooth()
  2334. },
  2335. changeLockNbState: function () {
  2336. var that = this
  2337. taskId = 111
  2338. that.initBluetooth()
  2339. },
  2340. genOfflinePincode: function () {
  2341. var that = this
  2342. wx.showLoading({
  2343. title: '生成离线密码中',
  2344. })
  2345. var startTime = util1.getLocalTime(8)
  2346. var endTime = new Date(startTime.getTime() + 5 * 60 * 1000) //有效期5分钟
  2347. plugin.genOfflinePincode(lockDevice.name, lockMac, basecode, 0, startTime, endTime)
  2348. .then(function (data) {
  2349. console.debug('data', data)
  2350. wx.hideLoading()
  2351. if (data.code == 200) {
  2352. wx.showModal({
  2353. title: '提示',
  2354. content: `生成离线密码${data.data},有效期至${util1.formatTime(endTime)}`,
  2355. showCancel: false
  2356. })
  2357. } else {
  2358. wx.showModal({
  2359. title: '提示',
  2360. content: data.data,
  2361. showCancel: false
  2362. })
  2363. }
  2364. })
  2365. },
  2366. onQueryBindState: function () {
  2367. var that = this
  2368. wx.showLoading({
  2369. title: '查询中',
  2370. })
  2371. var bytes = plugin.queryLockState(lockDevice.name)
  2372. console.debug('bytes', bytes)
  2373. that.sendBytes(bytes)
  2374. },
  2375. onQueryBattery: function () {
  2376. var that = this
  2377. wx.showLoading({
  2378. title: '查询中',
  2379. })
  2380. var bytes = plugin.queryLockBattery(lockDevice.name)
  2381. console.debug('bytes', bytes)
  2382. that.sendBytes(bytes)
  2383. },
  2384. onQueryNbImei: function () {
  2385. var that = this
  2386. wx.showLoading({
  2387. title: '查询中',
  2388. })
  2389. var bytes = plugin.queryNbImei(lockDevice.name)
  2390. console.debug('bytes', bytes)
  2391. that.sendBytes(bytes)
  2392. },
  2393. onBindLock: function () {
  2394. var that = this
  2395. wx.showLoading({
  2396. title: '绑定中',
  2397. })
  2398. var bytes = plugin.sendBindLock(lockDevice.name, lockId, lockManagerId, basecode)
  2399. console.debug('bytes----', bytes)
  2400. that.sendBytes(bytes)
  2401. },
  2402. onUnbindLock: function () {
  2403. var that = this
  2404. wx.showLoading({
  2405. title: '解绑中',
  2406. })
  2407. var bytes = plugin.sendUnbindLock(lockDevice.name, lockId, lockManagerId, basecode)
  2408. console.debug('bytes', bytes)
  2409. that.sendBytes(bytes)
  2410. },
  2411. onOpenLock: function () {
  2412. var that = this
  2413. wx.showLoading({
  2414. title: that.data.isJack ? '上电中' : '解锁中',
  2415. })
  2416. var bytes = plugin.sendOpenLockP1(lockDevice.name, basecode)
  2417. console.debug('bytes', bytes)
  2418. that.sendBytes(bytes)
  2419. },
  2420. onLogin: function () {
  2421. var that = this
  2422. wx.showLoading({
  2423. title: '登录中',
  2424. })
  2425. var bytes = plugin.login1(lockDevice.name, basecode)
  2426. console.debug('bytes', bytes)
  2427. that.sendBytes(bytes)
  2428. },
  2429. onSyncClock: function () {
  2430. var that = this
  2431. wx.showLoading({
  2432. title: '同步时钟中',
  2433. })
  2434. console.log(lockDevice.name, basecode, util1.getLocalTime(8), '0000')
  2435. var bytes = plugin.syncClock(lockDevice.name, basecode, util1.getLocalTime(8))
  2436. console.debug('bytes', bytes)
  2437. that.sendBytes(bytes)
  2438. },
  2439. onAddPincode: function () {
  2440. var that = this
  2441. wx.showLoading({
  2442. title: '添加密码中',
  2443. })
  2444. var startTime = util1.getLocalTime(8)
  2445. var endTime = new Date(startTime.getTime() + 30 * 24 * 60 * 60 * 1000) //有效期5分钟
  2446. pincode = util1.randomPrime6()
  2447. pincodeIndex = Math.floor(Math.random() * 100)
  2448. console.log(lockDevice.name, basecode, pincode, pincodeIndex, startTime, endTime, 'lockDevice.name, basecode, pincode, pincodeIndex, startTime, endTime')
  2449. var bytes = plugin.addPincode(lockDevice.name, basecode, pincode, pincodeIndex, startTime, endTime)
  2450. console.log('bytes', bytes)
  2451. that.sendBytes(bytes)
  2452. },
  2453. onDelPincode: function () {
  2454. var that = this
  2455. wx.showLoading({
  2456. title: '删除密码中',
  2457. })
  2458. var bytes = plugin.delPincode(lockDevice.name, basecode, pincode, pincodeIndex)
  2459. console.debug('bytes', bytes)
  2460. that.sendBytes(bytes)
  2461. },
  2462. onAddRfCard: function () {
  2463. var that = this
  2464. wx.showLoading({
  2465. title: '添加房卡中',
  2466. })
  2467. var startTime = util1.getLocalTime(8)
  2468. var endTime = new Date(startTime.getTime() + 5 * 60 * 1000) //有效期5分钟
  2469. rfCardIndex = Math.floor(Math.random() * 100)
  2470. var bytes = plugin.addRfCard(lockDevice.name, basecode, rfCardId, rfCardIndex, startTime, endTime)
  2471. console.debug('bytes', bytes)
  2472. that.sendBytes(bytes)
  2473. },
  2474. onDelRfCard: function () {
  2475. var that = this
  2476. wx.showLoading({
  2477. title: '删除房卡中',
  2478. })
  2479. var bytes = plugin.delRfCard(lockDevice.name, basecode, rfCardId, rfCardIndex)
  2480. console.debug('bytes', bytes)
  2481. that.sendBytes(bytes)
  2482. },
  2483. onAddFingerprint: function () {
  2484. var that = this
  2485. wx.showLoading({
  2486. title: '添加指纹中',
  2487. })
  2488. var startTime = util1.getLocalTime(8)
  2489. var endTime = new Date(startTime.getTime() + 5 * 60 * 1000) //有效期5分钟
  2490. fingerprintIndex = Math.floor(Math.random() * 100)
  2491. var bytes = plugin.addFingerprint(lockDevice.name, basecode, fingerprintIndex, startTime, endTime)
  2492. console.debug('bytes', bytes)
  2493. that.sendBytes(bytes)
  2494. },
  2495. onDelFingerprint: function () {
  2496. var that = this
  2497. wx.showLoading({
  2498. title: '删除指纹中',
  2499. })
  2500. var bytes = plugin.delFingerprint(lockDevice.name, basecode, fingerprintIndex)
  2501. console.debug('bytes', bytes)
  2502. that.sendBytes(bytes)
  2503. },
  2504. onChangeAdminPincode: function () {
  2505. var that = this
  2506. wx.showLoading({
  2507. title: '修改管理密码中',
  2508. })
  2509. var bytes = plugin.changeAdminPincode(lockDevice.name, lockMac, 12345678, 87654321)
  2510. console.debug('bytes', bytes)
  2511. that.sendBytes(bytes)
  2512. },
  2513. onQueryLockSlotState: function () {
  2514. var that = this
  2515. wx.showLoading({
  2516. title: '查询门锁方舌状态',
  2517. })
  2518. var bytes = plugin.queryLockSlotState(lockDevice.name)
  2519. console.debug('bytes', bytes)
  2520. that.sendBytes(bytes)
  2521. },
  2522. onQueryLockUnlockState: function () {
  2523. var that = this
  2524. wx.showLoading({
  2525. title: '查询门锁开关状态',
  2526. })
  2527. var bytes = plugin.queryLockUnlockState(lockDevice.name)
  2528. console.debug('bytes', bytes)
  2529. that.sendBytes(bytes)
  2530. },
  2531. onChangeLockUnlockState: function () {
  2532. var that = this
  2533. wx.showLoading({
  2534. title: that.data.isUnloked ? '退出常开模式' : '进入常开模式',
  2535. })
  2536. var bytes = plugin.setLockUnlockState(lockDevice.name, !that.data.isUnloked)
  2537. console.debug('bytes', bytes)
  2538. that.sendBytes(bytes)
  2539. },
  2540. onChangeLockMutedState: function () {
  2541. var that = this
  2542. wx.showLoading({
  2543. title: that.data.isMuted ? '退出静音模式' : '进入静音模式',
  2544. })
  2545. var bytes = plugin.setLockMuteState(lockDevice.name, !that.data.isMuted)
  2546. console.debug('bytes', bytes)
  2547. that.sendBytes(bytes)
  2548. },
  2549. onChangeLockNbState: function () {
  2550. var that = this
  2551. wx.showLoading({
  2552. title: that.data.isNbEnable ? '禁用NB功能' : '打开NB功能',
  2553. })
  2554. var bytes = plugin.setNbFun(lockDevice.name, !that.data.isNbEnable)
  2555. console.debug('bytes', bytes)
  2556. that.sendBytes(bytes)
  2557. },
  2558. doWork: function () {
  2559. var that = this
  2560. switch (taskId) {
  2561. case 11: {
  2562. that.onBindLock()
  2563. break
  2564. }
  2565. case 12: {
  2566. that.onUnbindLock()
  2567. break
  2568. }
  2569. case 21: {
  2570. that.onQueryBindState()
  2571. break
  2572. }
  2573. case 22: {
  2574. that.onQueryBattery()
  2575. break
  2576. }
  2577. case 31: {
  2578. that.onQueryNbImei()
  2579. break
  2580. }
  2581. case 32: {
  2582. that.onLogin()
  2583. break
  2584. }
  2585. case 41: {
  2586. that.onOpenLock()
  2587. break
  2588. }
  2589. case 42: {
  2590. that.onSyncClock()
  2591. break
  2592. }
  2593. case 51: {
  2594. that.onAddPincode()
  2595. break
  2596. }
  2597. case 52: {
  2598. that.onDelPincode()
  2599. break
  2600. }
  2601. case 61: {
  2602. if (lockModel > 70) {
  2603. that.onAddRfCard()
  2604. } else {
  2605. wx.showModal({
  2606. title: '提示',
  2607. content: '请刷卡!',
  2608. showCancel: false
  2609. })
  2610. }
  2611. break
  2612. }
  2613. case 62: {
  2614. that.onDelRfCard()
  2615. break
  2616. }
  2617. case 71: {
  2618. that.onAddFingerprint()
  2619. break
  2620. }
  2621. case 72: {
  2622. that.onDelFingerprint()
  2623. break
  2624. }
  2625. case 81: {
  2626. that.onChangeAdminPincode()
  2627. break
  2628. }
  2629. case 91: {
  2630. that.onQueryLockSlotState()
  2631. break
  2632. }
  2633. case 92: {
  2634. that.onQueryLockUnlockState()
  2635. break
  2636. }
  2637. case 101: {
  2638. that.onChangeLockUnlockState()
  2639. break
  2640. }
  2641. case 102: {
  2642. that.onChangeLockMutedState()
  2643. break
  2644. }
  2645. case 111: {
  2646. this.onChangeLockNbState()
  2647. break
  2648. }
  2649. case 121: {
  2650. this.onConfigurewifi()
  2651. }
  2652. default: {
  2653. }
  2654. }
  2655. },
  2656. initBluetooth: function () {
  2657. var that = this
  2658. wx.getConnectedBluetoothDevices({
  2659. services: [config.uuid.serviceUuid],
  2660. success: function (res) {
  2661. res.devices.map(function (it) {
  2662. if (it.deviceId == connectedDeviceId || it.name == name) {
  2663. isConnected = true
  2664. }
  2665. })
  2666. that.setData({
  2667. isConnected: isConnected
  2668. })
  2669. console.log(isInitReady, 'isConnected', isConnected)
  2670. if (isConnected) {
  2671. if (isInitReady) {
  2672. let lock = that.data.lock
  2673. let superAdmin = []
  2674. var superAdminIdlist = lock.mac.slice(lock.mac.length - 11, lock.mac.length).split(":").join("")
  2675. for (let i = 0; i < superAdminIdlist.length; i++) {
  2676. if (superAdminIdlist[i] >= 0 && superAdminIdlist[i] <= 9) {
  2677. superAdmin.push(superAdminIdlist[i])
  2678. } else {
  2679. let adminid = superAdminIdlist.charCodeAt(i)
  2680. superAdmin.push(adminid)
  2681. }
  2682. }
  2683. let superAdminId = superAdmin.join('').slice(superAdmin.length - 8, superAdmin.length)
  2684. basecode = superAdminId
  2685. console.log(basecode,"basecode")
  2686. setTimeout(() => {
  2687. that.doWork()
  2688. }, 500)
  2689. } else {
  2690. that.setupConnection()
  2691. }
  2692. } else {
  2693. that.connectTo()
  2694. }
  2695. },
  2696. })
  2697. },
  2698. connectTo: function () {
  2699. var that = this
  2700. wx.showLoading({
  2701. title: '连接中',
  2702. })
  2703. wx.createBLEConnection({
  2704. deviceId: lockDevice.deviceId,
  2705. timeout: config.ble.connectTimeOut,
  2706. success: function (res) {
  2707. console.debug('connectTo', res)
  2708. isConnected = true
  2709. wx.hideLoading()
  2710. setTimeout(function () {
  2711. that.setupConnection()
  2712. }, 500)
  2713. },
  2714. fail: function (e) {
  2715. console.debug('connectTo', e)
  2716. wx.hideLoading()
  2717. switch (e.errCode) {
  2718. case 10003: {
  2719. wx.showModal({
  2720. title: '连接失败',
  2721. content: '是否重新连接?',
  2722. success: function (res) {
  2723. if (res.confirm) {
  2724. that.connectTo()
  2725. }
  2726. }
  2727. })
  2728. break
  2729. }
  2730. case 10012: {
  2731. wx.showModal({
  2732. title: '连接失败',
  2733. content: '蓝牙连接超时',
  2734. showCancel: false
  2735. })
  2736. break
  2737. }
  2738. case 10002: {
  2739. wx.showModal({
  2740. title: '连接失败',
  2741. content: '没有找到指定设备',
  2742. showCancel: false
  2743. })
  2744. break
  2745. }
  2746. }
  2747. }
  2748. })
  2749. },
  2750. setupConnection: function () {
  2751. var that = this
  2752. wx.showLoading({
  2753. title: '初始化连接中',
  2754. })
  2755. wx.getBLEDeviceServices({
  2756. deviceId: lockDevice.deviceId,
  2757. success: function (res) {
  2758. console.log('Services', res)
  2759. wx.getBLEDeviceCharacteristics({
  2760. deviceId: lockDevice.deviceId,
  2761. serviceId: config.uuid.serviceUuid.toUpperCase(),
  2762. success: function (res) {
  2763. console.log('Characteristics', res)
  2764. wx.showLoading({
  2765. title: '连接成功',
  2766. })
  2767. wx.onBLECharacteristicValueChange(function (res) {
  2768. console.log(res, 'reslllllll')
  2769. var bytes = new Uint8Array(res.value)
  2770. console.log('bytes', bytes)
  2771. var data = plugin.parseBytes(lockDevice.name, basecode, bytes)
  2772. console.log('data', data)
  2773. switch (data.cmd) {
  2774. case 'reportLockBattery': {
  2775. if (data.data.battery < 10) {
  2776. wx.showModal({
  2777. title: '电量报警',
  2778. content: `门锁当前电量${data.data.battery}%!\n电量严重不足,请立即更换电池!`,
  2779. showCancel: false
  2780. })
  2781. } else if (data.data.battery < 30) {
  2782. wx.showModal({
  2783. title: '电量预警',
  2784. content: `门锁当前电量${data.data.battery}%!\n请及时更换电池!`,
  2785. showCancel: false
  2786. })
  2787. }
  2788. break
  2789. }
  2790. case 'reportRfCardResult': {
  2791. if (taskId == 61) {
  2792. wx.showModal({
  2793. title: '检测到新卡',
  2794. content: `是否添加此房卡,卡号:${data.data.cardId}`,
  2795. success: function (res) {
  2796. if (res.confirm) {
  2797. rfCardId = data.data.cardId
  2798. that.onAddRfCard()
  2799. }
  2800. }
  2801. })
  2802. } else {
  2803. if (lockModel > 70) {
  2804. if (data.data.isValid) {
  2805. wx.showModal({
  2806. title: '提示',
  2807. content: `房卡开锁成功,序号:${data.data.index}`,
  2808. showCancel: false
  2809. })
  2810. } else {
  2811. wx.showModal({
  2812. title: '提示',
  2813. content: `多次刷房卡开锁失败!`,
  2814. showCancel: false
  2815. })
  2816. }
  2817. } else {
  2818. if (data.data.isValid) {
  2819. wx.showModal({
  2820. title: '提示',
  2821. content: `房卡开锁成功,卡号:${data.data.cardId}`,
  2822. showCancel: false
  2823. })
  2824. } else {
  2825. wx.showModal({
  2826. title: '提示',
  2827. content: `房卡未授权,卡号:${data.data.cardId}`,
  2828. showCancel: false
  2829. })
  2830. }
  2831. }
  2832. }
  2833. break
  2834. }
  2835. case 'reportPincodeResult': {
  2836. if (lockModel > 70) {
  2837. if (data.data.isValid) {
  2838. wx.showModal({
  2839. title: '提示',
  2840. content: `密码开锁成功,序号:${data.data.index}`,
  2841. showCancel: false
  2842. })
  2843. } else {
  2844. wx.showModal({
  2845. title: '提示',
  2846. content: `多次密码开锁失败!`,
  2847. showCancel: false
  2848. })
  2849. }
  2850. } else {
  2851. if (data.data.isValid) {
  2852. wx.showModal({
  2853. title: '提示',
  2854. content: `密码:${data.data.pincode}开锁成功!`,
  2855. showCancel: false
  2856. })
  2857. } else {
  2858. wx.showModal({
  2859. title: '提示',
  2860. content: `密码:${data.data.pincode}未授权!`,
  2861. showCancel: false
  2862. })
  2863. }
  2864. }
  2865. break
  2866. }
  2867. case 'reportFingerprintResult': {
  2868. if (data.data.isValid) {
  2869. wx.showModal({
  2870. title: '提示',
  2871. content: `指纹开锁成功,序号:${data.data.index}`,
  2872. showCancel: false
  2873. })
  2874. } else {
  2875. wx.showModal({
  2876. title: '提示',
  2877. content: `多次指纹开锁失败!`,
  2878. showCancel: false
  2879. })
  2880. }
  2881. break
  2882. }
  2883. case 'queryLockState': {
  2884. wx.hideLoading()
  2885. if (data.code != 200) {
  2886. wx.showModal({
  2887. title: '提示',
  2888. content: '查询失败!',
  2889. showCancel: false,
  2890. success: function (res) {}
  2891. })
  2892. break
  2893. }
  2894. that.setData({
  2895. lock: {
  2896. mac: data.data.mac,
  2897. lockType: util1.getLockType(lockModel),
  2898. },
  2899. isBindLock: data.data.isBind
  2900. })
  2901. lockMac = data.data.mac
  2902. if (taskId > 0) {
  2903. if (data.data.isBind) {
  2904. wx.showModal({
  2905. title: data.data.mac,
  2906. content: '此设备已经硬件绑定!',
  2907. showCancel: false,
  2908. success: function (res) {}
  2909. })
  2910. } else {
  2911. wx.showModal({
  2912. title: data.data.mac,
  2913. content: '此设备硬件未绑定!',
  2914. showCancel: false,
  2915. success: function (res) {}
  2916. })
  2917. }
  2918. }
  2919. taskId = 0
  2920. break
  2921. }
  2922. case 'queryLockBattery': {
  2923. wx.hideLoading()
  2924. if (data.code != 200) {
  2925. wx.showModal({
  2926. title: '提示',
  2927. content: '查询失败!',
  2928. showCancel: false,
  2929. success: function (res) {}
  2930. })
  2931. break
  2932. }
  2933. taskId = 0
  2934. wx.showModal({
  2935. title: '提示',
  2936. content: `此门锁电量为${data.data.battery}%`,
  2937. showCancel: false,
  2938. success: function (res) {}
  2939. })
  2940. break
  2941. }
  2942. case 'queryNbImei': {
  2943. wx.hideLoading()
  2944. if (data.code != 200) {
  2945. wx.showModal({
  2946. title: '提示',
  2947. content: '查询失败!',
  2948. showCancel: false,
  2949. success: function (res) {}
  2950. })
  2951. break
  2952. }
  2953. taskId = 0
  2954. that.data.deviceInfo.imei = data.data.imei
  2955. wx.showModal({
  2956. title: '提示',
  2957. content: `此NB设备IMEI为${data.data.imei}`,
  2958. showCancel: false,
  2959. success: function (res) {
  2960. let lock = that.data.lock
  2961. lock.imei = data.data.imei
  2962. that.setData({
  2963. lock
  2964. })
  2965. }
  2966. })
  2967. break
  2968. }
  2969. case 'setNbFun': {
  2970. wx.hideLoading()
  2971. if (data.code != 200) {
  2972. wx.showModal({
  2973. title: '提示',
  2974. content: '设置Nb功能失败!',
  2975. showCancel: false,
  2976. success: function (res) {}
  2977. })
  2978. break
  2979. }
  2980. taskId = 0
  2981. wx.showModal({
  2982. title: '提示',
  2983. content: that.data.isNbEnable ? 'NB功能已禁用' : 'NB功能已打开',
  2984. showCancel: false,
  2985. })
  2986. that.setData({
  2987. isNbEnable: !that.data.isNbEnable
  2988. })
  2989. break
  2990. }
  2991. case 'sendBindLock': {
  2992. wx.hideLoading()
  2993. if (data.code != 200) {
  2994. wx.showModal({
  2995. title: '提示',
  2996. content: '绑定失败!',
  2997. showCancel: false,
  2998. success: function (res) {}
  2999. })
  3000. break
  3001. }
  3002. taskId = 0
  3003. that.setData({
  3004. isBindLock: data.data.isBind
  3005. })
  3006. // if (data.data.isBind) {
  3007. // var dataStr = {
  3008. // code: "lwj/registerSupperAdmin",
  3009. // data: {
  3010. // lockerId: that.data.deviceNum,
  3011. // lockerSuperAdminId: basecode,
  3012. // bluetoothMac: lockMac,
  3013. // }
  3014. // }
  3015. // WXAPI.sendCommand(dataStr).then((res2) => {
  3016. // })
  3017. // wx.showToast({
  3018. // title: '绑定成功!',
  3019. // })
  3020. // } else {
  3021. // wx.showToast({
  3022. // title: '绑定失败!',
  3023. // })
  3024. // }
  3025. break
  3026. }
  3027. case 'sendUnbindLock': {
  3028. wx.hideLoading()
  3029. if (data.code != 200) {
  3030. wx.showModal({
  3031. title: '提示',
  3032. content: '解绑失败!',
  3033. showCancel: false,
  3034. success: function (res) {}
  3035. })
  3036. break
  3037. }
  3038. taskId = 0
  3039. that.setData({
  3040. isBindLock: data.data.isBind
  3041. })
  3042. if (data.data.isBind) {
  3043. wx.showToast({
  3044. title: '解绑失败!',
  3045. })
  3046. } else {
  3047. var data = [{
  3048. siteId: that.data.lock.roomId,
  3049. deviceId: that.data.lock.id,
  3050. }]
  3051. WXAPI.unbindDeviceSite(data).then(res => {
  3052. if (res.success) {
  3053. let lock = that.data.lock
  3054. lock.roomName = ''
  3055. lock.id = ''
  3056. lock.roomId = ''
  3057. that.setData({
  3058. lock
  3059. })
  3060. }
  3061. })
  3062. wx.showToast({
  3063. title: '解绑成功!',
  3064. })
  3065. that.unbindRoom()
  3066. }
  3067. break
  3068. }
  3069. case 'login1':
  3070. case 'sendOpenLockP1': {
  3071. if (data.code != 200) {
  3072. wx.hideLoading()
  3073. if (taskId == 41) {
  3074. wx.showModal({
  3075. title: '提示',
  3076. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  3077. showCancel: false,
  3078. success: function (res) {}
  3079. })
  3080. } else if (taskId == 32) {
  3081. wx.showModal({
  3082. title: '提示',
  3083. content: '登录失败!',
  3084. showCancel: false,
  3085. success: function (res) {}
  3086. })
  3087. }
  3088. break
  3089. }
  3090. if (taskId == 41) {
  3091. var bytes = plugin.sendOpenLockP2(lockDevice.name, basecode, data.data.randomN)
  3092. console.debug('bytes', bytes)
  3093. that.sendBytes(bytes)
  3094. } else if (taskId == 32) {
  3095. var bytes = plugin.login2(lockDevice.name, basecode, data.data.randomN)
  3096. console.debug('bytes', bytes)
  3097. that.sendBytes(bytes)
  3098. }
  3099. break;
  3100. }
  3101. case 'login':
  3102. case 'sendOpenLockP2': {
  3103. wx.hideLoading()
  3104. if (data.code != 200) {
  3105. if (taskId == 41) {
  3106. wx.showModal({
  3107. title: '提示',
  3108. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  3109. showCancel: false,
  3110. success: function (res) {}
  3111. })
  3112. } else if (taskId == 32) {
  3113. wx.showModal({
  3114. title: '提示',
  3115. content: '登录失败!',
  3116. showCancel: false,
  3117. success: function (res) {}
  3118. })
  3119. }
  3120. break
  3121. }
  3122. isLockLogin = true
  3123. if (taskId == 41) {
  3124. var data = {
  3125. code: "ble/bleUnlockRecord",
  3126. data: {
  3127. deviceNum: that.data.deviceNum,
  3128. roomId: that.data.lock.roomId,
  3129. roomName: that.data.lock.roomName,
  3130. cardName: that.data.adminuserinfo.username,
  3131. productId: 1201,
  3132. userId: '29283991'
  3133. }
  3134. }
  3135. WXAPI.sendCommand(data).then(res => {
  3136. console.log(res)
  3137. })
  3138. wx.showToast({
  3139. title: that.data.isJack ? '上电成功!' : '解锁成功!',
  3140. })
  3141. } else if (taskId == 32) {
  3142. wx.showToast({
  3143. title: '登录成功!',
  3144. })
  3145. }
  3146. taskId = 0
  3147. break;
  3148. }
  3149. case 'syncClock': {
  3150. wx.hideLoading()
  3151. if (data.code != 200) {
  3152. wx.showModal({
  3153. title: '提示',
  3154. content: '同步时间失败!' + data.data.msg,
  3155. showCancel: false,
  3156. success: function (res) {}
  3157. })
  3158. break
  3159. }
  3160. taskId = 0
  3161. wx.showModal({
  3162. title: '提示',
  3163. content: '时间更新成功!',
  3164. showCancel: false
  3165. })
  3166. break;
  3167. }
  3168. case 'addPincode': {
  3169. wx.hideLoading()
  3170. if (data.code != 200) {
  3171. wx.showModal({
  3172. title: '提示',
  3173. content: '添加密码失败!' + data.data.msg,
  3174. showCancel: false,
  3175. success: function (res) {}
  3176. })
  3177. break
  3178. }
  3179. taskId = 0
  3180. that.setData({
  3181. isPincodeAdd: true
  3182. })
  3183. wx.showModal({
  3184. title: '提示',
  3185. content: `添加密码${pincode}成功!`,
  3186. showCancel: false
  3187. })
  3188. break
  3189. }
  3190. case 'delPincode': {
  3191. wx.hideLoading()
  3192. if (data.code != 200) {
  3193. wx.showModal({
  3194. title: '提示',
  3195. content: '删除密码失败!',
  3196. showCancel: false,
  3197. success: function (res) {}
  3198. })
  3199. break
  3200. }
  3201. taskId = 0
  3202. wx.showModal({
  3203. title: '提示',
  3204. content: `删除密码${pincode}成功!`,
  3205. showCancel: false,
  3206. })
  3207. that.setData({
  3208. isPincodeAdd: false
  3209. })
  3210. pincode = -1
  3211. pincodeIndex = -1
  3212. break
  3213. }
  3214. case 'addRfCard': {
  3215. wx.hideLoading()
  3216. if (data.code == 100) {
  3217. wx.showLoading({
  3218. title: data.data.msg,
  3219. })
  3220. break
  3221. } else if (data.code != 200) {
  3222. wx.showModal({
  3223. title: '提示',
  3224. content: '添加房卡失败!' + data.data.msg,
  3225. showCancel: false,
  3226. success: function (res) {}
  3227. })
  3228. break
  3229. }
  3230. taskId = 0
  3231. that.setData({
  3232. isRfCardAdd: true
  3233. })
  3234. if (lockModel > 70) {
  3235. wx.showModal({
  3236. title: '提示',
  3237. content: `添加房卡成功,序号${rfCardIndex}`,
  3238. showCancel: false
  3239. })
  3240. } else {
  3241. wx.showModal({
  3242. title: '提示',
  3243. content: `添加房卡成功,卡号${rfCardId}`,
  3244. showCancel: false
  3245. })
  3246. }
  3247. break
  3248. }
  3249. case 'delRfCard': {
  3250. wx.hideLoading()
  3251. if (data.code != 200) {
  3252. wx.showModal({
  3253. title: '提示',
  3254. content: '删除房卡失败!',
  3255. showCancel: false,
  3256. success: function (res) {}
  3257. })
  3258. break
  3259. }
  3260. taskId = 0
  3261. that.setData({
  3262. isRfCardAdd: false
  3263. })
  3264. if (lockModel > 70) {
  3265. wx.showModal({
  3266. title: '提示',
  3267. content: `删除房卡成功,序号${rfCardIndex}`,
  3268. showCancel: false,
  3269. })
  3270. } else {
  3271. wx.showModal({
  3272. title: '提示',
  3273. content: `删除房卡成功,卡号${rfCardId}`,
  3274. showCancel: false,
  3275. })
  3276. }
  3277. rfCardId = -1
  3278. rfCardIndex = -1
  3279. break
  3280. }
  3281. case 'addFingerprint': {
  3282. wx.hideLoading()
  3283. if (data.code == 100) {
  3284. wx.showLoading({
  3285. title: data.data.msg,
  3286. })
  3287. break
  3288. } else if (data.code != 200) {
  3289. wx.showModal({
  3290. title: '提示',
  3291. content: '添加指纹失败!' + data.data.msg,
  3292. showCancel: false,
  3293. success: function (res) {}
  3294. })
  3295. break
  3296. }
  3297. taskId = 0
  3298. that.setData({
  3299. isFingerprintAdd: true
  3300. })
  3301. wx.showModal({
  3302. title: '提示',
  3303. content: `添加指纹成功,序号${fingerprintIndex}`,
  3304. showCancel: false
  3305. })
  3306. break
  3307. }
  3308. case 'delFingerprint': {
  3309. wx.hideLoading()
  3310. if (data.code != 200) {
  3311. wx.showModal({
  3312. title: '提示',
  3313. content: '删除指纹失败!',
  3314. showCancel: false,
  3315. success: function (res) {}
  3316. })
  3317. break
  3318. }
  3319. taskId = 0
  3320. wx.showModal({
  3321. title: '提示',
  3322. content: `删除指纹成功,序号${fingerprintIndex}`,
  3323. showCancel: false,
  3324. })
  3325. that.setData({
  3326. isFingerprintAdd: false
  3327. })
  3328. fingerprintIndex = -1
  3329. break
  3330. }
  3331. case 'changeAdminPincode': {
  3332. wx.hideLoading()
  3333. if (data.code != 200) {
  3334. wx.showModal({
  3335. title: '提示',
  3336. content: '修改管理密码失败!',
  3337. showCancel: false,
  3338. success: function (res) {}
  3339. })
  3340. break
  3341. }
  3342. taskId = 0
  3343. wx.showToast({
  3344. title: '修改管理密码成功!',
  3345. })
  3346. }
  3347. case 'configurewifi': {
  3348. if (data.code == 300) {
  3349. wx.hideLoading()
  3350. clearTimeout(that.wifitimer)
  3351. wx.showModal({
  3352. title: '提示',
  3353. content: '配网失败,请重新尝试',
  3354. showCancel: false,
  3355. success: function (res) {}
  3356. })
  3357. }
  3358. if (data.code == 200) {
  3359. wx.hideLoading()
  3360. clearTimeout(that.wifitimer)
  3361. that.show2 = false
  3362. wx.showToast({
  3363. title: '配网成功',
  3364. })
  3365. }
  3366. break;
  3367. }
  3368. case 'queryLockSlotState': {
  3369. wx.hideLoading()
  3370. if (data.code != 200) {
  3371. wx.showModal({
  3372. title: '提示',
  3373. content: '查询失败!',
  3374. showCancel: false,
  3375. success: function (res) {}
  3376. })
  3377. break
  3378. }
  3379. taskId = 0
  3380. wx.showModal({
  3381. title: '提示',
  3382. content: data.data.state == 0 ? '此门锁方舌关闭' : '此门锁方舌打开',
  3383. showCancel: false,
  3384. success: function (res) {}
  3385. })
  3386. break
  3387. }
  3388. case 'queryLockUnlockState': {
  3389. wx.hideLoading()
  3390. if (data.code != 200) {
  3391. wx.showModal({
  3392. title: '提示',
  3393. content: '查询失败!',
  3394. showCancel: false,
  3395. success: function (res) {}
  3396. })
  3397. break
  3398. }
  3399. taskId = 0
  3400. wx.showModal({
  3401. title: '提示',
  3402. content: data.data.state == 0 ? '此门锁已关闭' : '此门锁已打开',
  3403. showCancel: false,
  3404. success: function (res) {}
  3405. })
  3406. break
  3407. }
  3408. case 'setLockUnlockState': {
  3409. wx.hideLoading()
  3410. if (data.code != 200) {
  3411. wx.showModal({
  3412. title: '提示',
  3413. content: '设置常开指令失败!',
  3414. showCancel: false,
  3415. success: function (res) {}
  3416. })
  3417. break
  3418. }
  3419. taskId = 0
  3420. wx.showModal({
  3421. title: '提示',
  3422. content: data.data.state == 0 ? '常开模式已退出' : '常开模式已开启',
  3423. showCancel: false,
  3424. })
  3425. that.setData({
  3426. isUnloked: data.data.state == 1
  3427. })
  3428. break
  3429. }
  3430. case 'setLockMuteState': {
  3431. wx.hideLoading()
  3432. if (data.code != 200) {
  3433. wx.showModal({
  3434. title: '提示',
  3435. content: '设置静音指令失败!',
  3436. showCancel: false,
  3437. success: function (res) {}
  3438. })
  3439. break
  3440. }
  3441. taskId = 0
  3442. wx.showModal({
  3443. title: '提示',
  3444. content: data.data.state == 1 ? '静音模式已退出' : '静音模式已开启',
  3445. showCancel: false,
  3446. })
  3447. that.setData({
  3448. isMuted: data.data.state == 0
  3449. })
  3450. break
  3451. }
  3452. }
  3453. })
  3454. wx.notifyBLECharacteristicValueChange({
  3455. deviceId: lockDevice.deviceId,
  3456. serviceId: config.uuid.serviceUuid.toUpperCase(),
  3457. characteristicId: config.uuid.notifyUuid.toUpperCase(),
  3458. state: true,
  3459. success: function (res) {
  3460. console.log('setupNotify', res)
  3461. isInitReady = true
  3462. setTimeout(function () {
  3463. wx.hideLoading()
  3464. that.onQueryBindState()
  3465. }, 500)
  3466. },
  3467. })
  3468. },
  3469. })
  3470. },
  3471. })
  3472. },
  3473. sendBytes(bytes) {
  3474. var that = this
  3475. setTimeout(function () {
  3476. wx.writeBLECharacteristicValue({
  3477. deviceId: lockDevice.deviceId,
  3478. serviceId: config.uuid.serviceUuid.toUpperCase(),
  3479. characteristicId: config.uuid.writeUuid.toUpperCase(),
  3480. value: bytes,
  3481. success: function (res) {
  3482. },
  3483. })
  3484. }, 50)
  3485. },
  3486. /**
  3487. * 页面上拉触底事件的处理函数
  3488. */
  3489. onReachBottom: function () {
  3490. },
  3491. /**
  3492. * 用户点击右上角分享
  3493. */
  3494. onShareAppMessage: function () {
  3495. }
  3496. })