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.

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