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.

2995 lines
85 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. // pages/roomDetail/roomDetail.js
  2. const config = require('../../config')
  3. const util1 = require('../../utils/util1.js')
  4. const plugin = requirePlugin("myPlugin")
  5. const WXAPI = require('../../utils/request')
  6. import ICINLocker from "../../utils/ICINPakage/ICINLocker"
  7. var util = require('../../utils/util');
  8. import md5 from "../../utils/ICINPakage/md5.min";
  9. import IotTask from "../../utils/IotTask"
  10. import LwJ from "../../utils/LWJ"
  11. import {
  12. BLE
  13. } from "../../utils/btls/ble";
  14. // import { clearInterval } from "timers";
  15. const app = getApp();
  16. var bleall = require('../../utils/bleall');
  17. const emitter = app.globalData.emitter
  18. import moment from "../../utils/moment"
  19. // ArrayBuffer转16进度字符串示例
  20. function ab2hex(buffer) {
  21. var hexArr = Array.prototype.map.call(
  22. new Uint8Array(buffer),
  23. function (bit) {
  24. return ('00' + bit.toString(16)).slice(-2)
  25. }
  26. )
  27. return hexArr.join(',');
  28. }
  29. function CurentTime() {
  30. var now = new Date();
  31. var year = now.getFullYear(); //年
  32. var month = now.getMonth() + 1; //月
  33. var day = now.getDate(); //日
  34. var hh = now.getHours(); //时
  35. var mm = now.getMinutes(); //分
  36. var clock = year + "-";
  37. if (month < 10)
  38. clock += "0";
  39. clock += month + "-";
  40. if (day < 10)
  41. clock += "0";
  42. clock += day + " ";
  43. // if (hh < 10)
  44. // clock += "0";
  45. // clock += '00' + ":";
  46. // // if (mm < 10) clock += '0';
  47. clock += '00:00:00';
  48. return (clock);
  49. }
  50. function CurentTime1() {
  51. var now = new Date();
  52. var year = now.getFullYear(); //年
  53. var month = now.getMonth() + 1; //月
  54. var day = now.getDate(); //日
  55. var hh = now.getHours(); //时
  56. var mm = now.getMinutes(); //分
  57. var clock = year + "-";
  58. if (month < 10)
  59. clock += "0";
  60. clock += month + "-";
  61. if (day < 10)
  62. clock += "0";
  63. clock += day + " ";
  64. // if (hh < 10)
  65. // clock += "0";
  66. // clock += hh + ":";
  67. // if (mm < 10) clock += '0';
  68. // clock += mm;
  69. clock += '00:00:00';
  70. return (clock);
  71. }
  72. var isConnected = false
  73. var connectedDeviceId = ''
  74. var isSearch = false
  75. var isInitReady = false
  76. var basecode = 29283991
  77. var lockDevice = {
  78. name: ''
  79. }
  80. var taskId = 0
  81. var lockModel = ''
  82. var lockMac = ''
  83. var isLockLogin = false
  84. var pincode = ''
  85. var pincodeIndex
  86. Page({
  87. /**
  88. * 页面的初始数据
  89. */
  90. data: {
  91. show2: false, // 配网
  92. wifiName: '',
  93. wifiPwd: '',
  94. toSearch: true,
  95. info: "", //显示框
  96. deviceinfo: {
  97. rssi: 0,
  98. battery: 0,
  99. lockStatus: 0,
  100. isOnline: 0,
  101. event: '',
  102. bleStatus: ''
  103. },
  104. index: 0,
  105. fingerprintId: '',
  106. openlock: '',
  107. IssuingPersonnel: true,
  108. isMuted: false,
  109. backstatus: false,
  110. cgInfo: '',
  111. zgBlueStatus: false,
  112. timer: '',
  113. count: 0,
  114. show: false,
  115. actions: [{
  116. name: '静音',
  117. color: '#ee0a24'
  118. },
  119. {
  120. name: '低音',
  121. color: '#333'
  122. },
  123. {
  124. name: '高音',
  125. color: '#333'
  126. },
  127. ],
  128. actionsLwj: [{
  129. name: '设置静音',
  130. color: '#ee0a24'
  131. },
  132. {
  133. name: '退出静音',
  134. color: '#333'
  135. }
  136. ],
  137. volume: '',
  138. bluestatus: app.globalData.backstatus,
  139. show1: false,
  140. TemporaryPassword: '',
  141. phone: '',
  142. userInfo: {
  143. type: ''
  144. },
  145. authority: false,
  146. NormallyOpenPermission: false,
  147. RemoteControlPermission: false,
  148. showbuleKey: false,
  149. deviceList: [],
  150. openShow: false,
  151. starttime: CurentTime(),
  152. endtime: CurentTime1(),
  153. datetimerange: [CurentTime(), CurentTime1()],
  154. startHour: 0,
  155. endHour: 23,
  156. array: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'],
  157. hexString: '',
  158. lockDevice: {},
  159. isSearch: false,
  160. genOfflinePincodeShow: false
  161. },
  162. /**
  163. * 生命周期函数--监听页面加载
  164. */
  165. onLoad: function (options) {
  166. app.globalData.zgBlueStatus = false
  167. this.AddressPermissions()
  168. this.getLocationPermissionMethods()
  169. let deviceinfo = wx.getStorageSync('deviceinfo')
  170. app.globalData.deviceNum = deviceinfo.deviceNum
  171. var userInfo1 = wx.getStorageSync('userInfo')
  172. let deviceinfoData = JSON.parse(JSON.stringify(deviceinfo))
  173. if (deviceinfo.manufactureId == 201 || deviceinfo.manufactureId == 221) {
  174. var data3 = {
  175. code: "zg/bleRegisterInfo",
  176. data: {
  177. lockerId: deviceinfo.deviceNum
  178. }
  179. }
  180. WXAPI.sendCommand(data3).then(res1 => {
  181. if (res1.success) {
  182. wx.setStorageSync('cgInfo', res1.data)
  183. this.setData({
  184. cgInfo: res1.data
  185. })
  186. }
  187. })
  188. }
  189. if (deviceinfo.roomId) {
  190. if (parseInt(userInfo1.type) < 3) {
  191. var data2 = {
  192. q: JSON.stringify({
  193. id: deviceinfo.roomId
  194. }),
  195. orderBy: "createTime",
  196. orderType: 'desc'
  197. }
  198. WXAPI.getSiteTenant(data2).then(res1 => {
  199. if (res1.data.list.length > 0) {
  200. var array = res1.data.list.reverse()
  201. wx.setStorageSync('info', array[0])
  202. deviceinfo['info'] = array[0].info
  203. this.setData({
  204. deviceinfo: deviceinfo
  205. })
  206. } else {
  207. wx.showToast({
  208. title: "还未下发人员,请先下发人员",
  209. duration: 2000,
  210. icon: 'none'
  211. })
  212. }
  213. })
  214. } else if (parseInt(userInfo1.type) == 3) {
  215. var data = {
  216. q: JSON.stringify({
  217. number: userInfo1.username
  218. }),
  219. pageNum: 0,
  220. pageSize: 0
  221. };
  222. WXAPI.getlistNum(data).then(res4 => {
  223. if (res4.success) {
  224. deviceinfo.info = res4.data.list[0].info
  225. this.setData({
  226. deviceinfo: deviceinfo
  227. })
  228. } else {
  229. wx.showToast({
  230. title: "还未下发人员,请先下发人员",
  231. duration: 2000,
  232. icon: 'none'
  233. })
  234. }
  235. })
  236. }
  237. } else {
  238. wx.navigateTo({
  239. url: "../index/index"
  240. })
  241. }
  242. if (userInfo1.type == 0) {
  243. this.setData({
  244. authority: true,
  245. NormallyOpenPermission: true,
  246. RemoteControlPermission: true
  247. })
  248. } else {
  249. userInfo1.authorities.map(li => {
  250. if (li == 'BLUETOOTH_INPUT') {
  251. this.setData({
  252. authority: true
  253. })
  254. }
  255. if (li == 'NORMALLY_OPEN_PERMISSION') {
  256. this.setData({
  257. NormallyOpenPermission: true
  258. })
  259. }
  260. if (li == 'REMOTE_CONTROL_PERMISSION') {
  261. this.setData({
  262. RemoteControlPermission: true
  263. })
  264. }
  265. })
  266. }
  267. this.setData({
  268. info: app.globalData.bleStatus,
  269. deviceinfo: deviceinfo,
  270. userInfo: userInfo1
  271. })
  272. if (options.open) {
  273. let eData = {
  274. currentTarget: {
  275. dataset: {
  276. i: 0
  277. }
  278. }
  279. }
  280. this.btntest1(eData)
  281. }
  282. if (deviceinfo.manufactureId == 101) {
  283. app.watch(this.getcartcount, 'backdata')
  284. app.watch(this.fingerprintFun, 'fingerprintId')
  285. app.watch(this.openlockfun, 'openlock')
  286. }
  287. },
  288. // 配网
  289. changeshow2(e) {
  290. var event = e.currentTarget.dataset.i
  291. var that = this;
  292. this.setData({
  293. event
  294. })
  295. var deviceinfo = this.data.deviceinfo
  296. if (deviceinfo.manufactureId == '1241') {
  297. if (event == '3') {
  298. this.setData({
  299. show2: true
  300. })
  301. }
  302. }else{
  303. wx.showToast({
  304. title: '该类型锁不支持配网功能',
  305. duration: 2000,
  306. icon: 'none'
  307. })
  308. }
  309. },
  310. configurationWifi() {
  311. let event = {
  312. currentTarget: {
  313. dataset: {
  314. i: '3'
  315. }
  316. }
  317. }
  318. if(!this.data.isSearch){
  319. this.btntest1(event)
  320. }else{
  321. this.configurewifj()
  322. }
  323. },
  324. onConfigurewifi() {
  325. var that = this
  326. var bytes = plugin.configureWifi(lockDevice.name, lockMac, that.data.wifiName, that.data.wifiPwd)
  327. that.sendBytes(bytes)
  328. this.setData({
  329. show2: false
  330. })
  331. },
  332. // 前往图像管理
  333. goImageManagement(e) {
  334. if(this.data.isSearch){
  335. wx.navigateTo({
  336. url: '/pagesA/facepeople/facepeople',
  337. })
  338. }else{
  339. this.btntest1(e)
  340. }
  341. },
  342. genOfflinePincodeShowMethods() {
  343. // if(this.data.isSearch){
  344. this.setData({
  345. genOfflinePincodeShow: true
  346. })
  347. // }else{
  348. // this.searchDevicesMethods()
  349. // }
  350. },
  351. genOfflinePincode: function () {
  352. var that = this
  353. // if(this.data.isSearch){
  354. wx.showLoading({
  355. title: '生成离线密码中',
  356. })
  357. var t1 = Number(moment(this.data.starttime).format('x')) + (parseInt(this.data.startHour) + 1) * 60 * 60 * 1000
  358. var t2 = new Date(this.data.endtime).getTime() + ((parseInt(this.data.endHour) + 1) * 60 * 60 * 1000)
  359. var startTime = util1.getLocalTime(8) //new Date(t1)//util1.getLocalTime(8)
  360. let time = t2 - startTime.getTime()
  361. var endTime = new Date(startTime.getTime() + time)
  362. plugin.genOfflinePincode(lockDevice.name, lockMac, basecode, 0, startTime, endTime)
  363. .then(function (data) {
  364. console.debug('data', data)
  365. wx.hideLoading()
  366. if (data.code == 200) {
  367. that.setData({
  368. genOfflinePincodeShow: false
  369. })
  370. wx.showModal({
  371. title: '提示',
  372. content: `生成离线密码${data.data},有效期至${util1.formatTime(endTime)}`,
  373. showCancel: false
  374. })
  375. } else {
  376. wx.showModal({
  377. title: '提示',
  378. content: data.data,
  379. showCancel: false
  380. })
  381. }
  382. })
  383. // }else{
  384. // this.searchDevicesMethods()
  385. // }
  386. },
  387. // 蓝牙同步任务
  388. synchroPlatformTask() {
  389. wx.showLoading({
  390. title: '同步平台任务中',
  391. icon: 'none',
  392. mask: true
  393. })
  394. const iotInstance = new IotTask(this.data.cgInfo.lockerId, this.iotCallBack)
  395. iotInstance.run()
  396. },
  397. iotCallBack(sendData) {
  398. let _this = this
  399. if (!sendData) return
  400. return new Promise((resolve, reject) => {
  401. console.log(_this.data.cgInfo.commonKey)
  402. ICINLocker.nbIotTransmit(sendData, _this.data.cgInfo.commonKey, (callback) => {
  403. console.log('发送数据' + new Date(), sendData)
  404. console.log('同步任务回调结果' + new Date(), callback)
  405. if (callback) {
  406. resolve(callback.nbIotResp)
  407. } else {
  408. reject('同步任务fail')
  409. }
  410. })
  411. })
  412. },
  413. bindDateChange: function (e) {
  414. var str = e.detail.value + " 00:00:00"
  415. this.data.datetimerange[0] = str
  416. this.setData({
  417. starttime: str,
  418. minDate1: str
  419. })
  420. },
  421. bindDateChange1: function (e) {
  422. var str = e.detail.value + " 00:00:00"
  423. this.data.datetimerange[1] = str
  424. this.setData({
  425. endtime: str
  426. })
  427. },
  428. bindPickerChangestartHour(e) {
  429. this.setData({
  430. startHour: e.detail.value
  431. })
  432. },
  433. bindPickerChangeendHour(e) {
  434. this.setData({
  435. endHour: e.detail.value
  436. })
  437. },
  438. onCloseBlue() {
  439. this.setData({
  440. showbuleKey: false
  441. })
  442. },
  443. addUser() {
  444. var cgInfo = this.data.cgInfo
  445. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId,
  446. (callback) => {
  447. if (callback.status == '00') {
  448. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, callback.signKey, (callback1) => {
  449. if (callback1.status == '00') {
  450. ICINLocker.addUserToLock(cgInfo.lockerId, cgInfo.superId, "BLEKEY_8d82e5d527e1", "0o01weit9ti9ti", "00", callback.signKey, "", callback1.commonKey, "00000000", "FFFFFFFF", (callback) => {
  451. console.log(callback)
  452. })
  453. }
  454. })
  455. }
  456. })
  457. },
  458. stringToHex(str) {
  459. var val = "";
  460. for (var i = 0; i < str.length; i++) {
  461. if (val == "")
  462. val = str.charCodeAt(i).toString(16);
  463. else
  464. val += str.charCodeAt(i).toString(16);
  465. }
  466. return val;
  467. },
  468. linkBlue() {
  469. wx.navigateTo({
  470. url: '/pages/addBlueButton/addBlueButton',
  471. })
  472. },
  473. searchBlueButton(e) {
  474. var that = this
  475. var cgInfo = this.data.cgInfo
  476. var comm = this.stringToHex(e.currentTarget.dataset.select.name)
  477. console.log(comm)
  478. var deviceId = e.currentTarget.dataset.select.deviceId
  479. var keyId = "0o01weit9ti9ti"
  480. var password = "3030000000000000000000000000000000000000"
  481. app.globalData.blueDeviceId = e.currentTarget.dataset.select.name
  482. var blueKeyId = e.currentTarget.dataset.select.name
  483. ICINLocker.connect(deviceId, true) // 此处 deviceId 存起来,当断开连接时使用
  484. .then((res) => {
  485. if (res.status === 0) {
  486. clearInterval(that.data.timer)
  487. this.setData({
  488. bleStatus: '蓝牙已连接',
  489. deviceId: deviceId
  490. })
  491. app.globalData.zgBlueStatus = true
  492. wx.showToast({
  493. title: '连接成功',
  494. icon: "none",
  495. duration: 2000
  496. })
  497. ICINLocker.readBluetoothBuckle(cgInfo.lockerId, comm, callback2 => {
  498. if (callback2.status == '00') {
  499. ICINLocker.registeBluetoothBuckle(cgInfo.superId, blueKeyId, keyId, password, "", cgInfo.authKey, comm, callback3 => {
  500. if (callback3.status == '00') {
  501. wx.hideLoading()
  502. wx.showToast({
  503. title: '添加成功',
  504. duration: 2000,
  505. icon: "none"
  506. })
  507. } else {
  508. wx.hideLoading()
  509. wx.showToast({
  510. title: '添加成功',
  511. duration: 2000,
  512. icon: "none"
  513. })
  514. }
  515. })
  516. } else {
  517. wx.hideLoading()
  518. wx.showToast({
  519. title: '读取失败',
  520. duration: 2000,
  521. icon: "none"
  522. })
  523. }
  524. });
  525. } else {
  526. wx.hideLoading()
  527. var msg = ''
  528. switch (res.errCode) {
  529. case 10001:
  530. msg = '调用失败,请打开蓝牙!';
  531. break;
  532. }
  533. wx.showToast({
  534. title: msg,
  535. duration: 2000,
  536. icon: 'none'
  537. })
  538. //此处处理返回值不为成功(0)的情况
  539. }
  540. }).catch((res) => {
  541. wx.hideLoading()
  542. console.log(res, '失败')
  543. // 此处处理未能连接成功问题
  544. })
  545. },
  546. onChange(event) {
  547. this.setData({
  548. phone: event.detail
  549. })
  550. },
  551. onChangewifi(e) {
  552. this.setData({
  553. wifiName: e.detail
  554. })
  555. },
  556. onChangewifi1(e) {
  557. this.setData({
  558. wifiPwd: e.detail
  559. })
  560. },
  561. // 发送临时密码
  562. sendMessage() {
  563. var re = /^1\d{10}$/
  564. if (re.test(this.data.phone)) {
  565. var data = {
  566. code: this.data.TemporaryPassword,
  567. phone: this.data.phone,
  568. device: this.data.deviceinfo.deviceNum,
  569. name: this.data.deviceinfo.roomName
  570. }
  571. WXAPI.sendEmergence(data).then(res => {
  572. if (res.success) {
  573. this.setData({
  574. show1: false
  575. })
  576. wx.showToast({
  577. title: "发送成功",
  578. duration: 2000,
  579. icon: "none"
  580. })
  581. } else {
  582. wx.showToast({
  583. title: "发送失败",
  584. duration: 2000,
  585. icon: "none"
  586. })
  587. }
  588. })
  589. } else {
  590. wx.showToast({
  591. title: "请输入正确的手机号",
  592. duration: 2000,
  593. icon: "none"
  594. })
  595. }
  596. },
  597. onCloseSet() {
  598. this.setData({
  599. openShow: false,
  600. genOfflinePincodeShow: false
  601. })
  602. },
  603. // zh设置常开
  604. setAlawyOpen() {
  605. this.setData({
  606. openShow: true
  607. })
  608. },
  609. UnsetMethods() {
  610. if (this.data.deviceinfo.manufactureId == 201 || this.data.deviceinfo.manufactureId == 221) {
  611. var data = {
  612. code: "zg/longopen/operation",
  613. data: {
  614. opendDoorType: 0,
  615. roomName: this.data.deviceinfo.roomName,
  616. lockerUserId: this.data.cgInfo.superId,
  617. lockerId: this.data.cgInfo.lockerId,
  618. startTime: this.data.datetimerange[0],
  619. endTime: this.data.datetimerange[1],
  620. openDoorSegmentList: [{
  621. startHour: parseInt(this.data.startHour) + 1,
  622. endHour: parseInt(this.data.endHour) + 1
  623. }],
  624. order: 61101
  625. }
  626. }
  627. WXAPI.sendCommand(data).then((res2) => {
  628. if (res2.data.success) {
  629. wx.showToast({
  630. title: '设置成功',
  631. icon: 'none',
  632. duration: 2000
  633. })
  634. this.setData({
  635. openShow: false
  636. })
  637. } else {
  638. wx.showToast({
  639. title: res2.msg,
  640. icon: 'none',
  641. duration: 2000
  642. })
  643. this.setData({
  644. openShow: false
  645. })
  646. }
  647. });
  648. }
  649. },
  650. setAlawalyOpen() {
  651. if (this.data.deviceinfo.manufactureId == 201 || this.data.deviceinfo.manufactureId == 221) {
  652. if (this.data.datetimerange[0] == '') {
  653. wx.showToast({
  654. title: '请选择开始日期',
  655. icon: 'none',
  656. duration: 2000
  657. })
  658. return
  659. }
  660. if (this.data.datetimerange[1] == '') {
  661. wx.showToast({
  662. title: '请选择结束日期',
  663. icon: 'none',
  664. duration: 2000
  665. })
  666. return
  667. }
  668. if (this.data.startHour != '' && this.data.endHour == '') {
  669. wx.showToast({
  670. title: '请选择结束时间段',
  671. icon: 'none',
  672. duration: 2000
  673. })
  674. return
  675. }
  676. if (this.data.startHour === '' && this.data.endHour != '') {
  677. wx.showToast({
  678. title: '请选择开始时间段',
  679. icon: 'none',
  680. duration: 2000
  681. })
  682. return
  683. }
  684. var data = {
  685. code: "zg/longopen/operation",
  686. data: {
  687. opendDoorType: 1,
  688. roomName: this.data.deviceinfo.roomName,
  689. lockerUserId: this.data.cgInfo.superId,
  690. lockerId: this.data.cgInfo.lockerId,
  691. startTime: this.data.datetimerange[0],
  692. endTime: this.data.datetimerange[1],
  693. openDoorSegmentList: [{
  694. startHour: parseInt(this.data.startHour) + 1,
  695. endHour: parseInt(this.data.endHour) + 1
  696. }],
  697. order: 61101
  698. }
  699. }
  700. if (this.data.startHour == '' && this.data.endHour == '') {
  701. data.data.openDoorSegmentList = []
  702. }
  703. WXAPI.sendCommand(data).then((res2) => {
  704. if (res2.data.success) {
  705. wx.showToast({
  706. title: '设置成功',
  707. icon: 'none',
  708. duration: 2000
  709. })
  710. this.setData({
  711. openShow: false
  712. })
  713. } else {
  714. wx.showToast({
  715. title: res2.msg,
  716. icon: 'none',
  717. duration: 2000
  718. })
  719. this.setData({
  720. openShow: false
  721. })
  722. }
  723. });
  724. } else {
  725. this.$message.error('该类型锁不支持此设置!');
  726. }
  727. },
  728. // 获取临时密码
  729. getTemporaryPassword() {
  730. var data = {
  731. code: "zg/getEmergence",
  732. data: {
  733. lockerId: this.data.deviceinfo.deviceNum
  734. }
  735. }
  736. WXAPI.sendCommand(data).then(res => {
  737. if (res.success) {
  738. this.setData({
  739. TemporaryPassword: res.data.data,
  740. show1: true
  741. })
  742. } else {
  743. wx.showToast({
  744. title: "获取失败",
  745. duration: 2000,
  746. icon: "none"
  747. })
  748. }
  749. })
  750. },
  751. // 关闭临时密码弹窗
  752. onClose1() {
  753. this.setData({
  754. show1: false
  755. });
  756. },
  757. // 关闭设置音量
  758. onClose() {
  759. this.setData({
  760. show: false
  761. });
  762. },
  763. onClose2() {
  764. this.setData({
  765. show2: false
  766. })
  767. },
  768. // 选择设置音量
  769. onSelect(event) {
  770. var volume = '',
  771. volume1 = '',
  772. isMuted = true
  773. if (event.detail.name == '静音' || event.detail.name == '设置静音') {
  774. volume = '00'
  775. volume1 = 0
  776. isMuted = false
  777. } else if (event.detail.name == '低音' || event.detail.name == '退出静音') {
  778. volume = '01'
  779. volume1 = 1
  780. isMuted = true
  781. } else if (event.detail.name == '高音') {
  782. volume = '02'
  783. volume1 = 2
  784. }
  785. this.setData({
  786. volume: volume
  787. })
  788. if (this.data.deviceinfo.manufactureId == 201 || this.data.deviceinfo.manufactureId == 221) {
  789. wx.showLoading({
  790. title: "正在设置...",
  791. mask: true
  792. });
  793. this.setVolume(volume)
  794. } else if (this.data.deviceinfo.manufactureId == 101) {
  795. wx.showLoading({
  796. title: "正在设置...",
  797. mask: true
  798. });
  799. this.setVolume1(volume)
  800. } else if (this.data.deviceinfo.manufactureId == 1201 || this.data.deviceinfo.manufactureId == 1241) {
  801. this.setData({
  802. isMuted: isMuted
  803. })
  804. this.changeLockMutedState()
  805. }
  806. },
  807. changeLockMutedState: function () {
  808. var that = this
  809. taskId = 102
  810. that.initBluetooth()
  811. },
  812. onChangeLockMutedState: function () {
  813. var that = this
  814. wx.showLoading({
  815. title: that.data.isMuted ? '退出静音模式' : '进入静音模式',
  816. })
  817. var bytes = plugin.setLockMuteState(lockDevice.name, !that.data.isMuted)
  818. console.debug('bytes', bytes)
  819. that.sendBytes(bytes)
  820. },
  821. fingerprintFun() {
  822. this.data.fingerprintId = app.globalData.fingerprintId
  823. },
  824. // 人员管理
  825. personManger(e) {
  826. if(this.data.isSearch){
  827. wx.navigateTo({
  828. url: '/pages/personManger/personManger',
  829. })
  830. }else{
  831. this.btntest1(e)
  832. }
  833. },
  834. gotoperson() {
  835. wx.navigateTo({
  836. url: '/pages/personManger/personManger',
  837. })
  838. },
  839. gotofaceadd() {
  840. wx.navigateTo({
  841. url: '/pagesA/facepeople/facepeople',
  842. })
  843. },
  844. openlockfun() {
  845. var that = this
  846. this.data.openlock = app.globalData.openlock
  847. var userInfo = wx.getStorageSync('userInfo')
  848. if (app.globalData.openlock == 1) {
  849. var rqTime = moment().format("X")
  850. var username = wx.getStorageSync('username'),
  851. password = wx.getStorageSync('password')
  852. var str = `${username}+${password}+${rqTime}`
  853. var signature = md5(str)
  854. var data = {
  855. code: "ld/bleUnlockRecord",
  856. data: {
  857. deviceNum: this.data.deviceinfo.deviceNum,
  858. userTelephone: "18270949468",
  859. password: "2021",
  860. roomId: that.data.deviceinfo.roomId,
  861. roomName: that.data.deviceinfo.roomName,
  862. cardName: userInfo.username,
  863. signature: signature
  864. }
  865. }
  866. console.log(data)
  867. WXAPI.sendCommand(data).then(res => {
  868. })
  869. } else {
  870. wx.showToast({
  871. title: "开门失败,请重新开门",
  872. duration: 2000,
  873. icon: "none"
  874. })
  875. }
  876. },
  877. getcartcount(val) {
  878. var that = this
  879. let deviceNum = that.data.deviceinfo.deviceNum
  880. if (app.globalData.backdata == 3 && this.data.backstatus) {
  881. that.startFp_29(deviceNum, 0x02)
  882. } else if (app.globalData.backdata == 2 && this.data.backstatus) {
  883. that.startFp_29(deviceNum, 0x01)
  884. } else if (app.globalData.backdata == 1 && this.data.backstatus) {
  885. var data = {
  886. managerTelephone: "18270949468",
  887. managerPassword: "202108",
  888. userTelephone: JSON.parse(that.data.deviceinfo.info).userTelephone,
  889. userPassword: JSON.parse(that.data.deviceinfo.info).userPassword,
  890. startTime: "20210813010101",
  891. endTime: "20680813010101"
  892. }
  893. this.data.backstatus = false
  894. that.startFp_63(data.managerTelephone, data.managerPassword, data.userTelephone, data.userPassword,
  895. data.startTime, data.endTime, 16)
  896. }
  897. },
  898. startFp_63(managerTelephone, managerPassword, userTelephone, userPassword, startTime, endTime, num) {
  899. wx.showLoading({
  900. title: "正在发送...",
  901. mask: true
  902. });
  903. setTimeout(() => {
  904. wx.hideLoading()
  905. }, 1000);
  906. let cmd = 0x63
  907. let mt = util.stringToUint8Array(managerTelephone)
  908. let mp = util.stringToUint8Array(managerPassword)
  909. let ut = util.stringToUint8Array(userTelephone)
  910. let up = util.stringToUint8Array(userPassword)
  911. let ust = util.time40ToBytes(startTime)
  912. let uet = util.time40ToBytes(endTime)
  913. let fst = util.time40ToBytes(startTime)
  914. let fet = util.time40ToBytes(endTime)
  915. let length = 1 + 11 + 6 + 11 + 6 + 5 + 5 + 4 + 2 + 10 + 5 + 5 + 1 + 2 + 1
  916. let b = new Uint8Array(length)
  917. b[0] = cmd
  918. b.set(mt, 1)
  919. b.set(mp, 12)
  920. b.set(ut, 18)
  921. b.set(up, 29)
  922. b.set(ust, 35)
  923. b.set(uet, 40)
  924. //权限
  925. b[45] = 0x46;
  926. b[46] = 0x46;
  927. b[47] = 0x46;
  928. b[48] = 0x46;
  929. //密码长度 uint16
  930. b[49] = 0
  931. b[50] = 0x0a
  932. //密码数据
  933. b[51] = this.data.fingerprintId
  934. b[52] = 0xff
  935. b[53] = 0xff
  936. b[54] = 0xff
  937. b[55] = 0xff
  938. b[56] = 0xff
  939. b[57] = 0xff
  940. b[58] = 0xff
  941. b[59] = 0xff
  942. b[60] = 0xff
  943. b.set(fst, 61)
  944. b.set(fet, 66)
  945. b[71] = 0xff;
  946. b[72] = 0xff;
  947. b[73] = 0xff;
  948. b[74] = num; //添加指纹
  949. app.globalData.ble.send(cmd, b)
  950. },
  951. delete_63(managerTelephone, managerPassword, userTelephone, userPassword, startTime, endTime, id) {
  952. wx.showLoading({
  953. title: "正在发送...",
  954. mask: true
  955. });
  956. setTimeout(() => {
  957. wx.hideLoading()
  958. }, 1000);
  959. let cmd = 0x63
  960. let mt = util.stringToUint8Array(managerTelephone)
  961. let mp = util.stringToUint8Array(managerPassword)
  962. let ut = util.stringToUint8Array(userTelephone)
  963. let up = util.stringToUint8Array(userPassword)
  964. let ust = util.time40ToBytes(startTime)
  965. let uet = util.time40ToBytes(endTime)
  966. let fst = util.time40ToBytes(startTime)
  967. let fet = util.time40ToBytes(endTime)
  968. let length = 1 + 11 + 6 + 11 + 6 + 5 + 5 + 4 + 2 + 10 + 5 + 5 + 1 + 2 + 1
  969. let b = new Uint8Array(length)
  970. b[0] = cmd
  971. b.set(mt, 1)
  972. b.set(mp, 12)
  973. b.set(ut, 18)
  974. b.set(up, 29)
  975. b.set(ust, 35)
  976. b.set(uet, 40)
  977. //权限
  978. b[45] = 0x46;
  979. b[46] = 0x46;
  980. b[47] = 0x46;
  981. b[48] = 0x46;
  982. //密码长度 uint16
  983. b[49] = 0
  984. b[50] = 0x0a
  985. //密码数据
  986. b[51] = id
  987. b[52] = 0xff
  988. b[53] = 0xff
  989. b[54] = 0xff
  990. b[55] = 0xff
  991. b[56] = 0xff
  992. b[57] = 0xff
  993. b[58] = 0xff
  994. b[59] = 0xff
  995. b[60] = 0xff
  996. b.set(fst, 61)
  997. b.set(fet, 66)
  998. b[71] = 0xff;
  999. b[72] = 0xff;
  1000. b[73] = 0xff;
  1001. b[74] = 18; //删除指纹
  1002. app.globalData.ble.send(cmd, b)
  1003. },
  1004. startFp_29(deviceNum, status) {
  1005. wx.showLoading({
  1006. title: "正在发送...",
  1007. mask: true
  1008. });
  1009. setTimeout(() => {
  1010. wx.hideLoading()
  1011. }, 1000);
  1012. let cmd = 0x29
  1013. let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  1014. let length = 1 + 20 + 5 + 1 + 1
  1015. let b = new Uint8Array(length)
  1016. b[0] = cmd
  1017. b.set(dn, 1)
  1018. //send data=0x0036000008
  1019. b[21] = 0x00;
  1020. b[22] = 0x36;
  1021. b[23] = 0;
  1022. b[24] = 0;
  1023. b[25] = 0x08
  1024. b[26] = status //status: 0x03, 0x02, 0x01
  1025. b[27] = 0x01
  1026. app.globalData.ble.send(cmd, b)
  1027. },
  1028. // 设置密码
  1029. permissionsfun() {
  1030. wx.navigateTo({
  1031. url: "/pages/permissions/permissions"
  1032. })
  1033. },
  1034. // 跳转开锁记录页面
  1035. getlogList() {
  1036. wx.navigateTo({
  1037. url: "/pages/openLockLog/openLockLog?&roomId=" + this.data.deviceinfo.roomId
  1038. })
  1039. },
  1040. // zg蓝牙连接
  1041. openTheDoor() {
  1042. // if(this.data.deviceinfo.info){
  1043. // JSON.parse(this.data.deviceinfo.info)
  1044. wx.showLoading({
  1045. title: '连接中',
  1046. mask: true,
  1047. icon: 'none'
  1048. })
  1049. var userInfo = wx.getStorageSync('userInfo')
  1050. console.log(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId)
  1051. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, (callback) => {
  1052. console.log(callback, '管理员获取密钥')
  1053. if (callback.status == '00') {
  1054. var userSignKey = callback.signKey ? callback.signKey : callback.commonKey || ''
  1055. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, userSignKey, (callback1) => {
  1056. console.log(callback1, '管理员获取通信')
  1057. if (callback1.status == '00') {
  1058. var commonKey = callback1.commonKey
  1059. ICINLocker.openTheDoor(this.data.cgInfo.lockerId, this.data.cgInfo.superId, userSignKey, this.data.cgInfo.superId, '', '00', commonKey, (callback2) => {
  1060. if (callback2.status == '00') {
  1061. var rqTime = moment().format("X")
  1062. var username = wx.getStorageSync('username'),
  1063. password = wx.getStorageSync('password')
  1064. var str = `${username}+${password}+${rqTime}`
  1065. var signature = md5(str)
  1066. var data = {
  1067. code: "zg/bleUnlockRecord",
  1068. data: {
  1069. lockerId: this.data.cgInfo.lockerId,
  1070. lockerUserId: this.data.cgInfo.superId,
  1071. roomId: this.data.deviceinfo.roomId,
  1072. roomName: this.data.deviceinfo.roomName,
  1073. cardName: userInfo.username,
  1074. signature: signature
  1075. }
  1076. }
  1077. console.log(data, '蓝牙开锁')
  1078. wx.hideLoading()
  1079. wx.showToast({
  1080. title: '开锁成功',
  1081. duration: 2000,
  1082. icon: 'none'
  1083. })
  1084. WXAPI.sendCommand(data).then(res => {
  1085. console.log(res)
  1086. })
  1087. } else {
  1088. wx.hideLoading()
  1089. wx.showToast({
  1090. title: '开锁失败',
  1091. duration: 2000,
  1092. icon: 'none'
  1093. })
  1094. }
  1095. })
  1096. } else {
  1097. wx.hideLoading()
  1098. wx.showToast({
  1099. title: '连接失败',
  1100. duration: 2000,
  1101. icon: 'none'
  1102. })
  1103. }
  1104. })
  1105. } else {
  1106. wx.hideLoading()
  1107. }
  1108. });
  1109. // }else{
  1110. // wx.showToast({
  1111. // title: '请先下发人员',
  1112. // duration:2000,
  1113. // icon:'none'
  1114. // })
  1115. // }
  1116. },
  1117. // 添加指纹
  1118. addFingerPrints() {
  1119. var userInfo = JSON.parse(this.data.deviceinfo.info)
  1120. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, this.data.cgInfo.authKey, (callback) => {
  1121. 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) => {
  1122. console.log(callback)
  1123. })
  1124. })
  1125. },
  1126. // 蓝牙初始化
  1127. btntest1(e) {
  1128. wx.showLoading({
  1129. title: '正在搜索',
  1130. mask: true,
  1131. icon: 'none'
  1132. })
  1133. var event = e.currentTarget.dataset.i
  1134. var that = this;
  1135. this.data.event = event
  1136. var deviceinfo = this.data.deviceinfo
  1137. if (deviceinfo.manufactureId == 201 || deviceinfo.manufactureId == 221) {
  1138. if (app.globalData.zgBlueStatus) {
  1139. if (event == 0) {
  1140. this.openTheDoor()
  1141. } else if (event == 3) {
  1142. this.addFingerPrints()
  1143. } else if (event == 6) {
  1144. this.setData({
  1145. show: true
  1146. })
  1147. } else if (event == 11) {
  1148. this.synchroPlatformTask()
  1149. }
  1150. } else {
  1151. that.goBlue()
  1152. }
  1153. } else if (deviceinfo.manufactureId == 101) {
  1154. if (app.globalData.bleStatus == '蓝牙已连接') {
  1155. if (event == 0) {
  1156. this.btntest2()
  1157. } else if (event == 3) {
  1158. this.btntest3()
  1159. } else if (event == 6) {
  1160. // this.setVoice()
  1161. this.setData({
  1162. show: true
  1163. })
  1164. } else if (event == 7) {
  1165. wx.showModal({
  1166. title: "常开设置",
  1167. cancelText: '关闭',
  1168. confirmText: '开启',
  1169. success: (res) => {
  1170. if (res.confirm) {
  1171. that.setOpen()
  1172. } else if (res.cancel) {
  1173. that.setOpen1()
  1174. }
  1175. }
  1176. })
  1177. }
  1178. } else {
  1179. this.startconnect()
  1180. }
  1181. } else if (deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241) {
  1182. if (this.data.isSearch) {
  1183. if (event == '0') {
  1184. // let iotLwj = new LwJ(this.data.lockDevice,isConnected,connectedDeviceId,isInitReady,this.data.lockDevice.lockModel)
  1185. // iotLwj.openLock(41)
  1186. this.LwjopenLock()
  1187. } else if (event == 6) {
  1188. this.setData({
  1189. show: true
  1190. })
  1191. }else if(event == '3') {
  1192. this.configurewifj()
  1193. }else if(event == '8') {
  1194. this.personnelmanagement()
  1195. }else if(event == '11') {
  1196. this.facemanagement()
  1197. }
  1198. } else {
  1199. this.searchDevicesMethods()
  1200. }
  1201. }
  1202. },
  1203. onQueryBindState: function () {
  1204. var that = this
  1205. wx.showLoading({
  1206. title: '查询中',
  1207. })
  1208. var bytes = plugin.queryLockState(lockDevice.name)
  1209. console.debug('bytes', bytes)
  1210. that.sendBytes(bytes)
  1211. },
  1212. searchDevicesMethods() {
  1213. var that = this;
  1214. wx.showLoading({
  1215. title: '正在搜索',
  1216. // mask: true
  1217. })
  1218. this.setData({
  1219. searchClick: false
  1220. })
  1221. wx.openBluetoothAdapter({
  1222. success: function (res) {
  1223. wx.startBluetoothDevicesDiscovery({
  1224. success: function (res) {
  1225. wx.getBluetoothDevices({
  1226. success: function (res) {
  1227. console.log(res)
  1228. res.devices.map(it => {
  1229. var status = it.name.indexOf('WSL')
  1230. if (status != -1) {
  1231. if (it.RSSI != 127) {
  1232. if (it.advertisData != null) {
  1233. it.adData = util1.ab2hex(it.advertisData)
  1234. if (it.adData.length > 10) {
  1235. var macStr = it.adData.substring(4, 16).toUpperCase()
  1236. //console.log('macStr', macStr)
  1237. it.mac = macStr.substr(10, 2) + ':' + macStr.substr(8, 2) + ':' + macStr.substr(6, 2) + ':' + macStr.substr(4, 2) + ':' + macStr.substr(2, 2) + ':' + macStr.substr(0, 2)
  1238. if (it.adData.substring(1, 2) == '1') {
  1239. it.isLightOn = true
  1240. it.textColor = 'green'
  1241. } else {
  1242. it.isLightOn = false
  1243. it.textColor = 'black'
  1244. }
  1245. if (it.adData.substring(3, 4) == '1') {
  1246. it.textColor = 'pink'
  1247. it.isBind = true
  1248. } else {
  1249. it.isBind = false
  1250. }
  1251. }
  1252. } else {
  1253. it.textColor = 'black'
  1254. }
  1255. lockModel = util1.getLockModel(it.name)
  1256. it.lockType = util1.getLockType(lockModel)
  1257. if (it.name == that.data.deviceinfo.deviceNum) {
  1258. app.addDeviceWithDevName(it.name, it)
  1259. connectedDeviceId = it.deviceId
  1260. lockDevice = it
  1261. console.log(lockDevice, it, 'lockDevice,it')
  1262. app.globalData.isSearch = true
  1263. that.setData({
  1264. isSearch: true,
  1265. // lockDevice:it
  1266. })
  1267. // let iotLwj = new LwJ(it,isConnected,connectedDeviceId,isInitReady,it.lockModel)
  1268. // iotLwj.connectTo()
  1269. if (that.data.event == '0') {
  1270. // iotLwj.openLock(41)
  1271. that.LwjopenLock()
  1272. } else if (that.data.event == 6) {
  1273. that.setData({
  1274. show: true
  1275. })
  1276. } else if (that.data.event == '3') {
  1277. that.configurewifj()
  1278. }else if(that.data.event == '8') {
  1279. that.personnelmanagement()
  1280. }else if(that.data.event == '11') {
  1281. that.facemanagement()
  1282. }
  1283. wx.hideLoading({
  1284. success: (res) => {},
  1285. })
  1286. }
  1287. }
  1288. }
  1289. })
  1290. if (!that.data.isSearch && that.data.toSearch) {
  1291. that.searchDevicesMethods()
  1292. }
  1293. }
  1294. })
  1295. },
  1296. fail: function (res) {
  1297. wx.hideLoading({
  1298. success: (res) => {
  1299. wx.showToast({
  1300. title: res.errMsg,
  1301. duration: 2000,
  1302. icon: 'none'
  1303. })
  1304. },
  1305. })
  1306. }
  1307. })
  1308. },
  1309. fail: function (res) {
  1310. console.log('请打开蓝牙和定位功能')
  1311. wx.hideLoading({
  1312. success: (res) => {
  1313. wx.showToast({
  1314. title: '请打开蓝牙和定位功能',
  1315. duration: 2000,
  1316. icon: 'none'
  1317. })
  1318. },
  1319. })
  1320. }
  1321. })
  1322. },
  1323. LwjopenLock: function () {
  1324. var that = this
  1325. taskId = 41
  1326. that.initBluetooth()
  1327. },
  1328. configurewifj() {
  1329. var that = this
  1330. taskId = 121
  1331. that.initBluetooth()
  1332. },
  1333. // 人员管理
  1334. personnelmanagement() {
  1335. var that = this
  1336. taskId = 9010
  1337. that.initBluetooth()
  1338. },
  1339. // 图像管理
  1340. facemanagement() {
  1341. var that = this
  1342. taskId = 9011
  1343. that.initBluetooth()
  1344. },
  1345. LwjonOpenLock: function () {
  1346. var that = this
  1347. wx.showLoading({
  1348. title: that.data.isJack ? '上电中' : '解锁中',
  1349. })
  1350. console.log(lockDevice.name, 'lockDevice.name0开锁中')
  1351. var bytes = plugin.sendOpenLockP1(lockDevice.name, basecode)
  1352. console.debug('bytes', bytes)
  1353. that.sendBytes(bytes)
  1354. },
  1355. initBluetooth: function () {
  1356. var that = this
  1357. wx.getConnectedBluetoothDevices({
  1358. services: [config.uuid.serviceUuid],
  1359. success: function (res) {
  1360. res.devices.map(function (it) {
  1361. if (it.deviceId == connectedDeviceId || it.name == lockDevice.name) {
  1362. isConnected = true
  1363. }
  1364. })
  1365. that.setData({
  1366. isConnected: isConnected
  1367. })
  1368. console.log('isConnected', isConnected)
  1369. if (isConnected) {
  1370. if (isInitReady) {
  1371. console.log(isInitReady, 'isInitReady', taskId)
  1372. setTimeout(() => {
  1373. that.doWork()
  1374. }, 500)
  1375. } else {
  1376. that.setupConnection()
  1377. }
  1378. } else {
  1379. that.connectTo()
  1380. }
  1381. },
  1382. })
  1383. },
  1384. doWork: function () {
  1385. var that = this
  1386. switch (taskId) {
  1387. case 11: {
  1388. that.onBindLock()
  1389. break
  1390. }
  1391. case 12: {
  1392. that.onUnbindLock()
  1393. break
  1394. }
  1395. case 21: {
  1396. that.onQueryBindState()
  1397. break
  1398. }
  1399. case 22: {
  1400. that.onQueryBattery()
  1401. break
  1402. }
  1403. case 31: {
  1404. that.onQueryNbImei()
  1405. break
  1406. }
  1407. case 32: {
  1408. that.onLogin()
  1409. break
  1410. }
  1411. case 41: {
  1412. that.LwjonOpenLock()
  1413. break
  1414. }
  1415. case 42: {
  1416. that.onSyncClock()
  1417. break
  1418. }
  1419. case 51: {
  1420. that.onAddPincode()
  1421. break
  1422. }
  1423. case 52: {
  1424. that.onDelPincode()
  1425. break
  1426. }
  1427. case 61: {
  1428. if (lockModel > 70) {
  1429. that.onAddRfCard()
  1430. } else {
  1431. wx.showModal({
  1432. title: '提示',
  1433. content: '请刷卡!',
  1434. showCancel: false
  1435. })
  1436. }
  1437. break
  1438. }
  1439. case 62: {
  1440. that.onDelRfCard()
  1441. break
  1442. }
  1443. case 71: {
  1444. that.onAddFingerprint()
  1445. break
  1446. }
  1447. case 72: {
  1448. that.onDelFingerprint()
  1449. break
  1450. }
  1451. case 81: {
  1452. that.onChangeAdminPincode()
  1453. break
  1454. }
  1455. case 91: {
  1456. that.onQueryLockSlotState()
  1457. break
  1458. }
  1459. case 92: {
  1460. that.onQueryLockUnlockState()
  1461. break
  1462. }
  1463. case 101: {
  1464. that.onChangeLockUnlockState()
  1465. break
  1466. }
  1467. case 102: {
  1468. that.onChangeLockMutedState()
  1469. break
  1470. }
  1471. case 111: {
  1472. this.onChangeLockNbState()
  1473. }
  1474. case 121: {
  1475. this.onConfigurewifi()
  1476. }
  1477. // 人员管理
  1478. case 9010: {
  1479. this.gotoperson()
  1480. }
  1481. // 图像管理
  1482. case 9011: {
  1483. this.gotofaceadd()
  1484. }
  1485. default: {
  1486. }
  1487. }
  1488. },
  1489. connectTo: function () {
  1490. var that = this
  1491. wx.showLoading({
  1492. title: '连接中',
  1493. })
  1494. wx.createBLEConnection({
  1495. deviceId: lockDevice.deviceId,
  1496. timeout: config.ble.connectTimeOut,
  1497. success: function (res) {
  1498. console.debug('connectTo', res)
  1499. isConnected = true
  1500. wx.hideLoading()
  1501. setTimeout(function () {
  1502. that.setupConnection()
  1503. }, 500)
  1504. },
  1505. fail: function (e) {
  1506. console.debug('connectTo', e)
  1507. wx.hideLoading()
  1508. switch (e.errCode) {
  1509. case 10003: {
  1510. wx.showModal({
  1511. title: '连接失败',
  1512. content: '是否重新连接?',
  1513. success: function (res) {
  1514. if (res.confirm) {
  1515. that.connectTo()
  1516. }
  1517. }
  1518. })
  1519. break
  1520. }
  1521. case 10012: {
  1522. wx.showModal({
  1523. title: '连接失败',
  1524. content: '蓝牙连接超时',
  1525. showCancel: false
  1526. })
  1527. break
  1528. }
  1529. case 10002: {
  1530. wx.showModal({
  1531. title: '连接失败',
  1532. content: '没有找到指定设备',
  1533. showCancel: false
  1534. })
  1535. break
  1536. }
  1537. }
  1538. }
  1539. })
  1540. },
  1541. setupConnection: function () {
  1542. var that = this
  1543. wx.showLoading({
  1544. title: '初始化连接中',
  1545. })
  1546. wx.getBLEDeviceServices({
  1547. deviceId: lockDevice.deviceId,
  1548. success: function (res) {
  1549. console.log('Services', res)
  1550. wx.getBLEDeviceCharacteristics({
  1551. deviceId: lockDevice.deviceId,
  1552. serviceId: config.uuid.serviceUuid.toUpperCase(),
  1553. success: function (res) {
  1554. console.log('Characteristics', res)
  1555. wx.showLoading({
  1556. title: '连接成功',
  1557. })
  1558. wx.onBLECharacteristicValueChange(function (res) {
  1559. var bytes = new Uint8Array(res.value)
  1560. console.log('bytes', bytes)
  1561. console.log(lockDevice.name, 'lockDevice.name1')
  1562. var data = plugin.parseBytes(lockDevice.name, basecode, bytes)
  1563. console.log('data', data)
  1564. switch (data.cmd) {
  1565. case 'reportLockBattery': {
  1566. if (data.data.battery < 10) {
  1567. wx.showModal({
  1568. title: '电量报警',
  1569. content: `门锁当前电量${data.data.battery}%!\n电量严重不足,请立即更换电池!`,
  1570. showCancel: false
  1571. })
  1572. } else if (data.data.battery < 30) {
  1573. wx.showModal({
  1574. title: '电量预警',
  1575. content: `门锁当前电量${data.data.battery}%!\n请及时更换电池!`,
  1576. showCancel: false
  1577. })
  1578. }
  1579. break
  1580. }
  1581. case 'reportRfCardResult': {
  1582. if (taskId == 61) {
  1583. wx.showModal({
  1584. title: '检测到新卡',
  1585. content: `是否添加此房卡,卡号:${data.data.cardId}`,
  1586. success: function (res) {
  1587. if (res.confirm) {
  1588. rfCardId = data.data.cardId
  1589. that.onAddRfCard()
  1590. }
  1591. }
  1592. })
  1593. } else {
  1594. if (lockModel > 70) {
  1595. if (data.data.isValid) {
  1596. wx.showModal({
  1597. title: '提示',
  1598. content: `房卡开锁成功,序号:${data.data.index}`,
  1599. showCancel: false
  1600. })
  1601. } else {
  1602. wx.showModal({
  1603. title: '提示',
  1604. content: `多次刷房卡开锁失败!`,
  1605. showCancel: false
  1606. })
  1607. }
  1608. } else {
  1609. if (data.data.isValid) {
  1610. wx.showModal({
  1611. title: '提示',
  1612. content: `房卡开锁成功,卡号:${data.data.cardId}`,
  1613. showCancel: false
  1614. })
  1615. } else {
  1616. wx.showModal({
  1617. title: '提示',
  1618. content: `房卡未授权,卡号:${data.data.cardId}`,
  1619. showCancel: false
  1620. })
  1621. }
  1622. }
  1623. }
  1624. break
  1625. }
  1626. case 'reportPincodeResult': {
  1627. if (lockModel > 70) {
  1628. if (data.data.isValid) {
  1629. wx.showModal({
  1630. title: '提示',
  1631. content: `密码开锁成功,序号:${data.data.index}`,
  1632. showCancel: false
  1633. })
  1634. } else {
  1635. wx.showModal({
  1636. title: '提示',
  1637. content: `多次密码开锁失败!`,
  1638. showCancel: false
  1639. })
  1640. }
  1641. } else {
  1642. if (data.data.isValid) {
  1643. wx.showModal({
  1644. title: '提示',
  1645. content: `密码:${data.data.pincode}开锁成功!`,
  1646. showCancel: false
  1647. })
  1648. } else {
  1649. wx.showModal({
  1650. title: '提示',
  1651. content: `密码:${data.data.pincode}未授权!`,
  1652. showCancel: false
  1653. })
  1654. }
  1655. }
  1656. break
  1657. }
  1658. case 'reportFingerprintResult': {
  1659. if (data.data.isValid) {
  1660. wx.showModal({
  1661. title: '提示',
  1662. content: `指纹开锁成功,序号:${data.data.index}`,
  1663. showCancel: false
  1664. })
  1665. } else {
  1666. wx.showModal({
  1667. title: '提示',
  1668. content: `多次指纹开锁失败!`,
  1669. showCancel: false
  1670. })
  1671. }
  1672. break
  1673. }
  1674. case 'queryLockState': {
  1675. wx.hideLoading()
  1676. if (data.code != 200) {
  1677. wx.showModal({
  1678. title: '提示',
  1679. content: '查询失败!',
  1680. showCancel: false,
  1681. success: function (res) {}
  1682. })
  1683. break
  1684. }
  1685. that.setData({
  1686. lock: {
  1687. mac: data.data.mac,
  1688. lockType: util1.getLockType(lockModel),
  1689. },
  1690. isBindLock: data.data.isBind
  1691. })
  1692. lockMac = data.data.mac
  1693. if (taskId > 0) {
  1694. if (data.data.isBind) {
  1695. wx.showModal({
  1696. title: data.data.mac,
  1697. content: '此设备已经硬件绑定!',
  1698. showCancel: false,
  1699. success: function (res) {}
  1700. })
  1701. } else {
  1702. wx.showModal({
  1703. title: data.data.mac,
  1704. content: '此设备硬件未绑定!',
  1705. showCancel: false,
  1706. success: function (res) {}
  1707. })
  1708. }
  1709. }
  1710. taskId = 0
  1711. break
  1712. }
  1713. case 'queryLockBattery': {
  1714. wx.hideLoading()
  1715. if (data.code != 200) {
  1716. wx.showModal({
  1717. title: '提示',
  1718. content: '查询失败!',
  1719. showCancel: false,
  1720. success: function (res) {}
  1721. })
  1722. break
  1723. }
  1724. taskId = 0
  1725. wx.showModal({
  1726. title: '提示',
  1727. content: `此门锁电量为${data.data.battery}%`,
  1728. showCancel: false,
  1729. success: function (res) {}
  1730. })
  1731. break
  1732. }
  1733. case 'queryNbImei': {
  1734. wx.hideLoading()
  1735. if (data.code != 200) {
  1736. wx.showModal({
  1737. title: '提示',
  1738. content: '查询失败!',
  1739. showCancel: false,
  1740. success: function (res) {}
  1741. })
  1742. break
  1743. }
  1744. taskId = 0
  1745. wx.showModal({
  1746. title: '提示',
  1747. content: `此NB设备IMEI为${data.data.imei}`,
  1748. showCancel: false,
  1749. success: function (res) {}
  1750. })
  1751. break
  1752. }
  1753. case 'setNbFun': {
  1754. wx.hideLoading()
  1755. if (data.code != 200) {
  1756. wx.showModal({
  1757. title: '提示',
  1758. content: '设置Nb功能失败!',
  1759. showCancel: false,
  1760. success: function (res) {}
  1761. })
  1762. break
  1763. }
  1764. taskId = 0
  1765. wx.showModal({
  1766. title: '提示',
  1767. content: that.data.isNbEnable ? 'NB功能已禁用' : 'NB功能已打开',
  1768. showCancel: false,
  1769. })
  1770. that.setData({
  1771. isNbEnable: !that.data.isNbEnable
  1772. })
  1773. break
  1774. }
  1775. case 'sendBindLock': {
  1776. wx.hideLoading()
  1777. if (data.code != 200) {
  1778. wx.showModal({
  1779. title: '提示',
  1780. content: '绑定失败!',
  1781. showCancel: false,
  1782. success: function (res) {}
  1783. })
  1784. break
  1785. }
  1786. taskId = 0
  1787. that.setData({
  1788. isBindLock: data.data.isBind
  1789. })
  1790. if (data.data.isBind) {
  1791. wx.showToast({
  1792. title: '绑定成功!',
  1793. })
  1794. } else {
  1795. wx.showToast({
  1796. title: '绑定失败!',
  1797. })
  1798. }
  1799. break
  1800. }
  1801. case 'sendUnbindLock': {
  1802. wx.hideLoading()
  1803. if (data.code != 200) {
  1804. wx.showModal({
  1805. title: '提示',
  1806. content: '解绑失败!',
  1807. showCancel: false,
  1808. success: function (res) {}
  1809. })
  1810. break
  1811. }
  1812. taskId = 0
  1813. that.setData({
  1814. isBindLock: data.data.isBind
  1815. })
  1816. if (data.data.isBind) {
  1817. wx.showToast({
  1818. title: '解绑失败!',
  1819. })
  1820. } else {
  1821. wx.showToast({
  1822. title: '解绑成功!',
  1823. })
  1824. }
  1825. break
  1826. }
  1827. case 'login1':
  1828. case 'sendOpenLockP1': {
  1829. if (data.code != 200) {
  1830. wx.hideLoading()
  1831. if (taskId == 41) {
  1832. wx.showModal({
  1833. title: '提示',
  1834. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  1835. showCancel: false,
  1836. success: function (res) {}
  1837. })
  1838. } else if (taskId == 32) {
  1839. wx.showModal({
  1840. title: '提示',
  1841. content: '登录失败!',
  1842. showCancel: false,
  1843. success: function (res) {}
  1844. })
  1845. }
  1846. break
  1847. }
  1848. if (taskId == 41) {
  1849. console.log(lockDevice.name, 'lockDevice.name2')
  1850. var bytes = plugin.sendOpenLockP2(lockDevice.name, basecode, data.data.randomN)
  1851. console.debug('bytes', bytes)
  1852. that.sendBytes(bytes)
  1853. } else if (taskId == 32) {
  1854. console.log(lockDevice.name, 'lockDevice.name3')
  1855. var bytes = plugin.login2(lockDevice.name, basecode, data.data.randomN)
  1856. console.debug('bytes', bytes)
  1857. that.sendBytes(bytes)
  1858. }
  1859. break;
  1860. }
  1861. case 'login':
  1862. case 'sendOpenLockP2': {
  1863. wx.hideLoading()
  1864. if (data.code != 200) {
  1865. if (taskId == 41) {
  1866. wx.showModal({
  1867. title: '提示',
  1868. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  1869. showCancel: false,
  1870. success: function (res) {}
  1871. })
  1872. } else if (taskId == 32) {
  1873. wx.showModal({
  1874. title: '提示',
  1875. content: '登录失败!',
  1876. showCancel: false,
  1877. success: function (res) {}
  1878. })
  1879. }
  1880. break
  1881. }
  1882. isLockLogin = true
  1883. if (taskId == 41) {
  1884. var data = {
  1885. code: "ble/bleUnlockRecord",
  1886. data: {
  1887. deviceNum: that.data.deviceinfo.deviceNum,
  1888. roomId: that.data.deviceinfo.roomId,
  1889. roomName: that.data.deviceinfo.roomName,
  1890. cardName: that.data.userInfo.username,
  1891. productId: that.data.deviceinfo.manufactureId,
  1892. userId: '29283991'
  1893. }
  1894. }
  1895. WXAPI.sendCommand(data).then(res => {
  1896. console.log(res)
  1897. })
  1898. wx.showToast({
  1899. title: that.data.isJack ? '上电成功!' : '解锁成功!',
  1900. })
  1901. } else if (taskId == 32) {
  1902. wx.showToast({
  1903. title: '登录成功!',
  1904. })
  1905. }
  1906. taskId = 0
  1907. break;
  1908. }
  1909. case 'syncClock': {
  1910. wx.hideLoading()
  1911. if (data.code != 200) {
  1912. wx.showModal({
  1913. title: '提示',
  1914. content: '同步时间失败!' + data.data.msg,
  1915. showCancel: false,
  1916. success: function (res) {}
  1917. })
  1918. break
  1919. }
  1920. taskId = 0
  1921. wx.showModal({
  1922. title: '提示',
  1923. content: '时间更新成功!',
  1924. showCancel: false
  1925. })
  1926. break;
  1927. }
  1928. case 'addPincode': {
  1929. wx.hideLoading()
  1930. if (data.code != 200) {
  1931. wx.showModal({
  1932. title: '提示',
  1933. content: '添加密码失败!' + data.data.msg,
  1934. showCancel: false,
  1935. success: function (res) {}
  1936. })
  1937. break
  1938. }
  1939. taskId = 0
  1940. that.setData({
  1941. isPincodeAdd: true
  1942. })
  1943. wx.showModal({
  1944. title: '提示',
  1945. content: `添加密码${pincode}成功!`,
  1946. showCancel: false
  1947. })
  1948. break
  1949. }
  1950. case 'delPincode': {
  1951. wx.hideLoading()
  1952. if (data.code != 200) {
  1953. wx.showModal({
  1954. title: '提示',
  1955. content: '删除密码失败!',
  1956. showCancel: false,
  1957. success: function (res) {}
  1958. })
  1959. break
  1960. }
  1961. taskId = 0
  1962. wx.showModal({
  1963. title: '提示',
  1964. content: `删除密码${pincode}成功!`,
  1965. showCancel: false,
  1966. })
  1967. that.setData({
  1968. isPincodeAdd: false
  1969. })
  1970. pincode = -1
  1971. pincodeIndex = -1
  1972. break
  1973. }
  1974. case 'addRfCard': {
  1975. wx.hideLoading()
  1976. if (data.code == 100) {
  1977. wx.showLoading({
  1978. title: data.data.msg,
  1979. })
  1980. break
  1981. } else if (data.code != 200) {
  1982. wx.showModal({
  1983. title: '提示',
  1984. content: '添加房卡失败!' + data.data.msg,
  1985. showCancel: false,
  1986. success: function (res) {}
  1987. })
  1988. break
  1989. }
  1990. taskId = 0
  1991. that.setData({
  1992. isRfCardAdd: true
  1993. })
  1994. if (lockModel > 70) {
  1995. wx.showModal({
  1996. title: '提示',
  1997. content: `添加房卡成功,序号${rfCardIndex}`,
  1998. showCancel: false
  1999. })
  2000. } else {
  2001. wx.showModal({
  2002. title: '提示',
  2003. content: `添加房卡成功,卡号${rfCardId}`,
  2004. showCancel: false
  2005. })
  2006. }
  2007. break
  2008. }
  2009. case 'delRfCard': {
  2010. wx.hideLoading()
  2011. if (data.code != 200) {
  2012. wx.showModal({
  2013. title: '提示',
  2014. content: '删除房卡失败!',
  2015. showCancel: false,
  2016. success: function (res) {}
  2017. })
  2018. break
  2019. }
  2020. taskId = 0
  2021. that.setData({
  2022. isRfCardAdd: false
  2023. })
  2024. if (lockModel > 70) {
  2025. wx.showModal({
  2026. title: '提示',
  2027. content: `删除房卡成功,序号${rfCardIndex}`,
  2028. showCancel: false,
  2029. })
  2030. } else {
  2031. wx.showModal({
  2032. title: '提示',
  2033. content: `删除房卡成功,卡号${rfCardId}`,
  2034. showCancel: false,
  2035. })
  2036. }
  2037. rfCardId = -1
  2038. rfCardIndex = -1
  2039. break
  2040. }
  2041. case 'addFingerprint': {
  2042. wx.hideLoading()
  2043. if (data.code == 100) {
  2044. wx.showLoading({
  2045. title: data.data.msg,
  2046. })
  2047. break
  2048. } else if (data.code != 200) {
  2049. wx.showModal({
  2050. title: '提示',
  2051. content: '添加指纹失败!' + data.data.msg,
  2052. showCancel: false,
  2053. success: function (res) {}
  2054. })
  2055. break
  2056. }
  2057. taskId = 0
  2058. that.setData({
  2059. isFingerprintAdd: true
  2060. })
  2061. wx.showModal({
  2062. title: '提示',
  2063. content: `添加指纹成功,序号${fingerprintIndex}`,
  2064. showCancel: false
  2065. })
  2066. break
  2067. }
  2068. case 'delFingerprint': {
  2069. wx.hideLoading()
  2070. if (data.code != 200) {
  2071. wx.showModal({
  2072. title: '提示',
  2073. content: '删除指纹失败!',
  2074. showCancel: false,
  2075. success: function (res) {}
  2076. })
  2077. break
  2078. }
  2079. taskId = 0
  2080. wx.showModal({
  2081. title: '提示',
  2082. content: `删除指纹成功,序号${fingerprintIndex}`,
  2083. showCancel: false,
  2084. })
  2085. that.setData({
  2086. isFingerprintAdd: false
  2087. })
  2088. fingerprintIndex = -1
  2089. break
  2090. }
  2091. case 'changeAdminPincode': {
  2092. wx.hideLoading()
  2093. if (data.code != 200) {
  2094. wx.showModal({
  2095. title: '提示',
  2096. content: '修改管理密码失败!',
  2097. showCancel: false,
  2098. success: function (res) {}
  2099. })
  2100. break
  2101. }
  2102. taskId = 0
  2103. wx.showToast({
  2104. title: '修改管理密码成功!',
  2105. })
  2106. }
  2107. case 'queryLockSlotState': {
  2108. wx.hideLoading()
  2109. if (data.code != 200) {
  2110. wx.showModal({
  2111. title: '提示',
  2112. content: '查询失败!',
  2113. showCancel: false,
  2114. success: function (res) {}
  2115. })
  2116. break
  2117. }
  2118. taskId = 0
  2119. wx.showModal({
  2120. title: '提示',
  2121. content: data.data.state == 0 ? '此门锁方舌关闭' : '此门锁方舌打开',
  2122. showCancel: false,
  2123. success: function (res) {}
  2124. })
  2125. break
  2126. }
  2127. case 'queryLockUnlockState': {
  2128. wx.hideLoading()
  2129. if (data.code != 200) {
  2130. wx.showModal({
  2131. title: '提示',
  2132. content: '查询失败!',
  2133. showCancel: false,
  2134. success: function (res) {}
  2135. })
  2136. break
  2137. }
  2138. taskId = 0
  2139. wx.showModal({
  2140. title: '提示',
  2141. content: data.data.state == 0 ? '此门锁已关闭' : '此门锁已打开',
  2142. showCancel: false,
  2143. success: function (res) {}
  2144. })
  2145. break
  2146. }
  2147. case 'setLockUnlockState': {
  2148. wx.hideLoading()
  2149. if (data.code != 200) {
  2150. wx.showModal({
  2151. title: '提示',
  2152. content: '设置常开指令失败!',
  2153. showCancel: false,
  2154. success: function (res) {}
  2155. })
  2156. break
  2157. }
  2158. taskId = 0
  2159. wx.showModal({
  2160. title: '提示',
  2161. content: data.data.state == 0 ? '常开模式已退出' : '常开模式已开启',
  2162. showCancel: false,
  2163. })
  2164. that.setData({
  2165. isUnloked: data.data.state == 1
  2166. })
  2167. break
  2168. }
  2169. case 'setLockMuteState': {
  2170. wx.hideLoading()
  2171. if (data.code != 200) {
  2172. wx.showModal({
  2173. title: '提示',
  2174. content: '设置静音指令失败!',
  2175. showCancel: false,
  2176. success: function (res) {}
  2177. })
  2178. break
  2179. }
  2180. taskId = 0
  2181. wx.showModal({
  2182. title: '提示',
  2183. content: data.data.state == 1 ? '静音模式已退出' : '静音模式已开启',
  2184. showCancel: false,
  2185. })
  2186. that.setData({
  2187. isMuted: data.data.state == 0
  2188. })
  2189. break
  2190. }
  2191. }
  2192. })
  2193. wx.notifyBLECharacteristicValueChange({
  2194. deviceId: lockDevice.deviceId,
  2195. serviceId: config.uuid.serviceUuid.toUpperCase(),
  2196. characteristicId: config.uuid.notifyUuid.toUpperCase(),
  2197. state: true,
  2198. success: function (res) {
  2199. console.log('setupNotify', res)
  2200. isInitReady = true
  2201. setTimeout(function () {
  2202. wx.hideLoading()
  2203. // that.onQueryBindState()
  2204. if (taskId == 41 && that.data.event == '0') {
  2205. that.doWork()
  2206. }else if(taskId == 121 && that.data.event == '3') {
  2207. that.doWork()
  2208. }else if(taskId == 9010 && that.data.event == '8') {
  2209. that.doWork()
  2210. }else if(taskId == 9011 && that.data.event == '11') {
  2211. that.doWork()
  2212. }
  2213. }, 500)
  2214. },
  2215. })
  2216. },
  2217. })
  2218. },
  2219. })
  2220. },
  2221. addPincode: function () {
  2222. var that = this
  2223. taskId = 51
  2224. that.initBluetooth()
  2225. },
  2226. onAddPincode: function () {
  2227. var that = this
  2228. wx.showLoading({
  2229. title: '添加密码中',
  2230. })
  2231. var startTime = util1.getLocalTime(8)
  2232. var endTime = new Date(startTime.getTime() + 5 * 60 * 1000) //有效期5分钟
  2233. pincode = 949468 //util1.randomPrime6()
  2234. pincodeIndex = 22 //Math.floor(Math.random() * 100)
  2235. var bytes = plugin.addPincode(lockDevice.name, basecode, pincode, pincodeIndex, startTime, endTime)
  2236. console.debug('bytes', bytes)
  2237. that.sendBytes(bytes)
  2238. },
  2239. sendBytes(bytes) {
  2240. console.log(lockDevice, config, bytes, 'sendBytes---')
  2241. setTimeout(function () {
  2242. wx.writeBLECharacteristicValue({
  2243. deviceId: lockDevice.deviceId,
  2244. serviceId: config.uuid.serviceUuid.toUpperCase(),
  2245. characteristicId: config.uuid.writeUuid.toUpperCase(),
  2246. value: bytes,
  2247. success: function (res) {
  2248. },
  2249. })
  2250. }, 50)
  2251. },
  2252. goBlue() {
  2253. var that = this
  2254. wx.showLoading({
  2255. title: '搜索设备中',
  2256. mask: true
  2257. })
  2258. // wx.removeStorageSync("connectedDeviceId")
  2259. ICINLocker.scanDevices(this.data.deviceinfo.deviceNum)
  2260. .then((res) => {
  2261. if (res.status === 0) {
  2262. var deviceId = res.deviceId
  2263. //成功找到蓝牙情况下进行锁连接
  2264. app.globalData.blueDeviceId = res.deviceId
  2265. ICINLocker.connect(res.deviceId, false) // 此处 deviceId 存起来,当断开连接时使用
  2266. .then((res) => {
  2267. if (res.status === 0) {
  2268. clearInterval(that.data.timer)
  2269. this.setData({
  2270. bleStatus: '蓝牙已连接',
  2271. deviceId: deviceId
  2272. })
  2273. app.globalData.zgBlueStatus = true
  2274. wx.hideLoading()
  2275. wx.showToast({
  2276. title: '连接成功',
  2277. icon: "none",
  2278. duration: 2000
  2279. })
  2280. setTimeout(() => {
  2281. if (this.data.event === 0) {
  2282. this.openTheDoor()
  2283. } else if (this.data.event == 3) {
  2284. this.addFingerPrints()
  2285. } else if (this.data.event == 6) {
  2286. this.setData({
  2287. show: true
  2288. })
  2289. } else if (this.data.event == 11) {
  2290. this.synchroPlatformTask()
  2291. }
  2292. }, 500)
  2293. } else {
  2294. wx.hideLoading()
  2295. var msg = ''
  2296. switch (res.errCode) {
  2297. case 10001:
  2298. msg = '调用失败,请打开蓝牙!';
  2299. break;
  2300. }
  2301. wx.showToast({
  2302. title: msg,
  2303. duration: 2000,
  2304. icon: 'none'
  2305. })
  2306. //此处处理返回值不为成功(0)的情况
  2307. }
  2308. }).catch((res) => {
  2309. wx.hideLoading()
  2310. console.log(res, '失败')
  2311. // 此处处理未能连接成功问题
  2312. })
  2313. }
  2314. })
  2315. .catch((res) => {
  2316. //此处处理未能连接到蓝牙的问题
  2317. console.log(res)
  2318. if (res.status == 1) {
  2319. if (res.statusReason.errCode == 10001) {
  2320. wx.hideLoading()
  2321. wx.showToast({
  2322. title: '请检查手机蓝牙和定位功能是否打开?',
  2323. duration: 2000,
  2324. icon: 'none'
  2325. })
  2326. } else {
  2327. if (!app.globalData.zgBlueStatus && that.data.bluestatus) {
  2328. that.goBlue()
  2329. } else {
  2330. wx.showToast({
  2331. title: res.statusReason,
  2332. duration: 2000,
  2333. icon: 'none'
  2334. })
  2335. wx.hideLoading()
  2336. }
  2337. }
  2338. } else {
  2339. wx.hideLoading()
  2340. }
  2341. })
  2342. },
  2343. /**
  2344. * *设置音量
  2345. * @param {门锁ID} _lockId
  2346. * @param {用户ID 最多20字节} _userId
  2347. * @param {r 声音选项 00: 静音 01: 低音 02高音} _action
  2348. * @param _commonKey
  2349. * @param {回调方法} callback
  2350. **/
  2351. // 设置音量
  2352. setVolume1(volume) {
  2353. wx.showLoading({
  2354. title: "正在发送...",
  2355. mask: true
  2356. });
  2357. setTimeout(() => {
  2358. wx.hideLoading()
  2359. }, 1000);
  2360. let cmd = 0xF2
  2361. // let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  2362. let length = 2
  2363. let b = new Uint8Array(length)
  2364. b[0] = cmd
  2365. b[1] = volume;
  2366. app.globalData.ble.send(cmd, b, function (res) {
  2367. })
  2368. var dataOpenReport = {
  2369. code: "ble/volumeReport",
  2370. data: {
  2371. deviceNum: this.data.deviceinfo.deviceNum,
  2372. operate: parseInt(volume),
  2373. order: 61001
  2374. }
  2375. }
  2376. WXAPI.sendCommand(dataOpenReport).then(res => {
  2377. })
  2378. },
  2379. setVolume(volume) {
  2380. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  2381. (callback) => {
  2382. console.log(callback, '-----')
  2383. if (callback.status == '00') {
  2384. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, callback.signKey, (callback1) => {
  2385. console.log(callback1, '2222222')
  2386. if (callback1.status == '00') {
  2387. ICINLocker.setVolume(this.data.cgInfo.lockerId, this.data.cgInfo.superId, volume, callback1.commonKey, (callback2) => {
  2388. console.log(callback2, '333333333')
  2389. if (callback2.status == '00') {
  2390. var dataOpenReport = {
  2391. code: "ble/volumeReport",
  2392. data: {
  2393. deviceNum: this.data.deviceinfo.deviceNum,
  2394. operate: parseInt(volume),
  2395. order: 61001
  2396. }
  2397. }
  2398. WXAPI.sendCommand(dataOpenReport).then(res => {
  2399. })
  2400. wx.hideLoading()
  2401. wx.showToast({
  2402. title: '设置成功',
  2403. duration: 2000,
  2404. icon: 'none'
  2405. })
  2406. } else {
  2407. wx.hideLoading()
  2408. wx.showToast({
  2409. title: '设置失败',
  2410. duration: 2000,
  2411. icon: 'none'
  2412. })
  2413. }
  2414. })
  2415. } else {
  2416. wx.hideLoading()
  2417. wx.showToast({
  2418. title: '设置失败',
  2419. duration: 2000,
  2420. icon: 'none'
  2421. })
  2422. }
  2423. })
  2424. } else {
  2425. wx.hideLoading()
  2426. wx.showToast({
  2427. title: '设置失败',
  2428. duration: 2000,
  2429. icon: 'none'
  2430. })
  2431. }
  2432. });
  2433. },
  2434. //设置常开
  2435. setOpen() {
  2436. wx.showLoading({
  2437. title: "正在开启...",
  2438. mask: true
  2439. });
  2440. setTimeout(() => {
  2441. wx.hideLoading()
  2442. }, 1000);
  2443. let cmd = 0xF3
  2444. // let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  2445. let length = 2
  2446. let b = new Uint8Array(length)
  2447. b[0] = cmd
  2448. b[1] = 1;
  2449. app.globalData.ble.send(cmd, b, function (res) {})
  2450. var dataOpenReport = {
  2451. code: "ble/alwaysOpenReport",
  2452. data: {
  2453. deviceNum: this.data.deviceinfo.deviceNum,
  2454. roomName: this.data.deviceinfo.roomName,
  2455. operate: 1,
  2456. order: 61101
  2457. }
  2458. }
  2459. WXAPI.sendCommand(dataOpenReport).then(res => {
  2460. })
  2461. },
  2462. setOpen1() {
  2463. wx.showLoading({
  2464. title: "正在关闭...",
  2465. mask: true
  2466. });
  2467. setTimeout(() => {
  2468. wx.hideLoading()
  2469. }, 1000);
  2470. let cmd = 0xF3
  2471. // let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  2472. let length = 2
  2473. let b = new Uint8Array(length)
  2474. b[0] = cmd
  2475. b[1] = 0;
  2476. app.globalData.ble.send(cmd, b, function (res) {})
  2477. var dataOpenReport = {
  2478. code: "ble/alwaysOpenReport",
  2479. data: {
  2480. deviceNum: this.data.deviceinfo.deviceNum,
  2481. roomName: this.data.deviceinfo.roomName,
  2482. operate: 0,
  2483. order: 61101
  2484. }
  2485. }
  2486. WXAPI.sendCommand(dataOpenReport).then(res => {
  2487. })
  2488. },
  2489. //设置音量
  2490. setVoice() {
  2491. },
  2492. startconnect() {
  2493. //if(checkWechatVersion())
  2494. // {
  2495. wx.showLoading({
  2496. title: "连接蓝牙中",
  2497. mask: true
  2498. })
  2499. var deviceinfo = this.data.deviceinfo
  2500. const ble = new BLE(this.data.deviceinfo.deviceNum, emitter)
  2501. app.globalData.ble = ble
  2502. this.watchBLE()
  2503. app.globalData.ble.init()
  2504. // }
  2505. },
  2506. watchBLE() {
  2507. var that = this
  2508. var deviceinfo = this.data.deviceinfo
  2509. if (app.globalData.ble) {
  2510. app.globalData.ble.listen(res => {
  2511. if (res.type == 'connect') {
  2512. if (res.data == "未打开适配器") {
  2513. wx.hideLoading()
  2514. wx.showToast({
  2515. title: '请检查手机蓝牙和定位功能是否打开?',
  2516. duration: 2000,
  2517. icon: 'none'
  2518. })
  2519. } else {
  2520. if (res.data == '蓝牙已连接') {
  2521. this.data.info = res.data
  2522. app.globalData.bleStatus = res.data
  2523. console.log(res.data, 'pppp')
  2524. if (this.data.event == 0) {
  2525. this.btntest2()
  2526. } else if (this.data.event == 3) {
  2527. this.btntest3()
  2528. } else if (this.data.event == 6) {
  2529. // this.setVoice()
  2530. this.setData({
  2531. show: true
  2532. })
  2533. } else if (this.data.event == 7) {
  2534. wx.showModal({
  2535. title: "常开设置",
  2536. cancelText: '关闭',
  2537. confirmText: '开启',
  2538. success: (res) => {
  2539. if (res.confirm) {
  2540. that.setOpen()
  2541. } else if (res.cancel) {
  2542. that.setOpen1()
  2543. }
  2544. }
  2545. })
  2546. } else {
  2547. wx.hideLoading()
  2548. }
  2549. }
  2550. }
  2551. }
  2552. })
  2553. }
  2554. },
  2555. closeblue() {
  2556. wx.showLoading({
  2557. title: "正在停止...",
  2558. mask: true
  2559. });
  2560. setTimeout(() => {
  2561. wx.hideLoading()
  2562. }, 1000);
  2563. app.globalData.ble.close()
  2564. this.data.info = ''
  2565. app.globalData.bleStatus = false
  2566. this.data.bleStatus = false,
  2567. this.data.respond = []
  2568. },
  2569. closeblue1() {
  2570. // wx.showLoading({
  2571. // title: "正在停止...",
  2572. // });
  2573. app.globalData.ble.close()
  2574. // setTimeout(() => {
  2575. // wx.hideLoading()
  2576. // }, 1000);
  2577. this.data.info = ''
  2578. app.globalData.bleStatus = false
  2579. this.data.bleStatus = false,
  2580. this.data.respond = []
  2581. },
  2582. btntest3(event) {
  2583. var that = this
  2584. let deviceNum = that.data.deviceinfo.deviceNum
  2585. this.data.backstatus = true
  2586. that.startFp_29(deviceNum, 0x03)
  2587. // setTimeout(() => {
  2588. // that.getcartcount()
  2589. // }, 300)
  2590. },
  2591. btntest2(event) {
  2592. var that = this
  2593. let userTelephone = "18270949468"
  2594. let userPassword = "202108"
  2595. let pwd = "2021110309"
  2596. let openLockType = 2
  2597. var userInfo = wx.getStorageSync('userInfo')
  2598. var timestamp = moment().format("x")
  2599. bleall.openLock(userTelephone, userPassword, pwd, openLockType, timestamp, function (res) {
  2600. if (res.success) {
  2601. var rqTime = moment().format("X")
  2602. var username = wx.getStorageSync('username'),
  2603. password = wx.getStorageSync('password')
  2604. var str = `${username}+${password}+${rqTime}`
  2605. var signature = md5(str)
  2606. wx.hideLoading()
  2607. var data = {
  2608. code: "ld/bleUnlockRecord",
  2609. data: {
  2610. deviceNum: that.data.deviceNum,
  2611. userTelephone: userTelephone,
  2612. password: userPassword,
  2613. roomId: that.data.deviceinfo.roomId,
  2614. roomName: that.data.deviceinfo.roomName,
  2615. cardName: userInfo.username,
  2616. signature: signature
  2617. }
  2618. }
  2619. WXAPI.sendCommand(data).then(res => {
  2620. })
  2621. }
  2622. console.log(res.data)
  2623. if (res.data == "蓝牙功能暂不支持") {
  2624. wx.showToast({
  2625. title: '重新连接蓝牙中',
  2626. duration: 2000,
  2627. icon: "none"
  2628. })
  2629. that.startconnect()
  2630. }
  2631. })
  2632. },
  2633. openLock(userTelephone, userPassword, pwd, openLockType) {
  2634. wx.showLoading({
  2635. title: "正在发送...",
  2636. mask: true
  2637. });
  2638. setTimeout(() => {
  2639. wx.hideLoading()
  2640. }, 1000);
  2641. let cmd = 0x41
  2642. console.log(util, userTelephone)
  2643. let ut = util.stringToUint8Array(userTelephone)
  2644. let up = util.stringToUint8Array(userPassword)
  2645. let p = util.hexStringToBytesWithPadding(pwd, 10, 0xff)
  2646. let length = 1 + 11 + 6 + 10 + 1
  2647. let b = new Uint8Array(length)
  2648. b[0] = cmd
  2649. b.set(ut, 1)
  2650. b.set(up, 12)
  2651. b.set(p, 18)
  2652. b[28] = openLockType
  2653. console.log(b)
  2654. app.globalData.ble.send(cmd, b, length)
  2655. },
  2656. //远程开锁
  2657. remoteUnlocking() {
  2658. if (this.data.info == '蓝牙已连接') {
  2659. this.closeblue1()
  2660. }
  2661. if (this.data.deviceinfo.manufactureId == 101) {
  2662. var str2 = {
  2663. imei: this.data.deviceinfo.imei,
  2664. openLockType: 2,
  2665. is: true,
  2666. roomId: this.data.deviceinfo.roomId,
  2667. roomName: this.data.deviceinfo.roomName,
  2668. cardName: this.data.userInfo.username
  2669. };
  2670. WXAPI.openLock(str2).then(res => {
  2671. if (res.success) {
  2672. wx.showToast({
  2673. title: "已发送远程开门指令",
  2674. icon: "none",
  2675. duration: 2000
  2676. })
  2677. }
  2678. })
  2679. } else if (this.data.deviceinfo.manufactureId == 1201) {
  2680. var str2 = {
  2681. code: 'lwj/openLock',
  2682. data: {
  2683. lockerId: this.data.deviceinfo.deviceNum,
  2684. order: 6301,
  2685. is: true,
  2686. roomId: this.data.deviceinfo.roomId,
  2687. roomName: this.data.deviceinfo.roomName,
  2688. cardName: this.data.userInfo.username
  2689. }
  2690. };
  2691. WXAPI.sendCommand(str2).then(res => {
  2692. if (res.success) {
  2693. wx.showToast({
  2694. title: "已发送远程开门指令",
  2695. icon: "none",
  2696. duration: 2000
  2697. })
  2698. }
  2699. })
  2700. }
  2701. },
  2702. /**
  2703. * 生命周期函数--监听页面初次渲染完成
  2704. */
  2705. onReady: function () {
  2706. app.globalData.zgBlueStatus = false
  2707. },
  2708. AddressPermissions() {
  2709. wx.openBluetoothAdapter({
  2710. success: function (res) {
  2711. console.log('蓝牙已开启!');
  2712. },
  2713. fail: function (e) {
  2714. console.log(e)
  2715. wx.showToast({
  2716. title: '请打开蓝牙!',
  2717. duration: 2000,
  2718. icon: 'none'
  2719. })
  2720. }
  2721. });
  2722. },
  2723. getLocationPermissionMethods() {
  2724. ICINLocker.getLocationPermission().then((res) => {
  2725. if (res.status == 0) {
  2726. } else {
  2727. // 连接出现问题
  2728. }
  2729. }).catch((res) => {
  2730. //处理未能获得地理位置情况
  2731. wx.showToast({
  2732. title: '请打开微信定位功能!',
  2733. duration: 2000,
  2734. icon: 'none'
  2735. })
  2736. })
  2737. },
  2738. /**
  2739. * 生命周期函数--监听页面显示
  2740. */
  2741. onShow: function () {
  2742. var deviceinfo = wx.getStorageSync('deviceinfo')
  2743. var userInfo1 = wx.getStorageSync('userInfo')
  2744. if (deviceinfo.roomId) {
  2745. if (userInfo1.type != 3) {
  2746. var data2 = {
  2747. q: JSON.stringify({
  2748. id: deviceinfo.roomId
  2749. }),
  2750. orderBy: "createTime",
  2751. orderType: 'desc'
  2752. }
  2753. WXAPI.getSiteTenant(data2).then(res1 => {
  2754. if (res1.data.list.length > 0) {
  2755. var array = res1.data.list.reverse()
  2756. wx.setStorageSync('info', array[0])
  2757. deviceinfo.info = array[0].info
  2758. this.setData({
  2759. deviceinfo: deviceinfo
  2760. })
  2761. } else {
  2762. wx.showToast({
  2763. title: "还未下发人员,请先下发人员",
  2764. duration: 2000,
  2765. icon: 'none'
  2766. })
  2767. }
  2768. })
  2769. } else if (userInfo1.type == 3) {
  2770. this.setData({
  2771. deviceinfo: deviceinfo
  2772. })
  2773. }
  2774. } else {
  2775. wx.navigateTo({
  2776. url: "../index/index"
  2777. })
  2778. }
  2779. this.setData({
  2780. bleStatus: app.globalData.bleStatus
  2781. })
  2782. },
  2783. /**
  2784. * 生命周期函数--监听页面隐藏
  2785. */
  2786. /**
  2787. * 生命周期函数--监听页面卸载
  2788. */
  2789. onUnload: function () {
  2790. console.log(isConnected, connectedDeviceId)
  2791. if (isConnected) {
  2792. wx.closeBLEConnection({
  2793. deviceId: connectedDeviceId,
  2794. success: function (res) {
  2795. isConnected = false
  2796. },
  2797. })
  2798. }
  2799. // if (app.globalData.zgBlueStatus) {
  2800. // ICINLocker.disConnect(app.globalData.blueDeviceId);
  2801. // this.onReady()
  2802. // }
  2803. this.setData({
  2804. bluestatus: false,
  2805. toSearch: false
  2806. })
  2807. // wx.removeStorageSync("connectedDeviceId")
  2808. if (app.globalData.bleStatus) {
  2809. this.closeblue()
  2810. }
  2811. wx.hideLoading()
  2812. },
  2813. onHide() {
  2814. // wx.removeStorageSync("connectedDeviceId")
  2815. this.setData({
  2816. toSearch: false
  2817. })
  2818. wx.hideLoading()
  2819. if (app.globalData.bleStatus) {
  2820. this.closeblue()
  2821. }
  2822. },
  2823. /**
  2824. * 页面相关事件处理函数--监听用户下拉动作
  2825. */
  2826. onPullDownRefresh: function () {
  2827. // this.AddressPermissions()
  2828. var deviceinfo = wx.getStorageSync('deviceinfo')
  2829. app.globalData.deviceNum = deviceinfo.deviceNum
  2830. var userInfo1 = wx.getStorageSync('userInfo')
  2831. if (deviceinfo.manufactureId == 201 || deviceinfo.manufactureId == 221) {
  2832. var data3 = {
  2833. code: "zg/bleRegisterInfo",
  2834. data: {
  2835. lockerId: deviceinfo.deviceNum
  2836. }
  2837. }
  2838. WXAPI.sendCommand(data3).then(res1 => {
  2839. if (res1.success) {
  2840. wx.setStorageSync('cgInfo', res1.data)
  2841. this.setData({
  2842. cgInfo: res1.data
  2843. })
  2844. } else {
  2845. }
  2846. })
  2847. }
  2848. if (deviceinfo.roomId) {
  2849. if (userInfo1.type != 3) {
  2850. var data2 = {
  2851. q: JSON.stringify({
  2852. id: deviceinfo.roomId
  2853. }),
  2854. orderBy: "createTime",
  2855. orderType: 'desc'
  2856. }
  2857. WXAPI.getSiteTenant(data2).then(res1 => {
  2858. if (res1.data.list.length > 0) {
  2859. var array = res1.data.list.reverse()
  2860. wx.setStorageSync('info', array[0])
  2861. deviceinfo.info = array[0].info
  2862. this.setData({
  2863. deviceinfo: deviceinfo
  2864. })
  2865. } else {
  2866. wx.showToast({
  2867. title: "还未下发人员,请先下发人员",
  2868. duration: 2000,
  2869. icon: 'none'
  2870. })
  2871. }
  2872. })
  2873. } else if (userInfo1.type == 3) {
  2874. this.setData({
  2875. deviceinfo: deviceinfo
  2876. })
  2877. }
  2878. } else {
  2879. wx.navigateTo({
  2880. url: "../index/index"
  2881. })
  2882. }
  2883. this.setData({
  2884. info: app.globalData.bleStatus,
  2885. deviceinfo: deviceinfo
  2886. })
  2887. wx.stopPullDownRefresh()
  2888. },
  2889. /**
  2890. * 页面上拉触底事件的处理函数
  2891. */
  2892. onReachBottom: function () {
  2893. },
  2894. /**
  2895. * 用户点击右上角分享
  2896. */
  2897. onShareAppMessage: function () {
  2898. }
  2899. })