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.

1658 lines
77 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. // pagesA/facepeople/facepeople.js
  2. import moment from '../../utils/moment'
  3. function CurentTime() {
  4. var now = new Date();
  5. var year = now.getFullYear(); //年
  6. var month = now.getMonth() + 1; //月
  7. var day = now.getDate(); //日
  8. var hh = now.getHours(); //时
  9. var mm = now.getMinutes(); //分
  10. var clock = year + "-";
  11. if (month < 10)
  12. clock += "0";
  13. clock += month + "-";
  14. if (day < 10)
  15. clock += "0";
  16. clock += day + " ";
  17. // if (hh < 10)
  18. // clock += "0";
  19. // clock += '00' + ":";
  20. // // if (mm < 10) clock += '0';
  21. clock += '00:00:00';
  22. return (clock);
  23. }
  24. function CurentTime1() {
  25. var now = new Date();
  26. var year = now.getFullYear() + 3; //年
  27. var month = now.getMonth() + 1; //月
  28. var day = now.getDate(); //日
  29. var hh = now.getHours(); //时
  30. var mm = now.getMinutes(); //分
  31. var clock = year + "-";
  32. if (month < 10)
  33. clock += "0";
  34. clock += month + "-";
  35. if (day < 10)
  36. clock += "0";
  37. clock += day + " ";
  38. // if (hh < 10)
  39. // clock += "0";
  40. // clock += hh + ":";
  41. // if (mm < 10) clock += '0';
  42. // clock += mm;
  43. clock += '23:59:59';
  44. return (clock);
  45. }
  46. const app = getApp()
  47. const WXAPI = require("../../utils/request")
  48. const util = require("../../utils/util")
  49. const plugin = requirePlugin("myPlugin")
  50. var methods = require('../../utils/methods');
  51. var md5 = require('../../utils/md5.js');
  52. var bleall = require('../../utils/bleall');
  53. var util1 = require('../../utils/util1');
  54. const config = require('../../config')
  55. const ADD_NFC_MODE = 10
  56. var date = new Date()
  57. var isConnected = false
  58. var connectedDeviceId = ''
  59. var basecode = 29283991
  60. var lockId = 1
  61. var lockManagerId = 1
  62. var lockMac = ''
  63. var isInitReady = false
  64. var lockModel
  65. var lockDevice
  66. var taskId = 0
  67. var pincode = -1
  68. var pincodeIndex = -1
  69. var rfCardId = -1
  70. var rfCardIndex = -1
  71. var fingerprintIndex = -1
  72. var passwordLiAll = {
  73. id: ''
  74. }
  75. var faceaddIndex = -1
  76. var isLockLogin = false
  77. var serialNumber = ''
  78. Page({
  79. /**
  80. * 页面的初始数据
  81. */
  82. data: {
  83. date: moment().format('YYYY-MM-DD HH:mm:ss'),
  84. show: false,
  85. value: '',
  86. show2: false,
  87. facename: '',
  88. minDate: '',
  89. minDate1: '',
  90. endtime: '',
  91. starttime: '',
  92. datetimerange: [CurentTime(), CurentTime1()],
  93. chooseface: false,
  94. avatarPath: "", // 上传的图片数据
  95. facepic: "", // 上传的图片的base64格式
  96. isSearch: app.globalData.isSearch,
  97. cgInfo: {},
  98. deviceinfo: {},
  99. personLi: {},
  100. faceList: [],
  101. },
  102. /**
  103. * 生命周期函数--监听页面加载
  104. */
  105. onLoad: function (options) {
  106. var cgInfo = wx.getStorageSync('cgInfo')
  107. var deviceinfo = wx.getStorageSync('deviceinfo')
  108. var personLi = wx.getStorageSync('personLi')
  109. let minDate = wx.getStorageSync('minDate')
  110. let minDate1 = wx.getStorageSync('minDate1')
  111. console.log(cgInfo, deviceinfo, personLi, minDate, minDate1);
  112. this.setData({
  113. isSearch: false,
  114. cgInfo: cgInfo,
  115. minDate,
  116. minDate1,
  117. starttime: minDate,
  118. endtime: minDate1,
  119. deviceinfo: deviceinfo,
  120. personLi: personLi,
  121. })
  122. if (this.data.avatarPath) {
  123. this.setData({
  124. show2: true
  125. })
  126. }
  127. },
  128. CurentTime() {
  129. var now = new Date();
  130. var year = now.getFullYear(); //年
  131. var month = now.getMonth() + 1; //月
  132. var day = now.getDate(); //日
  133. var hh = now.getHours(); //时
  134. var mm = now.getMinutes(); //分
  135. var clock = year + "-";
  136. if (month < 10)
  137. clock += "0";
  138. clock += month + "-";
  139. if (day < 10)
  140. clock += "0";
  141. clock += day + " ";
  142. // if (hh < 10)
  143. // clock += "0";
  144. // clock += '00' + ":";
  145. // // if (mm < 10) clock += '0';
  146. clock += '00:00:00';
  147. return (clock);
  148. },
  149. changeshow2() {
  150. this.setData({
  151. show2: true
  152. })
  153. },
  154. onChange2(e) {
  155. this.setData({
  156. facename: e.detail
  157. })
  158. },
  159. bindDateChange: function (e) {
  160. var str = e.detail.value + " 00:00:00"
  161. this.data.datetimerange[0] = str
  162. this.setData({
  163. starttime: str,
  164. })
  165. },
  166. bindDateChange1: function (e) {
  167. var str = e.detail.value + " 23:59:59"
  168. this.data.datetimerange[1] = str
  169. this.setData({
  170. endtime: str
  171. })
  172. },
  173. onSearch() {
  174. },
  175. onCancel() {
  176. },
  177. // 新增人脸
  178. addFace() {
  179. // wx.chooseImage({
  180. // count: 1,
  181. // sizeType: ['original', 'compressed'],
  182. // success: function (res) {
  183. // console.log(res)
  184. // wx.getImageInfo({
  185. // src: res.tempFilePaths[0],
  186. // success(res) {
  187. // wx.navigateTo({
  188. // url: '/pagesA/selectFace/selectFace?data=' + JSON.stringify(res)
  189. // })
  190. // }
  191. // })
  192. // }
  193. // });
  194. wx.navigateTo({
  195. url: '/pagesA/selectFace/selectFace',
  196. })
  197. },
  198. // 弹出框
  199. changeshow() {
  200. this.setData({
  201. show: true
  202. })
  203. },
  204. onClose() {
  205. this.setData({
  206. show: false,
  207. show2: false
  208. })
  209. },
  210. // 跳转详情页
  211. gotoinfo() {
  212. wx.navigateTo({
  213. url: '/pagesA/faceinfo/faceinfo',
  214. })
  215. },
  216. // 增加人脸
  217. sendface() {
  218. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  219. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  220. var passwordStartTimecontrast = time3.getTime() / 1000
  221. var passwordEndTimecontrast = time4.getTime() / 1000
  222. if (passwordStartTimecontrast > passwordEndTimecontrast) {
  223. wx.showToast({
  224. title: '开始时间不能大于结束时间',
  225. duration: 2000,
  226. mask: true,
  227. icon: 'none'
  228. })
  229. return
  230. }
  231. wx.showLoading({
  232. title: '正在添加人脸',
  233. mask: true
  234. })
  235. var _this = this
  236. var deviceinfo = this.data.deviceinfo
  237. var info = JSON.parse(this.data.personLi.info)
  238. if (deviceinfo.manufactureId == 1241) {
  239. var time1 = new Date(_this.data.datetimerange[0].replace(/-/g, '/'))
  240. var time2 = new Date(_this.data.datetimerange[1].replace(/-/g, '/'))
  241. var passwordStartTime = time1.getTime() / 1000
  242. var passwordEndTime = time2.getTime() / 1000
  243. // let facepicture = wx.getFileSystemManager().readFileSync(_this.data.avatarPath, "base64")
  244. // facepic = `data:image/jpg;base64, ${facepicture}`
  245. var dataface = {
  246. code: "lwj/faceOperate",
  247. data: {
  248. action: 1,
  249. endTime: passwordEndTime,
  250. faceData: _this.data.facepic,
  251. lockerId: deviceinfo.deviceNum,
  252. lockerUserId: info.userPassword,
  253. startTime: passwordStartTime,
  254. }
  255. }
  256. console.log(_this.data.avatarPath, dataface);
  257. WXAPI.sendCommand(dataface).then(res => {
  258. console.log(res);
  259. if (res.success) {
  260. faceaddIndex = res.data.index
  261. serialNumber = res.data.serialNumber
  262. }else{
  263. wx.showToast({
  264. title: res.msg,
  265. icon: 'none',
  266. duration: 2000
  267. })
  268. }
  269. })
  270. }
  271. },
  272. sendBytes(bytes) {
  273. setTimeout(() => {
  274. wx.writeBLECharacteristicValue({
  275. deviceId: lockDevice.deviceId,
  276. serviceId: config.uuid.serviceUuid.toUpperCase(),
  277. characteristicId: config.uuid.writeUuid.toUpperCase(),
  278. value: bytes,
  279. success: function (res) {
  280. },
  281. })
  282. }, 50)
  283. },
  284. searchDevicesMethods() {
  285. var that = this;
  286. wx.showLoading({
  287. title: '正在搜索',
  288. // mask: true
  289. })
  290. this.setData({
  291. searchClick: false
  292. })
  293. wx.openBluetoothAdapter({
  294. success: function (res) {
  295. wx.startBluetoothDevicesDiscovery({
  296. success: function (res) {
  297. wx.getBluetoothDevices({
  298. success: function (res) {
  299. res.devices.map(it => {
  300. var status = it.name.indexOf('WSL_')
  301. if (status != -1) {
  302. if (it.RSSI != 127) {
  303. if (it.advertisData != null) {
  304. it.adData = util1.ab2hex(it.advertisData)
  305. if (it.adData.length > 10) {
  306. var macStr = it.adData.substring(4, 16).toUpperCase()
  307. //console.log('macStr', macStr)
  308. 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)
  309. if (it.adData.substring(1, 2) == '1') {
  310. it.isLightOn = true
  311. it.textColor = 'green'
  312. } else {
  313. it.isLightOn = false
  314. it.textColor = 'black'
  315. }
  316. if (it.adData.substring(3, 4) == '1') {
  317. it.textColor = 'pink'
  318. it.isBind = true
  319. } else {
  320. it.isBind = false
  321. }
  322. }
  323. } else {
  324. it.textColor = 'black'
  325. }
  326. lockModel = util1.getLockModel(it.name)
  327. it.lockType = util1.getLockType(lockModel)
  328. if (it.name == that.data.deviceinfo.deviceNum) {
  329. app.addDeviceWithDevName(it.name, it)
  330. lockDevice = it
  331. connectedDeviceId = it.deviceId
  332. that.setData({
  333. isSearch: true
  334. })
  335. that.initBluetooth()
  336. }
  337. }
  338. }
  339. })
  340. if (!that.data.isSearch) {
  341. that.searchDevicesMethods()
  342. }
  343. }
  344. })
  345. },
  346. fail: function (res) {
  347. wx.hideLoading({
  348. success: (res) => {
  349. wx.showToast({
  350. title: res.errMsg,
  351. duration: 2000,
  352. icon: 'none'
  353. })
  354. },
  355. })
  356. }
  357. })
  358. },
  359. fail: function (res) {
  360. console.log('请打开蓝牙和定位功能')
  361. wx.hideLoading({
  362. success: (res) => {
  363. wx.showToast({
  364. title: '请打开蓝牙和定位功能',
  365. duration: 2000,
  366. icon: 'none'
  367. })
  368. },
  369. })
  370. }
  371. })
  372. },
  373. initBluetooth: function () {
  374. var that = this
  375. wx.getConnectedBluetoothDevices({
  376. services: [config.uuid.serviceUuid],
  377. success: function (res) {
  378. res.devices.map(function (it) {
  379. if (it.deviceId == connectedDeviceId || it.name == that.data.deviceinfo.deviceNum) {
  380. isConnected = true
  381. }
  382. })
  383. that.setData({
  384. isConnected: isConnected
  385. })
  386. console.log(isInitReady, 'isConnected', isConnected)
  387. if (isConnected) {
  388. console.log("2144");
  389. if (isInitReady) {
  390. console.log("2146");
  391. that.doWork()
  392. } else {
  393. that.setupConnection()
  394. }
  395. } else {
  396. that.connectTo()
  397. }
  398. },
  399. })
  400. },
  401. connectTo: function () {
  402. var that = this
  403. wx.showLoading({
  404. title: '连接中',
  405. })
  406. wx.createBLEConnection({
  407. deviceId: lockDevice.deviceId,
  408. timeout: config.ble.connectTimeOut,
  409. success: function (res) {
  410. console.log('connectTo', res)
  411. isConnected = true
  412. // app.globalData.isConnected = true
  413. wx.hideLoading()
  414. setTimeout(function () {
  415. that.setupConnection()
  416. }, 500)
  417. },
  418. fail: function (e) {
  419. console.debug('connectTo', e)
  420. wx.hideLoading()
  421. switch (e.errCode) {
  422. case 10003: {
  423. wx.showModal({
  424. title: '连接失败',
  425. content: '是否重新连接?',
  426. success: function (res) {
  427. if (res.confirm) {
  428. that.connectTo()
  429. }
  430. }
  431. })
  432. break
  433. }
  434. case 10012: {
  435. wx.showModal({
  436. title: '连接失败',
  437. content: '蓝牙连接超时',
  438. showCancel: false
  439. })
  440. break
  441. }
  442. case 10002: {
  443. wx.showModal({
  444. title: '连接失败',
  445. content: '没有找到指定设备',
  446. showCancel: false
  447. })
  448. break
  449. }
  450. }
  451. }
  452. })
  453. },
  454. setupConnection: function () {
  455. var that = this
  456. wx.showLoading({
  457. title: '初始化连接中',
  458. })
  459. wx.getBLEDeviceServices({
  460. deviceId: lockDevice.deviceId,
  461. success: function (res) {
  462. console.log('Services', res)
  463. wx.getBLEDeviceCharacteristics({
  464. deviceId: lockDevice.deviceId,
  465. serviceId: config.uuid.serviceUuid.toUpperCase(),
  466. success: function (res) {
  467. console.log('Characteristics', res)
  468. wx.showToast({
  469. title: '连接成功',
  470. duration: 1000,
  471. icon: 'none'
  472. })
  473. wx.onBLECharacteristicValueChange(function (res) {
  474. console.log(res, 'reslllllll')
  475. var bytes = new Uint8Array(res.value)
  476. console.log('bytes', bytes)
  477. var data = plugin.parseBytes(lockDevice.name, basecode, bytes)
  478. console.log('data', data)
  479. switch (data.cmd) {
  480. case 'reportLockBattery': {
  481. if (data.data.battery < 10) {
  482. wx.showModal({
  483. title: '电量报警',
  484. content: `门锁当前电量${data.data.battery}%!\n电量严重不足,请立即更换电池!`,
  485. showCancel: false
  486. })
  487. } else if (data.data.battery < 30) {
  488. wx.showModal({
  489. title: '电量预警',
  490. content: `门锁当前电量${data.data.battery}%!\n请及时更换电池!`,
  491. showCancel: false
  492. })
  493. }
  494. break
  495. }
  496. case 'reportRfCardResult': {
  497. if (taskId == 61) {
  498. wx.showModal({
  499. title: '检测到新卡',
  500. content: `是否添加此房卡,卡号:${data.data.cardId}`,
  501. success: function (res) {
  502. if (res.confirm) {
  503. console.log(data.data, 'rfCardIdrfCardId')
  504. // rfCardId = randomMethods()//data.data.cardId
  505. that.onAddRfCard()
  506. }
  507. }
  508. })
  509. } else {
  510. if (lockModel > 70) {
  511. if (data.data.isValid) {
  512. wx.showModal({
  513. title: '提示',
  514. content: `房卡开锁成功,序号:${data.data.index}`,
  515. showCancel: false
  516. })
  517. } else {
  518. wx.showModal({
  519. title: '提示',
  520. content: `多次刷房卡开锁失败!`,
  521. showCancel: false
  522. })
  523. }
  524. } else {
  525. if (data.data.isValid) {
  526. wx.showModal({
  527. title: '提示',
  528. content: `房卡开锁成功,卡号:${data.data.cardId}`,
  529. showCancel: false
  530. })
  531. } else {
  532. wx.showModal({
  533. title: '提示',
  534. content: `房卡未授权,卡号:${data.data.cardId}`,
  535. showCancel: false
  536. })
  537. }
  538. }
  539. }
  540. break
  541. }
  542. case 'reportPincodeResult': {
  543. if (lockModel > 70) {
  544. if (data.data.isValid) {
  545. wx.showModal({
  546. title: '提示',
  547. content: `密码开锁成功,序号:${data.data.index}`,
  548. showCancel: false
  549. })
  550. } else {
  551. wx.showModal({
  552. title: '提示',
  553. content: `多次密码开锁失败!`,
  554. showCancel: false
  555. })
  556. }
  557. } else {
  558. if (data.data.isValid) {
  559. wx.showModal({
  560. title: '提示',
  561. content: `密码:${data.data.pincode}开锁成功!`,
  562. showCancel: false
  563. })
  564. } else {
  565. wx.showModal({
  566. title: '提示',
  567. content: `密码:${data.data.pincode}未授权!`,
  568. showCancel: false
  569. })
  570. }
  571. }
  572. break
  573. }
  574. case 'reportFingerprintResult': {
  575. if (data.data.isValid) {
  576. wx.showModal({
  577. title: '提示',
  578. content: `指纹开锁成功,序号:${data.data.index}`,
  579. showCancel: false
  580. })
  581. } else {
  582. wx.showModal({
  583. title: '提示',
  584. content: `多次指纹开锁失败!`,
  585. showCancel: false
  586. })
  587. }
  588. break
  589. }
  590. case 'queryLockState': {
  591. wx.hideLoading()
  592. if (data.code != 200) {
  593. wx.showModal({
  594. title: '提示',
  595. content: '查询失败!',
  596. showCancel: false,
  597. success: function (res) {}
  598. })
  599. break
  600. }
  601. that.setData({
  602. lock: {
  603. mac: data.data.mac,
  604. lockType: util1.getLockType(lockModel),
  605. },
  606. isBindLock: data.data.isBind
  607. })
  608. lockMac = data.data.mac
  609. if (taskId > 0) {
  610. if (data.data.isBind) {
  611. // wx.showModal({
  612. // title: data.data.mac,
  613. // content: '此设备已经硬件绑定!',
  614. // showCancel: false,
  615. // success: function (res) {}
  616. // })
  617. } else {
  618. wx.showModal({
  619. title: data.data.mac,
  620. content: '此设备硬件未绑定!',
  621. showCancel: false,
  622. success: function (res) {}
  623. })
  624. }
  625. }
  626. taskId = 0
  627. break
  628. }
  629. case 'queryLockBattery': {
  630. wx.hideLoading()
  631. if (data.code != 200) {
  632. wx.showModal({
  633. title: '提示',
  634. content: '查询失败!',
  635. showCancel: false,
  636. success: function (res) {}
  637. })
  638. break
  639. }
  640. taskId = 0
  641. wx.showModal({
  642. title: '提示',
  643. content: `此门锁电量为${data.data.battery}%`,
  644. showCancel: false,
  645. success: function (res) {}
  646. })
  647. break
  648. }
  649. case 'queryNbImei': {
  650. wx.hideLoading()
  651. if (data.code != 200) {
  652. wx.showModal({
  653. title: '提示',
  654. content: '查询失败!',
  655. showCancel: false,
  656. success: function (res) {}
  657. })
  658. break
  659. }
  660. taskId = 0
  661. wx.showModal({
  662. title: '提示',
  663. content: `此NB设备IMEI为${data.data.imei}`,
  664. showCancel: false,
  665. success: function (res) {}
  666. })
  667. break
  668. }
  669. case 'setNbFun': {
  670. wx.hideLoading()
  671. if (data.code != 200) {
  672. wx.showModal({
  673. title: '提示',
  674. content: '设置Nb功能失败!',
  675. showCancel: false,
  676. success: function (res) {}
  677. })
  678. break
  679. }
  680. taskId = 0
  681. wx.showModal({
  682. title: '提示',
  683. content: that.data.isNbEnable ? 'NB功能已禁用' : 'NB功能已打开',
  684. showCancel: false,
  685. })
  686. that.setData({
  687. isNbEnable: !that.data.isNbEnable
  688. })
  689. break
  690. }
  691. case 'sendBindLock': {
  692. wx.hideLoading()
  693. if (data.code != 200) {
  694. wx.showModal({
  695. title: '提示',
  696. content: '绑定失败!',
  697. showCancel: false,
  698. success: function (res) {}
  699. })
  700. break
  701. }
  702. taskId = 0
  703. that.setData({
  704. isBindLock: data.data.isBind
  705. })
  706. if (data.data.isBind) {
  707. wx.showToast({
  708. title: '绑定成功!',
  709. })
  710. } else {
  711. wx.showToast({
  712. title: '绑定失败!',
  713. })
  714. }
  715. break
  716. }
  717. case 'sendUnbindLock': {
  718. wx.hideLoading()
  719. if (data.code != 200) {
  720. wx.showModal({
  721. title: '提示',
  722. content: '解绑失败!',
  723. showCancel: false,
  724. success: function (res) {}
  725. })
  726. break
  727. }
  728. taskId = 0
  729. that.setData({
  730. isBindLock: data.data.isBind
  731. })
  732. if (data.data.isBind) {
  733. wx.showToast({
  734. title: '解绑失败!',
  735. })
  736. } else {
  737. wx.showToast({
  738. title: '解绑成功!',
  739. })
  740. }
  741. break
  742. }
  743. case 'login1':
  744. case 'sendOpenLockP1': {
  745. if (data.code != 200) {
  746. wx.hideLoading()
  747. if (taskId == 41) {
  748. wx.showModal({
  749. title: '提示',
  750. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  751. showCancel: false,
  752. success: function (res) {}
  753. })
  754. } else if (taskId == 32) {
  755. wx.showModal({
  756. title: '提示',
  757. content: '登录失败!',
  758. showCancel: false,
  759. success: function (res) {}
  760. })
  761. }
  762. break
  763. }
  764. if (taskId == 41) {
  765. var bytes = plugin.sendOpenLockP2(lockDevice.name, basecode, data.data.randomN)
  766. console.debug('bytes', bytes)
  767. that.sendBytes(bytes)
  768. } else if (taskId == 32) {
  769. var bytes = plugin.login2(lockDevice.name, basecode, data.data.randomN)
  770. console.debug('bytes', bytes)
  771. that.sendBytes(bytes)
  772. }
  773. break;
  774. }
  775. case 'login':
  776. case 'sendOpenLockP2': {
  777. wx.hideLoading()
  778. if (data.code != 200) {
  779. if (taskId == 41) {
  780. wx.showModal({
  781. title: '提示',
  782. content: that.data.isJack ? '上电失败!' : '解锁失败!',
  783. showCancel: false,
  784. success: function (res) {}
  785. })
  786. } else if (taskId == 32) {
  787. wx.showModal({
  788. title: '提示',
  789. content: '登录失败!',
  790. showCancel: false,
  791. success: function (res) {}
  792. })
  793. }
  794. break
  795. }
  796. isLockLogin = true
  797. if (taskId == 41) {
  798. // var data = {
  799. // code: "zg/bleUnlockRecord",
  800. // data: {
  801. // lockerId: that.data.deviceinfo.deviceNum,
  802. // roomId:that.data.deviceinfo.roomId,
  803. // roomName:that.data.deviceinfo.roomName,
  804. // cardName:that.data.userInfo.username
  805. // }
  806. // }
  807. var data = {
  808. code: "ble/bleUnlockRecord",
  809. data: {
  810. deviceNum: that.data.deviceinfo.deviceNum,
  811. roomId: that.data.deviceinfo.roomId,
  812. roomName: that.data.deviceinfo.roomName,
  813. cardName: that.data.userInfo.username,
  814. productId: that.data.deviceinfo.manufactureId,
  815. userId: '29283991'
  816. }
  817. }
  818. WXAPI.sendCommand(data).then(res => {
  819. console.log(res)
  820. })
  821. wx.showToast({
  822. title: that.data.isJack ? '上电成功!' : '解锁成功!',
  823. })
  824. } else if (taskId == 32) {
  825. wx.showToast({
  826. title: '登录成功!',
  827. })
  828. }
  829. taskId = 0
  830. break;
  831. }
  832. case 'syncClock': {
  833. wx.hideLoading()
  834. if (data.code != 200) {
  835. wx.showModal({
  836. title: '提示',
  837. content: '同步时间失败!' + data.data.msg,
  838. showCancel: false,
  839. success: function (res) {}
  840. })
  841. break
  842. }
  843. taskId = 0
  844. wx.showModal({
  845. title: '提示',
  846. content: '时间更新成功!',
  847. showCancel: false
  848. })
  849. break;
  850. }
  851. case 'addPincode': {
  852. // console.log(data.data,'data.data')
  853. // wx.hideLoading()
  854. let data2 = {
  855. "code": "ble/bleSendVoucherReply",
  856. "data": {
  857. "deviceNum": that.data.deviceinfo.deviceNum,
  858. "serialNumber": serialNumber,
  859. "index": pincodeIndex,
  860. "type": 7,
  861. "result": 1,
  862. "productId": that.data.deviceinfo.manufactureId
  863. }
  864. }
  865. if (data.code != 200) {
  866. data2 = {
  867. "code": "ble/bleSendVoucherReply",
  868. "data": {
  869. "deviceNum": that.data.deviceinfo.deviceNum,
  870. "serialNumber": serialNumber,
  871. "index": pincodeIndex,
  872. "type": 7,
  873. "result": 0,
  874. "productId": that.data.deviceinfo.manufactureId
  875. }
  876. }
  877. WXAPI.sendCommand(data2).then(res => {
  878. })
  879. wx.showModal({
  880. title: '提示',
  881. content: '添加密码失败!' + data.data.msg,
  882. showCancel: false,
  883. success: function (res) {}
  884. })
  885. break
  886. }
  887. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  888. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  889. var passwordStartTime = time1.getTime() / 1000
  890. var passwordEndTime = time2.getTime() / 1000
  891. var pzname = '',
  892. cardName = '';
  893. pzname = '蓝牙-密码' + (that.data.passwordList.length + 1)
  894. cardName = that.data.personLi.name + '-蓝牙-密码' + (that.data.passwordList.length + 1)
  895. var str = {
  896. // cardId: this.personInfo.cardId,
  897. imei: that.data.deviceinfo.imei,
  898. pzname: pzname,
  899. password: that.data.password.toString(),
  900. userTelephone: JSON.parse(that.data.personLi.info).userTelephone,
  901. operateMode: 7,
  902. userPassword: JSON.parse(that.data.personLi.info).userPassword,
  903. passwordStartTime: passwordStartTime,
  904. passwordEndTime: passwordEndTime,
  905. index: pincodeIndex,
  906. is: false,
  907. pass: true
  908. }
  909. var data1 = {
  910. cardId: that.data.personLi.cardId,
  911. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  912. deviceNum: that.data.deviceinfo.deviceNum,
  913. type: 4,
  914. imei: that.data.deviceinfo.imei,
  915. serial: serialNumber,
  916. startTime: passwordStartTime,
  917. endTime: passwordEndTime,
  918. };
  919. var datalist = {
  920. cardId: that.data.personLi.cardId,
  921. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  922. type: 14,
  923. startTime: passwordStartTime,
  924. endTime: passwordEndTime,
  925. };
  926. WXAPI.addCertificates(datalist).then(res6 => {
  927. console.log(datalist, '密码22', res6)
  928. })
  929. WXAPI.addCertificates(data1).then(res3 => {
  930. if (res3.success) {
  931. var updatedata = {
  932. id: res3.data,
  933. status: 1
  934. };
  935. WXAPI.updateCertificates(updatedata).then((res2) => {});
  936. WXAPI.sendCommand(data2).then(res => {
  937. })
  938. that.getPassword()
  939. that.setData({
  940. show: false
  941. })
  942. wx.hideLoading()
  943. wx.showToast({
  944. title: '添加成功',
  945. mask: true,
  946. icon: 'none',
  947. duration: 2000
  948. })
  949. } else {
  950. wx.hideLoading()
  951. wx.showToast({
  952. title: '添加失败',
  953. mask: true,
  954. icon: 'none',
  955. duration: 2000
  956. })
  957. }
  958. })
  959. taskId = 0
  960. that.setData({
  961. isPincodeAdd: true,
  962. show: false
  963. })
  964. wx.showModal({
  965. title: '提示',
  966. content: `添加密码${pincode}成功!`,
  967. showCancel: false
  968. })
  969. break
  970. }
  971. case 'delPincode': {
  972. wx.hideLoading()
  973. if (data.code != 200) {
  974. var datacom = {
  975. code: "lwj/passwordOperate",
  976. data: {
  977. lockerId: that.data.deviceinfo.deviceNum,
  978. serialNumber: serialNumber,
  979. index: pincodeIndex,
  980. action: 2,
  981. type: 9,
  982. result: 0
  983. }
  984. }
  985. WXAPI.sendCommand(datacom).then(res2 => {
  986. console.log(res2, '失败')
  987. })
  988. wx.showModal({
  989. title: '提示',
  990. content: '删除密码失败!',
  991. showCancel: false,
  992. success: function (res) {}
  993. })
  994. break
  995. }
  996. taskId = 0
  997. wx.showModal({
  998. title: '提示',
  999. content: `删除密码成功!`,
  1000. showCancel: false,
  1001. })
  1002. var datacom = {
  1003. code: "lwj/passwordOperate",
  1004. data: {
  1005. lockerId: that.data.deviceinfo.deviceNum,
  1006. serialNumber: serialNumber,
  1007. index: pincodeIndex,
  1008. action: 2,
  1009. type: 9,
  1010. result: 1
  1011. }
  1012. }
  1013. WXAPI.sendCommand(datacom).then(res2 => {
  1014. if (res2.success) {}
  1015. })
  1016. var data = {
  1017. ids: [passwordLiAll.id]
  1018. }
  1019. WXAPI.deleteCertificates(data).then(res1 => {
  1020. if (res1.success) {
  1021. that.getPassword()
  1022. wx.hideLoading()
  1023. wx.showToast({
  1024. title: '删除成功',
  1025. mask: true,
  1026. icon: 'none',
  1027. duration: 2000
  1028. })
  1029. } else {
  1030. wx.hideLoading()
  1031. wx.showToast({
  1032. title: '删除失败',
  1033. mask: true,
  1034. icon: 'none',
  1035. duration: 2000
  1036. })
  1037. }
  1038. })
  1039. that.setData({
  1040. isPincodeAdd: false
  1041. })
  1042. pincode = -1
  1043. pincodeIndex = -1
  1044. break
  1045. }
  1046. case 'addRfCard': {
  1047. wx.hideLoading()
  1048. if (data.code == 100) {
  1049. wx.showLoading({
  1050. title: data.data.msg,
  1051. })
  1052. break
  1053. } else if (data.code != 200) {
  1054. var datacom = {
  1055. code: "ble/bleSendVoucherReply",
  1056. data: {
  1057. deviceNum: that.data.deviceinfo.deviceNum,
  1058. serialNumber: serialNumber,
  1059. index: rfCardIndex,
  1060. type: ADD_NFC_MODE,
  1061. cardNo: '',
  1062. result: 0,
  1063. productId: that.data.deviceinfo.manufactureId
  1064. }
  1065. }
  1066. WXAPI.sendCommand(datacom).then(res2 => {})
  1067. wx.showModal({
  1068. title: '提示',
  1069. content: '添加房卡失败!' + data.data.msg,
  1070. showCancel: false,
  1071. success: function (res) {}
  1072. })
  1073. break
  1074. }
  1075. taskId = 0
  1076. that.setData({
  1077. isRfCardAdd: true
  1078. })
  1079. if (lockModel > 70) {
  1080. console.log(data.data, 'rfCardIndexrfCardIndex')
  1081. // rfCardId = randomMethods()
  1082. wx.showModal({
  1083. title: '提示',
  1084. content: `添加房卡成功,序号${rfCardIndex}`,
  1085. showCancel: false
  1086. })
  1087. that.addRfcardCertificates()
  1088. } else {
  1089. console.log(data.data, 'rfCardIndexrfCardIndex1')
  1090. // rfCardId = randomMethods()
  1091. wx.showModal({
  1092. title: '提示',
  1093. content: `添加房卡成功,卡号${rfCardId}`,
  1094. showCancel: false
  1095. })
  1096. that.addRfcardCertificates()
  1097. }
  1098. break
  1099. }
  1100. case 'delRfCard': {
  1101. wx.hideLoading()
  1102. if (data.code != 200) {
  1103. var datacom = {
  1104. code: "lwj/c",
  1105. data: {
  1106. lockerId: that.data.deviceinfo.deviceNum,
  1107. serialNumber: serialNumber,
  1108. index: rfCardIndex,
  1109. action: 2,
  1110. type: 12,
  1111. result: 0
  1112. }
  1113. }
  1114. WXAPI.sendCommand(datacom).then(res2 => {
  1115. console.log(res2, '失败')
  1116. })
  1117. wx.showModal({
  1118. title: '提示',
  1119. content: '删除房卡失败!',
  1120. showCancel: false,
  1121. success: function (res) {}
  1122. })
  1123. break
  1124. }
  1125. taskId = 0
  1126. that.setData({
  1127. isRfCardAdd: false
  1128. })
  1129. if (lockModel > 70) {
  1130. wx.showModal({
  1131. title: '提示',
  1132. content: `删除房卡成功,序号${rfCardIndex}`,
  1133. showCancel: false,
  1134. })
  1135. } else {
  1136. wx.showModal({
  1137. title: '提示',
  1138. content: `删除房卡成功,卡号${rfCardId}`,
  1139. showCancel: false,
  1140. })
  1141. }
  1142. var datacom = {
  1143. code: "lwj/c",
  1144. data: {
  1145. lockerId: that.data.deviceinfo.deviceNum,
  1146. serialNumber: serialNumber,
  1147. index: rfCardIndex,
  1148. action: 2,
  1149. type: 12,
  1150. result: 1
  1151. }
  1152. }
  1153. WXAPI.sendCommand(datacom).then(res2 => {
  1154. console.log(res2, '失败')
  1155. })
  1156. var data = {
  1157. ids: [passwordLiAll.id]
  1158. }
  1159. WXAPI.deleteCertificates(data).then(res1 => {
  1160. console.log(res1, '2936');
  1161. if (res1.success) {
  1162. that.getNfc()
  1163. wx.showToast({
  1164. title: '删除成功',
  1165. mask: true,
  1166. icon: 'none',
  1167. duration: 2000
  1168. })
  1169. } else {
  1170. wx.showToast({
  1171. title: '删除失败',
  1172. mask: true,
  1173. icon: 'none',
  1174. duration: 2000
  1175. })
  1176. }
  1177. })
  1178. rfCardId = -1
  1179. rfCardIndex = -1
  1180. break
  1181. }
  1182. case 'addFingerprint': {
  1183. wx.hideLoading()
  1184. if (data.code == 100) {
  1185. wx.showLoading({
  1186. title: data.data.msg,
  1187. })
  1188. break
  1189. } else if (data.code != 200) {
  1190. wx.showModal({
  1191. title: '提示',
  1192. content: '添加指纹失败!' + data.data.msg,
  1193. showCancel: false,
  1194. success: function (res) {}
  1195. })
  1196. var datacom = {
  1197. code: "ble/bleSendVoucherReply",
  1198. data: {
  1199. deviceNum: that.data.deviceinfo.deviceNum,
  1200. serialNumber: serialNumber,
  1201. index: 0,
  1202. type: 16,
  1203. result: 0,
  1204. productId: that.data.deviceinfo.manufactureId
  1205. }
  1206. }
  1207. WXAPI.sendCommand(datacom).then(res2 => {
  1208. if (res2.success) {}
  1209. })
  1210. break
  1211. }
  1212. taskId = 0
  1213. that.setData({
  1214. isFingerprintAdd: true
  1215. })
  1216. wx.showModal({
  1217. title: '提示',
  1218. content: `添加指纹成功,序号${fingerprintIndex}`,
  1219. showCancel: false
  1220. })
  1221. var time1 = new Date(that.data.starttime.replace(/-/g, '/'))
  1222. var time2 = new Date(that.data.endtime.replace(/-/g, '/'))
  1223. var passwordStartTime = time1.getTime() / 1000
  1224. var passwordEndTime = time2.getTime() / 1000
  1225. var cardName = '',
  1226. pzname = ''
  1227. if (that.data.pzname) {
  1228. cardName = that.data.personLi.name + '-蓝牙-' + that.data.pzname
  1229. pzname = '蓝牙-' + that.data.pzname
  1230. } else {
  1231. cardName = that.data.personLi.name + '-蓝牙-指纹' + (that.data.FpList.length + 1)
  1232. pzname = '蓝牙-指纹' + (that.data.FpList.length + 1)
  1233. }
  1234. var str = {
  1235. // cardId: this.personInfo.cardId,
  1236. imei: that.data.deviceinfo.imei,
  1237. pzname: pzname,
  1238. password: '',
  1239. fingerprintAlias: that.data.radioDetil,
  1240. userTelephone: JSON.parse(that.data.personLi.info).userTelephone,
  1241. operateMode: 16,
  1242. userPassword: JSON.parse(that.data.personLi.info).userPassword,
  1243. passwordStartTime: passwordStartTime,
  1244. passwordEndTime: passwordEndTime,
  1245. index: fingerprintIndex,
  1246. is: false,
  1247. pass: true
  1248. }
  1249. var data2 = {
  1250. cardId: that.data.personLi.cardId,
  1251. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1252. deviceNum: that.data.deviceinfo.deviceNum,
  1253. type: 1,
  1254. imei: that.data.deviceinfo.imei,
  1255. serial: serialNumber,
  1256. startTime: passwordStartTime,
  1257. endTime: passwordEndTime,
  1258. status: 1
  1259. };
  1260. var datalist = {
  1261. cardId: that.data.personLi.cardId,
  1262. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1263. type: 11,
  1264. startTime: passwordStartTime,
  1265. endTime: passwordEndTime
  1266. };
  1267. var datacom = {
  1268. code: "ble/bleSendVoucherReply",
  1269. data: {
  1270. deviceNum: that.data.deviceinfo.deviceNum,
  1271. serialNumber: serialNumber,
  1272. index: fingerprintIndex,
  1273. type: 16,
  1274. result: 1,
  1275. productId: that.data.deviceinfo.manufactureId
  1276. }
  1277. }
  1278. WXAPI.addCertificates(datalist).then(res6 => {})
  1279. console.log(data, '添加凭证')
  1280. WXAPI.addCertificates(data2).then(res3 => {
  1281. if (res3.success) {
  1282. var updatedata = {
  1283. id: res3.data,
  1284. status: 1
  1285. };
  1286. WXAPI.updateCertificates(updatedata).then((res2) => {});
  1287. WXAPI.sendCommand(datacom).then(res2 => {
  1288. if (res2.success) {}
  1289. })
  1290. console.log(res3, '添加凭证成功')
  1291. that.getFp()
  1292. that.setData({
  1293. show: false
  1294. })
  1295. wx.hideLoading()
  1296. wx.showToast({
  1297. title: '添加成功',
  1298. mask: true,
  1299. icon: 'none',
  1300. duration: 2000
  1301. })
  1302. } else {
  1303. wx.hideLoading()
  1304. wx.showToast({
  1305. title: '添加失败',
  1306. mask: true,
  1307. icon: 'none',
  1308. duration: 2000
  1309. })
  1310. }
  1311. })
  1312. break
  1313. }
  1314. case 'delFingerprint': {
  1315. wx.hideLoading()
  1316. if (data.code != 200) {
  1317. wx.showModal({
  1318. title: '提示',
  1319. content: '删除指纹失败!',
  1320. showCancel: false,
  1321. success: function (res) {}
  1322. })
  1323. break
  1324. }
  1325. taskId = 0
  1326. wx.showModal({
  1327. title: '提示',
  1328. content: `删除指纹成功,序号${fingerprintIndex}`,
  1329. showCancel: false,
  1330. })
  1331. that.setData({
  1332. isFingerprintAdd: false
  1333. })
  1334. fingerprintIndex = -1
  1335. break
  1336. }
  1337. case 'changeAdminPincode': {
  1338. wx.hideLoading()
  1339. if (data.code != 200) {
  1340. wx.showModal({
  1341. title: '提示',
  1342. content: '修改管理密码失败!',
  1343. showCancel: false,
  1344. success: function (res) {}
  1345. })
  1346. break
  1347. }
  1348. taskId = 0
  1349. wx.showToast({
  1350. title: '修改管理密码成功!',
  1351. })
  1352. }
  1353. case 'queryLockSlotState': {
  1354. wx.hideLoading()
  1355. if (data.code != 200) {
  1356. wx.showModal({
  1357. title: '提示',
  1358. content: '查询失败!',
  1359. showCancel: false,
  1360. success: function (res) {}
  1361. })
  1362. break
  1363. }
  1364. taskId = 0
  1365. wx.showModal({
  1366. title: '提示',
  1367. content: data.data.state == 0 ? '此门锁方舌关闭' : '此门锁方舌打开',
  1368. showCancel: false,
  1369. success: function (res) {}
  1370. })
  1371. break
  1372. }
  1373. case 'queryLockUnlockState': {
  1374. wx.hideLoading()
  1375. if (data.code != 200) {
  1376. wx.showModal({
  1377. title: '提示',
  1378. content: '查询失败!',
  1379. showCancel: false,
  1380. success: function (res) {}
  1381. })
  1382. break
  1383. }
  1384. taskId = 0
  1385. wx.showModal({
  1386. title: '提示',
  1387. content: data.data.state == 0 ? '此门锁已关闭' : '此门锁已打开',
  1388. showCancel: false,
  1389. success: function (res) {}
  1390. })
  1391. break
  1392. }
  1393. case 'setLockUnlockState': {
  1394. wx.hideLoading()
  1395. if (data.code != 200) {
  1396. wx.showModal({
  1397. title: '提示',
  1398. content: '设置常开指令失败!',
  1399. showCancel: false,
  1400. success: function (res) {}
  1401. })
  1402. break
  1403. }
  1404. taskId = 0
  1405. wx.showModal({
  1406. title: '提示',
  1407. content: data.data.state == 0 ? '常开模式已退出' : '常开模式已开启',
  1408. showCancel: false,
  1409. })
  1410. that.setData({
  1411. isUnloked: data.data.state == 1
  1412. })
  1413. break
  1414. }
  1415. case 'setLockMuteState': {
  1416. wx.hideLoading()
  1417. if (data.code != 200) {
  1418. wx.showModal({
  1419. title: '提示',
  1420. content: '设置静音指令失败!',
  1421. showCancel: false,
  1422. success: function (res) {}
  1423. })
  1424. break
  1425. }
  1426. taskId = 0
  1427. wx.showModal({
  1428. title: '提示',
  1429. content: data.data.state == 1 ? '静音模式已退出' : '静音模式已开启',
  1430. showCancel: false,
  1431. })
  1432. that.setData({
  1433. isMuted: data.data.state == 0
  1434. })
  1435. break
  1436. }
  1437. }
  1438. })
  1439. wx.notifyBLECharacteristicValueChange({
  1440. deviceId: lockDevice.deviceId,
  1441. serviceId: config.uuid.serviceUuid.toUpperCase(),
  1442. characteristicId: config.uuid.notifyUuid.toUpperCase(),
  1443. state: true,
  1444. success: function (res) {
  1445. console.log('setupNotify', res)
  1446. isInitReady = true
  1447. setTimeout(function () {
  1448. wx.hideLoading()
  1449. // that.onQueryBindState()
  1450. that.login()
  1451. }, 500)
  1452. },
  1453. })
  1454. },
  1455. })
  1456. },
  1457. })
  1458. },
  1459. doWork: function () {
  1460. var that = this
  1461. console.log(taskId);
  1462. switch (taskId) {
  1463. case 11: {
  1464. that.onBindLock()
  1465. break
  1466. }
  1467. case 12: {
  1468. that.onUnbindLock()
  1469. break
  1470. }
  1471. case 21: {
  1472. that.onQueryBindState()
  1473. break
  1474. }
  1475. case 22: {
  1476. that.onQueryBattery()
  1477. break
  1478. }
  1479. case 31: {
  1480. that.onQueryNbImei()
  1481. break
  1482. }
  1483. case 32: {
  1484. that.onLogin()
  1485. break
  1486. }
  1487. case 41: {
  1488. that.LwjonOpenLock()
  1489. break
  1490. }
  1491. case 42: {
  1492. that.onSyncClock()
  1493. break
  1494. }
  1495. case 51: {
  1496. that.onAddPincode()
  1497. break
  1498. }
  1499. case 52: {
  1500. that.onDelPincode()
  1501. break
  1502. }
  1503. case 61: {
  1504. // that.onAddRfCard()
  1505. // if (lockModel > 70) {
  1506. that.sendAddRfcard()
  1507. // } else {
  1508. // wx.showModal({
  1509. // title: '提示',
  1510. // content: '请刷卡!',
  1511. // showCancel: false
  1512. // })
  1513. // }
  1514. break
  1515. }
  1516. case 62: {
  1517. that.onDelRfCard()
  1518. break
  1519. }
  1520. case 71: {
  1521. that.onAddFingerprint()
  1522. break
  1523. }
  1524. case 72: {
  1525. that.onDelFingerprint()
  1526. break
  1527. }
  1528. case 81: {
  1529. that.onChangeAdminPincode()
  1530. break
  1531. }
  1532. case 91: {
  1533. that.onQueryLockSlotState()
  1534. break
  1535. }
  1536. case 92: {
  1537. that.onQueryLockUnlockState()
  1538. break
  1539. }
  1540. case 101: {
  1541. that.onChangeLockUnlockState()
  1542. break
  1543. }
  1544. case 102: {
  1545. that.onChangeLockMutedState()
  1546. break
  1547. }
  1548. case 111: {
  1549. this.onChangeLockNbState()
  1550. }
  1551. default: {
  1552. }
  1553. }
  1554. },
  1555. login: function () {
  1556. var that = this
  1557. taskId = 32
  1558. that.initBluetooth()
  1559. },
  1560. onLogin: function () {
  1561. var that = this
  1562. wx.showLoading({
  1563. title: '登录中',
  1564. })
  1565. var bytes = plugin.login1(lockDevice.name, basecode)
  1566. console.debug('bytes', bytes)
  1567. that.sendBytes(bytes)
  1568. },
  1569. /**
  1570. * 生命周期函数--监听页面初次渲染完成
  1571. */
  1572. onReady: function () {
  1573. },
  1574. /**
  1575. * 生命周期函数--监听页面显示
  1576. */
  1577. onShow: function () {
  1578. },
  1579. /**
  1580. * 生命周期函数--监听页面隐藏
  1581. */
  1582. onHide: function () {
  1583. },
  1584. /**
  1585. * 生命周期函数--监听页面卸载
  1586. */
  1587. onUnload: function () {
  1588. },
  1589. /**
  1590. * 页面相关事件处理函数--监听用户下拉动作
  1591. */
  1592. onPullDownRefresh: function () {
  1593. },
  1594. /**
  1595. * 页面上拉触底事件的处理函数
  1596. */
  1597. onReachBottom: function () {
  1598. },
  1599. /**
  1600. * 用户点击右上角分享
  1601. */
  1602. onShareAppMessage: function () {
  1603. }
  1604. })