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.

4336 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. // 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) {
  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. wx.showLoading({
  1021. title: '正在删除',
  1022. mask: true
  1023. })
  1024. var cgInfo = this.data.cgInfo
  1025. var personLi = this.data.FpList[index]
  1026. var deviceinfo = this.data.deviceinfo
  1027. var info = JSON.parse(personLi.content)
  1028. var person = this.data.personLi
  1029. var _this = this
  1030. this.getFpIndex(index, function (data) {
  1031. if (data.length > 0) {
  1032. var FPindex = data[0].face
  1033. } else {
  1034. wx.hideLoading()
  1035. wx.showToast({
  1036. title: '获取指纹ID失败',
  1037. mask:true,
  1038. duration: 2000,
  1039. icon: 'none'
  1040. })
  1041. }
  1042. })
  1043. },
  1044. delFp(index) {
  1045. wx.showLoading({
  1046. title: '正在删除',
  1047. mask: true
  1048. })
  1049. var cgInfo = this.data.cgInfo
  1050. var personLi = this.data.FpList[index]
  1051. var deviceinfo = this.data.deviceinfo
  1052. var info = JSON.parse(personLi.content)
  1053. var personInfo=JSON.parse(this.data.personLi.info)
  1054. var _this = this
  1055. this.getFpIndex(index, function (data) {
  1056. if (data.length > 0) {
  1057. var FPindex = data[0].face
  1058. var dataPasswod = {
  1059. code: "zg/fpOperate",
  1060. data: {
  1061. lockerId: deviceinfo.deviceNum,
  1062. imei: deviceinfo.imei,
  1063. lockerUserId: personInfo.userId,
  1064. keyId: personInfo.userId,
  1065. fingerId: FPindex,
  1066. fingerType: '0',
  1067. startTime: personLi.startTime,
  1068. endTime: personLi.endTime,
  1069. order: 6218,
  1070. action: 2,
  1071. type: 1,
  1072. roomName: _this.data.deviceinfo.roomName,
  1073. cardName: _this.data.personLi.name,
  1074. }
  1075. }
  1076. WXAPI.sendCommand(dataPasswod).then(res => {
  1077. console.log(res, '获取索引')
  1078. if (res.success) {
  1079. var fingerNo = FPindex.toString(16)
  1080. if (fingerNo < 10) {
  1081. fingerNo = '000' + fingerNo
  1082. } else {
  1083. fingerNo = '00' + fingerNo
  1084. }
  1085. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId,
  1086. (callback) => {
  1087. console.log(callback)
  1088. if (callback.status == '00') {
  1089. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, callback.signKey, (callback1) => {
  1090. console.log(callback1)
  1091. if (callback1.status == '00') {
  1092. var startTime = personLi.startTime.toString(16).toUpperCase()
  1093. var endTime = personLi.endTime.toString(16).toUpperCase()
  1094. console.log(cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, '01', fingerNo, '', callback.signKey, '00', startTime, endTime, callback1.commonKey, '-----')
  1095. ICINLocker.modifyFingerPrints(cgInfo.lockerId, cgInfo.superId, personInfo.userId, personInfo.userId, '01', fingerNo, '', callback.signKey, '00', startTime, endTime, callback1.commonKey, (
  1096. callback2) => {
  1097. console.log(callback2)
  1098. if (callback2.status == '00') {
  1099. var datacom = {
  1100. code: "zg/bleSendVoucherReply",
  1101. data: {
  1102. lockerId: deviceinfo.deviceNum,
  1103. serialNumber: res.data.serialNumber,
  1104. index: FPindex,
  1105. type: 18,
  1106. result: 1
  1107. }
  1108. }
  1109. WXAPI.sendCommand(datacom).then(res2 => {
  1110. console.log(res2, '成功----')
  1111. })
  1112. wx.showToast({
  1113. title: '下发成功',
  1114. mask:true,
  1115. icon: 'none',
  1116. duration: 2000
  1117. })
  1118. var data = {
  1119. ids: [personLi.id]
  1120. }
  1121. wx.hideLoading()
  1122. WXAPI.deleteCertificates(data).then(res1 => {
  1123. if (res1.success) {
  1124. _this.getFp()
  1125. wx.showToast({
  1126. title: '删除成功',
  1127. mask:true,
  1128. icon: 'none',
  1129. duration: 2000
  1130. })
  1131. } else {
  1132. wx.showToast({
  1133. title: '删除失败',
  1134. mask:true,
  1135. icon: 'none',
  1136. duration: 2000
  1137. })
  1138. }
  1139. })
  1140. } else {
  1141. wx.hideLoading()
  1142. wx.showToast({
  1143. title: '删除失败',
  1144. mask:true,
  1145. icon: 'none',
  1146. duration: 2000
  1147. })
  1148. var datacom = {
  1149. code: "zg/bleSendVoucherReply",
  1150. data: {
  1151. lockerId: deviceinfo.deviceNum,
  1152. serialNumber: res.data.serialNumber,
  1153. index: FPindex,
  1154. type: 18,
  1155. result: 0
  1156. }
  1157. }
  1158. WXAPI.sendCommand(datacom).then(res2 => {
  1159. console.log(res2, '失败')
  1160. })
  1161. }
  1162. })
  1163. } else {
  1164. wx.hideLoading()
  1165. wx.showToast({
  1166. title: '删除失败',
  1167. mask:true,
  1168. icon: 'none',
  1169. duration: 2000
  1170. })
  1171. var datacom = {
  1172. code: "zg/bleSendVoucherReply",
  1173. data: {
  1174. lockerId: deviceinfo.deviceNum,
  1175. serialNumber: res.data.serialNumber,
  1176. index: FPindex,
  1177. type: 18,
  1178. result: 0
  1179. }
  1180. }
  1181. WXAPI.sendCommand(datacom).then(res2 => {
  1182. console.log(res2, '失败')
  1183. })
  1184. }
  1185. })
  1186. } else {
  1187. wx.hideLoading()
  1188. wx.showToast({
  1189. title: '删除失败',
  1190. mask:true,
  1191. icon: 'none',
  1192. duration: 2000
  1193. })
  1194. var datacom = {
  1195. code: "zg/bleSendVoucherReply",
  1196. data: {
  1197. lockerId: deviceinfo.deviceNum,
  1198. serialNumber: res.data.serialNumber,
  1199. index: FPindex,
  1200. type: 18,
  1201. result: 0
  1202. }
  1203. }
  1204. WXAPI.sendCommand(datacom).then(res2 => {
  1205. console.log(res2, '失败')
  1206. })
  1207. }
  1208. })
  1209. } else {
  1210. var datacom = {
  1211. code: "zg/bleSendVoucherReply",
  1212. data: {
  1213. lockerId: deviceinfo.deviceNum,
  1214. serialNumber: res.data.serialNumber,
  1215. index: FPindex,
  1216. type: 18,
  1217. result: 0
  1218. }
  1219. }
  1220. WXAPI.sendCommand(datacom).then(res2 => {
  1221. console.log(res2, '失败')
  1222. })
  1223. var data = {
  1224. ids: [personLi.id]
  1225. }
  1226. wx.hideLoading()
  1227. WXAPI.deleteCertificates(data).then(res1 => {
  1228. if (res1.success) {
  1229. _this.getFp()
  1230. }
  1231. })
  1232. wx.hideLoading()
  1233. wx.showToast({
  1234. title: res.msg,
  1235. mask:true,
  1236. icon: 'none',
  1237. duration: 2000
  1238. })
  1239. }
  1240. })
  1241. } else {
  1242. wx.hideLoading()
  1243. wx.showToast({
  1244. title: '获取失败',
  1245. mask:true,
  1246. duration: 2000,
  1247. icon: 'none'
  1248. })
  1249. }
  1250. })
  1251. },
  1252. delPassword1(index) {
  1253. wx.showLoading({
  1254. title: '正在删除',
  1255. mask: true
  1256. })
  1257. var _this = this
  1258. var deviceinfo = this.data.deviceinfo
  1259. var passwordLi = this.data.passwordList[index]
  1260. passwordLiAll = passwordLi
  1261. var info = JSON.parse(passwordLi.content)
  1262. var data = {
  1263. managerTelephone: "18270949468",
  1264. managerPassword: "202108",
  1265. userTelephone: info.userTelephone,
  1266. userPassword: info.userPassword,
  1267. password: info.password,
  1268. startTime: info.passwordStartTime,
  1269. endTime: info.passwordEndTime
  1270. }
  1271. console.log(data)
  1272. var timestamp = moment().format("x")
  1273. bleall.startFp1_63(data.managerTelephone, data.managerPassword, data.userTelephone,
  1274. data.userPassword, data.password, data.startTime, data.endTime, 9, timestamp,
  1275. function (res) {
  1276. if (res.success) {
  1277. var data = {
  1278. ids: [passwordLi.id]
  1279. }
  1280. WXAPI.deleteCertificates(data).then(res1 => {
  1281. if (res1.success) {
  1282. var data3 = {
  1283. code: "ble/operateUserInfo",
  1284. data: {
  1285. deviceNum: deviceinfo.deviceNum,
  1286. imei: deviceinfo.imei,
  1287. userTelephone: info.userTelephone,
  1288. userPassword: info.userPassword,
  1289. password: info.password,
  1290. userStartTime: info.passwordStartTime,
  1291. userEndTime: info.passwordEndTime,
  1292. passwordStartTime: info.passwordStartTime,
  1293. passwordEndTime: info.passwordEndTime,
  1294. operateMode: 9,
  1295. order: 6209,
  1296. timestamp: timestamp,
  1297. managerTelephone: '18270949468',
  1298. managerPassword: '202108',
  1299. passwordLength: 10,
  1300. permission: 4294967295,
  1301. times: 255,
  1302. recycleTime: "65535",
  1303. roomName: _this.data.deviceinfo.roomName,
  1304. cardName: _this.data.personLi.name,
  1305. }
  1306. }
  1307. WXAPI.sendCommand(data3).then(res => {
  1308. if (res.success) {
  1309. var data4 = {
  1310. result: 1,
  1311. serial: res.data.serialNumber
  1312. }
  1313. WXAPI.updatePush(data4).then(res4 => {
  1314. })
  1315. }
  1316. })
  1317. _this.getPassword()
  1318. wx.hideLoading()
  1319. wx.showToast({
  1320. title: '删除成功',
  1321. icon: 'none',
  1322. mask:true,
  1323. duration: 2000
  1324. })
  1325. } else {
  1326. wx.hideLoading()
  1327. wx.showToast({
  1328. title: '删除失败',
  1329. icon: 'none',
  1330. mask:true,
  1331. duration: 2000
  1332. })
  1333. }
  1334. })
  1335. }
  1336. if (res.data == "蓝牙功能暂不支持") {
  1337. // wx.hideLoading()
  1338. // wx.showLoading({
  1339. // title: '重新连接蓝牙中'
  1340. // })
  1341. _this.startconnect()
  1342. }
  1343. })
  1344. },
  1345. startconnect() {
  1346. wx.showLoading({
  1347. title: "连接蓝牙中",
  1348. mask: true
  1349. })
  1350. this.setData({
  1351. showLoading:true
  1352. })
  1353. // this.setData({
  1354. // showLoading:true
  1355. // })
  1356. var deviceinfo = this.data.deviceinfo
  1357. const ble = new BLE(this.data.deviceinfo.deviceNum, emitter)
  1358. app.globalData.ble = ble
  1359. this.watchBLE()
  1360. app.globalData.ble.init()
  1361. // }
  1362. },
  1363. watchBLE() {
  1364. var that = this
  1365. if (app.globalData.ble) {
  1366. app.globalData.ble.listen(res => {
  1367. if (res.type == 'connect') {
  1368. if (res.data == "未打开适配器") {
  1369. this.setData({
  1370. showLoading:false
  1371. })
  1372. wx.hideLoading()
  1373. wx.showModal({
  1374. title: "提示",
  1375. content: "请检查手机蓝牙和定位功能是否打开?",
  1376. showCancel: false,
  1377. confirmText: "确定",
  1378. success(res) {}
  1379. });
  1380. } else {
  1381. if (res.data == '蓝牙已连接') {
  1382. app.globalData.bleStatus = res.data
  1383. this.setData({
  1384. showLoading:false
  1385. })
  1386. if (this.data.current == 0) {
  1387. this.sendPassword()
  1388. } else if (that.data.current == 1) {
  1389. this.delPassword1(this.data.currentIndex)
  1390. } else if (that.data.current == 2) {
  1391. this.sendFp()
  1392. }
  1393. }
  1394. }
  1395. }
  1396. })
  1397. }
  1398. },
  1399. delPasswordLwj(index){
  1400. wx.showLoading({
  1401. title: '正在删除',
  1402. mask: true
  1403. })
  1404. var _this = this
  1405. var deviceinfo = this.data.deviceinfo
  1406. var passwordLi = this.data.passwordList[index]
  1407. passwordLiAll = passwordLi
  1408. var info = JSON.parse(passwordLi.content)
  1409. var personInfo=JSON.parse(this.data.personLi.info)
  1410. var cgInfo = this.data.cgInfo
  1411. var dataPasswod = {
  1412. code: "lwj/passwordOperate",
  1413. data: {
  1414. lockerId: deviceinfo.deviceNum,
  1415. lockerUserId: personInfo.userId,
  1416. startTime:passwordLi.startTime,
  1417. endTime:passwordLi.endTime,
  1418. order: 6209,
  1419. operateMode:9,
  1420. action: 2,
  1421. password: info.password,
  1422. type: 9,
  1423. cardName:_this.data.personLi.name,
  1424. roomName:deviceinfo.roomName
  1425. }
  1426. }
  1427. console.log(dataPasswod,'dataPasswod',info)
  1428. WXAPI.sendCommand(dataPasswod).then(res => {
  1429. console.log(res, '获取索引')
  1430. if (res.success) {
  1431. pincodeIndex = res.data.index
  1432. serialNumber = res.data.serialNumber
  1433. taskId = 52
  1434. _this.initBluetooth()
  1435. }else{
  1436. wx.hideLoading()
  1437. wx.showToast({
  1438. title: res.msg,
  1439. mask:true,
  1440. icon: 'none',
  1441. duration: 2000
  1442. })
  1443. }
  1444. })
  1445. },
  1446. onDelRfCard: function () {
  1447. var that = this
  1448. wx.showLoading({
  1449. title: '删除房卡中',
  1450. })
  1451. var bytes = plugin.delRfCard(lockDevice.name, basecode, rfCardId, rfCardIndex)
  1452. console.debug('bytes', bytes)
  1453. that.sendBytes(bytes)
  1454. },
  1455. onDelPincode: function () {
  1456. var that = this
  1457. wx.showLoading({
  1458. title: '删除密码中',
  1459. })
  1460. var bytes = plugin.delPincode(lockDevice.name, basecode, pincode, pincodeIndex)
  1461. console.debug('bytes', bytes)
  1462. that.sendBytes(bytes)
  1463. },
  1464. delPassword(index) {
  1465. wx.showLoading({
  1466. title: '正在删除',
  1467. mask: true
  1468. })
  1469. var _this = this
  1470. var deviceinfo = this.data.deviceinfo
  1471. var passwordLi = this.data.passwordList[index]
  1472. passwordLiAll = passwordLi
  1473. var info = JSON.parse(passwordLi.content)
  1474. var personInfo=JSON.parse(this.data.personLi.info)
  1475. var cgInfo = this.data.cgInfo
  1476. var dataPasswod = {
  1477. code: "zg/tempPassword",
  1478. data: {
  1479. lockerId: deviceinfo.deviceNum,
  1480. imei: deviceinfo.imei,
  1481. passwordCount: 255,
  1482. lockerUserId: personInfo.userId,
  1483. keyId: personInfo.userId,
  1484. passwordStartTime: passwordLi.startTime,
  1485. passwordEndTime: passwordLi.endTime,
  1486. order: 6209,
  1487. action: 2,
  1488. password: info.password,
  1489. type: 1,
  1490. cardName:_this.data.personLi.name,
  1491. roomName:deviceinfo.roomName
  1492. }
  1493. }
  1494. console.log(dataPasswod,'dataPasswod',info)
  1495. WXAPI.sendCommand(dataPasswod).then(res => {
  1496. console.log(res, '获取索引')
  1497. if (res.success) {
  1498. var pwdNo = res.data.index.toString(16)
  1499. var passwordIndex = res.data.index
  1500. if (pwdNo < 9) {
  1501. pwdNo = '0' + pwdNo
  1502. } else {
  1503. pwdNo = pwdNo
  1504. }
  1505. ICINLocker.getUserSignKey(cgInfo.lockerId, cgInfo.superId, personInfo.userId, cgInfo.superId, cgInfo.authKey, '01', (callback) => {
  1506. console.log(callback)
  1507. if (callback.status == '00') {
  1508. var userSignKey = callback.userSignKey
  1509. ICINLocker.getCommonKey(cgInfo.lockerId,personInfo.userId, personInfo.userId, userSignKey, (callback) => {
  1510. if (callback.status == '00') {
  1511. console.log(callback, 'commonKey')
  1512. var commonKey = callback.commonKey
  1513. var startTime = passwordLi.startTime.toString(16).toUpperCase()
  1514. var endTime = passwordLi.endTime.toString(16).toUpperCase()
  1515. ICINLocker.handlePwd(deviceinfo.deviceNum, cgInfo.superId, personInfo.userId, info.password, pwdNo, cgInfo.superId, cgInfo.authKey, '', startTime, endTime, 0, commonKey, (callback) => {
  1516. console.log(callback)
  1517. if (callback.status == '00') {
  1518. var datacom = {
  1519. code: "zg/bleSendVoucherReply",
  1520. data: {
  1521. lockerId: deviceinfo.deviceNum,
  1522. serialNumber: res.data.serialNumber,
  1523. index: passwordIndex,
  1524. type: 9,
  1525. result: 1
  1526. }
  1527. }
  1528. WXAPI.sendCommand(datacom).then(res2 => {
  1529. if (res2.success) {}
  1530. })
  1531. var data = {
  1532. ids: [passwordLiAll.id]
  1533. }
  1534. WXAPI.deleteCertificates(data).then(res1 => {
  1535. if (res1.success) {
  1536. _this.getPassword()
  1537. wx.hideLoading()
  1538. wx.showToast({
  1539. title: '删除成功',
  1540. mask:true,
  1541. icon: 'none',
  1542. duration: 2000
  1543. })
  1544. } else {
  1545. wx.hideLoading()
  1546. wx.showToast({
  1547. title: '删除失败',
  1548. mask:true,
  1549. icon: 'none',
  1550. duration: 2000
  1551. })
  1552. }
  1553. })
  1554. } else {
  1555. wx.hideLoading()
  1556. wx.showToast({
  1557. title: '删除失败',
  1558. mask:true,
  1559. icon: 'none',
  1560. duration: 2000
  1561. })
  1562. var datacom = {
  1563. code: "zg/bleSendVoucherReply",
  1564. data: {
  1565. lockerId: deviceinfo.deviceNum,
  1566. serialNumber: res.data.serialNumber,
  1567. index: res.data.index,
  1568. type: 9,
  1569. result: 0
  1570. }
  1571. }
  1572. WXAPI.sendCommand(datacom).then(res2 => {
  1573. console.log(res2, '失败')
  1574. })
  1575. }
  1576. })
  1577. } else {
  1578. wx.hideLoading()
  1579. wx.showToast({
  1580. title: '删除失败',
  1581. mask:true,
  1582. icon: 'none',
  1583. duration: 2000
  1584. })
  1585. }
  1586. })
  1587. } else {
  1588. wx.hideLoading()
  1589. wx.showToast({
  1590. title: '删除失败',
  1591. mask:true,
  1592. icon: 'none',
  1593. duration: 2000
  1594. })
  1595. }
  1596. })
  1597. } else {
  1598. wx.hideLoading()
  1599. wx.showToast({
  1600. title: res.msg,
  1601. mask:true,
  1602. icon: 'none',
  1603. duration: 2000
  1604. })
  1605. }
  1606. })
  1607. },
  1608. getPassWordMehods(content,id,type){
  1609. var that=this
  1610. var data = {
  1611. pageNum: 0,
  1612. pageSize: 0,
  1613. orderBy: "create_at desc",
  1614. q: {
  1615. cardId: id,
  1616. password:content,
  1617. deviceNum:this.data.deviceinfo.deviceNum,
  1618. types: type,
  1619. inStatus:'0,1,702'
  1620. },
  1621. };
  1622. WXAPI.getCertificates(data).then(res=>{
  1623. if(res.success){
  1624. var dataOne=util.zlib_unzip(res.data)
  1625. if(dataOne.length>0){
  1626. wx.showModal({
  1627. title: '提示',
  1628. content: '该密码已存在,不能重复添加',
  1629. success (res1) {
  1630. if (res1.confirm) {
  1631. console.log('用户点击确定')
  1632. that.setData({
  1633. password:'',
  1634. passwordStatus:false
  1635. })
  1636. } else if (res1.cancel) {
  1637. console.log('用户点击取消')
  1638. that.setData({
  1639. password:'',
  1640. passwordStatus:false
  1641. })
  1642. }
  1643. }
  1644. })
  1645. }else{
  1646. this.setData({
  1647. passwordStatus:true
  1648. })
  1649. }
  1650. }else{
  1651. wx.showToast({
  1652. title: '获取失败',
  1653. duration:'2000',
  1654. mask:true,
  1655. icon:'none'
  1656. })
  1657. }
  1658. })
  1659. },
  1660. sendPassword() {
  1661. let passwordLength = this.data.password.toString()
  1662. if(passwordLength.length != 6){
  1663. wx.showToast({
  1664. title: '格式错误,密码为6位数字!',
  1665. icon:'none'
  1666. })
  1667. return false;
  1668. }
  1669. wx.showLoading({
  1670. title: '正在添加',
  1671. mask:true,
  1672. })
  1673. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  1674. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  1675. var passwordStartTimecontrast = time3.getTime() / 1000
  1676. var passwordEndTimecontrast = time4.getTime() / 1000
  1677. this.getPassWordMehods(this.data.password,this.data.personLi.cardId,14)
  1678. if(this.data.password==''){
  1679. wx.showToast({
  1680. title: '密码不能为空',
  1681. mask:true,
  1682. duration: 2000,
  1683. icon: 'none'
  1684. })
  1685. return
  1686. }
  1687. if(!this.data.passwordStatus){
  1688. wx.showToast({
  1689. title: '已存在该密码,请重输',
  1690. duration: 2000,
  1691. mask:true,
  1692. icon: 'none'
  1693. })
  1694. return
  1695. }
  1696. if (passwordStartTimecontrast > passwordEndTimecontrast) {
  1697. wx.showToast({
  1698. title: '开始时间不能大于结束时间',
  1699. duration: 2000,
  1700. mask:true,
  1701. icon: 'none'
  1702. })
  1703. return
  1704. }
  1705. wx.showLoading({
  1706. title: '正在添加',
  1707. mask:true
  1708. })
  1709. var _this = this
  1710. var deviceinfo = this.data.deviceinfo
  1711. var info = JSON.parse(this.data.personLi.info)
  1712. if (deviceinfo.manufactureId == 101) {
  1713. var time1 = moment(this.data.datetimerange[0]).format("YYYYMMDDHHmmss")
  1714. var time2 = moment(this.data.datetimerange[1]).format("YYYYMMDDHHmmss")
  1715. var time3 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  1716. var time4 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  1717. var passwordStartTime = time3.getTime() / 1000
  1718. var passwordEndTime = time4.getTime() / 1000
  1719. var data1 = {
  1720. managerTelephone: "18270949468",
  1721. managerPassword: '202108',
  1722. userTelephone: info.userTelephone,
  1723. userPassword: info.userPassword,
  1724. password: this.data.password,
  1725. startTime: time1,
  1726. endTime: time2
  1727. }
  1728. var timestamp = moment().format("x")
  1729. bleall.startFp1_63(data1.managerTelephone, data1.managerPassword, data1.userTelephone,
  1730. data1.userPassword, data1.password, data1.startTime, data1.endTime, 7, timestamp,
  1731. function (res) {
  1732. console.log(res)
  1733. if (res.success) {
  1734. var pzname='',cardName=''
  1735. pzname='蓝牙-密码'+(_this.data.passwordList.length+1)
  1736. cardName=_this.data.personLi.name+'-蓝牙-密码'+(_this.data.passwordList.length+1)
  1737. var str = {
  1738. // cardId: this.personInfo.cardId,
  1739. pzname:pzname,
  1740. imei: _this.data.deviceinfo.imei,
  1741. password: _this.data.password.toString(),
  1742. userTelephone: JSON.parse(_this.data.personLi.info).userTelephone,
  1743. operateMode: 7,
  1744. userPassword: JSON.parse(_this.data.personLi.info).userPassword,
  1745. passwordStartTime: time1,
  1746. passwordEndTime: time2,
  1747. is: false,
  1748. pass:true
  1749. }
  1750. var data3 = {
  1751. code: "ble/operateUserInfo",
  1752. data: {
  1753. deviceNum: _this.data.deviceinfo.deviceNum,
  1754. imei: _this.data.deviceinfo.imei,
  1755. userTelephone: info.userTelephone,
  1756. userPassword: info.userPassword,
  1757. password: _this.data.password,
  1758. userStartTime: time1,
  1759. userEndTime: time2,
  1760. passwordStartTime: time1,
  1761. passwordEndTime: time2,
  1762. operateMode: 7,
  1763. order: 6207,
  1764. timestamp: timestamp,
  1765. managerTelephone: '18270949468',
  1766. managerPassword: '202108',
  1767. passwordLength: 10,
  1768. permission: 4294967295,
  1769. times: 255,
  1770. recycleTime: "65535",
  1771. roomName: _this.data.deviceinfo.roomName,
  1772. cardName: cardName,
  1773. }
  1774. }
  1775. WXAPI.sendCommand(data3).then(res3 => {
  1776. if (res3.success) {
  1777. var data4 = {
  1778. result: 1,
  1779. serial: res3.data.serialNumber
  1780. }
  1781. WXAPI.updatePush(data4).then(res4 => {
  1782. })
  1783. var data = {
  1784. cardId: _this.data.personLi.cardId,
  1785. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1786. deviceNum: _this.data.deviceinfo.deviceNum,
  1787. type: 4,
  1788. imei: _this.data.deviceinfo.imei,
  1789. serial: res3.data.serialNumber,
  1790. startTime: passwordStartTime,
  1791. endTime: passwordEndTime,
  1792. };
  1793. var datalist = {
  1794. cardId: _this.data.personLi.cardId,
  1795. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1796. type: 14,
  1797. startTime: passwordStartTime,
  1798. endTime: passwordEndTime,
  1799. };
  1800. console.log(datalist,'密码11')
  1801. WXAPI.addCertificates(datalist).then(res6 => {
  1802. console.log(datalist,'密码22')
  1803. })
  1804. WXAPI.addCertificates(data).then(res3 => {
  1805. if (res3.success) {
  1806. var updatedata = {
  1807. id: res3.data,
  1808. status:1
  1809. };
  1810. WXAPI.updateCertificates(updatedata).then((res2) => {
  1811. });
  1812. _this.getPassword()
  1813. _this.setData({
  1814. show: false
  1815. })
  1816. wx.hideLoading()
  1817. wx.showToast({
  1818. title: '添加成功',
  1819. icon: 'none',
  1820. mask:true,
  1821. duration: 2000
  1822. })
  1823. } else {
  1824. wx.hideLoading()
  1825. wx.showToast({
  1826. title: '添加失败',
  1827. mask:true,
  1828. icon: 'none',
  1829. duration: 2000
  1830. })
  1831. }
  1832. })
  1833. } else {
  1834. wx.showToast({
  1835. title: res3.msg,
  1836. mask:true,
  1837. icon: 'none',
  1838. duration: 2000
  1839. })
  1840. }
  1841. })
  1842. }else{
  1843. wx.hideLoading()
  1844. if (res.data == "蓝牙功能暂不支持") {
  1845. // wx.showToast({
  1846. // title: '重新连接蓝牙中',
  1847. // duration: 2000,
  1848. // icon: "none"
  1849. // })
  1850. _this.startconnect()
  1851. }else{
  1852. wx.showToast({
  1853. title: '下发失败',
  1854. mask:true,
  1855. duration: 2000,
  1856. icon: "none"
  1857. })
  1858. }
  1859. }
  1860. })
  1861. } else if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  1862. var cgInfo = this.data.cgInfo
  1863. var time1 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  1864. var time2 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  1865. var passwordStartTime = time1.getTime() / 1000
  1866. var passwordEndTime = time2.getTime() / 1000
  1867. var pzname='',cardName=''
  1868. pzname='蓝牙-密码'+(_this.data.passwordList.length+1)
  1869. cardName=_this.data.personLi.name+'-蓝牙-密码'+(_this.data.passwordList.length+1)
  1870. var dataPasswod = {
  1871. code: "zg/tempPassword",
  1872. data: {
  1873. lockerId: deviceinfo.deviceNum,
  1874. imei: deviceinfo.imei,
  1875. passwordCount: 255,
  1876. lockerUserId: info.userId,
  1877. keyId: info.userId,
  1878. passwordStartTime: passwordStartTime,
  1879. passwordEndTime: passwordEndTime,
  1880. order: 6207,
  1881. action: 1,
  1882. password: this.data.password.toString(),
  1883. type: 1,
  1884. roomName: this.data.deviceinfo.roomName,
  1885. cardName: cardName,
  1886. }
  1887. }
  1888. WXAPI.sendCommand(dataPasswod).then(res => {
  1889. console.log(res, '获取索引')
  1890. if (res.success) {
  1891. var pwdNo = res.data.index
  1892. var passwordIndex = res.data.index
  1893. // var str = res.data.index
  1894. pwdNo = pwdNo.toString(16)
  1895. if (pwdNo.length < 2) {
  1896. pwdNo='0'+pwdNo
  1897. }
  1898. var startTime = passwordStartTime.toString(16).toUpperCase()
  1899. var endTime = passwordEndTime.toString(16).toUpperCase()
  1900. info.startTime=startTime
  1901. info.endTime=endTime
  1902. info.pwdNo=pwdNo
  1903. info.password=this.data.password.toString()
  1904. methods.bluetoothOperation_ZH(cgInfo,info,3).then(result=>{
  1905. if (result.status == '00' ||result.status == '0a' ) {
  1906. var datacom = {
  1907. code: "zg/bleSendVoucherReply",
  1908. data: {
  1909. lockerId: deviceinfo.deviceNum,
  1910. serialNumber: res.data.serialNumber,
  1911. index: passwordIndex,
  1912. type: 7,
  1913. result: 1
  1914. }
  1915. }
  1916. var str = {
  1917. // cardId: this.personInfo.cardId,
  1918. imei: _this.data.deviceinfo.imei,
  1919. pzname:pzname,
  1920. password: _this.data.password.toString(),
  1921. userTelephone: JSON.parse(_this.data.personLi.info).userTelephone,
  1922. operateMode: 7,
  1923. userPassword: JSON.parse(_this.data.personLi.info).userPassword,
  1924. passwordStartTime: passwordStartTime,
  1925. passwordEndTime: passwordEndTime,
  1926. is: false,
  1927. pass:true
  1928. }
  1929. var data = {
  1930. cardId: _this.data.personLi.cardId,
  1931. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1932. deviceNum: _this.data.deviceinfo.deviceNum,
  1933. type: 4,
  1934. imei: _this.data.deviceinfo.imei,
  1935. serial: res.data.serialNumber,
  1936. startTime: passwordStartTime,
  1937. endTime: passwordEndTime,
  1938. };
  1939. var datalist = {
  1940. cardId: _this.data.personLi.cardId,
  1941. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1942. type: 14,
  1943. startTime: passwordStartTime,
  1944. endTime: passwordEndTime,
  1945. };
  1946. console.log(datalist,'密码11')
  1947. WXAPI.addCertificates(datalist).then(res6 => {
  1948. console.log(datalist,'密码22',res6)
  1949. })
  1950. console.log(data, '添加凭证')
  1951. WXAPI.addCertificates(data).then(res3 => {
  1952. if (res3.success) {
  1953. var updatedata = {
  1954. id: res3.data,
  1955. status:1
  1956. };
  1957. WXAPI.updateCertificates(updatedata).then((res2) => {
  1958. });
  1959. WXAPI.sendCommand(datacom).then(res2 => {
  1960. if (res2.success) {}
  1961. })
  1962. console.log(res3, '添加凭证成功')
  1963. _this.getPassword()
  1964. _this.setData({
  1965. show: false
  1966. })
  1967. wx.hideLoading()
  1968. wx.showToast({
  1969. title: '添加成功',
  1970. mask:true,
  1971. icon: 'none',
  1972. duration: 2000
  1973. })
  1974. } else {
  1975. wx.hideLoading()
  1976. wx.showToast({
  1977. title: '添加失败',
  1978. mask:true,
  1979. icon: 'none',
  1980. duration: 2000
  1981. })
  1982. }
  1983. })
  1984. } else {
  1985. wx.showToast({
  1986. title: '添加失败',
  1987. mask:true,
  1988. icon: 'none',
  1989. duration: 2000
  1990. })
  1991. var datacom = {
  1992. code: "zg/bleSendVoucherReply",
  1993. data: {
  1994. lockerId: deviceinfo.deviceNum,
  1995. serialNumber: res.data.serialNumber,
  1996. index: res.data.index,
  1997. type: 7,
  1998. result: 0
  1999. }
  2000. }
  2001. WXAPI.sendCommand(datacom).then(res2 => {
  2002. console.log(res2, '失败')
  2003. _this.setData({
  2004. show: false
  2005. })
  2006. })
  2007. }
  2008. }).catch(err=>{
  2009. wx.hideLoading()
  2010. wx.showToast({
  2011. title: '添加失败',
  2012. icon: 'none',
  2013. mask:true,
  2014. duration: 2000
  2015. })
  2016. var datacom = {
  2017. code: "zg/bleSendVoucherReply",
  2018. data: {
  2019. lockerId: deviceinfo.deviceNum,
  2020. serialNumber: res.data.serialNumber,
  2021. index: res.data.index,
  2022. type: 7,
  2023. result: 0
  2024. }
  2025. }
  2026. WXAPI.sendCommand(datacom).then(res2 => {
  2027. console.log(res2, '失败')
  2028. _this.setData({
  2029. show: false
  2030. })
  2031. })
  2032. })
  2033. } else {
  2034. wx.showToast({
  2035. title: res.msg,
  2036. duration: 2000,
  2037. mask:true,
  2038. icon: 'none'
  2039. })
  2040. }
  2041. })
  2042. }else if (deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241){
  2043. console.log(this.data.isSearch);
  2044. if(this.data.isSearch){
  2045. wx.hideLoading()
  2046. this.addPincode()
  2047. }else{
  2048. this.searchDevicesMethods()
  2049. }
  2050. }
  2051. },
  2052. onAddPincode: function () {
  2053. console.log("2073123");
  2054. var that = this
  2055. wx.showLoading({
  2056. title: '添加密码中',
  2057. })
  2058. var info = JSON.parse(this.data.personLi.info)
  2059. let deviceinfo = this.data.deviceinfo
  2060. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  2061. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  2062. var passwordStartTime = time1.getTime() / 1000
  2063. var passwordEndTime = time2.getTime() / 1000
  2064. var pzname='',cardName=''
  2065. pzname='蓝牙-密码'+(that.data.passwordList.length+1)
  2066. cardName=that.data.personLi.name+'-蓝牙-密码'+(that.data.passwordList.length+1)
  2067. var dataPasswod = {
  2068. code: "lwj/passwordOperate",
  2069. data: {
  2070. lockerId: deviceinfo.deviceNum,
  2071. lockerUserId: info.userId,
  2072. startTime:passwordStartTime,
  2073. endTime:passwordEndTime,
  2074. order: 6207,
  2075. operateMode:7,
  2076. action: 1,
  2077. password: this.data.password.toString(),
  2078. type: 7,
  2079. roomName: this.data.deviceinfo.roomName,
  2080. cardName: cardName,
  2081. }
  2082. }
  2083. WXAPI.sendCommand(dataPasswod).then(res => {
  2084. console.log(res, '获取索引')
  2085. if (res.success) {
  2086. var pwdNo = res.data.index
  2087. serialNumber = res.data.serialNumber
  2088. pincodeIndex = pwdNo
  2089. that.sendAddPincode()
  2090. }
  2091. })
  2092. // var startTime = util1.getLocalTime(8)
  2093. // var endTime = new Date(startTime.getTime() + 5 * 60 * 1000) //有效期5分钟
  2094. },
  2095. sendAddPincode(){
  2096. var that =this
  2097. var startTime = new Date(Number(moment(that.data.starttime).format('x')))
  2098. var endTime = new Date(Number(moment(that.data.endtime).format('x')))
  2099. pincode = this.data.password
  2100. console.log(lockDevice.name, basecode, pincode, pincodeIndex, startTime, endTime)
  2101. let bytes = plugin.addPincode(lockDevice.name, basecode, pincode, pincodeIndex, startTime, endTime)
  2102. console.log('bytes', bytes)
  2103. that.sendBytes(bytes)
  2104. },
  2105. addPincode: function () {
  2106. console.log("2124");
  2107. var that = this
  2108. taskId = 51
  2109. that.initBluetooth()
  2110. },
  2111. initBluetooth: function () {
  2112. var that = this
  2113. wx.getConnectedBluetoothDevices({
  2114. services: [config.uuid.serviceUuid],
  2115. success: function (res) {
  2116. res.devices.map(function (it) {
  2117. if (it.deviceId == connectedDeviceId || it.name == that.data.deviceinfo.deviceNum) {
  2118. isConnected = true
  2119. }
  2120. })
  2121. that.setData({
  2122. isConnected: isConnected
  2123. })
  2124. console.log(isInitReady,'isConnected', isConnected)
  2125. if (isConnected) {
  2126. console.log("2144");
  2127. if (isInitReady) {
  2128. console.log("2146");
  2129. that.doWork()
  2130. } else {
  2131. that.setupConnection()
  2132. }
  2133. } else {
  2134. that.connectTo()
  2135. }
  2136. },
  2137. })
  2138. },
  2139. setupConnection: function () {
  2140. var that = this
  2141. wx.showLoading({
  2142. title: '初始化连接中',
  2143. })
  2144. wx.getBLEDeviceServices({
  2145. deviceId: lockDevice.deviceId,
  2146. success: function (res) {
  2147. console.log('Services', res)
  2148. wx.getBLEDeviceCharacteristics({
  2149. deviceId: lockDevice.deviceId,
  2150. serviceId: config.uuid.serviceUuid.toUpperCase(),
  2151. success: function (res) {
  2152. console.log('Characteristics', res)
  2153. wx.showToast({
  2154. title: '连接成功',
  2155. duration:1000,
  2156. icon:'none'
  2157. })
  2158. wx.onBLECharacteristicValueChange(function (res) {
  2159. console.log(res,'reslllllll')
  2160. var bytes = new Uint8Array(res.value)
  2161. console.log('bytes', bytes)
  2162. var data = plugin.parseBytes(lockDevice.name, basecode, bytes)
  2163. console.log('data', data)
  2164. switch (data.cmd) {
  2165. case 'reportLockBattery': {
  2166. if (data.data.battery < 10) {
  2167. wx.showModal({
  2168. title: '电量报警',
  2169. content: `门锁当前电量${data.data.battery}%!\n电量严重不足,请立即更换电池!`,
  2170. showCancel: false
  2171. })
  2172. } else if (data.data.battery < 30) {
  2173. wx.showModal({
  2174. title: '电量预警',
  2175. content: `门锁当前电量${data.data.battery}%!\n请及时更换电池!`,
  2176. showCancel: false
  2177. })
  2178. }
  2179. break
  2180. }
  2181. case 'reportRfCardResult': {
  2182. if (taskId == 61) {
  2183. wx.showModal({
  2184. title: '检测到新卡',
  2185. content: `是否添加此房卡,卡号:${data.data.cardId}`,
  2186. success: function (res) {
  2187. if (res.confirm) {
  2188. console.log( data.data,'rfCardIdrfCardId')
  2189. // rfCardId = randomMethods()//data.data.cardId
  2190. that.onAddRfCard()
  2191. }
  2192. }
  2193. })
  2194. } else {
  2195. if (lockModel > 70) {
  2196. if (data.data.isValid) {
  2197. wx.showModal({
  2198. title: '提示',
  2199. content: `房卡开锁成功,序号:${data.data.index}`,
  2200. showCancel: false
  2201. })
  2202. } else {
  2203. wx.showModal({
  2204. title: '提示',
  2205. content: `多次刷房卡开锁失败!`,
  2206. showCancel: false
  2207. })
  2208. }
  2209. } else {
  2210. if (data.data.isValid) {
  2211. wx.showModal({
  2212. title: '提示',
  2213. content: `房卡开锁成功,卡号:${data.data.cardId}`,
  2214. showCancel: false
  2215. })
  2216. } else {
  2217. wx.showModal({
  2218. title: '提示',
  2219. content: `房卡未授权,卡号:${data.data.cardId}`,
  2220. showCancel: false
  2221. })
  2222. }
  2223. }
  2224. }
  2225. break
  2226. }
  2227. case 'reportPincodeResult': {
  2228. if (lockModel > 70) {
  2229. if (data.data.isValid) {
  2230. wx.showModal({
  2231. title: '提示',
  2232. content: `密码开锁成功,序号:${data.data.index}`,
  2233. showCancel: false
  2234. })
  2235. } else {
  2236. wx.showModal({
  2237. title: '提示',
  2238. content: `多次密码开锁失败!`,
  2239. showCancel: false
  2240. })
  2241. }
  2242. } else {
  2243. if (data.data.isValid) {
  2244. wx.showModal({
  2245. title: '提示',
  2246. content: `密码:${data.data.pincode}开锁成功!`,
  2247. showCancel: false
  2248. })
  2249. } else {
  2250. wx.showModal({
  2251. title: '提示',
  2252. content: `密码:${data.data.pincode}未授权!`,
  2253. showCancel: false
  2254. })
  2255. }
  2256. }
  2257. break
  2258. }
  2259. case 'reportFingerprintResult': {
  2260. if (data.data.isValid) {
  2261. wx.showModal({
  2262. title: '提示',
  2263. content: `指纹开锁成功,序号:${data.data.index}`,
  2264. showCancel: false
  2265. })
  2266. } else {
  2267. wx.showModal({
  2268. title: '提示',
  2269. content: `多次指纹开锁失败!`,
  2270. showCancel: false
  2271. })
  2272. }
  2273. break
  2274. }
  2275. case 'queryLockState': {
  2276. wx.hideLoading()
  2277. if (data.code != 200) {
  2278. wx.showModal({
  2279. title: '提示',
  2280. content: '查询失败!',
  2281. showCancel: false,
  2282. success: function (res) {}
  2283. })
  2284. break
  2285. }
  2286. that.setData({
  2287. lock: {
  2288. mac: data.data.mac,
  2289. lockType: util1.getLockType(lockModel),
  2290. },
  2291. isBindLock: data.data.isBind
  2292. })
  2293. lockMac = data.data.mac
  2294. if (taskId > 0) {
  2295. if (data.data.isBind) {
  2296. // wx.showModal({
  2297. // title: data.data.mac,
  2298. // content: '此设备已经硬件绑定!',
  2299. // showCancel: false,
  2300. // success: function (res) {}
  2301. // })
  2302. } else {
  2303. wx.showModal({
  2304. title: data.data.mac,
  2305. content: '此设备硬件未绑定!',
  2306. showCancel: false,
  2307. success: function (res) {}
  2308. })
  2309. }
  2310. }
  2311. taskId = 0
  2312. break
  2313. }
  2314. case 'queryLockBattery': {
  2315. wx.hideLoading()
  2316. if (data.code != 200) {
  2317. wx.showModal({
  2318. title: '提示',
  2319. content: '查询失败!',
  2320. showCancel: false,
  2321. success: function (res) {}
  2322. })
  2323. break
  2324. }
  2325. taskId = 0
  2326. wx.showModal({
  2327. title: '提示',
  2328. content: `此门锁电量为${data.data.battery}%`,
  2329. showCancel: false,
  2330. success: function (res) {}
  2331. })
  2332. break
  2333. }
  2334. case 'queryNbImei': {
  2335. wx.hideLoading()
  2336. if (data.code != 200) {
  2337. wx.showModal({
  2338. title: '提示',
  2339. content: '查询失败!',
  2340. showCancel: false,
  2341. success: function (res) {}
  2342. })
  2343. break
  2344. }
  2345. taskId = 0
  2346. wx.showModal({
  2347. title: '提示',
  2348. content: `此NB设备IMEI为${data.data.imei}`,
  2349. showCancel: false,
  2350. success: function (res) {}
  2351. })
  2352. break
  2353. }
  2354. case 'setNbFun': {
  2355. wx.hideLoading()
  2356. if (data.code != 200) {
  2357. wx.showModal({
  2358. title: '提示',
  2359. content: '设置Nb功能失败!',
  2360. showCancel: false,
  2361. success: function (res) {}
  2362. })
  2363. break
  2364. }
  2365. taskId = 0
  2366. wx.showModal({
  2367. title: '提示',
  2368. content: that.data.isNbEnable ? 'NB功能已禁用' : 'NB功能已打开',
  2369. showCancel: false,
  2370. })
  2371. that.setData({
  2372. isNbEnable: !that.data.isNbEnable
  2373. })
  2374. break
  2375. }
  2376. case 'sendBindLock': {
  2377. wx.hideLoading()
  2378. if (data.code != 200) {
  2379. wx.showModal({
  2380. title: '提示',
  2381. content: '绑定失败!',
  2382. showCancel: false,
  2383. success: function (res) {}
  2384. })
  2385. break
  2386. }
  2387. taskId = 0
  2388. that.setData({
  2389. isBindLock: data.data.isBind
  2390. })
  2391. if (data.data.isBind) {
  2392. wx.showToast({
  2393. title: '绑定成功!',
  2394. })
  2395. } else {
  2396. wx.showToast({
  2397. title: '绑定失败!',
  2398. })
  2399. }
  2400. break
  2401. }
  2402. case 'sendUnbindLock': {
  2403. wx.hideLoading()
  2404. if (data.code != 200) {
  2405. wx.showModal({
  2406. title: '提示',
  2407. content: '解绑失败!',
  2408. showCancel: false,
  2409. success: function (res) {}
  2410. })
  2411. break
  2412. }
  2413. taskId = 0
  2414. that.setData({
  2415. isBindLock: data.data.isBind
  2416. })
  2417. if (data.data.isBind) {
  2418. wx.showToast({
  2419. title: '解绑失败!',
  2420. })
  2421. } else {
  2422. wx.showToast({
  2423. title: '解绑成功!',
  2424. })
  2425. }
  2426. break
  2427. }
  2428. case 'login1':
  2429. case 'sendOpenLockP1': {
  2430. if (data.code != 200) {
  2431. wx.hideLoading()
  2432. if (taskId == 41) {
  2433. wx.showModal({
  2434. title: '提示',
  2435. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  2436. showCancel: false,
  2437. success: function (res) {}
  2438. })
  2439. } else if (taskId == 32) {
  2440. wx.showModal({
  2441. title: '提示',
  2442. content: '登录失败!',
  2443. showCancel: false,
  2444. success: function (res) {}
  2445. })
  2446. }
  2447. break
  2448. }
  2449. if (taskId == 41) {
  2450. var bytes = plugin.sendOpenLockP2(lockDevice.name, basecode, data.data.randomN)
  2451. console.debug('bytes', bytes)
  2452. that.sendBytes(bytes)
  2453. } else if (taskId == 32) {
  2454. var bytes = plugin.login2(lockDevice.name, basecode, data.data.randomN)
  2455. console.debug('bytes', bytes)
  2456. that.sendBytes(bytes)
  2457. }
  2458. break;
  2459. }
  2460. case 'login':
  2461. case 'sendOpenLockP2': {
  2462. wx.hideLoading()
  2463. if (data.code != 200) {
  2464. if (taskId == 41) {
  2465. wx.showModal({
  2466. title: '提示',
  2467. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  2468. showCancel: false,
  2469. success: function (res) {}
  2470. })
  2471. } else if (taskId == 32) {
  2472. wx.showModal({
  2473. title: '提示',
  2474. content: '登录失败!',
  2475. showCancel: false,
  2476. success: function (res) {}
  2477. })
  2478. }
  2479. break
  2480. }
  2481. isLockLogin = true
  2482. if (taskId == 41) {
  2483. // var data = {
  2484. // code: "zg/bleUnlockRecord",
  2485. // data: {
  2486. // lockerId: that.data.deviceinfo.deviceNum,
  2487. // roomId:that.data.deviceinfo.roomId,
  2488. // roomName:that.data.deviceinfo.roomName,
  2489. // cardName:that.data.userInfo.username
  2490. // }
  2491. // }
  2492. var data = {
  2493. code: "ble/bleUnlockRecord",
  2494. data: {
  2495. deviceNum: that.data.deviceinfo.deviceNum,
  2496. roomId:that.data.deviceinfo.roomId,
  2497. roomName:that.data.deviceinfo.roomName,
  2498. cardName:that.data.userInfo.username,
  2499. productId:that.data.deviceinfo.manufactureId,
  2500. userId:'29283991'
  2501. }
  2502. }
  2503. WXAPI.sendCommand(data).then(res => {
  2504. console.log(res)
  2505. })
  2506. wx.showToast({
  2507. title: that.data.isJack ? '上电成功!' : '解锁成功!',
  2508. })
  2509. } else if (taskId == 32) {
  2510. wx.showToast({
  2511. title: '登录成功!',
  2512. })
  2513. }
  2514. taskId = 0
  2515. break;
  2516. }
  2517. case 'syncClock': {
  2518. wx.hideLoading()
  2519. if (data.code != 200) {
  2520. wx.showModal({
  2521. title: '提示',
  2522. content: '同步时间失败!' + data.data.msg,
  2523. showCancel: false,
  2524. success: function (res) {}
  2525. })
  2526. break
  2527. }
  2528. taskId = 0
  2529. wx.showModal({
  2530. title: '提示',
  2531. content: '时间更新成功!',
  2532. showCancel: false
  2533. })
  2534. break;
  2535. }
  2536. case 'addPincode': {
  2537. // console.log(data.data,'data.data')
  2538. // wx.hideLoading()
  2539. let data2={
  2540. "code":"ble/bleSendVoucherReply",
  2541. "data":{
  2542. "deviceNum":that.data.deviceinfo.deviceNum,
  2543. "serialNumber":serialNumber,
  2544. "index":pincodeIndex,
  2545. "type":7,
  2546. "result":1,
  2547. "productId":that.data.deviceinfo.manufactureId
  2548. }
  2549. }
  2550. if (data.code != 200) {
  2551. data2={
  2552. "code":"ble/bleSendVoucherReply",
  2553. "data":{
  2554. "deviceNum":that.data.deviceinfo.deviceNum,
  2555. "serialNumber":serialNumber,
  2556. "index":pincodeIndex,
  2557. "type":7,
  2558. "result":0,
  2559. "productId":that.data.deviceinfo.manufactureId
  2560. }
  2561. }
  2562. WXAPI.sendCommand(data2).then(res=>{
  2563. })
  2564. wx.showModal({
  2565. title: '提示',
  2566. content: '添加密码失败!' + data.data.msg,
  2567. showCancel: false,
  2568. success: function (res) {}
  2569. })
  2570. break
  2571. }
  2572. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  2573. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  2574. var passwordStartTime = time1.getTime() / 1000
  2575. var passwordEndTime = time2.getTime() / 1000
  2576. var pzname='',cardName='';
  2577. pzname='蓝牙-密码'+(that.data.passwordList.length+1)
  2578. cardName=that.data.personLi.name+'-蓝牙-密码'+(that.data.passwordList.length+1)
  2579. var str = {
  2580. // cardId: this.personInfo.cardId,
  2581. imei: that.data.deviceinfo.imei,
  2582. pzname:pzname,
  2583. password: that.data.password.toString(),
  2584. userTelephone: JSON.parse(that.data.personLi.info).userTelephone,
  2585. operateMode: 7,
  2586. userPassword: JSON.parse(that.data.personLi.info).userPassword,
  2587. passwordStartTime: passwordStartTime,
  2588. passwordEndTime: passwordEndTime,
  2589. index:pincodeIndex,
  2590. is: false,
  2591. pass:true
  2592. }
  2593. var data1 = {
  2594. cardId: that.data.personLi.cardId,
  2595. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  2596. deviceNum: that.data.deviceinfo.deviceNum,
  2597. type: 4,
  2598. imei: that.data.deviceinfo.imei,
  2599. serial: serialNumber,
  2600. startTime: passwordStartTime,
  2601. endTime: passwordEndTime,
  2602. };
  2603. var datalist = {
  2604. cardId: that.data.personLi.cardId,
  2605. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  2606. type: 14,
  2607. startTime: passwordStartTime,
  2608. endTime: passwordEndTime,
  2609. };
  2610. WXAPI.addCertificates(datalist).then(res6 => {
  2611. console.log(datalist,'密码22',res6)
  2612. })
  2613. WXAPI.addCertificates(data1).then(res3 => {
  2614. if (res3.success) {
  2615. var updatedata = {
  2616. id: res3.data,
  2617. status:1
  2618. };
  2619. WXAPI.updateCertificates(updatedata).then((res2) => {
  2620. });
  2621. WXAPI.sendCommand(data2).then(res=>{
  2622. })
  2623. that.getPassword()
  2624. that.setData({
  2625. show: false
  2626. })
  2627. wx.hideLoading()
  2628. wx.showToast({
  2629. title: '添加成功',
  2630. mask:true,
  2631. icon: 'none',
  2632. duration: 2000
  2633. })
  2634. } else {
  2635. wx.hideLoading()
  2636. wx.showToast({
  2637. title: '添加失败',
  2638. mask:true,
  2639. icon: 'none',
  2640. duration: 2000
  2641. })
  2642. }
  2643. })
  2644. taskId = 0
  2645. that.setData({
  2646. isPincodeAdd: true,
  2647. show: false
  2648. })
  2649. wx.showModal({
  2650. title: '提示',
  2651. content: `添加密码${pincode}成功!`,
  2652. showCancel: false
  2653. })
  2654. break
  2655. }
  2656. case 'delPincode': {
  2657. wx.hideLoading()
  2658. if (data.code != 200) {
  2659. var datacom = {
  2660. code: "lwj/passwordOperate",
  2661. data: {
  2662. lockerId: that.data.deviceinfo.deviceNum,
  2663. serialNumber: serialNumber,
  2664. index: pincodeIndex,
  2665. action:2,
  2666. type: 9,
  2667. result: 0
  2668. }
  2669. }
  2670. WXAPI.sendCommand(datacom).then(res2 => {
  2671. console.log(res2, '失败')
  2672. })
  2673. wx.showModal({
  2674. title: '提示',
  2675. content: '删除密码失败!',
  2676. showCancel: false,
  2677. success: function (res) {}
  2678. })
  2679. break
  2680. }
  2681. taskId = 0
  2682. wx.showModal({
  2683. title: '提示',
  2684. content: `删除密码成功!`,
  2685. showCancel: false,
  2686. })
  2687. var datacom = {
  2688. code: "lwj/passwordOperate",
  2689. data: {
  2690. lockerId: that.data.deviceinfo.deviceNum,
  2691. serialNumber: serialNumber,
  2692. index: pincodeIndex,
  2693. action:2,
  2694. type: 9,
  2695. result: 1
  2696. }
  2697. }
  2698. WXAPI.sendCommand(datacom).then(res2 => {
  2699. if (res2.success) {}
  2700. })
  2701. var data = {
  2702. ids: [passwordLiAll.id]
  2703. }
  2704. WXAPI.deleteCertificates(data).then(res1 => {
  2705. if (res1.success) {
  2706. that.getPassword()
  2707. wx.hideLoading()
  2708. wx.showToast({
  2709. title: '删除成功',
  2710. mask:true,
  2711. icon: 'none',
  2712. duration: 2000
  2713. })
  2714. } else {
  2715. wx.hideLoading()
  2716. wx.showToast({
  2717. title: '删除失败',
  2718. mask:true,
  2719. icon: 'none',
  2720. duration: 2000
  2721. })
  2722. }
  2723. })
  2724. that.setData({
  2725. isPincodeAdd: false
  2726. })
  2727. pincode = -1
  2728. pincodeIndex = -1
  2729. break
  2730. }
  2731. case 'addRfCard': {
  2732. wx.hideLoading()
  2733. if (data.code == 100) {
  2734. wx.showLoading({
  2735. title: data.data.msg,
  2736. })
  2737. break
  2738. } else if (data.code != 200) {
  2739. var datacom = {
  2740. code: "ble/bleSendVoucherReply",
  2741. data: {
  2742. deviceNum: that.data.deviceinfo.deviceNum,
  2743. serialNumber: serialNumber,
  2744. index: rfCardIndex,
  2745. type: ADD_NFC_MODE,
  2746. cardNo: '',
  2747. result: 0,
  2748. productId:that.data.deviceinfo.manufactureId
  2749. }
  2750. }
  2751. WXAPI.sendCommand(datacom).then(res2 => {})
  2752. wx.showModal({
  2753. title: '提示',
  2754. content: '添加房卡失败!' + data.data.msg,
  2755. showCancel: false,
  2756. success: function (res) {}
  2757. })
  2758. break
  2759. }
  2760. taskId = 0
  2761. that.setData({
  2762. isRfCardAdd: true
  2763. })
  2764. if (lockModel > 70) {
  2765. console.log(data.data,'rfCardIndexrfCardIndex')
  2766. // rfCardId = randomMethods()
  2767. wx.showModal({
  2768. title: '提示',
  2769. content: `添加房卡成功,序号${rfCardIndex}`,
  2770. showCancel: false
  2771. })
  2772. that.addRfcardCertificates()
  2773. } else {
  2774. console.log(data.data,'rfCardIndexrfCardIndex1')
  2775. // rfCardId = randomMethods()
  2776. wx.showModal({
  2777. title: '提示',
  2778. content: `添加房卡成功,卡号${rfCardId}`,
  2779. showCancel: false
  2780. })
  2781. that.addRfcardCertificates()
  2782. }
  2783. break
  2784. }
  2785. case 'delRfCard': {
  2786. wx.hideLoading()
  2787. if (data.code != 200) {
  2788. var datacom = {
  2789. code: "lwj/c",
  2790. data: {
  2791. lockerId: that.data.deviceinfo.deviceNum,
  2792. serialNumber: serialNumber,
  2793. index: rfCardIndex,
  2794. action:2,
  2795. type: 12,
  2796. result: 0
  2797. }
  2798. }
  2799. WXAPI.sendCommand(datacom).then(res2 => {
  2800. console.log(res2, '失败')
  2801. })
  2802. wx.showModal({
  2803. title: '提示',
  2804. content: '删除房卡失败!',
  2805. showCancel: false,
  2806. success: function (res) {}
  2807. })
  2808. break
  2809. }
  2810. taskId = 0
  2811. that.setData({
  2812. isRfCardAdd: false
  2813. })
  2814. if (lockModel > 70) {
  2815. wx.showModal({
  2816. title: '提示',
  2817. content: `删除房卡成功,序号${rfCardIndex}`,
  2818. showCancel: false,
  2819. })
  2820. } else {
  2821. wx.showModal({
  2822. title: '提示',
  2823. content: `删除房卡成功,卡号${rfCardId}`,
  2824. showCancel: false,
  2825. })
  2826. }
  2827. var datacom = {
  2828. code: "lwj/c",
  2829. data: {
  2830. lockerId: that.data.deviceinfo.deviceNum,
  2831. serialNumber: serialNumber,
  2832. index: rfCardIndex,
  2833. action:2,
  2834. type: 12,
  2835. result: 1
  2836. }
  2837. }
  2838. WXAPI.sendCommand(datacom).then(res2 => {
  2839. console.log(res2, '失败')
  2840. })
  2841. var data = {
  2842. ids: [passwordLiAll.id]
  2843. }
  2844. WXAPI.deleteCertificates(data).then(res1 => {
  2845. if (res1.success) {
  2846. that.getNfc()
  2847. wx.showToast({
  2848. title: '删除成功',
  2849. mask:true,
  2850. icon: 'none',
  2851. duration: 2000
  2852. })
  2853. } else {
  2854. wx.showToast({
  2855. title: '删除失败',
  2856. mask:true,
  2857. icon: 'none',
  2858. duration: 2000
  2859. })
  2860. }
  2861. })
  2862. rfCardId = -1
  2863. rfCardIndex = -1
  2864. break
  2865. }
  2866. case 'addFingerprint': {
  2867. wx.hideLoading()
  2868. if (data.code == 100) {
  2869. wx.showLoading({
  2870. title: data.data.msg,
  2871. })
  2872. break
  2873. } else if (data.code != 200) {
  2874. wx.showModal({
  2875. title: '提示',
  2876. content: '添加指纹失败!' + data.data.msg,
  2877. showCancel: false,
  2878. success: function (res) {}
  2879. })
  2880. var datacom = {
  2881. code: "ble/bleSendVoucherReply",
  2882. data: {
  2883. deviceNum: that.data.deviceinfo.deviceNum,
  2884. serialNumber: serialNumber,
  2885. index:0,
  2886. type: 16,
  2887. result: 0,
  2888. productId:that.data.deviceinfo.manufactureId
  2889. }
  2890. }
  2891. WXAPI.sendCommand(datacom).then(res2 => {
  2892. if (res2.success) {}
  2893. })
  2894. break
  2895. }
  2896. taskId = 0
  2897. that.setData({
  2898. isFingerprintAdd: true
  2899. })
  2900. wx.showModal({
  2901. title: '提示',
  2902. content: `添加指纹成功,序号${fingerprintIndex}`,
  2903. showCancel: false
  2904. })
  2905. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  2906. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  2907. var passwordStartTime = time1.getTime() / 1000
  2908. var passwordEndTime = time2.getTime() / 1000
  2909. var cardName='',pzname=''
  2910. if(that.data.pzname){
  2911. cardName=that.data.personLi.name+'-蓝牙-'+that.data.pzname
  2912. pzname='蓝牙-'+that.data.pzname
  2913. }else{
  2914. cardName=that.data.personLi.name+'-蓝牙-指纹'+(that.data.FpList.length+1)
  2915. pzname='蓝牙-指纹'+(that.data.FpList.length+1)
  2916. }
  2917. var str = {
  2918. // cardId: this.personInfo.cardId,
  2919. imei: that.data.deviceinfo.imei,
  2920. pzname: pzname,
  2921. password: '',
  2922. fingerprintAlias:that.data.radioDetil,
  2923. userTelephone: JSON.parse(that.data.personLi.info).userTelephone,
  2924. operateMode: 16,
  2925. userPassword: JSON.parse(that.data.personLi.info).userPassword,
  2926. passwordStartTime: passwordStartTime,
  2927. passwordEndTime: passwordEndTime,
  2928. index:fingerprintIndex,
  2929. is: false,
  2930. pass:true
  2931. }
  2932. var data2 = {
  2933. cardId: that.data.personLi.cardId,
  2934. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  2935. deviceNum: that.data.deviceinfo.deviceNum,
  2936. type: 1,
  2937. imei: that.data.deviceinfo.imei,
  2938. serial:serialNumber,
  2939. startTime: passwordStartTime,
  2940. endTime: passwordEndTime,
  2941. status: 1
  2942. };
  2943. var datalist = {
  2944. cardId: that.data.personLi.cardId,
  2945. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  2946. type: 11,
  2947. startTime: passwordStartTime,
  2948. endTime: passwordEndTime
  2949. };
  2950. var datacom = {
  2951. code: "ble/bleSendVoucherReply",
  2952. data: {
  2953. deviceNum: that.data.deviceinfo.deviceNum,
  2954. serialNumber: serialNumber,
  2955. index:fingerprintIndex,
  2956. type: 16,
  2957. result: 1,
  2958. productId:that.data.deviceinfo.manufactureId
  2959. }
  2960. }
  2961. WXAPI.addCertificates(datalist).then(res6 => {})
  2962. console.log(data, '添加凭证')
  2963. WXAPI.addCertificates(data2).then(res3 => {
  2964. if (res3.success) {
  2965. var updatedata = {
  2966. id: res3.data,
  2967. status:1
  2968. };
  2969. WXAPI.updateCertificates(updatedata).then((res2) => {
  2970. });
  2971. WXAPI.sendCommand(datacom).then(res2 => {
  2972. if (res2.success) {}
  2973. })
  2974. console.log(res3, '添加凭证成功')
  2975. that.getFp()
  2976. that.setData({
  2977. show: false
  2978. })
  2979. wx.hideLoading()
  2980. wx.showToast({
  2981. title: '添加成功',
  2982. mask:true,
  2983. icon: 'none',
  2984. duration: 2000
  2985. })
  2986. } else {
  2987. wx.hideLoading()
  2988. wx.showToast({
  2989. title: '添加失败',
  2990. mask:true,
  2991. icon: 'none',
  2992. duration: 2000
  2993. })
  2994. }
  2995. })
  2996. break
  2997. }
  2998. case 'delFingerprint': {
  2999. wx.hideLoading()
  3000. if (data.code != 200) {
  3001. wx.showModal({
  3002. title: '提示',
  3003. content: '删除指纹失败!',
  3004. showCancel: false,
  3005. success: function (res) {}
  3006. })
  3007. break
  3008. }
  3009. taskId = 0
  3010. wx.showModal({
  3011. title: '提示',
  3012. content: `删除指纹成功,序号${fingerprintIndex}`,
  3013. showCancel: false,
  3014. })
  3015. that.setData({
  3016. isFingerprintAdd: false
  3017. })
  3018. fingerprintIndex = -1
  3019. break
  3020. }
  3021. case 'changeAdminPincode': {
  3022. wx.hideLoading()
  3023. if (data.code != 200) {
  3024. wx.showModal({
  3025. title: '提示',
  3026. content: '修改管理密码失败!',
  3027. showCancel: false,
  3028. success: function (res) {}
  3029. })
  3030. break
  3031. }
  3032. taskId = 0
  3033. wx.showToast({
  3034. title: '修改管理密码成功!',
  3035. })
  3036. }
  3037. case 'queryLockSlotState': {
  3038. wx.hideLoading()
  3039. if (data.code != 200) {
  3040. wx.showModal({
  3041. title: '提示',
  3042. content: '查询失败!',
  3043. showCancel: false,
  3044. success: function (res) {}
  3045. })
  3046. break
  3047. }
  3048. taskId = 0
  3049. wx.showModal({
  3050. title: '提示',
  3051. content: data.data.state == 0 ? '此门锁方舌关闭' : '此门锁方舌打开',
  3052. showCancel: false,
  3053. success: function (res) {}
  3054. })
  3055. break
  3056. }
  3057. case 'queryLockUnlockState': {
  3058. wx.hideLoading()
  3059. if (data.code != 200) {
  3060. wx.showModal({
  3061. title: '提示',
  3062. content: '查询失败!',
  3063. showCancel: false,
  3064. success: function (res) {}
  3065. })
  3066. break
  3067. }
  3068. taskId = 0
  3069. wx.showModal({
  3070. title: '提示',
  3071. content: data.data.state == 0 ? '此门锁已关闭' : '此门锁已打开',
  3072. showCancel: false,
  3073. success: function (res) {}
  3074. })
  3075. break
  3076. }
  3077. case 'setLockUnlockState': {
  3078. wx.hideLoading()
  3079. if (data.code != 200) {
  3080. wx.showModal({
  3081. title: '提示',
  3082. content: '设置常开指令失败!',
  3083. showCancel: false,
  3084. success: function (res) {}
  3085. })
  3086. break
  3087. }
  3088. taskId = 0
  3089. wx.showModal({
  3090. title: '提示',
  3091. content: data.data.state == 0 ? '常开模式已退出' : '常开模式已开启',
  3092. showCancel: false,
  3093. })
  3094. that.setData({
  3095. isUnloked: data.data.state == 1
  3096. })
  3097. break
  3098. }
  3099. case 'setLockMuteState': {
  3100. wx.hideLoading()
  3101. if (data.code != 200) {
  3102. wx.showModal({
  3103. title: '提示',
  3104. content: '设置静音指令失败!',
  3105. showCancel: false,
  3106. success: function (res) {}
  3107. })
  3108. break
  3109. }
  3110. taskId = 0
  3111. wx.showModal({
  3112. title: '提示',
  3113. content: data.data.state == 1 ? '静音模式已退出' : '静音模式已开启',
  3114. showCancel: false,
  3115. })
  3116. that.setData({
  3117. isMuted: data.data.state == 0
  3118. })
  3119. break
  3120. }
  3121. }
  3122. })
  3123. wx.notifyBLECharacteristicValueChange({
  3124. deviceId: lockDevice.deviceId,
  3125. serviceId: config.uuid.serviceUuid.toUpperCase(),
  3126. characteristicId: config.uuid.notifyUuid.toUpperCase(),
  3127. state: true,
  3128. success: function (res) {
  3129. console.log('setupNotify', res)
  3130. isInitReady = true
  3131. setTimeout(function () {
  3132. wx.hideLoading()
  3133. // that.onQueryBindState()
  3134. that.login()
  3135. }, 500)
  3136. },
  3137. })
  3138. },
  3139. })
  3140. },
  3141. })
  3142. },
  3143. onQueryBindState: function () {
  3144. var that = this
  3145. wx.showLoading({
  3146. title: '查询中',
  3147. })
  3148. var bytes = plugin.queryLockState(lockDevice.name)
  3149. console.debug('bytes', bytes)
  3150. that.sendBytes(bytes)
  3151. },
  3152. queryBindState: function () {
  3153. var that = this
  3154. taskId = 21
  3155. that.initBluetooth()
  3156. },
  3157. doWork: function () {
  3158. var that = this
  3159. console.log(taskId);
  3160. switch (taskId) {
  3161. case 11: {
  3162. that.onBindLock()
  3163. break
  3164. }
  3165. case 12: {
  3166. that.onUnbindLock()
  3167. break
  3168. }
  3169. case 21: {
  3170. that.onQueryBindState()
  3171. break
  3172. }
  3173. case 22: {
  3174. that.onQueryBattery()
  3175. break
  3176. }
  3177. case 31: {
  3178. that.onQueryNbImei()
  3179. break
  3180. }
  3181. case 32: {
  3182. that.onLogin()
  3183. break
  3184. }
  3185. case 41: {
  3186. that.LwjonOpenLock()
  3187. break
  3188. }
  3189. case 42: {
  3190. that.onSyncClock()
  3191. break
  3192. }
  3193. case 51: {
  3194. that.onAddPincode()
  3195. break
  3196. }
  3197. case 52: {
  3198. that.onDelPincode()
  3199. break
  3200. }
  3201. case 61: {
  3202. // that.onAddRfCard()
  3203. // if (lockModel > 70) {
  3204. that.sendAddRfcard()
  3205. // } else {
  3206. // wx.showModal({
  3207. // title: '提示',
  3208. // content: '请刷卡!',
  3209. // showCancel: false
  3210. // })
  3211. // }
  3212. break
  3213. }
  3214. case 62: {
  3215. that.onDelRfCard()
  3216. break
  3217. }
  3218. case 71: {
  3219. that.onAddFingerprint()
  3220. break
  3221. }
  3222. case 72: {
  3223. that.onDelFingerprint()
  3224. break
  3225. }
  3226. case 81: {
  3227. that.onChangeAdminPincode()
  3228. break
  3229. }
  3230. case 91: {
  3231. that.onQueryLockSlotState()
  3232. break
  3233. }
  3234. case 92: {
  3235. that.onQueryLockUnlockState()
  3236. break
  3237. }
  3238. case 101: {
  3239. that.onChangeLockUnlockState()
  3240. break
  3241. }
  3242. case 102: {
  3243. that.onChangeLockMutedState()
  3244. break
  3245. }
  3246. case 111: {
  3247. this.onChangeLockNbState()
  3248. }
  3249. default: {
  3250. }
  3251. }
  3252. },
  3253. connectTo: function () {
  3254. var that = this
  3255. wx.showLoading({
  3256. title: '连接中',
  3257. })
  3258. wx.createBLEConnection({
  3259. deviceId: lockDevice.deviceId,
  3260. timeout: config.ble.connectTimeOut,
  3261. success: function (res) {
  3262. console.log('connectTo', res)
  3263. isConnected = true
  3264. // app.globalData.isConnected = true
  3265. wx.hideLoading()
  3266. setTimeout(function () {
  3267. that.setupConnection()
  3268. }, 500)
  3269. },
  3270. fail: function (e) {
  3271. console.debug('connectTo', e)
  3272. wx.hideLoading()
  3273. switch (e.errCode) {
  3274. case 10003: {
  3275. wx.showModal({
  3276. title: '连接失败',
  3277. content: '是否重新连接?',
  3278. success: function (res) {
  3279. if (res.confirm) {
  3280. that.connectTo()
  3281. }
  3282. }
  3283. })
  3284. break
  3285. }
  3286. case 10012: {
  3287. wx.showModal({
  3288. title: '连接失败',
  3289. content: '蓝牙连接超时',
  3290. showCancel: false
  3291. })
  3292. break
  3293. }
  3294. case 10002: {
  3295. wx.showModal({
  3296. title: '连接失败',
  3297. content: '没有找到指定设备',
  3298. showCancel: false
  3299. })
  3300. break
  3301. }
  3302. }
  3303. }
  3304. })
  3305. },
  3306. searchDevicesMethods(){
  3307. var that = this;
  3308. wx.showLoading({
  3309. title: '正在搜索',
  3310. // mask: true
  3311. })
  3312. this.setData({
  3313. searchClick:false
  3314. })
  3315. wx.openBluetoothAdapter({
  3316. success: function (res) {
  3317. wx.startBluetoothDevicesDiscovery({
  3318. success: function (res) {
  3319. wx.getBluetoothDevices({
  3320. success: function (res) {
  3321. res.devices.map(it=>{
  3322. var status=it.name.indexOf('WSL_')
  3323. if(status!=-1){
  3324. if (it.RSSI != 127) {
  3325. if (it.advertisData != null) {
  3326. it.adData = util1.ab2hex(it.advertisData)
  3327. if (it.adData.length > 10) {
  3328. var macStr = it.adData.substring(4, 16).toUpperCase()
  3329. //console.log('macStr', macStr)
  3330. 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)
  3331. if (it.adData.substring(1, 2) == '1') {
  3332. it.isLightOn = true
  3333. it.textColor = 'green'
  3334. } else {
  3335. it.isLightOn = false
  3336. it.textColor = 'black'
  3337. }
  3338. if (it.adData.substring(3, 4) == '1') {
  3339. it.textColor = 'pink'
  3340. it.isBind = true
  3341. } else {
  3342. it.isBind = false
  3343. }
  3344. }
  3345. } else {
  3346. it.textColor = 'black'
  3347. }
  3348. lockModel = util1.getLockModel(it.name)
  3349. it.lockType = util1.getLockType(lockModel)
  3350. if(it.name == that.data.deviceinfo.deviceNum){
  3351. app.addDeviceWithDevName(it.name, it)
  3352. lockDevice = it
  3353. connectedDeviceId = it.deviceId
  3354. that.setData({
  3355. isSearch:true
  3356. })
  3357. that.initBluetooth()
  3358. }
  3359. }
  3360. }
  3361. })
  3362. if(!that.data.isSearch){
  3363. that.searchDevicesMethods()
  3364. }
  3365. }
  3366. })
  3367. },
  3368. fail:function(res){
  3369. wx.hideLoading({
  3370. success: (res) => {
  3371. wx.showToast({
  3372. title: res.errMsg,
  3373. duration:2000,
  3374. icon:'none'
  3375. })
  3376. },
  3377. })
  3378. }
  3379. })
  3380. },
  3381. fail: function (res) {
  3382. console.log('请打开蓝牙和定位功能')
  3383. wx.hideLoading({
  3384. success: (res) => {
  3385. wx.showToast({
  3386. title: '请打开蓝牙和定位功能',
  3387. duration:2000,
  3388. icon:'none'
  3389. })
  3390. },
  3391. })
  3392. }
  3393. })
  3394. },
  3395. LwjonOpenLock: function () {
  3396. var that = this
  3397. wx.showLoading({
  3398. title: that.data.isJack ? '上电中' : '解锁中',
  3399. })
  3400. console.log(lockDevice.name,'lockDevice.name0')
  3401. var bytes = plugin.sendOpenLockP1(lockDevice.name, basecode)
  3402. console.debug('bytes', bytes)
  3403. that.sendBytes(bytes)
  3404. },
  3405. openLock: function () {
  3406. var that = this
  3407. taskId = 41
  3408. that.initBluetooth()
  3409. },
  3410. sendBytes(bytes) {
  3411. setTimeout(()=> {
  3412. wx.writeBLECharacteristicValue({
  3413. deviceId: lockDevice.deviceId,
  3414. serviceId: config.uuid.serviceUuid.toUpperCase(),
  3415. characteristicId: config.uuid.writeUuid.toUpperCase(),
  3416. value: bytes,
  3417. success: function (res) {
  3418. },
  3419. })
  3420. }, 50)
  3421. },
  3422. sendNfc() {
  3423. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  3424. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  3425. var passwordStartTimecontrast = time3.getTime() / 1000
  3426. var passwordEndTimecontrast = time4.getTime() / 1000
  3427. if (passwordStartTimecontrast > passwordEndTimecontrast) {
  3428. wx.showToast({
  3429. title: '开始时间不能大于结束时间',
  3430. duration: 2000,
  3431. mask:true,
  3432. icon: 'none'
  3433. })
  3434. return
  3435. }
  3436. wx.showLoading({
  3437. title: '正在添加',
  3438. mask: true
  3439. })
  3440. var _this = this
  3441. var deviceinfo = this.data.deviceinfo
  3442. var info = JSON.parse(this.data.personLi.info)
  3443. if (deviceinfo.manufactureId == 101) {
  3444. } else if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  3445. var cgInfo = this.data.cgInfo
  3446. var time1 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  3447. var time2 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  3448. var passwordStartTime = time1.getTime() / 1000
  3449. var passwordEndTime = time2.getTime() / 1000
  3450. var pzname=_this.data.pzname,cardName=''
  3451. if(pzname==""){
  3452. pzname='蓝牙-NFC'+(_this.data.NfcList.length+1)
  3453. cardName=_this.data.personLi.name+'-蓝牙-NFC'+(_this.data.NfcList.length+1)
  3454. }else{
  3455. pzname='蓝牙-'+pzname
  3456. cardName=_this.data.personLi.name+'-蓝牙-'+pzname
  3457. }
  3458. var dataPasswod = {
  3459. code: "zg/cardOperate",
  3460. data: {
  3461. lockerId: deviceinfo.deviceNum,
  3462. imei: deviceinfo.imei,
  3463. lockerUserId: info.userId,
  3464. keyId: info.userId,
  3465. action: 1,
  3466. taskStatus: 1,
  3467. order: 6210,
  3468. startTime: passwordStartTime,
  3469. endTime: passwordEndTime,
  3470. cardType: 50,
  3471. type: ADD_NFC_MODE,
  3472. roomName: this.data.deviceinfo.roomName,
  3473. cardName: cardName,
  3474. }
  3475. }
  3476. console.log(dataPasswod,'dataPasswod')
  3477. WXAPI.sendCommand(dataPasswod).then(res => {
  3478. console.log(res,'resres')
  3479. if (res.success) {
  3480. var pwdNo = res.data.index
  3481. var passwordIndex = res.data.index
  3482. var serialNumber=res.data.serialNumber
  3483. pwdNo = pwdNo.toString(16)
  3484. if (pwdNo.length < 2) {
  3485. pwdNo='0'+pwdNo
  3486. }
  3487. var startTime = passwordStartTime.toString(16).toUpperCase()
  3488. var endTime = passwordEndTime.toString(16).toUpperCase()
  3489. info.startTime=startTime
  3490. info.endTime=endTime
  3491. info.pwdNo = pwdNo
  3492. methods.bluetoothOperation_ZH(cgInfo,info,7).then(result=>{
  3493. if (result.status == '00') {
  3494. let carNoId=this.processCardNumber(result.cardNo)
  3495. var datacom = {
  3496. code: "zg/bleSendVoucherReply",
  3497. data: {
  3498. lockerId: deviceinfo.deviceNum,
  3499. serialNumber: serialNumber,
  3500. index: passwordIndex,
  3501. type: ADD_NFC_MODE,
  3502. cardNo: carNoId.toUpperCase(),
  3503. result: 1
  3504. }
  3505. }
  3506. WXAPI.sendCommand(datacom).then(res2 => {
  3507. if (res2.success) {
  3508. var str = {
  3509. // cardId: this.personInfo.cardId,
  3510. pzname:pzname,
  3511. imei: _this.data.deviceinfo.imei,
  3512. password: carNoId.toUpperCase(),
  3513. blueCardNo:result.cardNo,
  3514. userTelephone: JSON.parse(_this.data.personLi.info).userTelephone,
  3515. operateMode: 10,
  3516. userPassword: JSON.parse(_this.data.personLi.info).userPassword,
  3517. passwordStartTime: passwordStartTime,
  3518. passwordEndTime: passwordEndTime,
  3519. is: false,
  3520. roomName:_this.data.deviceinfo.roomName,
  3521. }
  3522. var data = {
  3523. cardId: _this.data.personLi.cardId,
  3524. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3525. deviceNum: _this.data.deviceinfo.deviceNum,
  3526. type: 3,
  3527. blueCardNo:result.cardNo,
  3528. imei: _this.data.deviceinfo.imei,
  3529. serial: serialNumber,
  3530. startTime: passwordStartTime,
  3531. endTime: passwordEndTime,
  3532. };
  3533. console.log(data, '添加凭证')
  3534. var datalist = {
  3535. cardId: _this.data.personLi.cardId,
  3536. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3537. type: 13,
  3538. startTime: passwordStartTime,
  3539. endTime: passwordEndTime,
  3540. };
  3541. WXAPI.addCertificates(datalist).then(res6 => {
  3542. console.log(datalist,'NFC',res6)
  3543. })
  3544. WXAPI.addCertificates(data).then(res3 => {
  3545. if (res3.success) {
  3546. var updatedata = {
  3547. id: res3.data,
  3548. status:1
  3549. };
  3550. WXAPI.updateCertificates(updatedata).then((res2) => {
  3551. });
  3552. console.log(res3, '添加凭证成功')
  3553. _this.getNfc()
  3554. _this.setData({
  3555. show: false
  3556. })
  3557. wx.hideLoading()
  3558. wx.showToast({
  3559. title: '添加成功',
  3560. mask:true,
  3561. icon: 'none',
  3562. duration: 2000
  3563. })
  3564. } else {
  3565. wx.hideLoading()
  3566. wx.showToast({
  3567. title: '添加失败',
  3568. mask:true,
  3569. icon: 'none',
  3570. duration: 2000
  3571. })
  3572. }
  3573. })
  3574. }
  3575. })
  3576. } else {
  3577. wx.hideLoading()
  3578. wx.showToast({
  3579. title: '添加失败',
  3580. mask:true,
  3581. icon: 'none',
  3582. duration: 2000
  3583. })
  3584. var datacom = {
  3585. code: "zg/bleSendVoucherReply",
  3586. data: {
  3587. lockerId: deviceinfo.deviceNum,
  3588. serialNumber: serialNumber,
  3589. index: passwordIndex,
  3590. type: ADD_NFC_MODE,
  3591. result: 0
  3592. }
  3593. }
  3594. WXAPI.sendCommand(datacom).then(res2 => {
  3595. console.log(res2, '失败')
  3596. _this.setData({
  3597. show: false
  3598. })
  3599. })
  3600. }
  3601. }).catch(err=>{
  3602. var datacom = {
  3603. code: "zg/bleSendVoucherReply",
  3604. data: {
  3605. lockerId: deviceinfo.deviceNum,
  3606. serialNumber: serialNumber,
  3607. index: passwordIndex,
  3608. type: ADD_NFC_MODE,
  3609. result: 0
  3610. }
  3611. }
  3612. WXAPI.sendCommand(datacom).then(res2 => {
  3613. _this.setData({
  3614. show: false
  3615. })
  3616. })
  3617. wx.showToast({
  3618. title: '添加失败',
  3619. mask:true,
  3620. icon: 'none',
  3621. duration: 2000
  3622. })
  3623. })
  3624. } else {
  3625. wx.showToast({
  3626. title: res.msg,
  3627. duration: 2000,
  3628. mask:true,
  3629. icon: 'none'
  3630. })
  3631. }
  3632. })
  3633. }else if (deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241){
  3634. if(this.data.isSearch){
  3635. wx.hideLoading()
  3636. this.addRfCard()
  3637. }else{
  3638. this.searchDevicesMethods()
  3639. }
  3640. }
  3641. },
  3642. addRfCard: function () {
  3643. console.log("3691NFC");
  3644. var that = this
  3645. taskId = 61
  3646. that.initBluetooth()
  3647. },
  3648. onAddRfCard: function () {
  3649. var that = this
  3650. wx.showLoading({
  3651. title: '添加房卡中',
  3652. })
  3653. var startTime = new Date(Number(moment(that.data.starttime).format('x')))
  3654. var endTime = new Date(Number(moment(that.data.endtime).format('x')))
  3655. var bytes = plugin.addRfCard(lockDevice.name, basecode, rfCardId, rfCardIndex, startTime, endTime)
  3656. console.debug('bytes', bytes)
  3657. that.sendBytes(bytes)
  3658. },
  3659. addRfcardCertificates(){
  3660. var that = this
  3661. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  3662. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  3663. var passwordStartTime = time1.getTime() / 1000
  3664. var passwordEndTime = time2.getTime() / 1000
  3665. var pzname='',cardName='';
  3666. pzname='蓝牙-NFC'+(that.data.passwordList.length+1)
  3667. cardName=that.data.personLi.name+'-蓝牙-NFC'+(that.data.passwordList.length+1)
  3668. let carNoId = rfCardId
  3669. var datacom = {
  3670. code: "ble/bleSendVoucherReply",
  3671. data: {
  3672. deviceNum: that.data.deviceinfo.deviceNum,
  3673. serialNumber: serialNumber,
  3674. index: rfCardIndex,
  3675. type: ADD_NFC_MODE,
  3676. cardNo: rfCardId.toUpperCase(),
  3677. result: 1,
  3678. productId:that.data.deviceinfo.manufactureId
  3679. }
  3680. }
  3681. WXAPI.sendCommand(datacom).then(res2 => {
  3682. if (res2.success) {
  3683. var str = {
  3684. // cardId: this.personInfo.cardId,
  3685. pzname:pzname,
  3686. imei: that.data.deviceinfo.imei,
  3687. password: carNoId.toUpperCase(),
  3688. blueCardNo:rfCardIndex,
  3689. userTelephone: JSON.parse(that.data.personLi.info).userTelephone,
  3690. operateMode: 10,
  3691. userPassword: JSON.parse(that.data.personLi.info).userPassword,
  3692. passwordStartTime: passwordStartTime,
  3693. passwordEndTime: passwordEndTime,
  3694. is: false,
  3695. index:rfCardIndex,
  3696. roomName:that.data.deviceinfo.roomName,
  3697. }
  3698. var data2 = {
  3699. cardId: that.data.personLi.cardId,
  3700. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3701. deviceNum: that.data.deviceinfo.deviceNum,
  3702. type: 3,
  3703. blueCardNo:carNoId,
  3704. imei: that.data.deviceinfo.imei,
  3705. serial: serialNumber,
  3706. startTime: passwordStartTime,
  3707. endTime: passwordEndTime,
  3708. };
  3709. console.log(data2, '添加凭证')
  3710. var datalist = {
  3711. cardId: that.data.personLi.cardId,
  3712. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3713. type: 13,
  3714. startTime: passwordStartTime,
  3715. endTime: passwordEndTime,
  3716. };
  3717. WXAPI.addCertificates(datalist).then(res6 => {
  3718. console.log(datalist,'NFC',res6)
  3719. })
  3720. WXAPI.addCertificates(data2).then(res3 => {
  3721. if (res3.success) {
  3722. var updatedata = {
  3723. id: res3.data,
  3724. status:1
  3725. };
  3726. WXAPI.updateCertificates(updatedata).then((res2) => {
  3727. });
  3728. console.log(res3, '添加凭证成功')
  3729. that.getNfc()
  3730. that.setData({
  3731. show: false
  3732. })
  3733. wx.hideLoading()
  3734. wx.showToast({
  3735. title: '添加成功',
  3736. mask:true,
  3737. icon: 'none',
  3738. duration: 2000
  3739. })
  3740. } else {
  3741. wx.hideLoading()
  3742. wx.showToast({
  3743. title: '添加失败',
  3744. mask:true,
  3745. icon: 'none',
  3746. duration: 2000
  3747. })
  3748. }
  3749. })
  3750. }else{
  3751. wx.showToast({
  3752. title: res2.message,
  3753. duration:2000,
  3754. icon:'none'
  3755. })
  3756. }
  3757. })
  3758. },
  3759. sendAddRfcard(){
  3760. var that = this
  3761. var info = JSON.parse(this.data.personLi.info)
  3762. let deviceinfo = this.data.deviceinfo
  3763. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  3764. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  3765. var passwordStartTime = time1.getTime() / 1000
  3766. var passwordEndTime = time2.getTime() / 1000
  3767. var pzname='',cardName=''
  3768. pzname='蓝牙-NFC'+(that.data.NfcList.length+1)
  3769. cardName=that.data.personLi.name+'-蓝牙-NFC'+(that.data.NfcList.length+1)
  3770. rfCardId = randomMethods()
  3771. var dataPasswod = {
  3772. code: "lwj/cardOperate",
  3773. data: {
  3774. lockerId: deviceinfo.deviceNum,
  3775. lockerUserId: info.userId,
  3776. startTime:passwordStartTime,
  3777. endTime:passwordEndTime,
  3778. order: 6210,
  3779. operateMode:10,
  3780. action: 1,
  3781. cardNo: rfCardId,
  3782. type: 10,
  3783. roomName: this.data.deviceinfo.roomName,
  3784. cardName: cardName,
  3785. }
  3786. }
  3787. WXAPI.sendCommand(dataPasswod).then(res => {
  3788. console.log(res, '获取索引')
  3789. if (res.success) {
  3790. var pwdNo = res.data.index
  3791. serialNumber = res.data.serialNumber
  3792. rfCardIndex = pwdNo
  3793. setTimeout(()=>{
  3794. that.onAddRfCard()
  3795. },500)
  3796. }
  3797. })
  3798. },
  3799. processCardNumber(cardNo){
  3800. var str1=cardNo.substr(0,8)
  3801. var str2=cardNo.substr(8,8)
  3802. var num=str2.split("")
  3803. var status=num.every(item=> item==0)
  3804. console.log(status,num,'numnum',str1,str2)
  3805. if(status){
  3806. var bbb = str1.split("")
  3807. var a, b;
  3808. var aIndex = 0;
  3809. var bIndex = 1;
  3810. var arr = [];
  3811. bbb.forEach((str, index) => {
  3812. if (index % 2 === 0) {
  3813. a = str;
  3814. aIndex += 1
  3815. } else {
  3816. b = str
  3817. bIndex += 1
  3818. }
  3819. if (a&&b&&(bIndex-aIndex === 1)) {
  3820. arr.push(a+b)
  3821. }
  3822. });
  3823. console.log(arr)
  3824. return arr.join("")
  3825. }else{
  3826. var ll=str1+str2
  3827. return ll
  3828. }
  3829. },
  3830. sendFp() {
  3831. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  3832. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  3833. var passwordStartTimecontrast = time3.getTime() / 1000
  3834. var passwordEndTimecontrast = time4.getTime() / 1000
  3835. if (passwordStartTimecontrast > passwordEndTimecontrast) {
  3836. wx.showToast({
  3837. title: '开始时间不能大于结束时间',
  3838. duration: 2000,
  3839. mask:true,
  3840. icon: 'none'
  3841. })
  3842. return
  3843. }
  3844. if(this.data.radioDetil==''){
  3845. wx.showToast({
  3846. title: '请选择是那个指纹?',
  3847. mask:true,
  3848. duration: 2000,
  3849. icon: 'none'
  3850. })
  3851. return
  3852. }
  3853. wx.showLoading({
  3854. title: '正在添加指纹',
  3855. mask: true
  3856. })
  3857. var _this = this
  3858. var deviceinfo = this.data.deviceinfo
  3859. var info = JSON.parse(this.data.personLi.info)
  3860. if (deviceinfo.manufactureId == 101) {
  3861. let deviceNum = deviceinfo.deviceNum
  3862. this.setData({
  3863. backstatus: true
  3864. })
  3865. var timestamp = moment().format("x")
  3866. var time1 = moment(this.data.datetimerange[0]).format("YYYYMMDDHHmmss")
  3867. var time2 = moment(this.data.datetimerange[1]).format("YYYYMMDDHHmmss")
  3868. bleall.startFp_29(deviceNum, 0x03, timestamp, function (res) {
  3869. console.log(res, 'resresres')
  3870. if (res.success) {
  3871. wx.showLoading({
  3872. title: '正在添加指纹',
  3873. mask: true
  3874. })
  3875. }
  3876. if (res.data == "蓝牙功能暂不支持") {
  3877. wx.hideLoading()
  3878. _this.startconnect()
  3879. }
  3880. })
  3881. } else if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  3882. var cgInfo = this.data.cgInfo
  3883. var time1 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  3884. var time2 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  3885. var passwordStartTime = time1.getTime() / 1000
  3886. var passwordEndTime = time2.getTime() / 1000
  3887. var cardName='',pzname=''
  3888. if(this.data.pzname){
  3889. cardName=_this.data.personLi.name+'-蓝牙-'+_this.data.pzname
  3890. pzname='蓝牙-'+_this.data.pzname
  3891. }else{
  3892. cardName=_this.data.personLi.name+'-蓝牙-指纹'+(_this.data.FpList.length+1)
  3893. pzname='蓝牙-指纹'+(_this.data.FpList.length+1)
  3894. }
  3895. var dataPasswod = {
  3896. code: "zg/addFingerPrint",
  3897. data: {
  3898. lockerId: deviceinfo.deviceNum,
  3899. imei: deviceinfo.imei,
  3900. lockerUserId: info.userPassword,
  3901. keyId: info.userPassword,
  3902. fingerType: 0,
  3903. order: 6216,
  3904. fingerId: '',
  3905. roomName: deviceinfo.roomName,
  3906. cardName: cardName,
  3907. startTime: passwordStartTime,
  3908. endTime: passwordEndTime,
  3909. file: '',
  3910. type: 1
  3911. }
  3912. }
  3913. WXAPI.sendCommand(dataPasswod).then(res => {
  3914. console.log(res, '获取索引')
  3915. if (res.success) {
  3916. var startTime = passwordStartTime.toString(16).toUpperCase()
  3917. var endTime = passwordEndTime.toString(16).toUpperCase()
  3918. info.startTime=startTime
  3919. info.endTime=endTime
  3920. methods.bluetoothOperation_ZH(cgInfo,info,5).then(result=>{
  3921. if (result.status == '00' && result.completeFlag == '01') {
  3922. console.log(result,'callback2callback2')
  3923. var datacom = {
  3924. code: "zg/bleSendVoucherReply",
  3925. data: {
  3926. lockerId: deviceinfo.deviceNum,
  3927. serialNumber: res.data.serialNumber,
  3928. index: result.fingerprintNo,
  3929. type: 16,
  3930. result: 1
  3931. }
  3932. }
  3933. console.log(datacom)
  3934. var str = {
  3935. // cardId: this.personInfo.cardId,
  3936. imei: _this.data.deviceinfo.imei,
  3937. pzname: pzname,
  3938. password: '',
  3939. fingerprintAlias:_this.data.radioDetil,
  3940. userTelephone: JSON.parse(_this.data.personLi.info).userTelephone,
  3941. operateMode: 16,
  3942. userPassword: JSON.parse(_this.data.personLi.info).userPassword,
  3943. passwordStartTime: passwordStartTime,
  3944. passwordEndTime: passwordEndTime,
  3945. is: false,
  3946. pass:true
  3947. }
  3948. var data = {
  3949. cardId: _this.data.personLi.cardId,
  3950. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3951. deviceNum: _this.data.deviceinfo.deviceNum,
  3952. type: 1,
  3953. imei: _this.data.deviceinfo.imei,
  3954. serial: res.data.serialNumber,
  3955. startTime: passwordStartTime,
  3956. endTime: passwordEndTime,
  3957. status: 1
  3958. };
  3959. var datalist = {
  3960. cardId: _this.data.personLi.cardId,
  3961. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  3962. type: 11,
  3963. startTime: passwordStartTime,
  3964. endTime: passwordEndTime
  3965. };
  3966. WXAPI.addCertificates(datalist).then(res6 => {})
  3967. console.log(data, '添加凭证')
  3968. WXAPI.addCertificates(data).then(res3 => {
  3969. if (res3.success) {
  3970. var updatedata = {
  3971. id: res3.data,
  3972. status:1
  3973. };
  3974. WXAPI.updateCertificates(updatedata).then((res2) => {
  3975. });
  3976. WXAPI.sendCommand(datacom).then(res2 => {
  3977. if (res2.success) {}
  3978. })
  3979. console.log(res3, '添加凭证成功')
  3980. _this.getFp()
  3981. _this.setData({
  3982. show: false
  3983. })
  3984. wx.hideLoading()
  3985. wx.showToast({
  3986. title: '添加成功',
  3987. mask:true,
  3988. icon: 'none',
  3989. duration: 2000
  3990. })
  3991. } else {
  3992. wx.hideLoading()
  3993. wx.showToast({
  3994. title: '添加失败',
  3995. mask:true,
  3996. icon: 'none',
  3997. duration: 2000
  3998. })
  3999. }
  4000. })
  4001. }
  4002. }).catch(err=>{
  4003. var datacom = {
  4004. code: "zg/bleSendVoucherReply",
  4005. data: {
  4006. lockerId: deviceinfo.deviceNum,
  4007. serialNumber: res.data.serialNumber,
  4008. index:0,
  4009. type: 16,
  4010. result: 0
  4011. }
  4012. }
  4013. WXAPI.sendCommand(datacom).then(res2 => {
  4014. if (res2.success) {}
  4015. })
  4016. })
  4017. } else {
  4018. var datacom = {
  4019. code: "zg/bleSendVoucherReply",
  4020. data: {
  4021. lockerId: deviceinfo.deviceNum,
  4022. serialNumber: res.data.serialNumber,
  4023. index:0,
  4024. type: 16,
  4025. result: 0
  4026. }
  4027. }
  4028. WXAPI.sendCommand(datacom).then(res2 => {
  4029. if (res2.success) {}
  4030. })
  4031. wx.showToast({
  4032. title: res.msg,
  4033. duration: 2000,
  4034. mask:true,
  4035. icon: 'none'
  4036. })
  4037. }
  4038. })
  4039. }else if(deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241){
  4040. if(this.data.isSearch){
  4041. // fingerprintIndex = 1
  4042. // serialNumber = 1686309639840
  4043. // this.onAddFingerprint()
  4044. // return
  4045. var time1 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  4046. var time2 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  4047. var passwordStartTime = time1.getTime() / 1000
  4048. var passwordEndTime = time2.getTime() / 1000
  4049. var cardName='',pzname=''
  4050. if(this.data.pzname){
  4051. cardName=_this.data.personLi.name+'-蓝牙-'+_this.data.pzname
  4052. pzname='蓝牙-'+_this.data.pzname
  4053. }else{
  4054. cardName=_this.data.personLi.name+'-蓝牙-指纹'+(_this.data.FpList.length+1)
  4055. pzname='蓝牙-指纹'+(_this.data.FpList.length+1)
  4056. }
  4057. var dataPasswod = {
  4058. code: "lwj/fpOperate",
  4059. data: {
  4060. lockerId: deviceinfo.deviceNum,
  4061. action:1,
  4062. lockerUserId: info.userPassword,
  4063. fpData: '',
  4064. operateMode: 16,
  4065. order: 6216,
  4066. roomName: deviceinfo.roomName,
  4067. cardName: cardName,
  4068. startTime: passwordStartTime,
  4069. endTime: passwordEndTime,
  4070. type: 1
  4071. }
  4072. }
  4073. WXAPI.sendCommand(dataPasswod).then(res => {
  4074. if(res.success){
  4075. fingerprintIndex = res.data.index
  4076. serialNumber = res.data.serialNumber
  4077. this.onAddFingerprint()
  4078. }
  4079. })
  4080. }else{
  4081. this.searchDevicesMethods()
  4082. }
  4083. }
  4084. },
  4085. login: function () {
  4086. var that = this
  4087. taskId = 32
  4088. that.initBluetooth()
  4089. },
  4090. onLogin: function () {
  4091. var that = this
  4092. wx.showLoading({
  4093. title: '登录中',
  4094. })
  4095. var bytes = plugin.login1(lockDevice.name, basecode)
  4096. console.debug('bytes', bytes)
  4097. that.sendBytes(bytes)
  4098. },
  4099. onAddFingerprint: function () {
  4100. var that = this
  4101. wx.showLoading({
  4102. title: '添加指纹中',
  4103. })
  4104. // var startTime = util1.getLocalTime(8)
  4105. // var endTime = new Date(startTime.getTime() + 5 * 60 * 1000) //有效期5分钟
  4106. var startTime = new Date(Number(moment(that.data.starttime).format('x')))
  4107. var endTime = new Date(Number(moment(that.data.endtime).format('x')))
  4108. // fingerprintIndex = Math.floor(Math.random() * 100)
  4109. var bytes = plugin.addFingerprint(lockDevice.name, basecode, fingerprintIndex, startTime, endTime)
  4110. console.debug('bytes', bytes)
  4111. that.sendBytes(bytes)
  4112. },
  4113. // 关闭添加人员弹窗
  4114. onClose() {
  4115. this.setData({
  4116. show: false
  4117. });
  4118. },
  4119. onChange(event) {
  4120. console.log(event.detail)
  4121. this.setData({
  4122. activeKey: event.detail
  4123. })
  4124. },
  4125. getPassword() {
  4126. var data = {
  4127. pageNum: 0,
  4128. pageSize: 0,
  4129. q: JSON.stringify({
  4130. cardId: this.data.personLi.cardId,
  4131. deviceNum: this.data.deviceinfo.deviceNum,
  4132. types: "4",
  4133. inStatus:'0,1,702'
  4134. })
  4135. }
  4136. console.log(data)
  4137. WXAPI.getCertificates(data).then(res => {
  4138. var dataOne=util.zlib_unzip(res.data)
  4139. if (res.success) {
  4140. dataOne.map(li => {
  4141. li['pzname'] = JSON.parse(li.content).pzname
  4142. li['password'] = util.plusXing(JSON.parse(li.content).password, 2, 2, '*')
  4143. })
  4144. this.setData({
  4145. passwordList: dataOne
  4146. })
  4147. }
  4148. })
  4149. },
  4150. getNfc() {
  4151. var data = {
  4152. pageNum: 0,
  4153. pageSize: 0,
  4154. q: JSON.stringify({
  4155. cardId: this.data.personLi.cardId,
  4156. deviceNum: this.data.deviceinfo.deviceNum,
  4157. types: "3",
  4158. inStatus:'0,1,702'
  4159. })
  4160. }
  4161. WXAPI.getCertificates(data).then(res => {
  4162. console.log(res)
  4163. var dataOne=util.zlib_unzip(res.data)
  4164. console.log(dataOne)
  4165. if (res.success) {
  4166. dataOne.map(li => {
  4167. li['pzname'] = JSON.parse(li.content).pzname
  4168. li['password'] = util.plusXing(JSON.parse(li.content).password, 2, 2, '*')
  4169. })
  4170. this.setData({
  4171. NfcList: dataOne
  4172. })
  4173. }
  4174. })
  4175. },
  4176. getFp() {
  4177. var data = {
  4178. pageNum: 0,
  4179. pageSize: 0,
  4180. q: JSON.stringify({
  4181. cardId: this.data.personLi.cardId,
  4182. deviceNum: this.data.deviceinfo.deviceNum,
  4183. types: "1",
  4184. inStatus:'0,1,702'
  4185. })
  4186. }
  4187. WXAPI.getCertificates(data).then(res => {
  4188. var dataOne=util.zlib_unzip(res.data)
  4189. if (res.success) {
  4190. dataOne.map(li => {
  4191. li['pzname'] = JSON.parse(li.content).pzname
  4192. li['password'] = ''
  4193. li['fingerprintAlias'] = JSON.parse(li.content).fingerprintAlias || ''
  4194. })
  4195. this.setData({
  4196. FpList: dataOne
  4197. })
  4198. }
  4199. })
  4200. },
  4201. getCarId() {
  4202. var data = {
  4203. pageNum: 0,
  4204. pageSize: 0,
  4205. q: JSON.stringify({
  4206. cardId: this.data.personLi.cardId,
  4207. deviceNum: this.data.deviceinfo.deviceNum,
  4208. types: "2",
  4209. inStatus:'0,1,702'
  4210. })
  4211. }
  4212. WXAPI.getCertificates(data).then(res => {
  4213. var dataOne=util.zlib_unzip(res.data)
  4214. if (res.success) {
  4215. dataOne.map(li => {
  4216. li['pzname'] = JSON.parse(li.content).pzname
  4217. li['password'] = util.plusXing(JSON.parse(li.content).password, 2, 2, '*')
  4218. })
  4219. this.setData({
  4220. CarIdList: dataOne
  4221. })
  4222. }
  4223. })
  4224. },
  4225. /**
  4226. * 生命周期函数--监听页面初次渲染完成
  4227. */
  4228. onReady: function () {
  4229. },
  4230. /**
  4231. * 生命周期函数--监听页面显示
  4232. */
  4233. onShow: function () {
  4234. },
  4235. /**
  4236. * 生命周期函数--监听页面隐藏
  4237. */
  4238. onHide: function () {
  4239. },
  4240. /**
  4241. * 生命周期函数--监听页面卸载
  4242. */
  4243. onUnload: function () {
  4244. if (isConnected) {
  4245. console.log(connectedDeviceId,'connectedDeviceId')
  4246. wx.closeBLEConnection({
  4247. deviceId: connectedDeviceId,
  4248. success: function (res) {
  4249. isConnected = false
  4250. app.globalData.isConnected =false
  4251. },
  4252. })
  4253. }
  4254. },
  4255. /**
  4256. * 页面相关事件处理函数--监听用户下拉动作
  4257. */
  4258. onPullDownRefresh: function () {
  4259. },
  4260. /**
  4261. * 页面上拉触底事件的处理函数
  4262. */
  4263. onReachBottom: function () {
  4264. },
  4265. /**
  4266. * 用户点击右上角分享
  4267. */
  4268. onShareAppMessage: function () {
  4269. }
  4270. })