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.

3525 lines
107 KiB

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