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.

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