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.

4338 lines
142 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. // pages/addperson/addperson.js
  2. const app = getApp()
  3. const WXAPI = require('../../utils/request')
  4. import ICINLocker from "../../utils/ICINPakage/ICINLocker"
  5. var util = require('../../utils/util');
  6. var util1 = require('../../utils/util1');
  7. const config = require('../../config')
  8. const plugin = requirePlugin("myPlugin")
  9. var methods = require('../../utils/methods');
  10. var md5 = require('../../utils/md5.js');
  11. var bleall = require('../../utils/bleall');
  12. import moment from "../../utils/moment"
  13. import {
  14. BLE
  15. } from "../../utils/btls/ble";
  16. const emitter = app.globalData.emitter
  17. const ADD_NFC_MODE=10
  18. // ArrayBuffer转16进度字符串示例
  19. function ab2hex(buffer) {
  20. var hexArr = Array.prototype.map.call(
  21. new Uint8Array(buffer),
  22. function (bit) {
  23. return ('00' + bit.toString(16)).slice(-2)
  24. }
  25. )
  26. return hexArr.join(',');
  27. }
  28. function CurentTime() {
  29. var now = new Date();
  30. var year = now.getFullYear(); //年
  31. var month = now.getMonth() + 1; //月
  32. var day = now.getDate(); //日
  33. var hh = now.getHours(); //时
  34. var mm = now.getMinutes(); //分
  35. var clock = year + "-";
  36. if (month < 10)
  37. clock += "0";
  38. clock += month + "-";
  39. if (day < 10)
  40. clock += "0";
  41. clock += day + " ";
  42. // if (hh < 10)
  43. // clock += "0";
  44. // clock += '00' + ":";
  45. // // if (mm < 10) clock += '0';
  46. clock += '00:00:00';
  47. return (clock);
  48. }
  49. function CurentTime1() {
  50. var now = new Date();
  51. var year = now.getFullYear() + 3; //年
  52. var month = now.getMonth() + 1; //月
  53. var day = now.getDate(); //日
  54. var hh = now.getHours(); //时
  55. var mm = now.getMinutes(); //分
  56. var clock = year + "-";
  57. if (month < 10)
  58. clock += "0";
  59. clock += month + "-";
  60. if (day < 10)
  61. clock += "0";
  62. clock += day + " ";
  63. // if (hh < 10)
  64. // clock += "0";
  65. // clock += hh + ":";
  66. // if (mm < 10) clock += '0';
  67. // clock += mm;
  68. clock += '23:59:59';
  69. return (clock);
  70. }
  71. var date = new Date()
  72. var isConnected = false
  73. var connectedDeviceId = ''
  74. var basecode = 29283991
  75. var lockId = 1
  76. var lockManagerId = 1
  77. var lockMac = ''
  78. var isInitReady = false
  79. var lockModel
  80. var lockDevice
  81. var taskId = 0
  82. var pincode = -1
  83. var pincodeIndex = -1
  84. var rfCardId = -1
  85. var rfCardIndex = -1
  86. var fingerprintIndex = -1
  87. var passwordLiAll = {id:''}
  88. var isLockLogin = false
  89. var serialNumber = ''
  90. let letterRandom = [
  91. "0",
  92. "1",
  93. "2",
  94. "3",
  95. "4",
  96. "5",
  97. "6",
  98. "7",
  99. "8",
  100. "9",
  101. "a",
  102. "b",
  103. "c",
  104. "d",
  105. "e",
  106. "f",
  107. "g",
  108. "h",
  109. "i",
  110. "j",
  111. "k",
  112. "l",
  113. "m",
  114. "n",
  115. "o",
  116. "p",
  117. "q",
  118. "r",
  119. "s",
  120. "t",
  121. "u",
  122. "v",
  123. "w",
  124. "x",
  125. "y",
  126. "z",
  127. "A",
  128. "B",
  129. "C",
  130. "D",
  131. "E",
  132. "F",
  133. "G",
  134. "H",
  135. "I",
  136. "J",
  137. "K",
  138. "L",
  139. "M",
  140. "N",
  141. "O",
  142. "P",
  143. "Q",
  144. "R",
  145. "S",
  146. "T",
  147. "U",
  148. "V",
  149. "W",
  150. "X",
  151. "Y",
  152. "Z",
  153. ];
  154. function randomMethods(){
  155. let str= ''
  156. for (let i = 0; i < 8; i++) {
  157. str+=
  158. letterRandom[Math.round(Math.random() * (letterRandom.length - 1))];
  159. }
  160. return str
  161. }
  162. Page({
  163. /**
  164. * 页面的初始数据
  165. */
  166. data: {
  167. isBindLock: false,
  168. isPincodeAdd: false,
  169. isRfCardAdd: false,
  170. isFingerprintAdd: false,
  171. isUnloked: false,
  172. isMuted: false,
  173. isNbEnable: true,
  174. lockModel: 0,
  175. lock: {},
  176. isSearch:app.globalData.isSearch,
  177. activeKey: 0,
  178. NfcList: [],
  179. FpList:[],
  180. passwordList: [],
  181. show: false,
  182. datetimerange: [CurentTime(), CurentTime1()],
  183. minDate: '',
  184. minDate1: '',
  185. endtime: '',
  186. starttime: '',
  187. addIndex: 0,
  188. pzname: '',
  189. current: '',
  190. currentIndex: '',
  191. fingerprintId: '',
  192. backstatus: false,
  193. radioDetil:'',
  194. passwordStatus:true,
  195. items: [
  196. {value: '0', name: '左手大拇指',checked:false},
  197. {value: '1', name: '左手食指',checked:false},
  198. {value: '2', name: '右手大拇指',checked:false},
  199. {value: '3', name: '右手食指',checked:false}
  200. ],
  201. showLoading:false,
  202. requestSatatus:true,
  203. password:''
  204. },
  205. /**
  206. * 生命周期函数--监听页面加载
  207. */
  208. onLoad: function (options) {
  209. var cgInfo = wx.getStorageSync('cgInfo')
  210. var deviceinfo = wx.getStorageSync('deviceinfo')
  211. var personLi = wx.getStorageSync('personLi')
  212. let minDate = wx.getStorageSync('minDate')
  213. let minDate1 = wx.getStorageSync('minDate1')
  214. this.setData({
  215. cgInfo: cgInfo,minDate,minDate1,
  216. starttime:minDate,
  217. endtime:minDate1,
  218. deviceinfo: deviceinfo,
  219. personLi: personLi,
  220. isSearch: false
  221. })
  222. this.getPassword()
  223. this.getNfc()
  224. this.getCarId()
  225. this.getFp()
  226. if(deviceinfo.manufactureId == 1201){
  227. this.searchDevicesMethods()
  228. }else if(deviceinfo.manufactureId == 101){
  229. app.watch(this.getcartcount, 'backdata')
  230. app.watch(this.fingerprintFun, 'fingerprintId')
  231. }
  232. },
  233. // 指纹选择
  234. radioChange(e){
  235. var personLi=wx.getStorageSync('personLi')
  236. var pzname=''
  237. if(e.detail.value==0){
  238. pzname="左手大拇指"
  239. }else if(e.detail.value==1){
  240. pzname="左手食指"
  241. }else if(e.detail.value==2){
  242. pzname="右手大拇指"
  243. }else if(e.detail.value==3){
  244. pzname="右手食指"
  245. }
  246. this.setData({
  247. radioDetil:pzname
  248. })
  249. this.getfingerprintMrhods(pzname,personLi.cardId,11)
  250. },
  251. getfingerprintMrhods(pzname,id,type){
  252. var that=this
  253. var items=[
  254. {value: '0', name: '左手大拇指',checked:false},
  255. {value: '1', name: '左手食指',checked:false},
  256. {value: '2', name: '右手大拇指',checked:false},
  257. {value: '3', name: '右手食指',checked:false}
  258. ]
  259. var data = {
  260. pageNum: 0,
  261. pageSize: 0,
  262. orderBy: "create_at desc",
  263. q: {
  264. cardId: id,
  265. types: type,
  266. deviceNum:this.data.deviceinfo.deviceNum,
  267. inStatus:'0,1,702'
  268. },
  269. };
  270. WXAPI.getCertificates(data).then(res=>{
  271. var dataOne=util.zlib_unzip(res.data)
  272. if(res.success){
  273. dataOne.map(li=>{
  274. var content = JSON.parse(li.content)
  275. if (content.fingerprintAlias == pzname) {
  276. wx.showModal({
  277. title: '提示',
  278. content: '该指纹已存在,请选择其他',
  279. success (res1) {
  280. if (res1.confirm) {
  281. console.log('用户点击确定')
  282. that.setData({
  283. items,
  284. radioDetil:''
  285. })
  286. } else if (res1.cancel) {
  287. console.log('用户点击取消')
  288. that.setData({
  289. items,
  290. radioDetil:''
  291. })
  292. }
  293. }
  294. })
  295. }
  296. })
  297. }else{
  298. wx.showToast({
  299. title: '获取失败',
  300. mask:true,
  301. duration:'2000',
  302. icon:'none'
  303. })
  304. }
  305. })
  306. },
  307. fingerprintFun() {
  308. this.data.fingerprintId = app.globalData.fingerprintId
  309. },
  310. getcartcount(val) {
  311. var that = this
  312. var _this = this
  313. let deviceNum = that.data.deviceinfo.deviceNum
  314. var timestamp = moment().format("x")
  315. wx.showLoading({
  316. title: '添加指纹中',
  317. mask:true
  318. })
  319. if (app.globalData.backdata == 3 && this.data.backstatus) {
  320. bleall.startFp_29(deviceNum, 0x02, timestamp, function (res) {})
  321. } else if (app.globalData.backdata == 2 && this.data.backstatus) {
  322. bleall.startFp_29(deviceNum, 0x01, timestamp, function (res) {})
  323. } else if (app.globalData.backdata == 1 && this.data.backstatus) {
  324. console.log(app.globalData.backdata, this.data.backstatus,'app.globalData.backdata, this.data.backstatus',this.data.fingerprintId)
  325. if(this.data.fingerprintId!=255){
  326. var info = JSON.parse(this.data.personLi.info)
  327. var time1 = moment(this.data.datetimerange[0]).format("YYYYMMDDHHmmss")
  328. var time2 = moment(this.data.datetimerange[1]).format("YYYYMMDDHHmmss")
  329. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  330. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  331. var passwordStartTime = time3.getTime() / 1000
  332. var passwordEndTime = time4.getTime() / 1000
  333. var data = {
  334. managerTelephone: "18270949468",
  335. managerPassword: "202108",
  336. userTelephone: info.userTelephone,
  337. userPassword: info.userPassword,
  338. startTime: time1,
  339. endTime: time2
  340. }
  341. console.log(data, this.data.fingerprintId)
  342. // if(app.globalData.fingerprintId != -1){
  343. // setTimeout(() => {
  344. // app.globalData.backdata = -1
  345. this.setData({
  346. backstatus: false
  347. })
  348. let fingerprintId = ''
  349. console.log(_this.data.fingerprintId, typeof (_this.data.fingerprintId))
  350. if (Number(_this.data.fingerprintId) < 9) {
  351. fingerprintId = '0' + _this.data.fingerprintId.toString(16)
  352. } else {
  353. fingerprintId = _this.data.fingerprintId.toString(16)
  354. }
  355. let deviceinfo = that.data.deviceinfo
  356. bleall.startFp_63(data.managerTelephone, data.managerPassword, data.userTelephone, data.userPassword,
  357. data.startTime, data.endTime, 16, this.data.fingerprintId, timestamp,
  358. function (res) {
  359. console.log(res, 'resres')
  360. if (res.success) {
  361. wx.hideLoading()
  362. var cardName='',pzname=''
  363. if(that.data.pzname){
  364. cardName=that.data.personLi.name+'-蓝牙-'+that.data.pzname
  365. pzname='蓝牙-'+that.data.pzname
  366. }else{
  367. cardName=that.data.personLi.name+'-蓝牙-指纹'+that.data.FpList.length+1
  368. pzname='蓝牙-指纹'+that.data.FpList.length+1
  369. }
  370. var str = {
  371. // cardId: this.personInfo.cardId,
  372. imei: _this.data.deviceinfo.imei,
  373. pzname:pzname,
  374. password: '',
  375. userTelephone: info.userTelephone,
  376. operateMode: 16,
  377. fingerprintAlias:_this.data.radioDetil,
  378. userPassword: info.userPassword,
  379. passwordStartTime: time1,
  380. passwordEndTime: time2,
  381. is: false,
  382. pass:true
  383. }
  384. var data3 = {
  385. code: "ble/operateUserInfo",
  386. data: {
  387. deviceNum: deviceinfo.deviceNum,
  388. imei: deviceinfo.imei,
  389. userTelephone: info.userTelephone,
  390. userPassword: info.userPassword,
  391. password: fingerprintId,
  392. userStartTime: time1,
  393. userEndTime: time2,
  394. passwordStartTime: time1,
  395. passwordEndTime: time2,
  396. operateMode: 16,
  397. order: 6216,
  398. timestamp: timestamp,
  399. managerTelephone: '18270949468',
  400. managerPassword: '202108',
  401. passwordLength: 10,
  402. permission: 4294967295,
  403. times: 255,
  404. recycleTime: "65535",
  405. roomName: _this.data.deviceinfo.roomName,
  406. cardName:cardName,
  407. }
  408. }
  409. console.log(data3, 'pppppp')
  410. WXAPI.sendCommand(data3).then(res3 => {
  411. console.log(res3, 'resres3')
  412. if (res3.success) {
  413. var data4 = {
  414. result: 1,
  415. serial: res3.data.serialNumber
  416. }
  417. WXAPI.updatePush(data4).then(res4 => {
  418. })
  419. var data6 = {
  420. result: 1,
  421. serial: res3.data.serialNumber,
  422. face: fingerprintId
  423. }
  424. WXAPI.editPushBySerial(data6).then(res4 => {
  425. })
  426. var data = {
  427. cardId: _this.data.personLi.cardId,
  428. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  429. deviceNum: _this.data.deviceinfo.deviceNum,
  430. type: 1,
  431. imei: _this.data.deviceinfo.imei,
  432. serial: res3.data.serialNumber,
  433. startTime: passwordStartTime,
  434. endTime: passwordEndTime,
  435. };
  436. var datalist = {
  437. cardId: _this.data.personLi.cardId,
  438. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  439. type: 11,
  440. startTime: passwordStartTime,
  441. endTime: passwordEndTime,
  442. };
  443. WXAPI.addCertificates(datalist).then(res6 => {})
  444. console.log(data, '添加凭证')
  445. WXAPI.addCertificates(data).then(res4 => {
  446. if (res4.success) {
  447. var updatedata = {
  448. id: res4.data,
  449. status:1
  450. };
  451. WXAPI.updateCertificates(updatedata).then((res2) => {
  452. });
  453. console.log(res3, '添加凭证成功')
  454. _this.getFp()
  455. _this.setData({
  456. show: false
  457. })
  458. wx.hideLoading()
  459. wx.showToast({
  460. title: '添加成功',
  461. icon: 'none',
  462. mask:true,
  463. duration: 2000
  464. })
  465. } else {
  466. wx.hideLoading()
  467. wx.showToast({
  468. title: '添加失败',
  469. mask:true,
  470. icon: 'none',
  471. duration: 2000
  472. })
  473. }
  474. })
  475. } else {
  476. wx.hideLoading()
  477. wx.showToast({
  478. title: res3.msg,
  479. mask:true,
  480. icon: 'none',
  481. duration: 2000
  482. })
  483. }
  484. })
  485. }else{
  486. wx.hideLoading()
  487. wx.showToast({
  488. title: '添加失败',
  489. duration:2000,
  490. icon:'none'
  491. })
  492. }
  493. if (res.data == "蓝牙功能暂不支持") {
  494. _this.startconnect()
  495. }
  496. })
  497. // }, 200)
  498. // }
  499. }else{
  500. wx.hideLoading()
  501. wx.showToast({
  502. title: '添加失败',
  503. mask:true,
  504. duration:2000,
  505. icon:'none'
  506. })
  507. }
  508. }
  509. },
  510. // 删除开锁方式
  511. delMode(e) {
  512. var current = e.currentTarget.dataset.current
  513. var index = e.currentTarget.dataset.index
  514. var cgInfo = this.data.cgInfo
  515. var deviceinfo = this.data.deviceinfo
  516. this.setData({
  517. current: current,
  518. currentIndex: index
  519. })
  520. if (deviceinfo.manufactureId == 101) {
  521. if (current == 1) {
  522. this.delPassword1(index)
  523. } else if (current == 2) {
  524. this.delNfc1(index)
  525. }else if (current == 3) {
  526. this.delFp1(index)
  527. }
  528. } else if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  529. if (current == 1) {
  530. this.delPassword(index)
  531. } else if (current == 2) {
  532. this.delNfc1(index)
  533. } else if (current == 3) {
  534. this.delFp(index)
  535. }
  536. }else if (deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241) {
  537. if (current == 1) {
  538. this.delPasswordLwj(index)
  539. } else if (current == 2) {
  540. this.delNfcLwj(index)
  541. } else if (current == 3) {
  542. this.delFpLwj(index)
  543. }
  544. }
  545. },
  546. getNFCIndexLwj(index, callback){
  547. var data = {
  548. q: JSON.stringify({
  549. cardId: this.data.personLi.cardId,
  550. inStatus:"1",
  551. types:'3',
  552. deviceNum:this.data.NfcList[index].deviceNum,
  553. // this.data.NfcList[index].serial,
  554. // result:1
  555. }),
  556. pageNum: 1,
  557. pageSize: 10,
  558. orderBy: "create_at desc"
  559. };
  560. WXAPI.getCertificates(data).then(res => {
  561. if (res.success) {
  562. var dataOne=util.zlib_unzip(res.data)
  563. console.log(dataOne,'ddd')
  564. callback(dataOne)
  565. } else {
  566. wx.showToast({
  567. title: '获取失败',
  568. mask:true,
  569. duration: 2000,
  570. icon: 'none'
  571. })
  572. }
  573. })
  574. },
  575. getNFCIndex(index, callback) {
  576. var data = {
  577. q: JSON.stringify({
  578. serial: this.data.NfcList[index].serial,
  579. result:1
  580. }),
  581. pageNum: 1,
  582. pageSize: 10,
  583. };
  584. WXAPI.getDeviceResult(data).then(res => {
  585. if (res.success) {
  586. var dataOne=util.zlib_unzip(res.data)
  587. console.log(dataOne,'ddd')
  588. callback(dataOne)
  589. } else {
  590. wx.showToast({
  591. title: '获取失败',
  592. mask:true,
  593. duration: 2000,
  594. icon: 'none'
  595. })
  596. }
  597. })
  598. },
  599. getFpIndex(index, callback) {
  600. var data = {
  601. q: JSON.stringify({
  602. serial: this.data.FpList[index].serial,
  603. }),
  604. pageNum: 1,
  605. pageSize: 10,
  606. };
  607. WXAPI.getDeviceResult(data).then(res => {
  608. if (res.success) {
  609. var dataOne=util.zlib_unzip(res.data)
  610. console.log(dataOne,'ddd')
  611. callback(dataOne)
  612. } else {
  613. wx.showToast({
  614. title: '获取失败',
  615. duration: 2000,
  616. mask:true,
  617. icon: 'none'
  618. })
  619. }
  620. })
  621. },
  622. addPassword(e) {
  623. this.setData({
  624. show: true,
  625. current: e.currentTarget.dataset.current,
  626. addIndex: e.currentTarget.dataset.addindex
  627. })
  628. },
  629. onChange1(event) {
  630. // event.detail 为当前输入的值
  631. this.setData({
  632. password: event.detail
  633. })
  634. },
  635. onChange2(event) {
  636. // event.detail 为当前输入的值
  637. this.setData({
  638. pzname: event.detail
  639. })
  640. },
  641. bindDateChange: function (e) {
  642. var str = e.detail.value + " 00:00:00"
  643. this.data.datetimerange[0] = str
  644. this.setData({
  645. starttime: str,
  646. })
  647. },
  648. bindDateChange1: function (e) {
  649. var str = e.detail.value + " 23:59:59"
  650. this.data.datetimerange[1] = str
  651. this.setData({
  652. endtime: str
  653. })
  654. },
  655. delNfc1(index){
  656. wx.showLoading({
  657. title: '正在删除',
  658. mask: true
  659. })
  660. var cgInfo = this.data.cgInfo
  661. var personLi = this.data.NfcList[index]
  662. var deviceinfo = this.data.deviceinfo
  663. var info = JSON.parse(personLi.content)
  664. var personInfo=JSON.parse(this.data.personLi.info)
  665. var _this = this
  666. this.getNFCIndex(index, function (data) {
  667. console.log(data,'datatdatata',data[0])
  668. if (data.length > 0 && data[0].face!=null ) {
  669. var FPindex = data[0].face
  670. var dataPasswod = {
  671. code: "zg/cardOperate",
  672. data: {
  673. lockerId: deviceinfo.deviceNum,
  674. imei: deviceinfo.imei,
  675. lockerUserId: personInfo.userId,
  676. keyId: personInfo.userId,
  677. action: 2,
  678. taskStatus:1,
  679. cardType:50,
  680. cardNo:info.password,
  681. cardIndex:FPindex,
  682. startTime: personLi.startTime,
  683. endTime: personLi.endTime,
  684. order: 6212,
  685. type: 12,
  686. roomName: _this.data.deviceinfo.roomName,
  687. cardName: _this.data.personLi.name+personLi.pzname,
  688. }
  689. }
  690. WXAPI.sendCommand(dataPasswod).then(res => {
  691. console.log(res, '获取索引',FPindex)
  692. if (res.success) {
  693. var serialNumber= res.data.serialNumber
  694. var fingerNo = FPindex.toString(16)
  695. if (fingerNo.length==1) {
  696. fingerNo = '0' + fingerNo
  697. } else {
  698. fingerNo = fingerNo
  699. }
  700. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId,
  701. (callback) => {
  702. console.log(callback,fingerNo)
  703. if (callback.status == '00') {
  704. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, callback.signKey, (callback1) => {
  705. console.log(callback1)
  706. if (callback1.status == '00') {
  707. var startTime = personLi.startTime.toString(16).toUpperCase()
  708. var endTime = personLi.endTime.toString(16).toUpperCase()
  709. console.log(cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, fingerNo.toUpperCase(), '--','01', callback.signKey, startTime, endTime, callback1.commonKey)
  710. ICINLocker.modifyRFCard(cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, fingerNo.toUpperCase(), '','01', callback.signKey, startTime, endTime, callback1.commonKey, (
  711. callback2) => {
  712. console.log(callback2)
  713. if (callback2.status == '00') {
  714. var datacom = {
  715. code: "zg/bleSendVoucherReply",
  716. data: {
  717. lockerId: deviceinfo.deviceNum,
  718. serialNumber:serialNumber,
  719. index: FPindex,
  720. type: 12,
  721. result: 1
  722. }
  723. }
  724. WXAPI.sendCommand(datacom).then(res2 => {
  725. console.log(res2, '成功----')
  726. })
  727. wx.showToast({
  728. title: '下发成功',
  729. mask:true,
  730. icon: 'none',
  731. duration: 2000
  732. })
  733. var data = {
  734. ids: [personLi.id]
  735. }
  736. wx.hideLoading()
  737. WXAPI.deleteCertificates(data).then(res1 => {
  738. if (res1.success) {
  739. _this.getNfc()
  740. wx.showToast({
  741. title: '删除成功',
  742. mask:true,
  743. icon: 'none',
  744. duration: 2000
  745. })
  746. } else {
  747. wx.showToast({
  748. title: '删除失败',
  749. mask:true,
  750. icon: 'none',
  751. duration: 2000
  752. })
  753. }
  754. })
  755. } else {
  756. wx.hideLoading()
  757. wx.showToast({
  758. title: '删除失败',
  759. mask:true,
  760. icon: 'none',
  761. duration: 2000
  762. })
  763. var datacom = {
  764. code: "zg/bleSendVoucherReply",
  765. data: {
  766. lockerId: deviceinfo.deviceNum,
  767. serialNumber: serialNumber,
  768. index: FPindex,
  769. type: 12,
  770. result: 0
  771. }
  772. }
  773. WXAPI.sendCommand(datacom).then(res2 => {
  774. console.log(res2, '失败')
  775. })
  776. }
  777. })
  778. } else {
  779. wx.hideLoading()
  780. wx.showToast({
  781. title: '删除失败',
  782. mask:true,
  783. icon: 'none',
  784. duration: 2000
  785. })
  786. var datacom = {
  787. code: "zg/bleSendVoucherReply",
  788. data: {
  789. lockerId: deviceinfo.deviceNum,
  790. serialNumber: serialNumber,
  791. index: FPindex,
  792. type: 12,
  793. result: 0
  794. }
  795. }
  796. WXAPI.sendCommand(datacom).then(res2 => {
  797. console.log(res2, '失败')
  798. })
  799. }
  800. })
  801. } else {
  802. wx.hideLoading()
  803. wx.showToast({
  804. title: '删除失败',
  805. mask:true,
  806. icon: 'none',
  807. duration: 2000
  808. })
  809. var datacom = {
  810. code: "zg/bleSendVoucherReply",
  811. data: {
  812. lockerId: deviceinfo.deviceNum,
  813. serialNumber: serialNumber,
  814. index: FPindex,
  815. type: 12,
  816. result: 0
  817. }
  818. }
  819. WXAPI.sendCommand(datacom).then(res2 => {
  820. console.log(res2, '失败')
  821. })
  822. }
  823. })
  824. } else {
  825. wx.showToast({
  826. title: res.msg,
  827. mask:true,
  828. icon: 'none',
  829. duration: 2000
  830. })
  831. }
  832. })
  833. } else {
  834. wx.hideLoading()
  835. wx.showToast({
  836. title: '删除失败',
  837. mask:true,
  838. duration: 2000,
  839. icon: 'none'
  840. })
  841. }
  842. })
  843. },
  844. delNfcLwj(index){
  845. wx.showLoading({
  846. title: '正在删除',
  847. mask: true
  848. })
  849. var personLi = this.data.NfcList[index]
  850. passwordLiAll = personLi
  851. var deviceinfo = this.data.deviceinfo
  852. var info = JSON.parse(personLi.content)
  853. var personInfo=JSON.parse(this.data.personLi.info)
  854. var _this = this
  855. this.getNFCIndexLwj(index, function (data) {
  856. if (data.length > 0) {
  857. let passwordIndex = JSON.parse(data[0].content).index || ''
  858. var dataPasswod = {
  859. code: "lwj/passwordOperate",
  860. data: {
  861. lockerId: deviceinfo.deviceNum,
  862. lockerUserId: personInfo.userId,
  863. startTime:personLi.startTime,
  864. endTime:personLi.endTime,
  865. order: 6212,
  866. operateMode:12,
  867. action: 2,
  868. // cardNo: info.password,
  869. passwordIndex:passwordIndex,
  870. type: 12,
  871. cardName:_this.data.personLi.name,
  872. roomName:deviceinfo.roomName
  873. }
  874. }
  875. console.log(dataPasswod,'dataPasswod',info)
  876. WXAPI.sendCommand(dataPasswod).then(res => {
  877. console.log(res, '获取索引')
  878. if (res.success) {
  879. rfCardIndex = res.data.index
  880. serialNumber = res.data.serialNumber
  881. rfCardId = info.password
  882. taskId = 62
  883. _this.initBluetooth()
  884. }else{
  885. wx.hideLoading()
  886. wx.showToast({
  887. title: res.msg,
  888. mask:true,
  889. icon: 'none',
  890. duration: 2000
  891. })
  892. }
  893. })
  894. } else {
  895. wx.hideLoading()
  896. wx.showToast({
  897. title: '删除失败',
  898. mask:true,
  899. duration: 2000,
  900. icon: 'none'
  901. })
  902. }
  903. })
  904. },
  905. delFp1(index) {
  906. wx.showLoading({
  907. title: '正在删除',
  908. mask: true
  909. })
  910. var cgInfo = this.data.cgInfo
  911. var personLi = this.data.FpList[index]
  912. var deviceinfo = this.data.deviceinfo
  913. var info = JSON.parse(personLi.content)
  914. var person = this.data.personLi
  915. var _this = this
  916. this.getFpIndex(index, function (data) {
  917. if (data.length > 0) {
  918. var FPindex = data[0].face
  919. var timestamp = moment().format("x")
  920. var fingerprintId = ''
  921. if (Number(FPindex) < 9) {
  922. fingerprintId = '0' + FPindex.toString(16)
  923. } else {
  924. fingerprintId = FPindex.toString(16)
  925. }
  926. var data1 = {
  927. managerTelephone: "18270949468",
  928. managerPassword: '202108',
  929. userTelephone: info.userTelephone,
  930. userPassword: info.userPassword,
  931. password: fingerprintId,
  932. startTime: "20210813010101",
  933. endTime: "20680813010101"
  934. }
  935. bleall.startFp1_63(data1.managerTelephone, data1.managerPassword, data1.userTelephone,
  936. data1.userPassword, data1.password, data1.startTime, data1.endTime, 18, timestamp,
  937. function (res) {
  938. if (res.success) {
  939. var dataPasswod = {
  940. code: "ble/operateUserInfo",
  941. data: {
  942. deviceNum: deviceinfo.deviceNum,
  943. imei: deviceinfo.imei,
  944. userTelephone: info.userTelephone,
  945. userPassword: info.userPassword,
  946. password: fingerprintId,
  947. userStartTime: info.passwordStartTime,
  948. userEndTime: info.passwordEndTime,
  949. passwordStartTime: info.passwordStartTime,
  950. passwordEndTime: info.passwordEndTime,
  951. operateMode: 18,
  952. order: 6218,
  953. timestamp: timestamp,
  954. managerTelephone: '18270949468',
  955. managerPassword: '202108',
  956. passwordLength: 10,
  957. permission: 4294967295,
  958. times: 255,
  959. recycleTime: "65535",
  960. roomName: _this.data.deviceinfo.roomName,
  961. cardName: _this.data.personLi.name,
  962. }
  963. }
  964. var data = {
  965. ids: [personLi.id]
  966. }
  967. wx.hideLoading()
  968. WXAPI.deleteCertificates(data).then(res1 => {
  969. if (res1.success) {
  970. _this.getFp()
  971. wx.showToast({
  972. title: '删除成功',
  973. mask:true,
  974. icon: 'none',
  975. duration: 2000
  976. })
  977. } else {
  978. wx.showToast({
  979. title: '删除失败',
  980. mask:true,
  981. icon: 'none',
  982. duration: 2000
  983. })
  984. }
  985. })
  986. WXAPI.sendCommand(dataPasswod).then(res1 => {
  987. console.log(res1, '获取索引')
  988. if (res1.success) {
  989. var data4 = {
  990. result: 1,
  991. serial: res1.data.serialNumber
  992. }
  993. WXAPI.updatePush(data4).then(res4 => {
  994. })
  995. } else {
  996. wx.showToast({
  997. title: res1.msg,
  998. mask:true,
  999. icon: 'none',
  1000. duration: 2000
  1001. })
  1002. }
  1003. })
  1004. }else{
  1005. wx.hideLoading()
  1006. }
  1007. })
  1008. } else {
  1009. wx.hideLoading()
  1010. wx.showToast({
  1011. title: '获取指纹ID失败',
  1012. mask:true,
  1013. duration: 2000,
  1014. icon: 'none'
  1015. })
  1016. }
  1017. })
  1018. },
  1019. delFpLwj(index){
  1020. console.log("删除指纹");
  1021. wx.showLoading({
  1022. title: '正在删除',
  1023. mask: true
  1024. })
  1025. var cgInfo = this.data.cgInfo
  1026. var personLi = this.data.FpList[index]
  1027. var deviceinfo = this.data.deviceinfo
  1028. var info = JSON.parse(personLi.content)
  1029. var person = this.data.personLi
  1030. var _this = this
  1031. this.getFpIndex(index, function (data) {
  1032. if (data.length > 0) {
  1033. var FPindex = data[0].face
  1034. // 删除
  1035. } else {
  1036. wx.hideLoading()
  1037. wx.showToast({
  1038. title: '获取指纹ID失败',
  1039. mask:true,
  1040. duration: 2000,
  1041. icon: 'none'
  1042. })
  1043. }
  1044. })
  1045. },
  1046. delFp(index) {
  1047. wx.showLoading({
  1048. title: '正在删除',
  1049. mask: true
  1050. })
  1051. var cgInfo = this.data.cgInfo
  1052. var personLi = this.data.FpList[index]
  1053. var deviceinfo = this.data.deviceinfo
  1054. var info = JSON.parse(personLi.content)
  1055. var personInfo=JSON.parse(this.data.personLi.info)
  1056. var _this = this
  1057. this.getFpIndex(index, function (data) {
  1058. if (data.length > 0) {
  1059. var FPindex = data[0].face
  1060. var dataPasswod = {
  1061. code: "zg/fpOperate",
  1062. data: {
  1063. lockerId: deviceinfo.deviceNum,
  1064. imei: deviceinfo.imei,
  1065. lockerUserId: personInfo.userId,
  1066. keyId: personInfo.userId,
  1067. fingerId: FPindex,
  1068. fingerType: '0',
  1069. startTime: personLi.startTime,
  1070. endTime: personLi.endTime,
  1071. order: 6218,
  1072. action: 2,
  1073. type: 1,
  1074. roomName: _this.data.deviceinfo.roomName,
  1075. cardName: _this.data.personLi.name,
  1076. }
  1077. }
  1078. WXAPI.sendCommand(dataPasswod).then(res => {
  1079. console.log(res, '获取索引')
  1080. if (res.success) {
  1081. var fingerNo = FPindex.toString(16)
  1082. if (fingerNo < 10) {
  1083. fingerNo = '000' + fingerNo
  1084. } else {
  1085. fingerNo = '00' + fingerNo
  1086. }
  1087. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId,
  1088. (callback) => {
  1089. console.log(callback)
  1090. if (callback.status == '00') {
  1091. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, callback.signKey, (callback1) => {
  1092. console.log(callback1)
  1093. if (callback1.status == '00') {
  1094. var startTime = personLi.startTime.toString(16).toUpperCase()
  1095. var endTime = personLi.endTime.toString(16).toUpperCase()
  1096. console.log(cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, '01', fingerNo, '', callback.signKey, '00', startTime, endTime, callback1.commonKey, '-----')
  1097. ICINLocker.modifyFingerPrints(cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, '01', fingerNo, '', callback.signKey, '00', startTime, endTime, callback1.commonKey, (
  1098. callback2) => {
  1099. console.log(callback2)
  1100. if (callback2.status == '00') {
  1101. var datacom = {
  1102. code: "zg/bleSendVoucherReply",
  1103. data: {
  1104. lockerId: deviceinfo.deviceNum,
  1105. serialNumber: res.data.serialNumber,
  1106. index: FPindex,
  1107. type: 18,
  1108. result: 1
  1109. }
  1110. }
  1111. WXAPI.sendCommand(datacom).then(res2 => {
  1112. console.log(res2, '成功----')
  1113. })
  1114. wx.showToast({
  1115. title: '下发成功',
  1116. mask:true,
  1117. icon: 'none',
  1118. duration: 2000
  1119. })
  1120. var data = {
  1121. ids: [personLi.id]
  1122. }
  1123. wx.hideLoading()
  1124. WXAPI.deleteCertificates(data).then(res1 => {
  1125. if (res1.success) {
  1126. _this.getFp()
  1127. wx.showToast({
  1128. title: '删除成功',
  1129. mask:true,
  1130. icon: 'none',
  1131. duration: 2000
  1132. })
  1133. } else {
  1134. wx.showToast({
  1135. title: '删除失败',
  1136. mask:true,
  1137. icon: 'none',
  1138. duration: 2000
  1139. })
  1140. }
  1141. })
  1142. } else {
  1143. wx.hideLoading()
  1144. wx.showToast({
  1145. title: '删除失败',
  1146. mask:true,
  1147. icon: 'none',
  1148. duration: 2000
  1149. })
  1150. var datacom = {
  1151. code: "zg/bleSendVoucherReply",
  1152. data: {
  1153. lockerId: deviceinfo.deviceNum,
  1154. serialNumber: res.data.serialNumber,
  1155. index: FPindex,
  1156. type: 18,
  1157. result: 0
  1158. }
  1159. }
  1160. WXAPI.sendCommand(datacom).then(res2 => {
  1161. console.log(res2, '失败')
  1162. })
  1163. }
  1164. })
  1165. } else {
  1166. wx.hideLoading()
  1167. wx.showToast({
  1168. title: '删除失败',
  1169. mask:true,
  1170. icon: 'none',
  1171. duration: 2000
  1172. })
  1173. var datacom = {
  1174. code: "zg/bleSendVoucherReply",
  1175. data: {
  1176. lockerId: deviceinfo.deviceNum,
  1177. serialNumber: res.data.serialNumber,
  1178. index: FPindex,
  1179. type: 18,
  1180. result: 0
  1181. }
  1182. }
  1183. WXAPI.sendCommand(datacom).then(res2 => {
  1184. console.log(res2, '失败')
  1185. })
  1186. }
  1187. })
  1188. } else {
  1189. wx.hideLoading()
  1190. wx.showToast({
  1191. title: '删除失败',
  1192. mask:true,
  1193. icon: 'none',
  1194. duration: 2000
  1195. })
  1196. var datacom = {
  1197. code: "zg/bleSendVoucherReply",
  1198. data: {
  1199. lockerId: deviceinfo.deviceNum,
  1200. serialNumber: res.data.serialNumber,
  1201. index: FPindex,
  1202. type: 18,
  1203. result: 0
  1204. }
  1205. }
  1206. WXAPI.sendCommand(datacom).then(res2 => {
  1207. console.log(res2, '失败')
  1208. })
  1209. }
  1210. })
  1211. } else {
  1212. var datacom = {
  1213. code: "zg/bleSendVoucherReply",
  1214. data: {
  1215. lockerId: deviceinfo.deviceNum,
  1216. serialNumber: res.data.serialNumber,
  1217. index: FPindex,
  1218. type: 18,
  1219. result: 0
  1220. }
  1221. }
  1222. WXAPI.sendCommand(datacom).then(res2 => {
  1223. console.log(res2, '失败')
  1224. })
  1225. var data = {
  1226. ids: [personLi.id]
  1227. }
  1228. wx.hideLoading()
  1229. WXAPI.deleteCertificates(data).then(res1 => {
  1230. if (res1.success) {
  1231. _this.getFp()
  1232. }
  1233. })
  1234. wx.hideLoading()
  1235. wx.showToast({
  1236. title: res.msg,
  1237. mask:true,
  1238. icon: 'none',
  1239. duration: 2000
  1240. })
  1241. }
  1242. })
  1243. } else {
  1244. wx.hideLoading()
  1245. wx.showToast({
  1246. title: '获取失败',
  1247. mask:true,
  1248. duration: 2000,
  1249. icon: 'none'
  1250. })
  1251. }
  1252. })
  1253. },
  1254. delPassword1(index) {
  1255. wx.showLoading({
  1256. title: '正在删除',
  1257. mask: true
  1258. })
  1259. var _this = this
  1260. var deviceinfo = this.data.deviceinfo
  1261. var passwordLi = this.data.passwordList[index]
  1262. passwordLiAll = passwordLi
  1263. var info = JSON.parse(passwordLi.content)
  1264. var data = {
  1265. managerTelephone: "18270949468",
  1266. managerPassword: "202108",
  1267. userTelephone: info.userTelephone,
  1268. userPassword: info.userPassword,
  1269. password: info.password,
  1270. startTime: info.passwordStartTime,
  1271. endTime: info.passwordEndTime
  1272. }
  1273. console.log(data)
  1274. var timestamp = moment().format("x")
  1275. bleall.startFp1_63(data.managerTelephone, data.managerPassword, data.userTelephone,
  1276. data.userPassword, data.password, data.startTime, data.endTime, 9, timestamp,
  1277. function (res) {
  1278. if (res.success) {
  1279. var data = {
  1280. ids: [passwordLi.id]
  1281. }
  1282. WXAPI.deleteCertificates(data).then(res1 => {
  1283. if (res1.success) {
  1284. var data3 = {
  1285. code: "ble/operateUserInfo",
  1286. data: {
  1287. deviceNum: deviceinfo.deviceNum,
  1288. imei: deviceinfo.imei,
  1289. userTelephone: info.userTelephone,
  1290. userPassword: info.userPassword,
  1291. password: info.password,
  1292. userStartTime: info.passwordStartTime,
  1293. userEndTime: info.passwordEndTime,
  1294. passwordStartTime: info.passwordStartTime,
  1295. passwordEndTime: info.passwordEndTime,
  1296. operateMode: 9,
  1297. order: 6209,
  1298. timestamp: timestamp,
  1299. managerTelephone: '18270949468',
  1300. managerPassword: '202108',
  1301. passwordLength: 10,
  1302. permission: 4294967295,
  1303. times: 255,
  1304. recycleTime: "65535",
  1305. roomName: _this.data.deviceinfo.roomName,
  1306. cardName: _this.data.personLi.name,
  1307. }
  1308. }
  1309. WXAPI.sendCommand(data3).then(res => {
  1310. if (res.success) {
  1311. var data4 = {
  1312. result: 1,
  1313. serial: res.data.serialNumber
  1314. }
  1315. WXAPI.updatePush(data4).then(res4 => {
  1316. })
  1317. }
  1318. })
  1319. _this.getPassword()
  1320. wx.hideLoading()
  1321. wx.showToast({
  1322. title: '删除成功',
  1323. icon: 'none',
  1324. mask:true,
  1325. duration: 2000
  1326. })
  1327. } else {
  1328. wx.hideLoading()
  1329. wx.showToast({
  1330. title: '删除失败',
  1331. icon: 'none',
  1332. mask:true,
  1333. duration: 2000
  1334. })
  1335. }
  1336. })
  1337. }
  1338. if (res.data == "蓝牙功能暂不支持") {
  1339. // wx.hideLoading()
  1340. // wx.showLoading({
  1341. // title: '重新连接蓝牙中'
  1342. // })
  1343. _this.startconnect()
  1344. }
  1345. })
  1346. },
  1347. startconnect() {
  1348. wx.showLoading({
  1349. title: "连接蓝牙中",
  1350. mask: true
  1351. })
  1352. this.setData({
  1353. showLoading:true
  1354. })
  1355. // this.setData({
  1356. // showLoading:true
  1357. // })
  1358. var deviceinfo = this.data.deviceinfo
  1359. const ble = new BLE(this.data.deviceinfo.deviceNum, emitter)
  1360. app.globalData.ble = ble
  1361. this.watchBLE()
  1362. app.globalData.ble.init()
  1363. // }
  1364. },
  1365. watchBLE() {
  1366. var that = this
  1367. if (app.globalData.ble) {
  1368. app.globalData.ble.listen(res => {
  1369. if (res.type == 'connect') {
  1370. if (res.data == "未打开适配器") {
  1371. this.setData({
  1372. showLoading:false
  1373. })
  1374. wx.hideLoading()
  1375. wx.showModal({
  1376. title: "提示",
  1377. content: "请检查手机蓝牙和定位功能是否打开?",
  1378. showCancel: false,
  1379. confirmText: "确定",
  1380. success(res) {}
  1381. });
  1382. } else {
  1383. if (res.data == '蓝牙已连接') {
  1384. app.globalData.bleStatus = res.data
  1385. this.setData({
  1386. showLoading:false
  1387. })
  1388. if (this.data.current == 0) {
  1389. this.sendPassword()
  1390. } else if (that.data.current == 1) {
  1391. this.delPassword1(this.data.currentIndex)
  1392. } else if (that.data.current == 2) {
  1393. this.sendFp()
  1394. }
  1395. }
  1396. }
  1397. }
  1398. })
  1399. }
  1400. },
  1401. delPasswordLwj(index){
  1402. wx.showLoading({
  1403. title: '正在删除',
  1404. mask: true
  1405. })
  1406. var _this = this
  1407. var deviceinfo = this.data.deviceinfo
  1408. var passwordLi = this.data.passwordList[index]
  1409. passwordLiAll = passwordLi
  1410. var info = JSON.parse(passwordLi.content)
  1411. var personInfo=JSON.parse(this.data.personLi.info)
  1412. var cgInfo = this.data.cgInfo
  1413. var dataPasswod = {
  1414. code: "lwj/passwordOperate",
  1415. data: {
  1416. lockerId: deviceinfo.deviceNum,
  1417. lockerUserId: personInfo.userId,
  1418. startTime:passwordLi.startTime,
  1419. endTime:passwordLi.endTime,
  1420. order: 6209,
  1421. operateMode:9,
  1422. action: 2,
  1423. password: info.password,
  1424. type: 9,
  1425. cardName:_this.data.personLi.name,
  1426. roomName:deviceinfo.roomName
  1427. }
  1428. }
  1429. console.log(dataPasswod,'dataPasswod',info)
  1430. WXAPI.sendCommand(dataPasswod).then(res => {
  1431. console.log(res, '获取索引')
  1432. if (res.success) {
  1433. pincodeIndex = res.data.index
  1434. serialNumber = res.data.serialNumber
  1435. taskId = 52
  1436. _this.initBluetooth()
  1437. }else{
  1438. wx.hideLoading()
  1439. wx.showToast({
  1440. title: res.msg,
  1441. mask:true,
  1442. icon: 'none',
  1443. duration: 2000
  1444. })
  1445. }
  1446. })
  1447. },
  1448. onDelRfCard: function () {
  1449. var that = this
  1450. wx.showLoading({
  1451. title: '删除房卡中',
  1452. })
  1453. var bytes = plugin.delRfCard(lockDevice.name, basecode, rfCardId, rfCardIndex)
  1454. console.debug('bytes', bytes)
  1455. that.sendBytes(bytes)
  1456. },
  1457. onDelPincode: function () {
  1458. var that = this
  1459. wx.showLoading({
  1460. title: '删除密码中',
  1461. })
  1462. var bytes = plugin.delPincode(lockDevice.name, basecode, pincode, pincodeIndex)
  1463. console.debug('bytes', bytes)
  1464. that.sendBytes(bytes)
  1465. },
  1466. delPassword(index) {
  1467. wx.showLoading({
  1468. title: '正在删除',
  1469. mask: true
  1470. })
  1471. var _this = this
  1472. var deviceinfo = this.data.deviceinfo
  1473. var passwordLi = this.data.passwordList[index]
  1474. passwordLiAll = passwordLi
  1475. var info = JSON.parse(passwordLi.content)
  1476. var personInfo=JSON.parse(this.data.personLi.info)
  1477. var cgInfo = this.data.cgInfo
  1478. var dataPasswod = {
  1479. code: "zg/tempPassword",
  1480. data: {
  1481. lockerId: deviceinfo.deviceNum,
  1482. imei: deviceinfo.imei,
  1483. passwordCount: 255,
  1484. lockerUserId: personInfo.userId,
  1485. keyId: personInfo.userId,
  1486. passwordStartTime: passwordLi.startTime,
  1487. passwordEndTime: passwordLi.endTime,
  1488. order: 6209,
  1489. action: 2,
  1490. password: info.password,
  1491. type: 1,
  1492. cardName:_this.data.personLi.name,
  1493. roomName:deviceinfo.roomName
  1494. }
  1495. }
  1496. console.log(dataPasswod,'dataPasswod',info)
  1497. WXAPI.sendCommand(dataPasswod).then(res => {
  1498. console.log(res, '获取索引')
  1499. if (res.success) {
  1500. var pwdNo = res.data.index.toString(16)
  1501. var passwordIndex = res.data.index
  1502. if (pwdNo < 9) {
  1503. pwdNo = '0' + pwdNo
  1504. } else {
  1505. pwdNo = pwdNo
  1506. }
  1507. ICINLocker.getUserSignKey(cgInfo.lockerId, cgInfo.superId, personInfo.userId, cgInfo.superId, cgInfo.authKey, '01', (callback) => {
  1508. console.log(callback)
  1509. if (callback.status == '00') {
  1510. var userSignKey = callback.userSignKey
  1511. ICINLocker.getCommonKey(cgInfo.lockerId,personInfo.userId, personInfo.userId, userSignKey, (callback) => {
  1512. if (callback.status == '00') {
  1513. console.log(callback, 'commonKey')
  1514. var commonKey = callback.commonKey
  1515. var startTime = passwordLi.startTime.toString(16).toUpperCase()
  1516. var endTime = passwordLi.endTime.toString(16).toUpperCase()
  1517. ICINLocker.handlePwd(deviceinfo.deviceNum, cgInfo.superId, personInfo.userId, info.password, pwdNo, cgInfo.superId, cgInfo.authKey, '', startTime, endTime, 0, commonKey, (callback) => {
  1518. console.log(callback)
  1519. if (callback.status == '00') {
  1520. var datacom = {
  1521. code: "zg/bleSendVoucherReply",
  1522. data: {
  1523. lockerId: deviceinfo.deviceNum,
  1524. serialNumber: res.data.serialNumber,
  1525. index: passwordIndex,
  1526. type: 9,
  1527. result: 1
  1528. }
  1529. }
  1530. WXAPI.sendCommand(datacom).then(res2 => {
  1531. if (res2.success) {}
  1532. })
  1533. var data = {
  1534. ids: [passwordLiAll.id]
  1535. }
  1536. WXAPI.deleteCertificates(data).then(res1 => {
  1537. if (res1.success) {
  1538. _this.getPassword()
  1539. wx.hideLoading()
  1540. wx.showToast({
  1541. title: '删除成功',
  1542. mask:true,
  1543. icon: 'none',
  1544. duration: 2000
  1545. })
  1546. } else {
  1547. wx.hideLoading()
  1548. wx.showToast({
  1549. title: '删除失败',
  1550. mask:true,
  1551. icon: 'none',
  1552. duration: 2000
  1553. })
  1554. }
  1555. })
  1556. } else {
  1557. wx.hideLoading()
  1558. wx.showToast({
  1559. title: '删除失败',
  1560. mask:true,
  1561. icon: 'none',
  1562. duration: 2000
  1563. })
  1564. var datacom = {
  1565. code: "zg/bleSendVoucherReply",
  1566. data: {
  1567. lockerId: deviceinfo.deviceNum,
  1568. serialNumber: res.data.serialNumber,
  1569. index: res.data.index,
  1570. type: 9,
  1571. result: 0
  1572. }
  1573. }
  1574. WXAPI.sendCommand(datacom).then(res2 => {
  1575. console.log(res2, '失败')
  1576. })
  1577. }
  1578. })
  1579. } else {
  1580. wx.hideLoading()
  1581. wx.showToast({
  1582. title: '删除失败',
  1583. mask:true,
  1584. icon: 'none',
  1585. duration: 2000
  1586. })
  1587. }
  1588. })
  1589. } else {
  1590. wx.hideLoading()
  1591. wx.showToast({
  1592. title: '删除失败',
  1593. mask:true,
  1594. icon: 'none',
  1595. duration: 2000
  1596. })
  1597. }
  1598. })
  1599. } else {
  1600. wx.hideLoading()
  1601. wx.showToast({
  1602. title: res.msg,
  1603. mask:true,
  1604. icon: 'none',
  1605. duration: 2000
  1606. })
  1607. }
  1608. })
  1609. },
  1610. getPassWordMehods(content,id,type){
  1611. var that=this
  1612. var data = {
  1613. pageNum: 0,
  1614. pageSize: 0,
  1615. orderBy: "create_at desc",
  1616. q: {
  1617. cardId: id,
  1618. password:content,
  1619. deviceNum:this.data.deviceinfo.deviceNum,
  1620. types: type,
  1621. inStatus:'0,1,702'
  1622. },
  1623. };
  1624. WXAPI.getCertificates(data).then(res=>{
  1625. if(res.success){
  1626. var dataOne=util.zlib_unzip(res.data)
  1627. if(dataOne.length>0){
  1628. wx.showModal({
  1629. title: '提示',
  1630. content: '该密码已存在,不能重复添加',
  1631. success (res1) {
  1632. if (res1.confirm) {
  1633. console.log('用户点击确定')
  1634. that.setData({
  1635. password:'',
  1636. passwordStatus:false
  1637. })
  1638. } else if (res1.cancel) {
  1639. console.log('用户点击取消')
  1640. that.setData({
  1641. password:'',
  1642. passwordStatus:false
  1643. })
  1644. }
  1645. }
  1646. })
  1647. }else{
  1648. this.setData({
  1649. passwordStatus:true
  1650. })
  1651. }
  1652. }else{
  1653. wx.showToast({
  1654. title: '获取失败',
  1655. duration:'2000',
  1656. mask:true,
  1657. icon:'none'
  1658. })
  1659. }
  1660. })
  1661. },
  1662. sendPassword() {
  1663. let passwordLength = this.data.password.toString()
  1664. if(passwordLength.length != 6){
  1665. wx.showToast({
  1666. title: '格式错误,密码为6位数字!',
  1667. icon:'none'
  1668. })
  1669. return false;
  1670. }
  1671. wx.showLoading({
  1672. title: '正在添加',
  1673. mask:true,
  1674. })
  1675. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  1676. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  1677. var passwordStartTimecontrast = time3.getTime() / 1000
  1678. var passwordEndTimecontrast = time4.getTime() / 1000
  1679. this.getPassWordMehods(this.data.password,this.data.personLi.cardId,14)
  1680. if(this.data.password==''){
  1681. wx.showToast({
  1682. title: '密码不能为空',
  1683. mask:true,
  1684. duration: 2000,
  1685. icon: 'none'
  1686. })
  1687. return
  1688. }
  1689. if(!this.data.passwordStatus){
  1690. wx.showToast({
  1691. title: '已存在该密码,请重输',
  1692. duration: 2000,
  1693. mask:true,
  1694. icon: 'none'
  1695. })
  1696. return
  1697. }
  1698. if (passwordStartTimecontrast > passwordEndTimecontrast) {
  1699. wx.showToast({
  1700. title: '开始时间不能大于结束时间',
  1701. duration: 2000,
  1702. mask:true,
  1703. icon: 'none'
  1704. })
  1705. return
  1706. }
  1707. wx.showLoading({
  1708. title: '正在添加',
  1709. mask:true
  1710. })
  1711. var _this = this
  1712. var deviceinfo = this.data.deviceinfo
  1713. var info = JSON.parse(this.data.personLi.info)
  1714. if (deviceinfo.manufactureId == 101) {
  1715. var time1 = moment(this.data.datetimerange[0]).format("YYYYMMDDHHmmss")
  1716. var time2 = moment(this.data.datetimerange[1]).format("YYYYMMDDHHmmss")
  1717. var time3 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  1718. var time4 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  1719. var passwordStartTime = time3.getTime() / 1000
  1720. var passwordEndTime = time4.getTime() / 1000
  1721. var data1 = {
  1722. managerTelephone: "18270949468",
  1723. managerPassword: '202108',
  1724. userTelephone: info.userTelephone,
  1725. userPassword: info.userPassword,
  1726. password: this.data.password,
  1727. startTime: time1,
  1728. endTime: time2
  1729. }
  1730. var timestamp = moment().format("x")
  1731. bleall.startFp1_63(data1.managerTelephone, data1.managerPassword, data1.userTelephone,
  1732. data1.userPassword, data1.password, data1.startTime, data1.endTime, 7, timestamp,
  1733. function (res) {
  1734. console.log(res)
  1735. if (res.success) {
  1736. var pzname='',cardName=''
  1737. pzname='蓝牙-密码'+(_this.data.passwordList.length+1)
  1738. cardName=_this.data.personLi.name+'-蓝牙-密码'+(_this.data.passwordList.length+1)
  1739. var str = {
  1740. // cardId: this.personInfo.cardId,
  1741. pzname:pzname,
  1742. imei: _this.data.deviceinfo.imei,
  1743. password: _this.data.password.toString(),
  1744. userTelephone: JSON.parse(_this.data.personLi.info).userTelephone,
  1745. operateMode: 7,
  1746. userPassword: JSON.parse(_this.data.personLi.info).userPassword,
  1747. passwordStartTime: time1,
  1748. passwordEndTime: time2,
  1749. is: false,
  1750. pass:true
  1751. }
  1752. var data3 = {
  1753. code: "ble/operateUserInfo",
  1754. data: {
  1755. deviceNum: _this.data.deviceinfo.deviceNum,
  1756. imei: _this.data.deviceinfo.imei,
  1757. userTelephone: info.userTelephone,
  1758. userPassword: info.userPassword,
  1759. password: _this.data.password,
  1760. userStartTime: time1,
  1761. userEndTime: time2,
  1762. passwordStartTime: time1,
  1763. passwordEndTime: time2,
  1764. operateMode: 7,
  1765. order: 6207,
  1766. timestamp: timestamp,
  1767. managerTelephone: '18270949468',
  1768. managerPassword: '202108',
  1769. passwordLength: 10,
  1770. permission: 4294967295,
  1771. times: 255,
  1772. recycleTime: "65535",
  1773. roomName: _this.data.deviceinfo.roomName,
  1774. cardName: cardName,
  1775. }
  1776. }
  1777. WXAPI.sendCommand(data3).then(res3 => {
  1778. if (res3.success) {
  1779. var data4 = {
  1780. result: 1,
  1781. serial: res3.data.serialNumber
  1782. }
  1783. WXAPI.updatePush(data4).then(res4 => {
  1784. })
  1785. var data = {
  1786. cardId: _this.data.personLi.cardId,
  1787. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1788. deviceNum: _this.data.deviceinfo.deviceNum,
  1789. type: 4,
  1790. imei: _this.data.deviceinfo.imei,
  1791. serial: res3.data.serialNumber,
  1792. startTime: passwordStartTime,
  1793. endTime: passwordEndTime,
  1794. };
  1795. var datalist = {
  1796. cardId: _this.data.personLi.cardId,
  1797. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1798. type: 14,
  1799. startTime: passwordStartTime,
  1800. endTime: passwordEndTime,
  1801. };
  1802. console.log(datalist,'密码11')
  1803. WXAPI.addCertificates(datalist).then(res6 => {
  1804. console.log(datalist,'密码22')
  1805. })
  1806. WXAPI.addCertificates(data).then(res3 => {
  1807. if (res3.success) {
  1808. var updatedata = {
  1809. id: res3.data,
  1810. status:1
  1811. };
  1812. WXAPI.updateCertificates(updatedata).then((res2) => {
  1813. });
  1814. _this.getPassword()
  1815. _this.setData({
  1816. show: false
  1817. })
  1818. wx.hideLoading()
  1819. wx.showToast({
  1820. title: '添加成功',
  1821. icon: 'none',
  1822. mask:true,
  1823. duration: 2000
  1824. })
  1825. } else {
  1826. wx.hideLoading()
  1827. wx.showToast({
  1828. title: '添加失败',
  1829. mask:true,
  1830. icon: 'none',
  1831. duration: 2000
  1832. })
  1833. }
  1834. })
  1835. } else {
  1836. wx.showToast({
  1837. title: res3.msg,
  1838. mask:true,
  1839. icon: 'none',
  1840. duration: 2000
  1841. })
  1842. }
  1843. })
  1844. }else{
  1845. wx.hideLoading()
  1846. if (res.data == "蓝牙功能暂不支持") {
  1847. // wx.showToast({
  1848. // title: '重新连接蓝牙中',
  1849. // duration: 2000,
  1850. // icon: "none"
  1851. // })
  1852. _this.startconnect()
  1853. }else{
  1854. wx.showToast({
  1855. title: '下发失败',
  1856. mask:true,
  1857. duration: 2000,
  1858. icon: "none"
  1859. })
  1860. }
  1861. }
  1862. })
  1863. } else if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  1864. var cgInfo = this.data.cgInfo
  1865. var time1 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  1866. var time2 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  1867. var passwordStartTime = time1.getTime() / 1000
  1868. var passwordEndTime = time2.getTime() / 1000
  1869. var pzname='',cardName=''
  1870. pzname='蓝牙-密码'+(_this.data.passwordList.length+1)
  1871. cardName=_this.data.personLi.name+'-蓝牙-密码'+(_this.data.passwordList.length+1)
  1872. var dataPasswod = {
  1873. code: "zg/tempPassword",
  1874. data: {
  1875. lockerId: deviceinfo.deviceNum,
  1876. imei: deviceinfo.imei,
  1877. passwordCount: 255,
  1878. lockerUserId: info.userId,
  1879. keyId: info.userId,
  1880. passwordStartTime: passwordStartTime,
  1881. passwordEndTime: passwordEndTime,
  1882. order: 6207,
  1883. action: 1,
  1884. password: this.data.password.toString(),
  1885. type: 1,
  1886. roomName: this.data.deviceinfo.roomName,
  1887. cardName: cardName,
  1888. }
  1889. }
  1890. WXAPI.sendCommand(dataPasswod).then(res => {
  1891. console.log(res, '获取索引')
  1892. if (res.success) {
  1893. var pwdNo = res.data.index
  1894. var passwordIndex = res.data.index
  1895. // var str = res.data.index
  1896. pwdNo = pwdNo.toString(16)
  1897. if (pwdNo.length < 2) {
  1898. pwdNo='0'+pwdNo
  1899. }
  1900. var startTime = passwordStartTime.toString(16).toUpperCase()
  1901. var endTime = passwordEndTime.toString(16).toUpperCase()
  1902. info.startTime=startTime
  1903. info.endTime=endTime
  1904. info.pwdNo=pwdNo
  1905. info.password=this.data.password.toString()
  1906. methods.bluetoothOperation_ZH(cgInfo,info,3).then(result=>{
  1907. if (result.status == '00' ||result.status == '0a' ) {
  1908. var datacom = {
  1909. code: "zg/bleSendVoucherReply",
  1910. data: {
  1911. lockerId: deviceinfo.deviceNum,
  1912. serialNumber: res.data.serialNumber,
  1913. index: passwordIndex,
  1914. type: 7,
  1915. result: 1
  1916. }
  1917. }
  1918. var str = {
  1919. // cardId: this.personInfo.cardId,
  1920. imei: _this.data.deviceinfo.imei,
  1921. pzname:pzname,
  1922. password: _this.data.password.toString(),
  1923. userTelephone: JSON.parse(_this.data.personLi.info).userTelephone,
  1924. operateMode: 7,
  1925. userPassword: JSON.parse(_this.data.personLi.info).userPassword,
  1926. passwordStartTime: passwordStartTime,
  1927. passwordEndTime: passwordEndTime,
  1928. is: false,
  1929. pass:true
  1930. }
  1931. var data = {
  1932. cardId: _this.data.personLi.cardId,
  1933. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1934. deviceNum: _this.data.deviceinfo.deviceNum,
  1935. type: 4,
  1936. imei: _this.data.deviceinfo.imei,
  1937. serial: res.data.serialNumber,
  1938. startTime: passwordStartTime,
  1939. endTime: passwordEndTime,
  1940. };
  1941. var datalist = {
  1942. cardId: _this.data.personLi.cardId,
  1943. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1944. type: 14,
  1945. startTime: passwordStartTime,
  1946. endTime: passwordEndTime,
  1947. };
  1948. console.log(datalist,'密码11')
  1949. WXAPI.addCertificates(datalist).then(res6 => {
  1950. console.log(datalist,'密码22',res6)
  1951. })
  1952. console.log(data, '添加凭证')
  1953. WXAPI.addCertificates(data).then(res3 => {
  1954. if (res3.success) {
  1955. var updatedata = {
  1956. id: res3.data,
  1957. status:1
  1958. };
  1959. WXAPI.updateCertificates(updatedata).then((res2) => {
  1960. });
  1961. WXAPI.sendCommand(datacom).then(res2 => {
  1962. if (res2.success) {}
  1963. })
  1964. console.log(res3, '添加凭证成功')
  1965. _this.getPassword()
  1966. _this.setData({
  1967. show: false
  1968. })
  1969. wx.hideLoading()
  1970. wx.showToast({
  1971. title: '添加成功',
  1972. mask:true,
  1973. icon: 'none',
  1974. duration: 2000
  1975. })
  1976. } else {
  1977. wx.hideLoading()
  1978. wx.showToast({
  1979. title: '添加失败',
  1980. mask:true,
  1981. icon: 'none',
  1982. duration: 2000
  1983. })
  1984. }
  1985. })
  1986. } else {
  1987. wx.showToast({
  1988. title: '添加失败',
  1989. mask:true,
  1990. icon: 'none',
  1991. duration: 2000
  1992. })
  1993. var datacom = {
  1994. code: "zg/bleSendVoucherReply",
  1995. data: {
  1996. lockerId: deviceinfo.deviceNum,
  1997. serialNumber: res.data.serialNumber,
  1998. index: res.data.index,
  1999. type: 7,
  2000. result: 0
  2001. }
  2002. }
  2003. WXAPI.sendCommand(datacom).then(res2 => {
  2004. console.log(res2, '失败')
  2005. _this.setData({
  2006. show: false
  2007. })
  2008. })
  2009. }
  2010. }).catch(err=>{
  2011. wx.hideLoading()
  2012. wx.showToast({
  2013. title: '添加失败',
  2014. icon: 'none',
  2015. mask:true,
  2016. duration: 2000
  2017. })
  2018. var datacom = {
  2019. code: "zg/bleSendVoucherReply",
  2020. data: {
  2021. lockerId: deviceinfo.deviceNum,
  2022. serialNumber: res.data.serialNumber,
  2023. index: res.data.index,
  2024. type: 7,
  2025. result: 0
  2026. }
  2027. }
  2028. WXAPI.sendCommand(datacom).then(res2 => {
  2029. console.log(res2, '失败')
  2030. _this.setData({
  2031. show: false
  2032. })
  2033. })
  2034. })
  2035. } else {
  2036. wx.showToast({
  2037. title: res.msg,
  2038. duration: 2000,
  2039. mask:true,
  2040. icon: 'none'
  2041. })
  2042. }
  2043. })
  2044. }else if (deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241){
  2045. console.log(this.data.isSearch);
  2046. if(this.data.isSearch){
  2047. wx.hideLoading()
  2048. this.addPincode()
  2049. }else{
  2050. this.searchDevicesMethods()
  2051. }
  2052. }
  2053. },
  2054. onAddPincode: function () {
  2055. console.log("2073123");
  2056. var that = this
  2057. wx.showLoading({
  2058. title: '添加密码中',
  2059. })
  2060. var info = JSON.parse(this.data.personLi.info)
  2061. let deviceinfo = this.data.deviceinfo
  2062. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  2063. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  2064. var passwordStartTime = time1.getTime() / 1000
  2065. var passwordEndTime = time2.getTime() / 1000
  2066. var pzname='',cardName=''
  2067. pzname='蓝牙-密码'+(that.data.passwordList.length+1)
  2068. cardName=that.data.personLi.name+'-蓝牙-密码'+(that.data.passwordList.length+1)
  2069. var dataPasswod = {
  2070. code: "lwj/passwordOperate",
  2071. data: {
  2072. lockerId: deviceinfo.deviceNum,
  2073. lockerUserId: info.userId,
  2074. startTime:passwordStartTime,
  2075. endTime:passwordEndTime,
  2076. order: 6207,
  2077. operateMode:7,
  2078. action: 1,
  2079. password: this.data.password.toString(),
  2080. type: 7,
  2081. roomName: this.data.deviceinfo.roomName,
  2082. cardName: cardName,
  2083. }
  2084. }
  2085. WXAPI.sendCommand(dataPasswod).then(res => {
  2086. console.log(res, '获取索引')
  2087. if (res.success) {
  2088. var pwdNo = res.data.index
  2089. serialNumber = res.data.serialNumber
  2090. pincodeIndex = pwdNo
  2091. that.sendAddPincode()
  2092. }
  2093. })
  2094. // var startTime = util1.getLocalTime(8)
  2095. // var endTime = new Date(startTime.getTime() + 5 * 60 * 1000) //有效期5分钟
  2096. },
  2097. sendAddPincode(){
  2098. var that =this
  2099. var startTime = new Date(Number(moment(that.data.starttime).format('x')))
  2100. var endTime = new Date(Number(moment(that.data.endtime).format('x')))
  2101. pincode = this.data.password
  2102. console.log(lockDevice.name, basecode, pincode, pincodeIndex, startTime, endTime)
  2103. let bytes = plugin.addPincode(lockDevice.name, basecode, pincode, pincodeIndex, startTime, endTime)
  2104. console.log('bytes', bytes)
  2105. that.sendBytes(bytes)
  2106. },
  2107. addPincode: function () {
  2108. console.log("2124");
  2109. var that = this
  2110. taskId = 51
  2111. that.initBluetooth()
  2112. },
  2113. initBluetooth: function () {
  2114. var that = this
  2115. wx.getConnectedBluetoothDevices({
  2116. services: [config.uuid.serviceUuid],
  2117. success: function (res) {
  2118. res.devices.map(function (it) {
  2119. if (it.deviceId == connectedDeviceId || it.name == that.data.deviceinfo.deviceNum) {
  2120. isConnected = true
  2121. }
  2122. })
  2123. that.setData({
  2124. isConnected: isConnected
  2125. })
  2126. console.log(isInitReady,'isConnected', isConnected)
  2127. if (isConnected) {
  2128. console.log("2144");
  2129. if (isInitReady) {
  2130. console.log("2146");
  2131. that.doWork()
  2132. } else {
  2133. that.setupConnection()
  2134. }
  2135. } else {
  2136. that.connectTo()
  2137. }
  2138. },
  2139. })
  2140. },
  2141. setupConnection: function () {
  2142. var that = this
  2143. wx.showLoading({
  2144. title: '初始化连接中',
  2145. })
  2146. wx.getBLEDeviceServices({
  2147. deviceId: lockDevice.deviceId,
  2148. success: function (res) {
  2149. console.log('Services', res)
  2150. wx.getBLEDeviceCharacteristics({
  2151. deviceId: lockDevice.deviceId,
  2152. serviceId: config.uuid.serviceUuid.toUpperCase(),
  2153. success: function (res) {
  2154. console.log('Characteristics', res)
  2155. wx.showToast({
  2156. title: '连接成功',
  2157. duration:1000,
  2158. icon:'none'
  2159. })
  2160. wx.onBLECharacteristicValueChange(function (res) {
  2161. console.log(res,'reslllllll')
  2162. var bytes = new Uint8Array(res.value)
  2163. console.log('bytes', bytes)
  2164. var data = plugin.parseBytes(lockDevice.name, basecode, bytes)
  2165. console.log('data', data)
  2166. switch (data.cmd) {
  2167. case 'reportLockBattery': {
  2168. if (data.data.battery < 10) {
  2169. wx.showModal({
  2170. title: '电量报警',
  2171. content: `门锁当前电量${data.data.battery}%!\n电量严重不足,请立即更换电池!`,
  2172. showCancel: false
  2173. })
  2174. } else if (data.data.battery < 30) {
  2175. wx.showModal({
  2176. title: '电量预警',
  2177. content: `门锁当前电量${data.data.battery}%!\n请及时更换电池!`,
  2178. showCancel: false
  2179. })
  2180. }
  2181. break
  2182. }
  2183. case 'reportRfCardResult': {
  2184. if (taskId == 61) {
  2185. wx.showModal({
  2186. title: '检测到新卡',
  2187. content: `是否添加此房卡,卡号:${data.data.cardId}`,
  2188. success: function (res) {
  2189. if (res.confirm) {
  2190. console.log( data.data,'rfCardIdrfCardId')
  2191. // rfCardId = randomMethods()//data.data.cardId
  2192. that.onAddRfCard()
  2193. }
  2194. }
  2195. })
  2196. } else {
  2197. if (lockModel > 70) {
  2198. if (data.data.isValid) {
  2199. wx.showModal({
  2200. title: '提示',
  2201. content: `房卡开锁成功,序号:${data.data.index}`,
  2202. showCancel: false
  2203. })
  2204. } else {
  2205. wx.showModal({
  2206. title: '提示',
  2207. content: `多次刷房卡开锁失败!`,
  2208. showCancel: false
  2209. })
  2210. }
  2211. } else {
  2212. if (data.data.isValid) {
  2213. wx.showModal({
  2214. title: '提示',
  2215. content: `房卡开锁成功,卡号:${data.data.cardId}`,
  2216. showCancel: false
  2217. })
  2218. } else {
  2219. wx.showModal({
  2220. title: '提示',
  2221. content: `房卡未授权,卡号:${data.data.cardId}`,
  2222. showCancel: false
  2223. })
  2224. }
  2225. }
  2226. }
  2227. break
  2228. }
  2229. case 'reportPincodeResult': {
  2230. if (lockModel > 70) {
  2231. if (data.data.isValid) {
  2232. wx.showModal({
  2233. title: '提示',
  2234. content: `密码开锁成功,序号:${data.data.index}`,
  2235. showCancel: false
  2236. })
  2237. } else {
  2238. wx.showModal({
  2239. title: '提示',
  2240. content: `多次密码开锁失败!`,
  2241. showCancel: false
  2242. })
  2243. }
  2244. } else {
  2245. if (data.data.isValid) {
  2246. wx.showModal({
  2247. title: '提示',
  2248. content: `密码:${data.data.pincode}开锁成功!`,
  2249. showCancel: false
  2250. })
  2251. } else {
  2252. wx.showModal({
  2253. title: '提示',
  2254. content: `密码:${data.data.pincode}未授权!`,
  2255. showCancel: false
  2256. })
  2257. }
  2258. }
  2259. break
  2260. }
  2261. case 'reportFingerprintResult': {
  2262. if (data.data.isValid) {
  2263. wx.showModal({
  2264. title: '提示',
  2265. content: `指纹开锁成功,序号:${data.data.index}`,
  2266. showCancel: false
  2267. })
  2268. } else {
  2269. wx.showModal({
  2270. title: '提示',
  2271. content: `多次指纹开锁失败!`,
  2272. showCancel: false
  2273. })
  2274. }
  2275. break
  2276. }
  2277. case 'queryLockState': {
  2278. wx.hideLoading()
  2279. if (data.code != 200) {
  2280. wx.showModal({
  2281. title: '提示',
  2282. content: '查询失败!',
  2283. showCancel: false,
  2284. success: function (res) {}
  2285. })
  2286. break
  2287. }
  2288. that.setData({
  2289. lock: {
  2290. mac: data.data.mac,
  2291. lockType: util1.getLockType(lockModel),
  2292. },
  2293. isBindLock: data.data.isBind
  2294. })
  2295. lockMac = data.data.mac
  2296. if (taskId > 0) {
  2297. if (data.data.isBind) {
  2298. // wx.showModal({
  2299. // title: data.data.mac,
  2300. // content: '此设备已经硬件绑定!',
  2301. // showCancel: false,
  2302. // success: function (res) {}
  2303. // })
  2304. } else {
  2305. wx.showModal({
  2306. title: data.data.mac,
  2307. content: '此设备硬件未绑定!',
  2308. showCancel: false,
  2309. success: function (res) {}
  2310. })
  2311. }
  2312. }
  2313. taskId = 0
  2314. break
  2315. }
  2316. case 'queryLockBattery': {
  2317. wx.hideLoading()
  2318. if (data.code != 200) {
  2319. wx.showModal({
  2320. title: '提示',
  2321. content: '查询失败!',
  2322. showCancel: false,
  2323. success: function (res) {}
  2324. })
  2325. break
  2326. }
  2327. taskId = 0
  2328. wx.showModal({
  2329. title: '提示',
  2330. content: `此门锁电量为${data.data.battery}%`,
  2331. showCancel: false,
  2332. success: function (res) {}
  2333. })
  2334. break
  2335. }
  2336. case 'queryNbImei': {
  2337. wx.hideLoading()
  2338. if (data.code != 200) {
  2339. wx.showModal({
  2340. title: '提示',
  2341. content: '查询失败!',
  2342. showCancel: false,
  2343. success: function (res) {}
  2344. })
  2345. break
  2346. }
  2347. taskId = 0
  2348. wx.showModal({
  2349. title: '提示',
  2350. content: `此NB设备IMEI为${data.data.imei}`,
  2351. showCancel: false,
  2352. success: function (res) {}
  2353. })
  2354. break
  2355. }
  2356. case 'setNbFun': {
  2357. wx.hideLoading()
  2358. if (data.code != 200) {
  2359. wx.showModal({
  2360. title: '提示',
  2361. content: '设置Nb功能失败!',
  2362. showCancel: false,
  2363. success: function (res) {}
  2364. })
  2365. break
  2366. }
  2367. taskId = 0
  2368. wx.showModal({
  2369. title: '提示',
  2370. content: that.data.isNbEnable ? 'NB功能已禁用' : 'NB功能已打开',
  2371. showCancel: false,
  2372. })
  2373. that.setData({
  2374. isNbEnable: !that.data.isNbEnable
  2375. })
  2376. break
  2377. }
  2378. case 'sendBindLock': {
  2379. wx.hideLoading()
  2380. if (data.code != 200) {
  2381. wx.showModal({
  2382. title: '提示',
  2383. content: '绑定失败!',
  2384. showCancel: false,
  2385. success: function (res) {}
  2386. })
  2387. break
  2388. }
  2389. taskId = 0
  2390. that.setData({
  2391. isBindLock: data.data.isBind
  2392. })
  2393. if (data.data.isBind) {
  2394. wx.showToast({
  2395. title: '绑定成功!',
  2396. })
  2397. } else {
  2398. wx.showToast({
  2399. title: '绑定失败!',
  2400. })
  2401. }
  2402. break
  2403. }
  2404. case 'sendUnbindLock': {
  2405. wx.hideLoading()
  2406. if (data.code != 200) {
  2407. wx.showModal({
  2408. title: '提示',
  2409. content: '解绑失败!',
  2410. showCancel: false,
  2411. success: function (res) {}
  2412. })
  2413. break
  2414. }
  2415. taskId = 0
  2416. that.setData({
  2417. isBindLock: data.data.isBind
  2418. })
  2419. if (data.data.isBind) {
  2420. wx.showToast({
  2421. title: '解绑失败!',
  2422. })
  2423. } else {
  2424. wx.showToast({
  2425. title: '解绑成功!',
  2426. })
  2427. }
  2428. break
  2429. }
  2430. case 'login1':
  2431. case 'sendOpenLockP1': {
  2432. if (data.code != 200) {
  2433. wx.hideLoading()
  2434. if (taskId == 41) {
  2435. wx.showModal({
  2436. title: '提示',
  2437. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  2438. showCancel: false,
  2439. success: function (res) {}
  2440. })
  2441. } else if (taskId == 32) {
  2442. wx.showModal({
  2443. title: '提示',
  2444. content: '登录失败!',
  2445. showCancel: false,
  2446. success: function (res) {}
  2447. })
  2448. }
  2449. break
  2450. }
  2451. if (taskId == 41) {
  2452. var bytes = plugin.sendOpenLockP2(lockDevice.name, basecode, data.data.randomN)
  2453. console.debug('bytes', bytes)
  2454. that.sendBytes(bytes)
  2455. } else if (taskId == 32) {
  2456. var bytes = plugin.login2(lockDevice.name, basecode, data.data.randomN)
  2457. console.debug('bytes', bytes)
  2458. that.sendBytes(bytes)
  2459. }
  2460. break;
  2461. }
  2462. case 'login':
  2463. case 'sendOpenLockP2': {
  2464. wx.hideLoading()
  2465. if (data.code != 200) {
  2466. if (taskId == 41) {
  2467. wx.showModal({
  2468. title: '提示',
  2469. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  2470. showCancel: false,
  2471. success: function (res) {}
  2472. })
  2473. } else if (taskId == 32) {
  2474. wx.showModal({
  2475. title: '提示',
  2476. content: '登录失败!',
  2477. showCancel: false,
  2478. success: function (res) {}
  2479. })
  2480. }
  2481. break
  2482. }
  2483. isLockLogin = true
  2484. if (taskId == 41) {
  2485. // var data = {
  2486. // code: "zg/bleUnlockRecord",
  2487. // data: {
  2488. // lockerId: that.data.deviceinfo.deviceNum,
  2489. // roomId:that.data.deviceinfo.roomId,
  2490. // roomName:that.data.deviceinfo.roomName,
  2491. // cardName:that.data.userInfo.username
  2492. // }
  2493. // }
  2494. var data = {
  2495. code: "ble/bleUnlockRecord",
  2496. data: {
  2497. deviceNum: that.data.deviceinfo.deviceNum,
  2498. roomId:that.data.deviceinfo.roomId,
  2499. roomName:that.data.deviceinfo.roomName,
  2500. cardName:that.data.userInfo.username,
  2501. productId:that.data.deviceinfo.manufactureId,
  2502. userId:'29283991'
  2503. }
  2504. }
  2505. WXAPI.sendCommand(data).then(res => {
  2506. console.log(res)
  2507. })
  2508. wx.showToast({
  2509. title: that.data.isJack ? '上电成功!' : '解锁成功!',
  2510. })
  2511. } else if (taskId == 32) {
  2512. wx.showToast({
  2513. title: '登录成功!',
  2514. })
  2515. }
  2516. taskId = 0
  2517. break;
  2518. }
  2519. case 'syncClock': {
  2520. wx.hideLoading()
  2521. if (data.code != 200) {
  2522. wx.showModal({
  2523. title: '提示',
  2524. content: '同步时间失败!' + data.data.msg,
  2525. showCancel: false,
  2526. success: function (res) {}
  2527. })
  2528. break
  2529. }
  2530. taskId = 0
  2531. wx.showModal({
  2532. title: '提示',
  2533. content: '时间更新成功!',
  2534. showCancel: false
  2535. })
  2536. break;
  2537. }
  2538. case 'addPincode': {
  2539. // console.log(data.data,'data.data')
  2540. // wx.hideLoading()
  2541. let data2={
  2542. "code":"ble/bleSendVoucherReply",
  2543. "data":{
  2544. "deviceNum":that.data.deviceinfo.deviceNum,
  2545. "serialNumber":serialNumber,
  2546. "index":pincodeIndex,
  2547. "type":7,
  2548. "result":1,
  2549. "productId":that.data.deviceinfo.manufactureId
  2550. }
  2551. }
  2552. if (data.code != 200) {
  2553. data2={
  2554. "code":"ble/bleSendVoucherReply",
  2555. "data":{
  2556. "deviceNum":that.data.deviceinfo.deviceNum,
  2557. "serialNumber":serialNumber,
  2558. "index":pincodeIndex,
  2559. "type":7,
  2560. "result":0,
  2561. "productId":that.data.deviceinfo.manufactureId
  2562. }
  2563. }
  2564. WXAPI.sendCommand(data2).then(res=>{
  2565. })
  2566. wx.showModal({
  2567. title: '提示',
  2568. content: '添加密码失败!' + data.data.msg,
  2569. showCancel: false,
  2570. success: function (res) {}
  2571. })
  2572. break
  2573. }
  2574. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  2575. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  2576. var passwordStartTime = time1.getTime() / 1000
  2577. var passwordEndTime = time2.getTime() / 1000
  2578. var pzname='',cardName='';
  2579. pzname='蓝牙-密码'+(that.data.passwordList.length+1)
  2580. cardName=that.data.personLi.name+'-蓝牙-密码'+(that.data.passwordList.length+1)
  2581. var str = {
  2582. // cardId: this.personInfo.cardId,
  2583. imei: that.data.deviceinfo.imei,
  2584. pzname:pzname,
  2585. password: that.data.password.toString(),
  2586. userTelephone: JSON.parse(that.data.personLi.info).userTelephone,
  2587. operateMode: 7,
  2588. userPassword: JSON.parse(that.data.personLi.info).userPassword,
  2589. passwordStartTime: passwordStartTime,
  2590. passwordEndTime: passwordEndTime,
  2591. index:pincodeIndex,
  2592. is: false,
  2593. pass:true
  2594. }
  2595. var data1 = {
  2596. cardId: that.data.personLi.cardId,
  2597. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  2598. deviceNum: that.data.deviceinfo.deviceNum,
  2599. type: 4,
  2600. imei: that.data.deviceinfo.imei,
  2601. serial: serialNumber,
  2602. startTime: passwordStartTime,
  2603. endTime: passwordEndTime,
  2604. };
  2605. var datalist = {
  2606. cardId: that.data.personLi.cardId,
  2607. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  2608. type: 14,
  2609. startTime: passwordStartTime,
  2610. endTime: passwordEndTime,
  2611. };
  2612. WXAPI.addCertificates(datalist).then(res6 => {
  2613. console.log(datalist,'密码22',res6)
  2614. })
  2615. WXAPI.addCertificates(data1).then(res3 => {
  2616. if (res3.success) {
  2617. var updatedata = {
  2618. id: res3.data,
  2619. status:1
  2620. };
  2621. WXAPI.updateCertificates(updatedata).then((res2) => {
  2622. });
  2623. WXAPI.sendCommand(data2).then(res=>{
  2624. })
  2625. that.getPassword()
  2626. that.setData({
  2627. show: false
  2628. })
  2629. wx.hideLoading()
  2630. wx.showToast({
  2631. title: '添加成功',
  2632. mask:true,
  2633. icon: 'none',
  2634. duration: 2000
  2635. })
  2636. } else {
  2637. wx.hideLoading()
  2638. wx.showToast({
  2639. title: '添加失败',
  2640. mask:true,
  2641. icon: 'none',
  2642. duration: 2000
  2643. })
  2644. }
  2645. })
  2646. taskId = 0
  2647. that.setData({
  2648. isPincodeAdd: true,
  2649. show: false
  2650. })
  2651. wx.showModal({
  2652. title: '提示',
  2653. content: `添加密码${pincode}成功!`,
  2654. showCancel: false
  2655. })
  2656. break
  2657. }
  2658. case 'delPincode': {
  2659. wx.hideLoading()
  2660. if (data.code != 200) {
  2661. var datacom = {
  2662. code: "lwj/passwordOperate",
  2663. data: {
  2664. lockerId: that.data.deviceinfo.deviceNum,
  2665. serialNumber: serialNumber,
  2666. index: pincodeIndex,
  2667. action:2,
  2668. type: 9,
  2669. result: 0
  2670. }
  2671. }
  2672. WXAPI.sendCommand(datacom).then(res2 => {
  2673. console.log(res2, '失败')
  2674. })
  2675. wx.showModal({
  2676. title: '提示',
  2677. content: '删除密码失败!',
  2678. showCancel: false,
  2679. success: function (res) {}
  2680. })
  2681. break
  2682. }
  2683. taskId = 0
  2684. wx.showModal({
  2685. title: '提示',
  2686. content: `删除密码成功!`,
  2687. showCancel: false,
  2688. })
  2689. var datacom = {
  2690. code: "lwj/passwordOperate",
  2691. data: {
  2692. lockerId: that.data.deviceinfo.deviceNum,
  2693. serialNumber: serialNumber,
  2694. index: pincodeIndex,
  2695. action:2,
  2696. type: 9,
  2697. result: 1
  2698. }
  2699. }
  2700. WXAPI.sendCommand(datacom).then(res2 => {
  2701. if (res2.success) {}
  2702. })
  2703. var data = {
  2704. ids: [passwordLiAll.id]
  2705. }
  2706. WXAPI.deleteCertificates(data).then(res1 => {
  2707. if (res1.success) {
  2708. that.getPassword()
  2709. wx.hideLoading()
  2710. wx.showToast({
  2711. title: '删除成功',
  2712. mask:true,
  2713. icon: 'none',
  2714. duration: 2000
  2715. })
  2716. } else {
  2717. wx.hideLoading()
  2718. wx.showToast({
  2719. title: '删除失败',
  2720. mask:true,
  2721. icon: 'none',
  2722. duration: 2000
  2723. })
  2724. }
  2725. })
  2726. that.setData({
  2727. isPincodeAdd: false
  2728. })
  2729. pincode = -1
  2730. pincodeIndex = -1
  2731. break
  2732. }
  2733. case 'addRfCard': {
  2734. wx.hideLoading()
  2735. if (data.code == 100) {
  2736. wx.showLoading({
  2737. title: data.data.msg,
  2738. })
  2739. break
  2740. } else if (data.code != 200) {
  2741. var datacom = {
  2742. code: "ble/bleSendVoucherReply",
  2743. data: {
  2744. deviceNum: that.data.deviceinfo.deviceNum,
  2745. serialNumber: serialNumber,
  2746. index: rfCardIndex,
  2747. type: ADD_NFC_MODE,
  2748. cardNo: '',
  2749. result: 0,
  2750. productId:that.data.deviceinfo.manufactureId
  2751. }
  2752. }
  2753. WXAPI.sendCommand(datacom).then(res2 => {})
  2754. wx.showModal({
  2755. title: '提示',
  2756. content: '添加房卡失败!' + data.data.msg,
  2757. showCancel: false,
  2758. success: function (res) {}
  2759. })
  2760. break
  2761. }
  2762. taskId = 0
  2763. that.setData({
  2764. isRfCardAdd: true
  2765. })
  2766. if (lockModel > 70) {
  2767. console.log(data.data,'rfCardIndexrfCardIndex')
  2768. // rfCardId = randomMethods()
  2769. wx.showModal({
  2770. title: '提示',
  2771. content: `添加房卡成功,序号${rfCardIndex}`,
  2772. showCancel: false
  2773. })
  2774. that.addRfcardCertificates()
  2775. } else {
  2776. console.log(data.data,'rfCardIndexrfCardIndex1')
  2777. // rfCardId = randomMethods()
  2778. wx.showModal({
  2779. title: '提示',
  2780. content: `添加房卡成功,卡号${rfCardId}`,
  2781. showCancel: false
  2782. })
  2783. that.addRfcardCertificates()
  2784. }
  2785. break
  2786. }
  2787. case 'delRfCard': {
  2788. wx.hideLoading()
  2789. if (data.code != 200) {
  2790. var datacom = {
  2791. code: "lwj/c",
  2792. data: {
  2793. lockerId: that.data.deviceinfo.deviceNum,
  2794. serialNumber: serialNumber,
  2795. index: rfCardIndex,
  2796. action:2,
  2797. type: 12,
  2798. result: 0
  2799. }
  2800. }
  2801. WXAPI.sendCommand(datacom).then(res2 => {
  2802. console.log(res2, '失败')
  2803. })
  2804. wx.showModal({
  2805. title: '提示',
  2806. content: '删除房卡失败!',
  2807. showCancel: false,
  2808. success: function (res) {}
  2809. })
  2810. break
  2811. }
  2812. taskId = 0
  2813. that.setData({
  2814. isRfCardAdd: false
  2815. })
  2816. if (lockModel > 70) {
  2817. wx.showModal({
  2818. title: '提示',
  2819. content: `删除房卡成功,序号${rfCardIndex}`,
  2820. showCancel: false,
  2821. })
  2822. } else {
  2823. wx.showModal({
  2824. title: '提示',
  2825. content: `删除房卡成功,卡号${rfCardId}`,
  2826. showCancel: false,
  2827. })
  2828. }
  2829. var datacom = {
  2830. code: "lwj/c",
  2831. data: {
  2832. lockerId: that.data.deviceinfo.deviceNum,
  2833. serialNumber: serialNumber,
  2834. index: rfCardIndex,
  2835. action:2,
  2836. type: 12,
  2837. result: 1
  2838. }
  2839. }
  2840. WXAPI.sendCommand(datacom).then(res2 => {
  2841. console.log(res2, '失败')
  2842. })
  2843. var data = {
  2844. ids: [passwordLiAll.id]
  2845. }
  2846. WXAPI.deleteCertificates(data).then(res1 => {
  2847. if (res1.success) {
  2848. that.getNfc()
  2849. wx.showToast({
  2850. title: '删除成功',
  2851. mask:true,
  2852. icon: 'none',
  2853. duration: 2000
  2854. })
  2855. } else {
  2856. wx.showToast({
  2857. title: '删除失败',
  2858. mask:true,
  2859. icon: 'none',
  2860. duration: 2000
  2861. })
  2862. }
  2863. })
  2864. rfCardId = -1
  2865. rfCardIndex = -1
  2866. break
  2867. }
  2868. case 'addFingerprint': {
  2869. wx.hideLoading()
  2870. if (data.code == 100) {
  2871. wx.showLoading({
  2872. title: data.data.msg,
  2873. })
  2874. break
  2875. } else if (data.code != 200) {
  2876. wx.showModal({
  2877. title: '提示',
  2878. content: '添加指纹失败!' + data.data.msg,
  2879. showCancel: false,
  2880. success: function (res) {}
  2881. })
  2882. var datacom = {
  2883. code: "ble/bleSendVoucherReply",
  2884. data: {
  2885. deviceNum: that.data.deviceinfo.deviceNum,
  2886. serialNumber: serialNumber,
  2887. index:0,
  2888. type: 16,
  2889. result: 0,
  2890. productId:that.data.deviceinfo.manufactureId
  2891. }
  2892. }
  2893. WXAPI.sendCommand(datacom).then(res2 => {
  2894. if (res2.success) {}
  2895. })
  2896. break
  2897. }
  2898. taskId = 0
  2899. that.setData({
  2900. isFingerprintAdd: true
  2901. })
  2902. wx.showModal({
  2903. title: '提示',
  2904. content: `添加指纹成功,序号${fingerprintIndex}`,
  2905. showCancel: false
  2906. })
  2907. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  2908. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  2909. var passwordStartTime = time1.getTime() / 1000
  2910. var passwordEndTime = time2.getTime() / 1000
  2911. var cardName='',pzname=''
  2912. if(that.data.pzname){
  2913. cardName=that.data.personLi.name+'-蓝牙-'+that.data.pzname
  2914. pzname='蓝牙-'+that.data.pzname
  2915. }else{
  2916. cardName=that.data.personLi.name+'-蓝牙-指纹'+(that.data.FpList.length+1)
  2917. pzname='蓝牙-指纹'+(that.data.FpList.length+1)
  2918. }
  2919. var str = {
  2920. // cardId: this.personInfo.cardId,
  2921. imei: that.data.deviceinfo.imei,
  2922. pzname: pzname,
  2923. password: '',
  2924. fingerprintAlias:that.data.radioDetil,
  2925. userTelephone: JSON.parse(that.data.personLi.info).userTelephone,
  2926. operateMode: 16,
  2927. userPassword: JSON.parse(that.data.personLi.info).userPassword,
  2928. passwordStartTime: passwordStartTime,
  2929. passwordEndTime: passwordEndTime,
  2930. index:fingerprintIndex,
  2931. is: false,
  2932. pass:true
  2933. }
  2934. var data2 = {
  2935. cardId: that.data.personLi.cardId,
  2936. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  2937. deviceNum: that.data.deviceinfo.deviceNum,
  2938. type: 1,
  2939. imei: that.data.deviceinfo.imei,
  2940. serial:serialNumber,
  2941. startTime: passwordStartTime,
  2942. endTime: passwordEndTime,
  2943. status: 1
  2944. };
  2945. var datalist = {
  2946. cardId: that.data.personLi.cardId,
  2947. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  2948. type: 11,
  2949. startTime: passwordStartTime,
  2950. endTime: passwordEndTime
  2951. };
  2952. var datacom = {
  2953. code: "ble/bleSendVoucherReply",
  2954. data: {
  2955. deviceNum: that.data.deviceinfo.deviceNum,
  2956. serialNumber: serialNumber,
  2957. index:fingerprintIndex,
  2958. type: 16,
  2959. result: 1,
  2960. productId:that.data.deviceinfo.manufactureId
  2961. }
  2962. }
  2963. WXAPI.addCertificates(datalist).then(res6 => {})
  2964. console.log(data, '添加凭证')
  2965. WXAPI.addCertificates(data2).then(res3 => {
  2966. if (res3.success) {
  2967. var updatedata = {
  2968. id: res3.data,
  2969. status:1
  2970. };
  2971. WXAPI.updateCertificates(updatedata).then((res2) => {
  2972. });
  2973. WXAPI.sendCommand(datacom).then(res2 => {
  2974. if (res2.success) {}
  2975. })
  2976. console.log(res3, '添加凭证成功')
  2977. that.getFp()
  2978. that.setData({
  2979. show: false
  2980. })
  2981. wx.hideLoading()
  2982. wx.showToast({
  2983. title: '添加成功',
  2984. mask:true,
  2985. icon: 'none',
  2986. duration: 2000
  2987. })
  2988. } else {
  2989. wx.hideLoading()
  2990. wx.showToast({
  2991. title: '添加失败',
  2992. mask:true,
  2993. icon: 'none',
  2994. duration: 2000
  2995. })
  2996. }
  2997. })
  2998. break
  2999. }
  3000. case 'delFingerprint': {
  3001. wx.hideLoading()
  3002. if (data.code != 200) {
  3003. wx.showModal({
  3004. title: '提示',
  3005. content: '删除指纹失败!',
  3006. showCancel: false,
  3007. success: function (res) {}
  3008. })
  3009. break
  3010. }
  3011. taskId = 0
  3012. wx.showModal({
  3013. title: '提示',
  3014. content: `删除指纹成功,序号${fingerprintIndex}`,
  3015. showCancel: false,
  3016. })
  3017. that.setData({
  3018. isFingerprintAdd: false
  3019. })
  3020. fingerprintIndex = -1
  3021. break
  3022. }
  3023. case 'changeAdminPincode': {
  3024. wx.hideLoading()
  3025. if (data.code != 200) {
  3026. wx.showModal({
  3027. title: '提示',
  3028. content: '修改管理密码失败!',
  3029. showCancel: false,
  3030. success: function (res) {}
  3031. })
  3032. break
  3033. }
  3034. taskId = 0
  3035. wx.showToast({
  3036. title: '修改管理密码成功!',
  3037. })
  3038. }
  3039. case 'queryLockSlotState': {
  3040. wx.hideLoading()
  3041. if (data.code != 200) {
  3042. wx.showModal({
  3043. title: '提示',
  3044. content: '查询失败!',
  3045. showCancel: false,
  3046. success: function (res) {}
  3047. })
  3048. break
  3049. }
  3050. taskId = 0
  3051. wx.showModal({
  3052. title: '提示',
  3053. content: data.data.state == 0 ? '此门锁方舌关闭' : '此门锁方舌打开',
  3054. showCancel: false,
  3055. success: function (res) {}
  3056. })
  3057. break
  3058. }
  3059. case 'queryLockUnlockState': {
  3060. wx.hideLoading()
  3061. if (data.code != 200) {
  3062. wx.showModal({
  3063. title: '提示',
  3064. content: '查询失败!',
  3065. showCancel: false,
  3066. success: function (res) {}
  3067. })
  3068. break
  3069. }
  3070. taskId = 0
  3071. wx.showModal({
  3072. title: '提示',
  3073. content: data.data.state == 0 ? '此门锁已关闭' : '此门锁已打开',
  3074. showCancel: false,
  3075. success: function (res) {}
  3076. })
  3077. break
  3078. }
  3079. case 'setLockUnlockState': {
  3080. wx.hideLoading()
  3081. if (data.code != 200) {
  3082. wx.showModal({
  3083. title: '提示',
  3084. content: '设置常开指令失败!',
  3085. showCancel: false,
  3086. success: function (res) {}
  3087. })
  3088. break
  3089. }
  3090. taskId = 0
  3091. wx.showModal({
  3092. title: '提示',
  3093. content: data.data.state == 0 ? '常开模式已退出' : '常开模式已开启',
  3094. showCancel: false,
  3095. })
  3096. that.setData({
  3097. isUnloked: data.data.state == 1
  3098. })
  3099. break
  3100. }
  3101. case 'setLockMuteState': {
  3102. wx.hideLoading()
  3103. if (data.code != 200) {
  3104. wx.showModal({
  3105. title: '提示',
  3106. content: '设置静音指令失败!',
  3107. showCancel: false,
  3108. success: function (res) {}
  3109. })
  3110. break
  3111. }
  3112. taskId = 0
  3113. wx.showModal({
  3114. title: '提示',
  3115. content: data.data.state == 1 ? '静音模式已退出' : '静音模式已开启',
  3116. showCancel: false,
  3117. })
  3118. that.setData({
  3119. isMuted: data.data.state == 0
  3120. })
  3121. break
  3122. }
  3123. }
  3124. })
  3125. wx.notifyBLECharacteristicValueChange({
  3126. deviceId: lockDevice.deviceId,
  3127. serviceId: config.uuid.serviceUuid.toUpperCase(),
  3128. characteristicId: config.uuid.notifyUuid.toUpperCase(),
  3129. state: true,
  3130. success: function (res) {
  3131. console.log('setupNotify', res)
  3132. isInitReady = true
  3133. setTimeout(function () {
  3134. wx.hideLoading()
  3135. // that.onQueryBindState()
  3136. that.login()
  3137. }, 500)
  3138. },
  3139. })
  3140. },
  3141. })
  3142. },
  3143. })
  3144. },
  3145. onQueryBindState: function () {
  3146. var that = this
  3147. wx.showLoading({
  3148. title: '查询中',
  3149. })
  3150. var bytes = plugin.queryLockState(lockDevice.name)
  3151. console.debug('bytes', bytes)
  3152. that.sendBytes(bytes)
  3153. },
  3154. queryBindState: function () {
  3155. var that = this
  3156. taskId = 21
  3157. that.initBluetooth()
  3158. },
  3159. doWork: function () {
  3160. var that = this
  3161. console.log(taskId);
  3162. switch (taskId) {
  3163. case 11: {
  3164. that.onBindLock()
  3165. break
  3166. }
  3167. case 12: {
  3168. that.onUnbindLock()
  3169. break
  3170. }
  3171. case 21: {
  3172. that.onQueryBindState()
  3173. break
  3174. }
  3175. case 22: {
  3176. that.onQueryBattery()
  3177. break
  3178. }
  3179. case 31: {
  3180. that.onQueryNbImei()
  3181. break
  3182. }
  3183. case 32: {
  3184. that.onLogin()
  3185. break
  3186. }
  3187. case 41: {
  3188. that.LwjonOpenLock()
  3189. break
  3190. }
  3191. case 42: {
  3192. that.onSyncClock()
  3193. break
  3194. }
  3195. case 51: {
  3196. that.onAddPincode()
  3197. break
  3198. }
  3199. case 52: {
  3200. that.onDelPincode()
  3201. break
  3202. }
  3203. case 61: {
  3204. // that.onAddRfCard()
  3205. // if (lockModel > 70) {
  3206. that.sendAddRfcard()
  3207. // } else {
  3208. // wx.showModal({
  3209. // title: '提示',
  3210. // content: '请刷卡!',
  3211. // showCancel: false
  3212. // })
  3213. // }
  3214. break
  3215. }
  3216. case 62: {
  3217. that.onDelRfCard()
  3218. break
  3219. }
  3220. case 71: {
  3221. that.onAddFingerprint()
  3222. break
  3223. }
  3224. case 72: {
  3225. that.onDelFingerprint()
  3226. break
  3227. }
  3228. case 81: {
  3229. that.onChangeAdminPincode()
  3230. break
  3231. }
  3232. case 91: {
  3233. that.onQueryLockSlotState()
  3234. break
  3235. }
  3236. case 92: {
  3237. that.onQueryLockUnlockState()
  3238. break
  3239. }
  3240. case 101: {
  3241. that.onChangeLockUnlockState()
  3242. break
  3243. }
  3244. case 102: {
  3245. that.onChangeLockMutedState()
  3246. break
  3247. }
  3248. case 111: {
  3249. this.onChangeLockNbState()
  3250. }
  3251. default: {
  3252. }
  3253. }
  3254. },
  3255. connectTo: function () {
  3256. var that = this
  3257. wx.showLoading({
  3258. title: '连接中',
  3259. })
  3260. wx.createBLEConnection({
  3261. deviceId: lockDevice.deviceId,
  3262. timeout: config.ble.connectTimeOut,
  3263. success: function (res) {
  3264. console.log('connectTo', res)
  3265. isConnected = true
  3266. // app.globalData.isConnected = true
  3267. wx.hideLoading()
  3268. setTimeout(function () {
  3269. that.setupConnection()
  3270. }, 500)
  3271. },
  3272. fail: function (e) {
  3273. console.debug('connectTo', e)
  3274. wx.hideLoading()
  3275. switch (e.errCode) {
  3276. case 10003: {
  3277. wx.showModal({
  3278. title: '连接失败',
  3279. content: '是否重新连接?',
  3280. success: function (res) {
  3281. if (res.confirm) {
  3282. that.connectTo()
  3283. }
  3284. }
  3285. })
  3286. break
  3287. }
  3288. case 10012: {
  3289. wx.showModal({
  3290. title: '连接失败',
  3291. content: '蓝牙连接超时',
  3292. showCancel: false
  3293. })
  3294. break
  3295. }
  3296. case 10002: {
  3297. wx.showModal({
  3298. title: '连接失败',
  3299. content: '没有找到指定设备',
  3300. showCancel: false
  3301. })
  3302. break
  3303. }
  3304. }
  3305. }
  3306. })
  3307. },
  3308. searchDevicesMethods(){
  3309. var that = this;
  3310. wx.showLoading({
  3311. title: '正在搜索',
  3312. // mask: true
  3313. })
  3314. this.setData({
  3315. searchClick:false
  3316. })
  3317. wx.openBluetoothAdapter({
  3318. success: function (res) {
  3319. wx.startBluetoothDevicesDiscovery({
  3320. success: function (res) {
  3321. wx.getBluetoothDevices({
  3322. success: function (res) {
  3323. res.devices.map(it=>{
  3324. var status=it.name.indexOf('WSL_')
  3325. if(status!=-1){
  3326. if (it.RSSI != 127) {
  3327. if (it.advertisData != null) {
  3328. it.adData = util1.ab2hex(it.advertisData)
  3329. if (it.adData.length > 10) {
  3330. var macStr = it.adData.substring(4, 16).toUpperCase()
  3331. //console.log('macStr', macStr)
  3332. 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)
  3333. if (it.adData.substring(1, 2) == '1') {
  3334. it.isLightOn = true
  3335. it.textColor = 'green'
  3336. } else {
  3337. it.isLightOn = false
  3338. it.textColor = 'black'
  3339. }
  3340. if (it.adData.substring(3, 4) == '1') {
  3341. it.textColor = 'pink'
  3342. it.isBind = true
  3343. } else {
  3344. it.isBind = false
  3345. }
  3346. }
  3347. } else {
  3348. it.textColor = 'black'
  3349. }
  3350. lockModel = util1.getLockModel(it.name)
  3351. it.lockType = util1.getLockType(lockModel)
  3352. if(it.name == that.data.deviceinfo.deviceNum){
  3353. app.addDeviceWithDevName(it.name, it)
  3354. lockDevice = it
  3355. connectedDeviceId = it.deviceId
  3356. that.setData({
  3357. isSearch:true
  3358. })
  3359. that.initBluetooth()
  3360. }
  3361. }
  3362. }
  3363. })
  3364. if(!that.data.isSearch){
  3365. that.searchDevicesMethods()
  3366. }
  3367. }
  3368. })
  3369. },
  3370. fail:function(res){
  3371. wx.hideLoading({
  3372. success: (res) => {
  3373. wx.showToast({
  3374. title: res.errMsg,
  3375. duration:2000,
  3376. icon:'none'
  3377. })
  3378. },
  3379. })
  3380. }
  3381. })
  3382. },
  3383. fail: function (res) {
  3384. console.log('请打开蓝牙和定位功能')
  3385. wx.hideLoading({
  3386. success: (res) => {
  3387. wx.showToast({
  3388. title: '请打开蓝牙和定位功能',
  3389. duration:2000,
  3390. icon:'none'
  3391. })
  3392. },
  3393. })
  3394. }
  3395. })
  3396. },
  3397. LwjonOpenLock: function () {
  3398. var that = this
  3399. wx.showLoading({
  3400. title: that.data.isJack ? '上电中' : '解锁中',
  3401. })
  3402. console.log(lockDevice.name,'lockDevice.name0')
  3403. var bytes = plugin.sendOpenLockP1(lockDevice.name, basecode)
  3404. console.debug('bytes', bytes)
  3405. that.sendBytes(bytes)
  3406. },
  3407. openLock: function () {
  3408. var that = this
  3409. taskId = 41
  3410. that.initBluetooth()
  3411. },
  3412. sendBytes(bytes) {
  3413. setTimeout(()=> {
  3414. wx.writeBLECharacteristicValue({
  3415. deviceId: lockDevice.deviceId,
  3416. serviceId: config.uuid.serviceUuid.toUpperCase(),
  3417. characteristicId: config.uuid.writeUuid.toUpperCase(),
  3418. value: bytes,
  3419. success: function (res) {
  3420. },
  3421. })
  3422. }, 50)
  3423. },
  3424. sendNfc() {
  3425. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  3426. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  3427. var passwordStartTimecontrast = time3.getTime() / 1000
  3428. var passwordEndTimecontrast = time4.getTime() / 1000
  3429. if (passwordStartTimecontrast > passwordEndTimecontrast) {
  3430. wx.showToast({
  3431. title: '开始时间不能大于结束时间',
  3432. duration: 2000,
  3433. mask:true,
  3434. icon: 'none'
  3435. })
  3436. return
  3437. }
  3438. wx.showLoading({
  3439. title: '正在添加',
  3440. mask: true
  3441. })
  3442. var _this = this
  3443. var deviceinfo = this.data.deviceinfo
  3444. var info = JSON.parse(this.data.personLi.info)
  3445. if (deviceinfo.manufactureId == 101) {
  3446. } else if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  3447. var cgInfo = this.data.cgInfo
  3448. var time1 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  3449. var time2 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  3450. var passwordStartTime = time1.getTime() / 1000
  3451. var passwordEndTime = time2.getTime() / 1000
  3452. var pzname=_this.data.pzname,cardName=''
  3453. if(pzname==""){
  3454. pzname='蓝牙-NFC'+(_this.data.NfcList.length+1)
  3455. cardName=_this.data.personLi.name+'-蓝牙-NFC'+(_this.data.NfcList.length+1)
  3456. }else{
  3457. pzname='蓝牙-'+pzname
  3458. cardName=_this.data.personLi.name+'-蓝牙-'+pzname
  3459. }
  3460. var dataPasswod = {
  3461. code: "zg/cardOperate",
  3462. data: {
  3463. lockerId: deviceinfo.deviceNum,
  3464. imei: deviceinfo.imei,
  3465. lockerUserId: info.userId,
  3466. keyId: info.userId,
  3467. action: 1,
  3468. taskStatus: 1,
  3469. order: 6210,
  3470. startTime: passwordStartTime,
  3471. endTime: passwordEndTime,
  3472. cardType: 50,
  3473. type: ADD_NFC_MODE,
  3474. roomName: this.data.deviceinfo.roomName,
  3475. cardName: cardName,
  3476. }
  3477. }
  3478. console.log(dataPasswod,'dataPasswod')
  3479. WXAPI.sendCommand(dataPasswod).then(res => {
  3480. console.log(res,'resres')
  3481. if (res.success) {
  3482. var pwdNo = res.data.index
  3483. var passwordIndex = res.data.index
  3484. var serialNumber=res.data.serialNumber
  3485. pwdNo = pwdNo.toString(16)
  3486. if (pwdNo.length < 2) {
  3487. pwdNo='0'+pwdNo
  3488. }
  3489. var startTime = passwordStartTime.toString(16).toUpperCase()
  3490. var endTime = passwordEndTime.toString(16).toUpperCase()
  3491. info.startTime=startTime
  3492. info.endTime=endTime
  3493. info.pwdNo = pwdNo
  3494. methods.bluetoothOperation_ZH(cgInfo,info,7).then(result=>{
  3495. if (result.status == '00') {
  3496. let carNoId=this.processCardNumber(result.cardNo)
  3497. var datacom = {
  3498. code: "zg/bleSendVoucherReply",
  3499. data: {
  3500. lockerId: deviceinfo.deviceNum,
  3501. serialNumber: serialNumber,
  3502. index: passwordIndex,
  3503. type: ADD_NFC_MODE,
  3504. cardNo: carNoId.toUpperCase(),
  3505. result: 1
  3506. }
  3507. }
  3508. WXAPI.sendCommand(datacom).then(res2 => {
  3509. if (res2.success) {
  3510. var str = {
  3511. // cardId: this.personInfo.cardId,
  3512. pzname:pzname,
  3513. imei: _this.data.deviceinfo.imei,
  3514. password: carNoId.toUpperCase(),
  3515. blueCardNo:result.cardNo,
  3516. userTelephone: JSON.parse(_this.data.personLi.info).userTelephone,
  3517. operateMode: 10,
  3518. userPassword: JSON.parse(_this.data.personLi.info).userPassword,
  3519. passwordStartTime: passwordStartTime,
  3520. passwordEndTime: passwordEndTime,
  3521. is: false,
  3522. roomName:_this.data.deviceinfo.roomName,
  3523. }
  3524. var data = {
  3525. cardId: _this.data.personLi.cardId,
  3526. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3527. deviceNum: _this.data.deviceinfo.deviceNum,
  3528. type: 3,
  3529. blueCardNo:result.cardNo,
  3530. imei: _this.data.deviceinfo.imei,
  3531. serial: serialNumber,
  3532. startTime: passwordStartTime,
  3533. endTime: passwordEndTime,
  3534. };
  3535. console.log(data, '添加凭证')
  3536. var datalist = {
  3537. cardId: _this.data.personLi.cardId,
  3538. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3539. type: 13,
  3540. startTime: passwordStartTime,
  3541. endTime: passwordEndTime,
  3542. };
  3543. WXAPI.addCertificates(datalist).then(res6 => {
  3544. console.log(datalist,'NFC',res6)
  3545. })
  3546. WXAPI.addCertificates(data).then(res3 => {
  3547. if (res3.success) {
  3548. var updatedata = {
  3549. id: res3.data,
  3550. status:1
  3551. };
  3552. WXAPI.updateCertificates(updatedata).then((res2) => {
  3553. });
  3554. console.log(res3, '添加凭证成功')
  3555. _this.getNfc()
  3556. _this.setData({
  3557. show: false
  3558. })
  3559. wx.hideLoading()
  3560. wx.showToast({
  3561. title: '添加成功',
  3562. mask:true,
  3563. icon: 'none',
  3564. duration: 2000
  3565. })
  3566. } else {
  3567. wx.hideLoading()
  3568. wx.showToast({
  3569. title: '添加失败',
  3570. mask:true,
  3571. icon: 'none',
  3572. duration: 2000
  3573. })
  3574. }
  3575. })
  3576. }
  3577. })
  3578. } else {
  3579. wx.hideLoading()
  3580. wx.showToast({
  3581. title: '添加失败',
  3582. mask:true,
  3583. icon: 'none',
  3584. duration: 2000
  3585. })
  3586. var datacom = {
  3587. code: "zg/bleSendVoucherReply",
  3588. data: {
  3589. lockerId: deviceinfo.deviceNum,
  3590. serialNumber: serialNumber,
  3591. index: passwordIndex,
  3592. type: ADD_NFC_MODE,
  3593. result: 0
  3594. }
  3595. }
  3596. WXAPI.sendCommand(datacom).then(res2 => {
  3597. console.log(res2, '失败')
  3598. _this.setData({
  3599. show: false
  3600. })
  3601. })
  3602. }
  3603. }).catch(err=>{
  3604. var datacom = {
  3605. code: "zg/bleSendVoucherReply",
  3606. data: {
  3607. lockerId: deviceinfo.deviceNum,
  3608. serialNumber: serialNumber,
  3609. index: passwordIndex,
  3610. type: ADD_NFC_MODE,
  3611. result: 0
  3612. }
  3613. }
  3614. WXAPI.sendCommand(datacom).then(res2 => {
  3615. _this.setData({
  3616. show: false
  3617. })
  3618. })
  3619. wx.showToast({
  3620. title: '添加失败',
  3621. mask:true,
  3622. icon: 'none',
  3623. duration: 2000
  3624. })
  3625. })
  3626. } else {
  3627. wx.showToast({
  3628. title: res.msg,
  3629. duration: 2000,
  3630. mask:true,
  3631. icon: 'none'
  3632. })
  3633. }
  3634. })
  3635. }else if (deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241){
  3636. if(this.data.isSearch){
  3637. wx.hideLoading()
  3638. this.addRfCard()
  3639. }else{
  3640. this.searchDevicesMethods()
  3641. }
  3642. }
  3643. },
  3644. addRfCard: function () {
  3645. console.log("3691NFC");
  3646. var that = this
  3647. taskId = 61
  3648. that.initBluetooth()
  3649. },
  3650. onAddRfCard: function () {
  3651. var that = this
  3652. wx.showLoading({
  3653. title: '添加房卡中',
  3654. })
  3655. var startTime = new Date(Number(moment(that.data.starttime).format('x')))
  3656. var endTime = new Date(Number(moment(that.data.endtime).format('x')))
  3657. var bytes = plugin.addRfCard(lockDevice.name, basecode, rfCardId, rfCardIndex, startTime, endTime)
  3658. console.debug('bytes', bytes)
  3659. that.sendBytes(bytes)
  3660. },
  3661. addRfcardCertificates(){
  3662. var that = this
  3663. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  3664. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  3665. var passwordStartTime = time1.getTime() / 1000
  3666. var passwordEndTime = time2.getTime() / 1000
  3667. var pzname='',cardName='';
  3668. pzname='蓝牙-NFC'+(that.data.passwordList.length+1)
  3669. cardName=that.data.personLi.name+'-蓝牙-NFC'+(that.data.passwordList.length+1)
  3670. let carNoId = rfCardId
  3671. var datacom = {
  3672. code: "ble/bleSendVoucherReply",
  3673. data: {
  3674. deviceNum: that.data.deviceinfo.deviceNum,
  3675. serialNumber: serialNumber,
  3676. index: rfCardIndex,
  3677. type: ADD_NFC_MODE,
  3678. cardNo: rfCardId.toUpperCase(),
  3679. result: 1,
  3680. productId:that.data.deviceinfo.manufactureId
  3681. }
  3682. }
  3683. WXAPI.sendCommand(datacom).then(res2 => {
  3684. if (res2.success) {
  3685. var str = {
  3686. // cardId: this.personInfo.cardId,
  3687. pzname:pzname,
  3688. imei: that.data.deviceinfo.imei,
  3689. password: carNoId.toUpperCase(),
  3690. blueCardNo:rfCardIndex,
  3691. userTelephone: JSON.parse(that.data.personLi.info).userTelephone,
  3692. operateMode: 10,
  3693. userPassword: JSON.parse(that.data.personLi.info).userPassword,
  3694. passwordStartTime: passwordStartTime,
  3695. passwordEndTime: passwordEndTime,
  3696. is: false,
  3697. index:rfCardIndex,
  3698. roomName:that.data.deviceinfo.roomName,
  3699. }
  3700. var data2 = {
  3701. cardId: that.data.personLi.cardId,
  3702. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3703. deviceNum: that.data.deviceinfo.deviceNum,
  3704. type: 3,
  3705. blueCardNo:carNoId,
  3706. imei: that.data.deviceinfo.imei,
  3707. serial: serialNumber,
  3708. startTime: passwordStartTime,
  3709. endTime: passwordEndTime,
  3710. };
  3711. console.log(data2, '添加凭证')
  3712. var datalist = {
  3713. cardId: that.data.personLi.cardId,
  3714. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3715. type: 13,
  3716. startTime: passwordStartTime,
  3717. endTime: passwordEndTime,
  3718. };
  3719. WXAPI.addCertificates(datalist).then(res6 => {
  3720. console.log(datalist,'NFC',res6)
  3721. })
  3722. WXAPI.addCertificates(data2).then(res3 => {
  3723. if (res3.success) {
  3724. var updatedata = {
  3725. id: res3.data,
  3726. status:1
  3727. };
  3728. WXAPI.updateCertificates(updatedata).then((res2) => {
  3729. });
  3730. console.log(res3, '添加凭证成功')
  3731. that.getNfc()
  3732. that.setData({
  3733. show: false
  3734. })
  3735. wx.hideLoading()
  3736. wx.showToast({
  3737. title: '添加成功',
  3738. mask:true,
  3739. icon: 'none',
  3740. duration: 2000
  3741. })
  3742. } else {
  3743. wx.hideLoading()
  3744. wx.showToast({
  3745. title: '添加失败',
  3746. mask:true,
  3747. icon: 'none',
  3748. duration: 2000
  3749. })
  3750. }
  3751. })
  3752. }else{
  3753. wx.showToast({
  3754. title: res2.message,
  3755. duration:2000,
  3756. icon:'none'
  3757. })
  3758. }
  3759. })
  3760. },
  3761. sendAddRfcard(){
  3762. var that = this
  3763. var info = JSON.parse(this.data.personLi.info)
  3764. let deviceinfo = this.data.deviceinfo
  3765. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  3766. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  3767. var passwordStartTime = time1.getTime() / 1000
  3768. var passwordEndTime = time2.getTime() / 1000
  3769. var pzname='',cardName=''
  3770. pzname='蓝牙-NFC'+(that.data.NfcList.length+1)
  3771. cardName=that.data.personLi.name+'-蓝牙-NFC'+(that.data.NfcList.length+1)
  3772. rfCardId = randomMethods()
  3773. var dataPasswod = {
  3774. code: "lwj/cardOperate",
  3775. data: {
  3776. lockerId: deviceinfo.deviceNum,
  3777. lockerUserId: info.userId,
  3778. startTime:passwordStartTime,
  3779. endTime:passwordEndTime,
  3780. order: 6210,
  3781. operateMode:10,
  3782. action: 1,
  3783. cardNo: rfCardId,
  3784. type: 10,
  3785. roomName: this.data.deviceinfo.roomName,
  3786. cardName: cardName,
  3787. }
  3788. }
  3789. WXAPI.sendCommand(dataPasswod).then(res => {
  3790. console.log(res, '获取索引')
  3791. if (res.success) {
  3792. var pwdNo = res.data.index
  3793. serialNumber = res.data.serialNumber
  3794. rfCardIndex = pwdNo
  3795. setTimeout(()=>{
  3796. that.onAddRfCard()
  3797. },500)
  3798. }
  3799. })
  3800. },
  3801. processCardNumber(cardNo){
  3802. var str1=cardNo.substr(0,8)
  3803. var str2=cardNo.substr(8,8)
  3804. var num=str2.split("")
  3805. var status=num.every(item=> item==0)
  3806. console.log(status,num,'numnum',str1,str2)
  3807. if(status){
  3808. var bbb = str1.split("")
  3809. var a, b;
  3810. var aIndex = 0;
  3811. var bIndex = 1;
  3812. var arr = [];
  3813. bbb.forEach((str, index) => {
  3814. if (index % 2 === 0) {
  3815. a = str;
  3816. aIndex += 1
  3817. } else {
  3818. b = str
  3819. bIndex += 1
  3820. }
  3821. if (a&&b&&(bIndex-aIndex === 1)) {
  3822. arr.push(a+b)
  3823. }
  3824. });
  3825. console.log(arr)
  3826. return arr.join("")
  3827. }else{
  3828. var ll=str1+str2
  3829. return ll
  3830. }
  3831. },
  3832. sendFp() {
  3833. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  3834. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  3835. var passwordStartTimecontrast = time3.getTime() / 1000
  3836. var passwordEndTimecontrast = time4.getTime() / 1000
  3837. if (passwordStartTimecontrast > passwordEndTimecontrast) {
  3838. wx.showToast({
  3839. title: '开始时间不能大于结束时间',
  3840. duration: 2000,
  3841. mask:true,
  3842. icon: 'none'
  3843. })
  3844. return
  3845. }
  3846. if(this.data.radioDetil==''){
  3847. wx.showToast({
  3848. title: '请选择是那个指纹?',
  3849. mask:true,
  3850. duration: 2000,
  3851. icon: 'none'
  3852. })
  3853. return
  3854. }
  3855. wx.showLoading({
  3856. title: '正在添加指纹',
  3857. mask: true
  3858. })
  3859. var _this = this
  3860. var deviceinfo = this.data.deviceinfo
  3861. var info = JSON.parse(this.data.personLi.info)
  3862. if (deviceinfo.manufactureId == 101) {
  3863. let deviceNum = deviceinfo.deviceNum
  3864. this.setData({
  3865. backstatus: true
  3866. })
  3867. var timestamp = moment().format("x")
  3868. var time1 = moment(this.data.datetimerange[0]).format("YYYYMMDDHHmmss")
  3869. var time2 = moment(this.data.datetimerange[1]).format("YYYYMMDDHHmmss")
  3870. bleall.startFp_29(deviceNum, 0x03, timestamp, function (res) {
  3871. console.log(res, 'resresres')
  3872. if (res.success) {
  3873. wx.showLoading({
  3874. title: '正在添加指纹',
  3875. mask: true
  3876. })
  3877. }
  3878. if (res.data == "蓝牙功能暂不支持") {
  3879. wx.hideLoading()
  3880. _this.startconnect()
  3881. }
  3882. })
  3883. } else if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  3884. var cgInfo = this.data.cgInfo
  3885. var time1 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  3886. var time2 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  3887. var passwordStartTime = time1.getTime() / 1000
  3888. var passwordEndTime = time2.getTime() / 1000
  3889. var cardName='',pzname=''
  3890. if(this.data.pzname){
  3891. cardName=_this.data.personLi.name+'-蓝牙-'+_this.data.pzname
  3892. pzname='蓝牙-'+_this.data.pzname
  3893. }else{
  3894. cardName=_this.data.personLi.name+'-蓝牙-指纹'+(_this.data.FpList.length+1)
  3895. pzname='蓝牙-指纹'+(_this.data.FpList.length+1)
  3896. }
  3897. var dataPasswod = {
  3898. code: "zg/addFingerPrint",
  3899. data: {
  3900. lockerId: deviceinfo.deviceNum,
  3901. imei: deviceinfo.imei,
  3902. lockerUserId: info.userPassword,
  3903. keyId: info.userPassword,
  3904. fingerType: 0,
  3905. order: 6216,
  3906. fingerId: '',
  3907. roomName: deviceinfo.roomName,
  3908. cardName: cardName,
  3909. startTime: passwordStartTime,
  3910. endTime: passwordEndTime,
  3911. file: '',
  3912. type: 1
  3913. }
  3914. }
  3915. WXAPI.sendCommand(dataPasswod).then(res => {
  3916. console.log(res, '获取索引')
  3917. if (res.success) {
  3918. var startTime = passwordStartTime.toString(16).toUpperCase()
  3919. var endTime = passwordEndTime.toString(16).toUpperCase()
  3920. info.startTime=startTime
  3921. info.endTime=endTime
  3922. methods.bluetoothOperation_ZH(cgInfo,info,5).then(result=>{
  3923. if (result.status == '00' && result.completeFlag == '01') {
  3924. console.log(result,'callback2callback2')
  3925. var datacom = {
  3926. code: "zg/bleSendVoucherReply",
  3927. data: {
  3928. lockerId: deviceinfo.deviceNum,
  3929. serialNumber: res.data.serialNumber,
  3930. index: result.fingerprintNo,
  3931. type: 16,
  3932. result: 1
  3933. }
  3934. }
  3935. console.log(datacom)
  3936. var str = {
  3937. // cardId: this.personInfo.cardId,
  3938. imei: _this.data.deviceinfo.imei,
  3939. pzname: pzname,
  3940. password: '',
  3941. fingerprintAlias:_this.data.radioDetil,
  3942. userTelephone: JSON.parse(_this.data.personLi.info).userTelephone,
  3943. operateMode: 16,
  3944. userPassword: JSON.parse(_this.data.personLi.info).userPassword,
  3945. passwordStartTime: passwordStartTime,
  3946. passwordEndTime: passwordEndTime,
  3947. is: false,
  3948. pass:true
  3949. }
  3950. var data = {
  3951. cardId: _this.data.personLi.cardId,
  3952. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3953. deviceNum: _this.data.deviceinfo.deviceNum,
  3954. type: 1,
  3955. imei: _this.data.deviceinfo.imei,
  3956. serial: res.data.serialNumber,
  3957. startTime: passwordStartTime,
  3958. endTime: passwordEndTime,
  3959. status: 1
  3960. };
  3961. var datalist = {
  3962. cardId: _this.data.personLi.cardId,
  3963. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3964. type: 11,
  3965. startTime: passwordStartTime,
  3966. endTime: passwordEndTime
  3967. };
  3968. WXAPI.addCertificates(datalist).then(res6 => {})
  3969. console.log(data, '添加凭证')
  3970. WXAPI.addCertificates(data).then(res3 => {
  3971. if (res3.success) {
  3972. var updatedata = {
  3973. id: res3.data,
  3974. status:1
  3975. };
  3976. WXAPI.updateCertificates(updatedata).then((res2) => {
  3977. });
  3978. WXAPI.sendCommand(datacom).then(res2 => {
  3979. if (res2.success) {}
  3980. })
  3981. console.log(res3, '添加凭证成功')
  3982. _this.getFp()
  3983. _this.setData({
  3984. show: false
  3985. })
  3986. wx.hideLoading()
  3987. wx.showToast({
  3988. title: '添加成功',
  3989. mask:true,
  3990. icon: 'none',
  3991. duration: 2000
  3992. })
  3993. } else {
  3994. wx.hideLoading()
  3995. wx.showToast({
  3996. title: '添加失败',
  3997. mask:true,
  3998. icon: 'none',
  3999. duration: 2000
  4000. })
  4001. }
  4002. })
  4003. }
  4004. }).catch(err=>{
  4005. var datacom = {
  4006. code: "zg/bleSendVoucherReply",
  4007. data: {
  4008. lockerId: deviceinfo.deviceNum,
  4009. serialNumber: res.data.serialNumber,
  4010. index:0,
  4011. type: 16,
  4012. result: 0
  4013. }
  4014. }
  4015. WXAPI.sendCommand(datacom).then(res2 => {
  4016. if (res2.success) {}
  4017. })
  4018. })
  4019. } else {
  4020. var datacom = {
  4021. code: "zg/bleSendVoucherReply",
  4022. data: {
  4023. lockerId: deviceinfo.deviceNum,
  4024. serialNumber: res.data.serialNumber,
  4025. index:0,
  4026. type: 16,
  4027. result: 0
  4028. }
  4029. }
  4030. WXAPI.sendCommand(datacom).then(res2 => {
  4031. if (res2.success) {}
  4032. })
  4033. wx.showToast({
  4034. title: res.msg,
  4035. duration: 2000,
  4036. mask:true,
  4037. icon: 'none'
  4038. })
  4039. }
  4040. })
  4041. }else if(deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241){
  4042. if(this.data.isSearch){
  4043. // fingerprintIndex = 1
  4044. // serialNumber = 1686309639840
  4045. // this.onAddFingerprint()
  4046. // return
  4047. var time1 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  4048. var time2 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  4049. var passwordStartTime = time1.getTime() / 1000
  4050. var passwordEndTime = time2.getTime() / 1000
  4051. var cardName='',pzname=''
  4052. if(this.data.pzname){
  4053. cardName=_this.data.personLi.name+'-蓝牙-'+_this.data.pzname
  4054. pzname='蓝牙-'+_this.data.pzname
  4055. }else{
  4056. cardName=_this.data.personLi.name+'-蓝牙-指纹'+(_this.data.FpList.length+1)
  4057. pzname='蓝牙-指纹'+(_this.data.FpList.length+1)
  4058. }
  4059. var dataPasswod = {
  4060. code: "lwj/fpOperate",
  4061. data: {
  4062. lockerId: deviceinfo.deviceNum,
  4063. action:1,
  4064. lockerUserId: info.userPassword,
  4065. fpData: '',
  4066. operateMode: 16,
  4067. order: 6216,
  4068. roomName: deviceinfo.roomName,
  4069. cardName: cardName,
  4070. startTime: passwordStartTime,
  4071. endTime: passwordEndTime,
  4072. type: 1
  4073. }
  4074. }
  4075. WXAPI.sendCommand(dataPasswod).then(res => {
  4076. if(res.success){
  4077. fingerprintIndex = res.data.index
  4078. serialNumber = res.data.serialNumber
  4079. this.onAddFingerprint()
  4080. }
  4081. })
  4082. }else{
  4083. this.searchDevicesMethods()
  4084. }
  4085. }
  4086. },
  4087. login: function () {
  4088. var that = this
  4089. taskId = 32
  4090. that.initBluetooth()
  4091. },
  4092. onLogin: function () {
  4093. var that = this
  4094. wx.showLoading({
  4095. title: '登录中',
  4096. })
  4097. var bytes = plugin.login1(lockDevice.name, basecode)
  4098. console.debug('bytes', bytes)
  4099. that.sendBytes(bytes)
  4100. },
  4101. onAddFingerprint: function () {
  4102. var that = this
  4103. wx.showLoading({
  4104. title: '添加指纹中',
  4105. })
  4106. // var startTime = util1.getLocalTime(8)
  4107. // var endTime = new Date(startTime.getTime() + 5 * 60 * 1000) //有效期5分钟
  4108. var startTime = new Date(Number(moment(that.data.starttime).format('x')))
  4109. var endTime = new Date(Number(moment(that.data.endtime).format('x')))
  4110. // fingerprintIndex = Math.floor(Math.random() * 100)
  4111. var bytes = plugin.addFingerprint(lockDevice.name, basecode, fingerprintIndex, startTime, endTime)
  4112. console.debug('bytes', bytes)
  4113. that.sendBytes(bytes)
  4114. },
  4115. // 关闭添加人员弹窗
  4116. onClose() {
  4117. this.setData({
  4118. show: false
  4119. });
  4120. },
  4121. onChange(event) {
  4122. console.log(event.detail)
  4123. this.setData({
  4124. activeKey: event.detail
  4125. })
  4126. },
  4127. getPassword() {
  4128. var data = {
  4129. pageNum: 0,
  4130. pageSize: 0,
  4131. q: JSON.stringify({
  4132. cardId: this.data.personLi.cardId,
  4133. deviceNum: this.data.deviceinfo.deviceNum,
  4134. types: "4",
  4135. inStatus:'0,1,702'
  4136. })
  4137. }
  4138. console.log(data)
  4139. WXAPI.getCertificates(data).then(res => {
  4140. var dataOne=util.zlib_unzip(res.data)
  4141. if (res.success) {
  4142. dataOne.map(li => {
  4143. li['pzname'] = JSON.parse(li.content).pzname
  4144. li['password'] = util.plusXing(JSON.parse(li.content).password, 2, 2, '*')
  4145. })
  4146. this.setData({
  4147. passwordList: dataOne
  4148. })
  4149. }
  4150. })
  4151. },
  4152. getNfc() {
  4153. var data = {
  4154. pageNum: 0,
  4155. pageSize: 0,
  4156. q: JSON.stringify({
  4157. cardId: this.data.personLi.cardId,
  4158. deviceNum: this.data.deviceinfo.deviceNum,
  4159. types: "3",
  4160. inStatus:'0,1,702'
  4161. })
  4162. }
  4163. WXAPI.getCertificates(data).then(res => {
  4164. console.log(res)
  4165. var dataOne=util.zlib_unzip(res.data)
  4166. console.log(dataOne)
  4167. if (res.success) {
  4168. dataOne.map(li => {
  4169. li['pzname'] = JSON.parse(li.content).pzname
  4170. li['password'] = util.plusXing(JSON.parse(li.content).password, 2, 2, '*')
  4171. })
  4172. this.setData({
  4173. NfcList: dataOne
  4174. })
  4175. }
  4176. })
  4177. },
  4178. getFp() {
  4179. var data = {
  4180. pageNum: 0,
  4181. pageSize: 0,
  4182. q: JSON.stringify({
  4183. cardId: this.data.personLi.cardId,
  4184. deviceNum: this.data.deviceinfo.deviceNum,
  4185. types: "1",
  4186. inStatus:'0,1,702'
  4187. })
  4188. }
  4189. WXAPI.getCertificates(data).then(res => {
  4190. var dataOne=util.zlib_unzip(res.data)
  4191. if (res.success) {
  4192. dataOne.map(li => {
  4193. li['pzname'] = JSON.parse(li.content).pzname
  4194. li['password'] = ''
  4195. li['fingerprintAlias'] = JSON.parse(li.content).fingerprintAlias || ''
  4196. })
  4197. this.setData({
  4198. FpList: dataOne
  4199. })
  4200. }
  4201. })
  4202. },
  4203. getCarId() {
  4204. var data = {
  4205. pageNum: 0,
  4206. pageSize: 0,
  4207. q: JSON.stringify({
  4208. cardId: this.data.personLi.cardId,
  4209. deviceNum: this.data.deviceinfo.deviceNum,
  4210. types: "2",
  4211. inStatus:'0,1,702'
  4212. })
  4213. }
  4214. WXAPI.getCertificates(data).then(res => {
  4215. var dataOne=util.zlib_unzip(res.data)
  4216. if (res.success) {
  4217. dataOne.map(li => {
  4218. li['pzname'] = JSON.parse(li.content).pzname
  4219. li['password'] = util.plusXing(JSON.parse(li.content).password, 2, 2, '*')
  4220. })
  4221. this.setData({
  4222. CarIdList: dataOne
  4223. })
  4224. }
  4225. })
  4226. },
  4227. /**
  4228. * 生命周期函数--监听页面初次渲染完成
  4229. */
  4230. onReady: function () {
  4231. },
  4232. /**
  4233. * 生命周期函数--监听页面显示
  4234. */
  4235. onShow: function () {
  4236. },
  4237. /**
  4238. * 生命周期函数--监听页面隐藏
  4239. */
  4240. onHide: function () {
  4241. },
  4242. /**
  4243. * 生命周期函数--监听页面卸载
  4244. */
  4245. onUnload: function () {
  4246. if (isConnected) {
  4247. console.log(connectedDeviceId,'connectedDeviceId')
  4248. wx.closeBLEConnection({
  4249. deviceId: connectedDeviceId,
  4250. success: function (res) {
  4251. isConnected = false
  4252. app.globalData.isConnected =false
  4253. },
  4254. })
  4255. }
  4256. },
  4257. /**
  4258. * 页面相关事件处理函数--监听用户下拉动作
  4259. */
  4260. onPullDownRefresh: function () {
  4261. },
  4262. /**
  4263. * 页面上拉触底事件的处理函数
  4264. */
  4265. onReachBottom: function () {
  4266. },
  4267. /**
  4268. * 用户点击右上角分享
  4269. */
  4270. onShareAppMessage: function () {
  4271. }
  4272. })