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.

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