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.

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