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.

3007 lines
86 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. // 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. wx.getBluetoothDevices({
  1245. success: function (res) {
  1246. console.log(res)
  1247. res.devices.map(it => {
  1248. var status = it.name.indexOf('WSL')
  1249. if (status != -1) {
  1250. if (it.RSSI != 127) {
  1251. if (it.advertisData != null) {
  1252. it.adData = util1.ab2hex(it.advertisData)
  1253. if (it.adData.length > 10) {
  1254. var macStr = it.adData.substring(4, 16).toUpperCase()
  1255. //console.log('macStr', macStr)
  1256. 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)
  1257. if (it.adData.substring(1, 2) == '1') {
  1258. it.isLightOn = true
  1259. it.textColor = 'green'
  1260. } else {
  1261. it.isLightOn = false
  1262. it.textColor = 'black'
  1263. }
  1264. if (it.adData.substring(3, 4) == '1') {
  1265. it.textColor = 'pink'
  1266. it.isBind = true
  1267. } else {
  1268. it.isBind = false
  1269. }
  1270. }
  1271. } else {
  1272. it.textColor = 'black'
  1273. }
  1274. lockModel = util1.getLockModel(it.name)
  1275. it.lockType = util1.getLockType(lockModel)
  1276. if (it.name == that.data.deviceinfo.deviceNum) {
  1277. app.addDeviceWithDevName(it.name, it)
  1278. connectedDeviceId = it.deviceId
  1279. lockDevice = it
  1280. console.log(lockDevice, it, 'lockDevice,it')
  1281. app.globalData.isSearch = true
  1282. that.setData({
  1283. isSearch: true,
  1284. // lockDevice:it
  1285. })
  1286. // let iotLwj = new LwJ(it,isConnected,connectedDeviceId,isInitReady,it.lockModel)
  1287. // iotLwj.connectTo()
  1288. if (that.data.event == '0') {
  1289. // iotLwj.openLock(41)
  1290. that.LwjopenLock()
  1291. } else if (that.data.event == 6) {
  1292. that.setData({
  1293. show: true
  1294. })
  1295. } else if (that.data.event == '3') {
  1296. console.log("1298wifi");
  1297. that.configurewifj()
  1298. }else if(that.data.event == '8') {
  1299. console.log("1301person");
  1300. that.personnelmanagement()
  1301. }
  1302. wx.hideLoading({
  1303. success: (res) => {},
  1304. })
  1305. }
  1306. }
  1307. }
  1308. })
  1309. if (!that.data.isSearch && that.data.toSearch) {
  1310. that.searchDevicesMethods()
  1311. }
  1312. }
  1313. })
  1314. },
  1315. fail: function (res) {
  1316. wx.hideLoading({
  1317. success: (res) => {
  1318. wx.showToast({
  1319. title: res.errMsg,
  1320. duration: 2000,
  1321. icon: 'none'
  1322. })
  1323. },
  1324. })
  1325. }
  1326. })
  1327. },
  1328. fail: function (res) {
  1329. console.log('请打开蓝牙和定位功能')
  1330. wx.hideLoading({
  1331. success: (res) => {
  1332. wx.showToast({
  1333. title: '请打开蓝牙和定位功能',
  1334. duration: 2000,
  1335. icon: 'none'
  1336. })
  1337. },
  1338. })
  1339. }
  1340. })
  1341. },
  1342. LwjopenLock: function () {
  1343. var that = this
  1344. taskId = 41
  1345. that.initBluetooth()
  1346. },
  1347. configurewifj() {
  1348. var that = this
  1349. taskId = 121
  1350. that.initBluetooth()
  1351. },
  1352. // 人员管理
  1353. personnelmanagement() {
  1354. var that = this
  1355. taskId = 9010
  1356. that.initBluetooth()
  1357. },
  1358. LwjonOpenLock: function () {
  1359. var that = this
  1360. wx.showLoading({
  1361. title: that.data.isJack ? '上电中' : '解锁中',
  1362. })
  1363. console.log(lockDevice.name, 'lockDevice.name0开锁中')
  1364. var bytes = plugin.sendOpenLockP1(lockDevice.name, basecode)
  1365. console.debug('bytes', bytes)
  1366. that.sendBytes(bytes)
  1367. },
  1368. initBluetooth: function () {
  1369. var that = this
  1370. wx.getConnectedBluetoothDevices({
  1371. services: [config.uuid.serviceUuid],
  1372. success: function (res) {
  1373. res.devices.map(function (it) {
  1374. if (it.deviceId == connectedDeviceId || it.name == lockDevice.name) {
  1375. isConnected = true
  1376. }
  1377. })
  1378. that.setData({
  1379. isConnected: isConnected
  1380. })
  1381. console.log('isConnected', isConnected)
  1382. if (isConnected) {
  1383. if (isInitReady) {
  1384. console.log(isInitReady, 'isInitReady', taskId)
  1385. setTimeout(() => {
  1386. that.doWork()
  1387. }, 500)
  1388. } else {
  1389. that.setupConnection()
  1390. }
  1391. } else {
  1392. that.connectTo()
  1393. }
  1394. },
  1395. })
  1396. },
  1397. doWork: function () {
  1398. console.log(taskId);
  1399. var that = this
  1400. switch (taskId) {
  1401. case 11: {
  1402. that.onBindLock()
  1403. break
  1404. }
  1405. case 12: {
  1406. that.onUnbindLock()
  1407. break
  1408. }
  1409. case 21: {
  1410. that.onQueryBindState()
  1411. break
  1412. }
  1413. case 22: {
  1414. that.onQueryBattery()
  1415. break
  1416. }
  1417. case 31: {
  1418. that.onQueryNbImei()
  1419. break
  1420. }
  1421. case 32: {
  1422. that.onLogin()
  1423. break
  1424. }
  1425. case 41: {
  1426. that.LwjonOpenLock()
  1427. break
  1428. }
  1429. case 42: {
  1430. that.onSyncClock()
  1431. break
  1432. }
  1433. case 51: {
  1434. that.onAddPincode()
  1435. break
  1436. }
  1437. case 52: {
  1438. that.onDelPincode()
  1439. break
  1440. }
  1441. case 61: {
  1442. if (lockModel > 70) {
  1443. that.onAddRfCard()
  1444. } else {
  1445. wx.showModal({
  1446. title: '提示',
  1447. content: '请刷卡!',
  1448. showCancel: false
  1449. })
  1450. }
  1451. break
  1452. }
  1453. case 62: {
  1454. that.onDelRfCard()
  1455. break
  1456. }
  1457. case 71: {
  1458. that.onAddFingerprint()
  1459. break
  1460. }
  1461. case 72: {
  1462. that.onDelFingerprint()
  1463. break
  1464. }
  1465. case 81: {
  1466. that.onChangeAdminPincode()
  1467. break
  1468. }
  1469. case 91: {
  1470. that.onQueryLockSlotState()
  1471. break
  1472. }
  1473. case 92: {
  1474. that.onQueryLockUnlockState()
  1475. break
  1476. }
  1477. case 101: {
  1478. that.onChangeLockUnlockState()
  1479. break
  1480. }
  1481. case 102: {
  1482. that.onChangeLockMutedState()
  1483. break
  1484. }
  1485. case 111: {
  1486. this.onChangeLockNbState()
  1487. }
  1488. case 121: {
  1489. this.onConfigurewifi()
  1490. break
  1491. }
  1492. case 9010: {
  1493. this.gotoperson()
  1494. break
  1495. }
  1496. default: {
  1497. }
  1498. }
  1499. },
  1500. connectTo: function () {
  1501. var that = this
  1502. wx.showLoading({
  1503. title: '连接中',
  1504. })
  1505. wx.createBLEConnection({
  1506. deviceId: lockDevice.deviceId,
  1507. timeout: config.ble.connectTimeOut,
  1508. success: function (res) {
  1509. console.debug('connectTo', res)
  1510. isConnected = true
  1511. wx.hideLoading()
  1512. setTimeout(function () {
  1513. that.setupConnection()
  1514. }, 500)
  1515. },
  1516. fail: function (e) {
  1517. console.debug('connectTo', e)
  1518. wx.hideLoading()
  1519. switch (e.errCode) {
  1520. case 10003: {
  1521. wx.showModal({
  1522. title: '连接失败',
  1523. content: '是否重新连接?',
  1524. success: function (res) {
  1525. if (res.confirm) {
  1526. that.connectTo()
  1527. }
  1528. }
  1529. })
  1530. break
  1531. }
  1532. case 10012: {
  1533. wx.showModal({
  1534. title: '连接失败',
  1535. content: '蓝牙连接超时',
  1536. showCancel: false
  1537. })
  1538. break
  1539. }
  1540. case 10002: {
  1541. wx.showModal({
  1542. title: '连接失败',
  1543. content: '没有找到指定设备',
  1544. showCancel: false
  1545. })
  1546. break
  1547. }
  1548. }
  1549. }
  1550. })
  1551. },
  1552. setupConnection: function () {
  1553. var that = this
  1554. wx.showLoading({
  1555. title: '初始化连接中',
  1556. })
  1557. wx.getBLEDeviceServices({
  1558. deviceId: lockDevice.deviceId,
  1559. success: function (res) {
  1560. console.log('Services', res)
  1561. wx.getBLEDeviceCharacteristics({
  1562. deviceId: lockDevice.deviceId,
  1563. serviceId: config.uuid.serviceUuid.toUpperCase(),
  1564. success: function (res) {
  1565. console.log('Characteristics', res)
  1566. wx.showLoading({
  1567. title: '连接成功',
  1568. })
  1569. wx.onBLECharacteristicValueChange(function (res) {
  1570. var bytes = new Uint8Array(res.value)
  1571. console.log('bytes', bytes)
  1572. console.log(lockDevice.name, 'lockDevice.name1')
  1573. var data = plugin.parseBytes(lockDevice.name, basecode, bytes)
  1574. console.log('data', data)
  1575. switch (data.cmd) {
  1576. case 'reportLockBattery': {
  1577. if (data.data.battery < 10) {
  1578. wx.showModal({
  1579. title: '电量报警',
  1580. content: `门锁当前电量${data.data.battery}%!\n电量严重不足,请立即更换电池!`,
  1581. showCancel: false
  1582. })
  1583. } else if (data.data.battery < 30) {
  1584. wx.showModal({
  1585. title: '电量预警',
  1586. content: `门锁当前电量${data.data.battery}%!\n请及时更换电池!`,
  1587. showCancel: false
  1588. })
  1589. }
  1590. break
  1591. }
  1592. case 'reportRfCardResult': {
  1593. if (taskId == 61) {
  1594. wx.showModal({
  1595. title: '检测到新卡',
  1596. content: `是否添加此房卡,卡号:${data.data.cardId}`,
  1597. success: function (res) {
  1598. if (res.confirm) {
  1599. rfCardId = data.data.cardId
  1600. that.onAddRfCard()
  1601. }
  1602. }
  1603. })
  1604. } else {
  1605. if (lockModel > 70) {
  1606. if (data.data.isValid) {
  1607. wx.showModal({
  1608. title: '提示',
  1609. content: `房卡开锁成功,序号:${data.data.index}`,
  1610. showCancel: false
  1611. })
  1612. } else {
  1613. wx.showModal({
  1614. title: '提示',
  1615. content: `多次刷房卡开锁失败!`,
  1616. showCancel: false
  1617. })
  1618. }
  1619. } else {
  1620. if (data.data.isValid) {
  1621. wx.showModal({
  1622. title: '提示',
  1623. content: `房卡开锁成功,卡号:${data.data.cardId}`,
  1624. showCancel: false
  1625. })
  1626. } else {
  1627. wx.showModal({
  1628. title: '提示',
  1629. content: `房卡未授权,卡号:${data.data.cardId}`,
  1630. showCancel: false
  1631. })
  1632. }
  1633. }
  1634. }
  1635. break
  1636. }
  1637. case 'reportPincodeResult': {
  1638. if (lockModel > 70) {
  1639. if (data.data.isValid) {
  1640. wx.showModal({
  1641. title: '提示',
  1642. content: `密码开锁成功,序号:${data.data.index}`,
  1643. showCancel: false
  1644. })
  1645. } else {
  1646. wx.showModal({
  1647. title: '提示',
  1648. content: `多次密码开锁失败!`,
  1649. showCancel: false
  1650. })
  1651. }
  1652. } else {
  1653. if (data.data.isValid) {
  1654. wx.showModal({
  1655. title: '提示',
  1656. content: `密码:${data.data.pincode}开锁成功!`,
  1657. showCancel: false
  1658. })
  1659. } else {
  1660. wx.showModal({
  1661. title: '提示',
  1662. content: `密码:${data.data.pincode}未授权!`,
  1663. showCancel: false
  1664. })
  1665. }
  1666. }
  1667. break
  1668. }
  1669. case 'reportFingerprintResult': {
  1670. if (data.data.isValid) {
  1671. wx.showModal({
  1672. title: '提示',
  1673. content: `指纹开锁成功,序号:${data.data.index}`,
  1674. showCancel: false
  1675. })
  1676. } else {
  1677. wx.showModal({
  1678. title: '提示',
  1679. content: `多次指纹开锁失败!`,
  1680. showCancel: false
  1681. })
  1682. }
  1683. break
  1684. }
  1685. case 'queryLockState': {
  1686. wx.hideLoading()
  1687. if (data.code != 200) {
  1688. wx.showModal({
  1689. title: '提示',
  1690. content: '查询失败!',
  1691. showCancel: false,
  1692. success: function (res) {}
  1693. })
  1694. break
  1695. }
  1696. that.setData({
  1697. lock: {
  1698. mac: data.data.mac,
  1699. lockType: util1.getLockType(lockModel),
  1700. },
  1701. isBindLock: data.data.isBind
  1702. })
  1703. lockMac = data.data.mac
  1704. if (taskId > 0) {
  1705. if (data.data.isBind) {
  1706. wx.showModal({
  1707. title: data.data.mac,
  1708. content: '此设备已经硬件绑定!',
  1709. showCancel: false,
  1710. success: function (res) {}
  1711. })
  1712. } else {
  1713. wx.showModal({
  1714. title: data.data.mac,
  1715. content: '此设备硬件未绑定!',
  1716. showCancel: false,
  1717. success: function (res) {}
  1718. })
  1719. }
  1720. }
  1721. taskId = 0
  1722. break
  1723. }
  1724. case 'queryLockBattery': {
  1725. wx.hideLoading()
  1726. if (data.code != 200) {
  1727. wx.showModal({
  1728. title: '提示',
  1729. content: '查询失败!',
  1730. showCancel: false,
  1731. success: function (res) {}
  1732. })
  1733. break
  1734. }
  1735. taskId = 0
  1736. wx.showModal({
  1737. title: '提示',
  1738. content: `此门锁电量为${data.data.battery}%`,
  1739. showCancel: false,
  1740. success: function (res) {}
  1741. })
  1742. break
  1743. }
  1744. case 'queryNbImei': {
  1745. wx.hideLoading()
  1746. if (data.code != 200) {
  1747. wx.showModal({
  1748. title: '提示',
  1749. content: '查询失败!',
  1750. showCancel: false,
  1751. success: function (res) {}
  1752. })
  1753. break
  1754. }
  1755. taskId = 0
  1756. wx.showModal({
  1757. title: '提示',
  1758. content: `此NB设备IMEI为${data.data.imei}`,
  1759. showCancel: false,
  1760. success: function (res) {}
  1761. })
  1762. break
  1763. }
  1764. case 'setNbFun': {
  1765. wx.hideLoading()
  1766. if (data.code != 200) {
  1767. wx.showModal({
  1768. title: '提示',
  1769. content: '设置Nb功能失败!',
  1770. showCancel: false,
  1771. success: function (res) {}
  1772. })
  1773. break
  1774. }
  1775. taskId = 0
  1776. wx.showModal({
  1777. title: '提示',
  1778. content: that.data.isNbEnable ? 'NB功能已禁用' : 'NB功能已打开',
  1779. showCancel: false,
  1780. })
  1781. that.setData({
  1782. isNbEnable: !that.data.isNbEnable
  1783. })
  1784. break
  1785. }
  1786. case 'sendBindLock': {
  1787. wx.hideLoading()
  1788. if (data.code != 200) {
  1789. wx.showModal({
  1790. title: '提示',
  1791. content: '绑定失败!',
  1792. showCancel: false,
  1793. success: function (res) {}
  1794. })
  1795. break
  1796. }
  1797. taskId = 0
  1798. that.setData({
  1799. isBindLock: data.data.isBind
  1800. })
  1801. if (data.data.isBind) {
  1802. wx.showToast({
  1803. title: '绑定成功!',
  1804. })
  1805. } else {
  1806. wx.showToast({
  1807. title: '绑定失败!',
  1808. })
  1809. }
  1810. break
  1811. }
  1812. case 'sendUnbindLock': {
  1813. wx.hideLoading()
  1814. if (data.code != 200) {
  1815. wx.showModal({
  1816. title: '提示',
  1817. content: '解绑失败!',
  1818. showCancel: false,
  1819. success: function (res) {}
  1820. })
  1821. break
  1822. }
  1823. taskId = 0
  1824. that.setData({
  1825. isBindLock: data.data.isBind
  1826. })
  1827. if (data.data.isBind) {
  1828. wx.showToast({
  1829. title: '解绑失败!',
  1830. })
  1831. } else {
  1832. wx.showToast({
  1833. title: '解绑成功!',
  1834. })
  1835. }
  1836. break
  1837. }
  1838. case 'login1':
  1839. case 'sendOpenLockP1': {
  1840. if (data.code != 200) {
  1841. wx.hideLoading()
  1842. if (taskId == 41) {
  1843. wx.showModal({
  1844. title: '提示',
  1845. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  1846. showCancel: false,
  1847. success: function (res) {}
  1848. })
  1849. } else if (taskId == 32) {
  1850. wx.showModal({
  1851. title: '提示',
  1852. content: '登录失败!',
  1853. showCancel: false,
  1854. success: function (res) {}
  1855. })
  1856. }
  1857. break
  1858. }
  1859. if (taskId == 41) {
  1860. console.log(lockDevice.name, 'lockDevice.name2')
  1861. var bytes = plugin.sendOpenLockP2(lockDevice.name, basecode, data.data.randomN)
  1862. console.debug('bytes', bytes)
  1863. that.sendBytes(bytes)
  1864. } else if (taskId == 32) {
  1865. console.log(lockDevice.name, 'lockDevice.name3')
  1866. var bytes = plugin.login2(lockDevice.name, basecode, data.data.randomN)
  1867. console.debug('bytes', bytes)
  1868. that.sendBytes(bytes)
  1869. }
  1870. break;
  1871. }
  1872. case 'login':
  1873. case 'sendOpenLockP2': {
  1874. wx.hideLoading()
  1875. if (data.code != 200) {
  1876. if (taskId == 41) {
  1877. wx.showModal({
  1878. title: '提示',
  1879. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  1880. showCancel: false,
  1881. success: function (res) {}
  1882. })
  1883. } else if (taskId == 32) {
  1884. wx.showModal({
  1885. title: '提示',
  1886. content: '登录失败!',
  1887. showCancel: false,
  1888. success: function (res) {}
  1889. })
  1890. }
  1891. break
  1892. }
  1893. isLockLogin = true
  1894. if (taskId == 41) {
  1895. var data = {
  1896. code: "ble/bleUnlockRecord",
  1897. data: {
  1898. deviceNum: that.data.deviceinfo.deviceNum,
  1899. roomId: that.data.deviceinfo.roomId,
  1900. roomName: that.data.deviceinfo.roomName,
  1901. cardName: that.data.userInfo.username,
  1902. productId: that.data.deviceinfo.manufactureId,
  1903. userId: '29283991'
  1904. }
  1905. }
  1906. WXAPI.sendCommand(data).then(res => {
  1907. console.log(res)
  1908. })
  1909. wx.showToast({
  1910. title: that.data.isJack ? '上电成功!' : '解锁成功!',
  1911. })
  1912. } else if (taskId == 32) {
  1913. wx.showToast({
  1914. title: '登录成功!',
  1915. })
  1916. }
  1917. taskId = 0
  1918. break;
  1919. }
  1920. case 'syncClock': {
  1921. wx.hideLoading()
  1922. if (data.code != 200) {
  1923. wx.showModal({
  1924. title: '提示',
  1925. content: '同步时间失败!' + data.data.msg,
  1926. showCancel: false,
  1927. success: function (res) {}
  1928. })
  1929. break
  1930. }
  1931. taskId = 0
  1932. wx.showModal({
  1933. title: '提示',
  1934. content: '时间更新成功!',
  1935. showCancel: false
  1936. })
  1937. break;
  1938. }
  1939. case 'addPincode': {
  1940. wx.hideLoading()
  1941. if (data.code != 200) {
  1942. wx.showModal({
  1943. title: '提示',
  1944. content: '添加密码失败!' + data.data.msg,
  1945. showCancel: false,
  1946. success: function (res) {}
  1947. })
  1948. break
  1949. }
  1950. taskId = 0
  1951. that.setData({
  1952. isPincodeAdd: true
  1953. })
  1954. wx.showModal({
  1955. title: '提示',
  1956. content: `添加密码${pincode}成功!`,
  1957. showCancel: false
  1958. })
  1959. break
  1960. }
  1961. case 'delPincode': {
  1962. wx.hideLoading()
  1963. if (data.code != 200) {
  1964. wx.showModal({
  1965. title: '提示',
  1966. content: '删除密码失败!',
  1967. showCancel: false,
  1968. success: function (res) {}
  1969. })
  1970. break
  1971. }
  1972. taskId = 0
  1973. wx.showModal({
  1974. title: '提示',
  1975. content: `删除密码${pincode}成功!`,
  1976. showCancel: false,
  1977. })
  1978. that.setData({
  1979. isPincodeAdd: false
  1980. })
  1981. pincode = -1
  1982. pincodeIndex = -1
  1983. break
  1984. }
  1985. case 'addRfCard': {
  1986. wx.hideLoading()
  1987. if (data.code == 100) {
  1988. wx.showLoading({
  1989. title: data.data.msg,
  1990. })
  1991. break
  1992. } else if (data.code != 200) {
  1993. wx.showModal({
  1994. title: '提示',
  1995. content: '添加房卡失败!' + data.data.msg,
  1996. showCancel: false,
  1997. success: function (res) {}
  1998. })
  1999. break
  2000. }
  2001. taskId = 0
  2002. that.setData({
  2003. isRfCardAdd: true
  2004. })
  2005. if (lockModel > 70) {
  2006. wx.showModal({
  2007. title: '提示',
  2008. content: `添加房卡成功,序号${rfCardIndex}`,
  2009. showCancel: false
  2010. })
  2011. } else {
  2012. wx.showModal({
  2013. title: '提示',
  2014. content: `添加房卡成功,卡号${rfCardId}`,
  2015. showCancel: false
  2016. })
  2017. }
  2018. break
  2019. }
  2020. case 'delRfCard': {
  2021. wx.hideLoading()
  2022. if (data.code != 200) {
  2023. wx.showModal({
  2024. title: '提示',
  2025. content: '删除房卡失败!',
  2026. showCancel: false,
  2027. success: function (res) {}
  2028. })
  2029. break
  2030. }
  2031. taskId = 0
  2032. that.setData({
  2033. isRfCardAdd: false
  2034. })
  2035. if (lockModel > 70) {
  2036. wx.showModal({
  2037. title: '提示',
  2038. content: `删除房卡成功,序号${rfCardIndex}`,
  2039. showCancel: false,
  2040. })
  2041. } else {
  2042. wx.showModal({
  2043. title: '提示',
  2044. content: `删除房卡成功,卡号${rfCardId}`,
  2045. showCancel: false,
  2046. })
  2047. }
  2048. rfCardId = -1
  2049. rfCardIndex = -1
  2050. break
  2051. }
  2052. case 'addFingerprint': {
  2053. wx.hideLoading()
  2054. if (data.code == 100) {
  2055. wx.showLoading({
  2056. title: data.data.msg,
  2057. })
  2058. break
  2059. } else if (data.code != 200) {
  2060. wx.showModal({
  2061. title: '提示',
  2062. content: '添加指纹失败!' + data.data.msg,
  2063. showCancel: false,
  2064. success: function (res) {}
  2065. })
  2066. break
  2067. }
  2068. taskId = 0
  2069. that.setData({
  2070. isFingerprintAdd: true
  2071. })
  2072. wx.showModal({
  2073. title: '提示',
  2074. content: `添加指纹成功,序号${fingerprintIndex}`,
  2075. showCancel: false
  2076. })
  2077. break
  2078. }
  2079. case 'delFingerprint': {
  2080. wx.hideLoading()
  2081. if (data.code != 200) {
  2082. wx.showModal({
  2083. title: '提示',
  2084. content: '删除指纹失败!',
  2085. showCancel: false,
  2086. success: function (res) {}
  2087. })
  2088. break
  2089. }
  2090. taskId = 0
  2091. wx.showModal({
  2092. title: '提示',
  2093. content: `删除指纹成功,序号${fingerprintIndex}`,
  2094. showCancel: false,
  2095. })
  2096. that.setData({
  2097. isFingerprintAdd: false
  2098. })
  2099. fingerprintIndex = -1
  2100. break
  2101. }
  2102. case 'changeAdminPincode': {
  2103. wx.hideLoading()
  2104. if (data.code != 200) {
  2105. wx.showModal({
  2106. title: '提示',
  2107. content: '修改管理密码失败!',
  2108. showCancel: false,
  2109. success: function (res) {}
  2110. })
  2111. break
  2112. }
  2113. taskId = 0
  2114. wx.showToast({
  2115. title: '修改管理密码成功!',
  2116. })
  2117. }
  2118. case 'queryLockSlotState': {
  2119. wx.hideLoading()
  2120. if (data.code != 200) {
  2121. wx.showModal({
  2122. title: '提示',
  2123. content: '查询失败!',
  2124. showCancel: false,
  2125. success: function (res) {}
  2126. })
  2127. break
  2128. }
  2129. taskId = 0
  2130. wx.showModal({
  2131. title: '提示',
  2132. content: data.data.state == 0 ? '此门锁方舌关闭' : '此门锁方舌打开',
  2133. showCancel: false,
  2134. success: function (res) {}
  2135. })
  2136. break
  2137. }
  2138. case 'queryLockUnlockState': {
  2139. wx.hideLoading()
  2140. if (data.code != 200) {
  2141. wx.showModal({
  2142. title: '提示',
  2143. content: '查询失败!',
  2144. showCancel: false,
  2145. success: function (res) {}
  2146. })
  2147. break
  2148. }
  2149. taskId = 0
  2150. wx.showModal({
  2151. title: '提示',
  2152. content: data.data.state == 0 ? '此门锁已关闭' : '此门锁已打开',
  2153. showCancel: false,
  2154. success: function (res) {}
  2155. })
  2156. break
  2157. }
  2158. case 'setLockUnlockState': {
  2159. wx.hideLoading()
  2160. if (data.code != 200) {
  2161. wx.showModal({
  2162. title: '提示',
  2163. content: '设置常开指令失败!',
  2164. showCancel: false,
  2165. success: function (res) {}
  2166. })
  2167. break
  2168. }
  2169. taskId = 0
  2170. wx.showModal({
  2171. title: '提示',
  2172. content: data.data.state == 0 ? '常开模式已退出' : '常开模式已开启',
  2173. showCancel: false,
  2174. })
  2175. that.setData({
  2176. isUnloked: data.data.state == 1
  2177. })
  2178. break
  2179. }
  2180. case 'setLockMuteState': {
  2181. wx.hideLoading()
  2182. if (data.code != 200) {
  2183. wx.showModal({
  2184. title: '提示',
  2185. content: '设置静音指令失败!',
  2186. showCancel: false,
  2187. success: function (res) {}
  2188. })
  2189. break
  2190. }
  2191. taskId = 0
  2192. wx.showModal({
  2193. title: '提示',
  2194. content: data.data.state == 1 ? '静音模式已退出' : '静音模式已开启',
  2195. showCancel: false,
  2196. })
  2197. that.setData({
  2198. isMuted: data.data.state == 0
  2199. })
  2200. break
  2201. }
  2202. }
  2203. })
  2204. wx.notifyBLECharacteristicValueChange({
  2205. deviceId: lockDevice.deviceId,
  2206. serviceId: config.uuid.serviceUuid.toUpperCase(),
  2207. characteristicId: config.uuid.notifyUuid.toUpperCase(),
  2208. state: true,
  2209. success: function (res) {
  2210. console.log('setupNotify', res)
  2211. isInitReady = true
  2212. setTimeout(function () {
  2213. wx.hideLoading()
  2214. // that.onQueryBindState()
  2215. // if (taskId == '41' && that.data.event == '0') {
  2216. // that.doWork()
  2217. // }else if(taskId == '121' && that.data.event == '3') {
  2218. // that.doWork()
  2219. // }else if(taskId == '9010' && that.data.event == '8') {
  2220. // that.doWork()
  2221. // }
  2222. that.doWork()
  2223. }, 500)
  2224. },
  2225. })
  2226. },
  2227. })
  2228. },
  2229. })
  2230. },
  2231. addPincode: function () {
  2232. var that = this
  2233. taskId = 51
  2234. that.initBluetooth()
  2235. },
  2236. onAddPincode: function () {
  2237. var that = this
  2238. wx.showLoading({
  2239. title: '添加密码中',
  2240. })
  2241. var startTime = util1.getLocalTime(8)
  2242. var endTime = new Date(startTime.getTime() + 5 * 60 * 1000) //有效期5分钟
  2243. pincode = 949468 //util1.randomPrime6()
  2244. pincodeIndex = 22 //Math.floor(Math.random() * 100)
  2245. var bytes = plugin.addPincode(lockDevice.name, basecode, pincode, pincodeIndex, startTime, endTime)
  2246. console.debug('bytes', bytes)
  2247. that.sendBytes(bytes)
  2248. },
  2249. sendBytes(bytes) {
  2250. console.log(lockDevice, config, bytes, 'sendBytes---')
  2251. setTimeout(function () {
  2252. wx.writeBLECharacteristicValue({
  2253. deviceId: lockDevice.deviceId,
  2254. serviceId: config.uuid.serviceUuid.toUpperCase(),
  2255. characteristicId: config.uuid.writeUuid.toUpperCase(),
  2256. value: bytes,
  2257. success: function (res) {
  2258. },
  2259. })
  2260. }, 50)
  2261. },
  2262. goBlue() {
  2263. var that = this
  2264. wx.showLoading({
  2265. title: '搜索设备中',
  2266. mask: true
  2267. })
  2268. // wx.removeStorageSync("connectedDeviceId")
  2269. ICINLocker.scanDevices(this.data.deviceinfo.deviceNum)
  2270. .then((res) => {
  2271. if (res.status === 0) {
  2272. var deviceId = res.deviceId
  2273. //成功找到蓝牙情况下进行锁连接
  2274. app.globalData.blueDeviceId = res.deviceId
  2275. ICINLocker.connect(res.deviceId, false) // 此处 deviceId 存起来,当断开连接时使用
  2276. .then((res) => {
  2277. if (res.status === 0) {
  2278. clearInterval(that.data.timer)
  2279. this.setData({
  2280. bleStatus: '蓝牙已连接',
  2281. deviceId: deviceId,
  2282. isSearch: true
  2283. })
  2284. app.globalData.zgBlueStatus = true
  2285. wx.hideLoading()
  2286. wx.showToast({
  2287. title: '连接成功',
  2288. icon: "none",
  2289. duration: 2000
  2290. })
  2291. setTimeout(() => {
  2292. if (this.data.event === 0) {
  2293. this.openTheDoor()
  2294. } else if (this.data.event == 3) {
  2295. this.addFingerPrints()
  2296. } else if (this.data.event == 6) {
  2297. this.setData({
  2298. show: true
  2299. })
  2300. } else if (this.data.event == 11) {
  2301. this.synchroPlatformTask()
  2302. }
  2303. }, 500)
  2304. } else {
  2305. wx.hideLoading()
  2306. var msg = ''
  2307. switch (res.errCode) {
  2308. case 10001:
  2309. msg = '调用失败,请打开蓝牙!';
  2310. break;
  2311. }
  2312. wx.showToast({
  2313. title: msg,
  2314. duration: 2000,
  2315. icon: 'none'
  2316. })
  2317. //此处处理返回值不为成功(0)的情况
  2318. }
  2319. }).catch((res) => {
  2320. wx.hideLoading()
  2321. console.log(res, '失败')
  2322. // 此处处理未能连接成功问题
  2323. })
  2324. }
  2325. })
  2326. .catch((res) => {
  2327. //此处处理未能连接到蓝牙的问题
  2328. console.log(res)
  2329. if (res.status == 1) {
  2330. if (res.statusReason.errCode == 10001) {
  2331. wx.hideLoading()
  2332. wx.showToast({
  2333. title: '请检查手机蓝牙和定位功能是否打开?',
  2334. duration: 2000,
  2335. icon: 'none'
  2336. })
  2337. } else {
  2338. if (!app.globalData.zgBlueStatus && that.data.bluestatus) {
  2339. that.goBlue()
  2340. } else {
  2341. wx.showToast({
  2342. title: res.statusReason,
  2343. duration: 2000,
  2344. icon: 'none'
  2345. })
  2346. wx.hideLoading()
  2347. }
  2348. }
  2349. } else {
  2350. wx.hideLoading()
  2351. }
  2352. })
  2353. },
  2354. /**
  2355. * *设置音量
  2356. * @param {门锁ID} _lockId
  2357. * @param {用户ID 最多20字节} _userId
  2358. * @param {r 声音选项 00: 静音 01: 低音 02高音} _action
  2359. * @param _commonKey
  2360. * @param {回调方法} callback
  2361. **/
  2362. // 设置音量
  2363. setVolume1(volume) {
  2364. wx.showLoading({
  2365. title: "正在发送...",
  2366. mask: true
  2367. });
  2368. setTimeout(() => {
  2369. wx.hideLoading()
  2370. }, 1000);
  2371. let cmd = 0xF2
  2372. // let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  2373. let length = 2
  2374. let b = new Uint8Array(length)
  2375. b[0] = cmd
  2376. b[1] = volume;
  2377. app.globalData.ble.send(cmd, b, function (res) {
  2378. })
  2379. var dataOpenReport = {
  2380. code: "ble/volumeReport",
  2381. data: {
  2382. deviceNum: this.data.deviceinfo.deviceNum,
  2383. operate: parseInt(volume),
  2384. order: 61001
  2385. }
  2386. }
  2387. WXAPI.sendCommand(dataOpenReport).then(res => {
  2388. })
  2389. },
  2390. setVolume(volume) {
  2391. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  2392. (callback) => {
  2393. console.log(callback, '-----')
  2394. if (callback.status == '00') {
  2395. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, callback.signKey, (callback1) => {
  2396. console.log(callback1, '2222222')
  2397. if (callback1.status == '00') {
  2398. ICINLocker.setVolume(this.data.cgInfo.lockerId, this.data.cgInfo.superId, volume, callback1.commonKey, (callback2) => {
  2399. console.log(callback2, '333333333')
  2400. if (callback2.status == '00') {
  2401. var dataOpenReport = {
  2402. code: "ble/volumeReport",
  2403. data: {
  2404. deviceNum: this.data.deviceinfo.deviceNum,
  2405. operate: parseInt(volume),
  2406. order: 61001
  2407. }
  2408. }
  2409. WXAPI.sendCommand(dataOpenReport).then(res => {
  2410. })
  2411. wx.hideLoading()
  2412. wx.showToast({
  2413. title: '设置成功',
  2414. duration: 2000,
  2415. icon: 'none'
  2416. })
  2417. } else {
  2418. wx.hideLoading()
  2419. wx.showToast({
  2420. title: '设置失败',
  2421. duration: 2000,
  2422. icon: 'none'
  2423. })
  2424. }
  2425. })
  2426. } else {
  2427. wx.hideLoading()
  2428. wx.showToast({
  2429. title: '设置失败',
  2430. duration: 2000,
  2431. icon: 'none'
  2432. })
  2433. }
  2434. })
  2435. } else {
  2436. wx.hideLoading()
  2437. wx.showToast({
  2438. title: '设置失败',
  2439. duration: 2000,
  2440. icon: 'none'
  2441. })
  2442. }
  2443. });
  2444. },
  2445. //设置常开
  2446. setOpen() {
  2447. wx.showLoading({
  2448. title: "正在开启...",
  2449. mask: true
  2450. });
  2451. setTimeout(() => {
  2452. wx.hideLoading()
  2453. }, 1000);
  2454. let cmd = 0xF3
  2455. // let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  2456. let length = 2
  2457. let b = new Uint8Array(length)
  2458. b[0] = cmd
  2459. b[1] = 1;
  2460. app.globalData.ble.send(cmd, b, function (res) {})
  2461. var dataOpenReport = {
  2462. code: "ble/alwaysOpenReport",
  2463. data: {
  2464. deviceNum: this.data.deviceinfo.deviceNum,
  2465. roomName: this.data.deviceinfo.roomName,
  2466. operate: 1,
  2467. order: 61101
  2468. }
  2469. }
  2470. WXAPI.sendCommand(dataOpenReport).then(res => {
  2471. })
  2472. },
  2473. setOpen1() {
  2474. wx.showLoading({
  2475. title: "正在关闭...",
  2476. mask: true
  2477. });
  2478. setTimeout(() => {
  2479. wx.hideLoading()
  2480. }, 1000);
  2481. let cmd = 0xF3
  2482. // let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  2483. let length = 2
  2484. let b = new Uint8Array(length)
  2485. b[0] = cmd
  2486. b[1] = 0;
  2487. app.globalData.ble.send(cmd, b, function (res) {})
  2488. var dataOpenReport = {
  2489. code: "ble/alwaysOpenReport",
  2490. data: {
  2491. deviceNum: this.data.deviceinfo.deviceNum,
  2492. roomName: this.data.deviceinfo.roomName,
  2493. operate: 0,
  2494. order: 61101
  2495. }
  2496. }
  2497. WXAPI.sendCommand(dataOpenReport).then(res => {
  2498. })
  2499. },
  2500. //设置音量
  2501. setVoice() {
  2502. },
  2503. startconnect() {
  2504. //if(checkWechatVersion())
  2505. // {
  2506. wx.showLoading({
  2507. title: "连接蓝牙中",
  2508. mask: true
  2509. })
  2510. var deviceinfo = this.data.deviceinfo
  2511. const ble = new BLE(this.data.deviceinfo.deviceNum, emitter)
  2512. app.globalData.ble = ble
  2513. this.watchBLE()
  2514. app.globalData.ble.init()
  2515. // }
  2516. },
  2517. watchBLE() {
  2518. var that = this
  2519. var deviceinfo = this.data.deviceinfo
  2520. if (app.globalData.ble) {
  2521. app.globalData.ble.listen(res => {
  2522. if (res.type == 'connect') {
  2523. if (res.data == "未打开适配器") {
  2524. wx.hideLoading()
  2525. wx.showToast({
  2526. title: '请检查手机蓝牙和定位功能是否打开?',
  2527. duration: 2000,
  2528. icon: 'none'
  2529. })
  2530. } else {
  2531. if (res.data == '蓝牙已连接') {
  2532. this.data.info = res.data
  2533. app.globalData.bleStatus = res.data
  2534. console.log(res.data, 'pppp')
  2535. if (this.data.event == 0) {
  2536. this.btntest2()
  2537. } else if (this.data.event == 3) {
  2538. this.btntest3()
  2539. } else if (this.data.event == 6) {
  2540. // this.setVoice()
  2541. this.setData({
  2542. show: true
  2543. })
  2544. } else if (this.data.event == 7) {
  2545. wx.showModal({
  2546. title: "常开设置",
  2547. cancelText: '关闭',
  2548. confirmText: '开启',
  2549. success: (res) => {
  2550. if (res.confirm) {
  2551. that.setOpen()
  2552. } else if (res.cancel) {
  2553. that.setOpen1()
  2554. }
  2555. }
  2556. })
  2557. } else {
  2558. wx.hideLoading()
  2559. }
  2560. }
  2561. }
  2562. }
  2563. })
  2564. }
  2565. },
  2566. closeblue() {
  2567. wx.showLoading({
  2568. title: "正在停止...",
  2569. mask: true
  2570. });
  2571. setTimeout(() => {
  2572. wx.hideLoading()
  2573. }, 1000);
  2574. app.globalData.ble.close()
  2575. this.data.info = ''
  2576. app.globalData.bleStatus = false
  2577. this.data.bleStatus = false,
  2578. this.data.respond = []
  2579. },
  2580. closeblue1() {
  2581. // wx.showLoading({
  2582. // title: "正在停止...",
  2583. // });
  2584. app.globalData.ble.close()
  2585. // setTimeout(() => {
  2586. // wx.hideLoading()
  2587. // }, 1000);
  2588. this.data.info = ''
  2589. app.globalData.bleStatus = false
  2590. this.data.bleStatus = false,
  2591. this.data.respond = []
  2592. },
  2593. btntest3(event) {
  2594. var that = this
  2595. let deviceNum = that.data.deviceinfo.deviceNum
  2596. this.data.backstatus = true
  2597. that.startFp_29(deviceNum, 0x03)
  2598. // setTimeout(() => {
  2599. // that.getcartcount()
  2600. // }, 300)
  2601. },
  2602. btntest2(event) {
  2603. var that = this
  2604. let userTelephone = "18270949468"
  2605. let userPassword = "202108"
  2606. let pwd = "2021110309"
  2607. let openLockType = 2
  2608. var userInfo = wx.getStorageSync('userInfo')
  2609. var timestamp = moment().format("x")
  2610. bleall.openLock(userTelephone, userPassword, pwd, openLockType, timestamp, function (res) {
  2611. if (res.success) {
  2612. var rqTime = moment().format("X")
  2613. var username = wx.getStorageSync('username'),
  2614. password = wx.getStorageSync('password')
  2615. var str = `${username}+${password}+${rqTime}`
  2616. var signature = md5(str)
  2617. wx.hideLoading()
  2618. var data = {
  2619. code: "ld/bleUnlockRecord",
  2620. data: {
  2621. deviceNum: that.data.deviceNum,
  2622. userTelephone: userTelephone,
  2623. password: userPassword,
  2624. roomId: that.data.deviceinfo.roomId,
  2625. roomName: that.data.deviceinfo.roomName,
  2626. cardName: userInfo.username,
  2627. signature: signature
  2628. }
  2629. }
  2630. WXAPI.sendCommand(data).then(res => {
  2631. })
  2632. }
  2633. console.log(res.data)
  2634. if (res.data == "蓝牙功能暂不支持") {
  2635. wx.showToast({
  2636. title: '重新连接蓝牙中',
  2637. duration: 2000,
  2638. icon: "none"
  2639. })
  2640. that.startconnect()
  2641. }
  2642. })
  2643. },
  2644. openLock(userTelephone, userPassword, pwd, openLockType) {
  2645. wx.showLoading({
  2646. title: "正在发送...",
  2647. mask: true
  2648. });
  2649. setTimeout(() => {
  2650. wx.hideLoading()
  2651. }, 1000);
  2652. let cmd = 0x41
  2653. console.log(util, userTelephone)
  2654. let ut = util.stringToUint8Array(userTelephone)
  2655. let up = util.stringToUint8Array(userPassword)
  2656. let p = util.hexStringToBytesWithPadding(pwd, 10, 0xff)
  2657. let length = 1 + 11 + 6 + 10 + 1
  2658. let b = new Uint8Array(length)
  2659. b[0] = cmd
  2660. b.set(ut, 1)
  2661. b.set(up, 12)
  2662. b.set(p, 18)
  2663. b[28] = openLockType
  2664. console.log(b)
  2665. app.globalData.ble.send(cmd, b, length)
  2666. },
  2667. //远程开锁
  2668. remoteUnlocking() {
  2669. if (this.data.info == '蓝牙已连接') {
  2670. this.closeblue1()
  2671. }
  2672. if (this.data.deviceinfo.manufactureId == 101) {
  2673. var str2 = {
  2674. imei: this.data.deviceinfo.imei,
  2675. openLockType: 2,
  2676. is: true,
  2677. roomId: this.data.deviceinfo.roomId,
  2678. roomName: this.data.deviceinfo.roomName,
  2679. cardName: this.data.userInfo.username
  2680. };
  2681. WXAPI.openLock(str2).then(res => {
  2682. if (res.success) {
  2683. wx.showToast({
  2684. title: "已发送远程开门指令",
  2685. icon: "none",
  2686. duration: 2000
  2687. })
  2688. }
  2689. })
  2690. } else if (this.data.deviceinfo.manufactureId == 1201) {
  2691. var str2 = {
  2692. code: 'lwj/openLock',
  2693. data: {
  2694. lockerId: this.data.deviceinfo.deviceNum,
  2695. order: 6301,
  2696. is: true,
  2697. roomId: this.data.deviceinfo.roomId,
  2698. roomName: this.data.deviceinfo.roomName,
  2699. cardName: this.data.userInfo.username
  2700. }
  2701. };
  2702. WXAPI.sendCommand(str2).then(res => {
  2703. if (res.success) {
  2704. wx.showToast({
  2705. title: "已发送远程开门指令",
  2706. icon: "none",
  2707. duration: 2000
  2708. })
  2709. }
  2710. })
  2711. }
  2712. },
  2713. /**
  2714. * 生命周期函数--监听页面初次渲染完成
  2715. */
  2716. onReady: function () {
  2717. app.globalData.zgBlueStatus = false
  2718. },
  2719. AddressPermissions() {
  2720. wx.openBluetoothAdapter({
  2721. success: function (res) {
  2722. console.log('蓝牙已开启!');
  2723. },
  2724. fail: function (e) {
  2725. console.log(e)
  2726. wx.showToast({
  2727. title: '请打开蓝牙!',
  2728. duration: 2000,
  2729. icon: 'none'
  2730. })
  2731. }
  2732. });
  2733. },
  2734. getLocationPermissionMethods() {
  2735. ICINLocker.getLocationPermission().then((res) => {
  2736. if (res.status == 0) {
  2737. } else {
  2738. // 连接出现问题
  2739. }
  2740. }).catch((res) => {
  2741. //处理未能获得地理位置情况
  2742. wx.showToast({
  2743. title: '请打开微信定位功能!',
  2744. duration: 2000,
  2745. icon: 'none'
  2746. })
  2747. })
  2748. },
  2749. /**
  2750. * 生命周期函数--监听页面显示
  2751. */
  2752. onShow: function () {
  2753. var deviceinfo = wx.getStorageSync('deviceinfo')
  2754. var userInfo1 = wx.getStorageSync('userInfo')
  2755. if (deviceinfo.roomId) {
  2756. if (userInfo1.type != 3) {
  2757. var data2 = {
  2758. q: JSON.stringify({
  2759. id: deviceinfo.roomId
  2760. }),
  2761. orderBy: "createTime",
  2762. orderType: 'desc'
  2763. }
  2764. WXAPI.getSiteTenant(data2).then(res1 => {
  2765. if (res1.data.list.length > 0) {
  2766. var array = res1.data.list.reverse()
  2767. wx.setStorageSync('info', array[0])
  2768. deviceinfo.info = array[0].info
  2769. this.setData({
  2770. deviceinfo: deviceinfo
  2771. })
  2772. } else {
  2773. wx.showToast({
  2774. title: "还未下发人员,请先下发人员",
  2775. duration: 2000,
  2776. icon: 'none'
  2777. })
  2778. }
  2779. })
  2780. } else if (userInfo1.type == 3) {
  2781. this.setData({
  2782. deviceinfo: deviceinfo
  2783. })
  2784. }
  2785. } else {
  2786. wx.navigateTo({
  2787. url: "../index/index"
  2788. })
  2789. }
  2790. this.setData({
  2791. bleStatus: app.globalData.bleStatus
  2792. })
  2793. },
  2794. /**
  2795. * 生命周期函数--监听页面隐藏
  2796. */
  2797. /**
  2798. * 生命周期函数--监听页面卸载
  2799. */
  2800. onUnload: function () {
  2801. console.log(isConnected, connectedDeviceId)
  2802. if (isConnected) {
  2803. wx.closeBLEConnection({
  2804. deviceId: connectedDeviceId,
  2805. success: function (res) {
  2806. isConnected = false
  2807. },
  2808. })
  2809. }
  2810. // if (app.globalData.zgBlueStatus) {
  2811. // ICINLocker.disConnect(app.globalData.blueDeviceId);
  2812. // this.onReady()
  2813. // }
  2814. this.setData({
  2815. bluestatus: false,
  2816. toSearch: false
  2817. })
  2818. // wx.removeStorageSync("connectedDeviceId")
  2819. if (app.globalData.bleStatus) {
  2820. this.closeblue()
  2821. }
  2822. wx.hideLoading()
  2823. },
  2824. onHide() {
  2825. // wx.removeStorageSync("connectedDeviceId")
  2826. this.setData({
  2827. toSearch: false
  2828. })
  2829. wx.hideLoading()
  2830. if (app.globalData.bleStatus) {
  2831. this.closeblue()
  2832. }
  2833. },
  2834. /**
  2835. * 页面相关事件处理函数--监听用户下拉动作
  2836. */
  2837. onPullDownRefresh: function () {
  2838. // this.AddressPermissions()
  2839. var deviceinfo = wx.getStorageSync('deviceinfo')
  2840. app.globalData.deviceNum = deviceinfo.deviceNum
  2841. var userInfo1 = wx.getStorageSync('userInfo')
  2842. if (deviceinfo.manufactureId == 201 || deviceinfo.manufactureId == 221) {
  2843. var data3 = {
  2844. code: "zg/bleRegisterInfo",
  2845. data: {
  2846. lockerId: deviceinfo.deviceNum
  2847. }
  2848. }
  2849. WXAPI.sendCommand(data3).then(res1 => {
  2850. if (res1.success) {
  2851. wx.setStorageSync('cgInfo', res1.data)
  2852. this.setData({
  2853. cgInfo: res1.data
  2854. })
  2855. } else {
  2856. }
  2857. })
  2858. }
  2859. if (deviceinfo.roomId) {
  2860. if (userInfo1.type != 3) {
  2861. var data2 = {
  2862. q: JSON.stringify({
  2863. id: deviceinfo.roomId
  2864. }),
  2865. orderBy: "createTime",
  2866. orderType: 'desc'
  2867. }
  2868. WXAPI.getSiteTenant(data2).then(res1 => {
  2869. if (res1.data.list.length > 0) {
  2870. var array = res1.data.list.reverse()
  2871. wx.setStorageSync('info', array[0])
  2872. deviceinfo.info = array[0].info
  2873. this.setData({
  2874. deviceinfo: deviceinfo
  2875. })
  2876. } else {
  2877. wx.showToast({
  2878. title: "还未下发人员,请先下发人员",
  2879. duration: 2000,
  2880. icon: 'none'
  2881. })
  2882. }
  2883. })
  2884. } else if (userInfo1.type == 3) {
  2885. this.setData({
  2886. deviceinfo: deviceinfo
  2887. })
  2888. }
  2889. } else {
  2890. wx.navigateTo({
  2891. url: "../index/index"
  2892. })
  2893. }
  2894. this.setData({
  2895. info: app.globalData.bleStatus,
  2896. deviceinfo: deviceinfo
  2897. })
  2898. wx.stopPullDownRefresh()
  2899. },
  2900. /**
  2901. * 页面上拉触底事件的处理函数
  2902. */
  2903. onReachBottom: function () {
  2904. },
  2905. /**
  2906. * 用户点击右上角分享
  2907. */
  2908. onShareAppMessage: function () {
  2909. }
  2910. })