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.

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