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.

3021 lines
87 KiB

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