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.

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