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.

4406 lines
143 KiB

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