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.

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