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.

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