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.

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