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.

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