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.

2105 lines
63 KiB

1 year ago
  1. // pages/roomDetail/roomDetail.js
  2. const WXAPI = require('../../utils/request')
  3. import ICINLocker from "../../utils/ICINPakage/ICINLocker"
  4. var methods = require('../../utils/methods');
  5. var util = require('../../utils/util');
  6. import {
  7. BLE
  8. } from "../../utils/btls/ble";
  9. // import { clearInterval } from "timers";
  10. const app = getApp();
  11. var bleall = require('../../utils/bleall');
  12. const emitter = app.globalData.emitter
  13. import moment from "../../utils/moment"
  14. const ADD_NFC_MODE=10
  15. // ArrayBuffer转16进度字符串示例
  16. function ab2hex(buffer) {
  17. var hexArr = Array.prototype.map.call(
  18. new Uint8Array(buffer),
  19. function (bit) {
  20. return ('00' + bit.toString(16)).slice(-2)
  21. }
  22. )
  23. return hexArr.join(',');
  24. }
  25. Page({
  26. /**
  27. * 页面的初始数据
  28. */
  29. data: {
  30. passwordStatus:false,
  31. addpassword:'',
  32. showTwo:false,
  33. showOne:false,
  34. starttime:'',
  35. endtime:'',
  36. minDate: '',
  37. minDate1: '',
  38. info: "", //显示框
  39. deviceinfo: {
  40. rssi: 0,
  41. battery: 0,
  42. lockStatus: 0,
  43. isOnline: 0,
  44. event: '',
  45. bleStatus: ''
  46. },
  47. index: 0,
  48. fingerprintId: '',
  49. openlock: '',
  50. IssuingPersonnel: true,
  51. backstatus: false,
  52. cgInfo: '',
  53. zgBlueStatus: false,
  54. timer: '',
  55. count: 0,
  56. show: false,
  57. actions: [{
  58. name: '静音',
  59. color: '#ee0a24'
  60. },
  61. {
  62. name: '低音',
  63. color: '#333'
  64. },
  65. {
  66. name: '高音',
  67. color: '#333'
  68. },
  69. ],
  70. volume: '',
  71. bluestatus: app.globalData.backstatus,
  72. show1: false,
  73. TemporaryPassword: '',
  74. phone: '',
  75. userInfo: {
  76. type: ''
  77. },
  78. authority: false,
  79. showbuleKey:false,
  80. deviceList:[],
  81. userRole:'',
  82. passwordList:[],
  83. NfcList:[],
  84. remotePasswordStatus:false
  85. },
  86. /**
  87. * 生命周期函数--监听页面加载
  88. */
  89. onLoad: function (options) {
  90. var userRole = wx.getStorageSync('userRole') || ''
  91. this.setData({
  92. userRole
  93. })
  94. app.globalData.zgBlueStatus = false
  95. this.AddressPermissions()
  96. let deviceinfo = wx.getStorageSync('deviceinfo')
  97. if(deviceinfo.manufactureId==201||deviceinfo.manufactureId == 221){
  98. var data3 = {
  99. code: "zg/bleRegisterInfo",
  100. signature:wx.getStorageSync('signature'),
  101. cardId:deviceinfo.cardId,
  102. data: {
  103. lockerId: deviceinfo.deviceNum
  104. }
  105. }
  106. WXAPI.sendCommandOne(data3).then(res1 => {
  107. if (res1.success) {
  108. wx.setStorageSync('cgInfo', res1.data)
  109. this.setData({
  110. cgInfo: res1.data
  111. })
  112. } else {
  113. }
  114. })
  115. }else{
  116. }
  117. this.getApartmentCardInfoMethods()
  118. this.getPassWordMehods()
  119. app.globalData.deviceNum = deviceinfo.deviceNum
  120. app.watch(this.getcartcount, 'backdata')
  121. app.watch(this.fingerprintFun, 'fingerprintId')
  122. app.watch(this.openlockfun, 'openlock')
  123. },
  124. // 获取合同信息
  125. getApartmentCardInfoMethods(){
  126. let deviceinfoList = wx.getStorageSync('deviceinfoList')
  127. if(deviceinfoList[0].cardId){
  128. let data={
  129. signature:wx.getStorageSync('signature'),
  130. id:deviceinfoList[0].cardId,
  131. }
  132. WXAPI.getApartmentCardInfo(data).then(res=>{
  133. if(res.success){
  134. let leases = res.data.leases
  135. if(leases.length>0){
  136. let leasesObject = leases[leases.length-1]
  137. let minDate = moment(leasesObject.signingTime).format('YYYY-MM-DD')
  138. let minDate1 = moment(leasesObject.contractTime).format('YYYY-MM-DD')
  139. this.setData({
  140. minDate:minDate,
  141. minDate1:minDate1
  142. })
  143. }else{
  144. wx.showToast({
  145. title: "还未签订合同",
  146. duration: 2000,
  147. icon: 'none'
  148. })
  149. }
  150. }else{
  151. wx.showToast({
  152. title: "获取合同信息失败",
  153. duration: 2000,
  154. icon: 'none'
  155. })
  156. }
  157. })
  158. }else{
  159. wx.showToast({
  160. title: "还未有对应合同",
  161. duration: 2000,
  162. icon: 'none'
  163. })
  164. }
  165. },
  166. // 添加远程密码
  167. addRemotePassword(){
  168. this.setData({
  169. showTwo:true,
  170. remotePasswordStatus:true
  171. })
  172. },
  173. // 前往密码列表
  174. goPasswordList(){
  175. wx.navigateTo({
  176. url: '/pagesA/passwordList/passwordList',
  177. })
  178. },
  179. // 交租跳转
  180. payRentMethods(){
  181. wx.navigateTo({
  182. url: '/pages/rentDetail/rentDetail',
  183. })
  184. },
  185. onCloseBlue(){
  186. this.setData({
  187. showbuleKey:false
  188. })
  189. },
  190. onCloseTwo(){
  191. this.setData({
  192. showTwo:false,
  193. remotePasswordStatus:false
  194. })
  195. },
  196. onCloseOne(){
  197. this.setData({
  198. showOne:false
  199. })
  200. },
  201. // 选择开始结束时间
  202. bindDateChangeAdd(e){
  203. var str = e.detail.value + " 00:00:00"
  204. this.setData({
  205. starttime: str
  206. })
  207. },
  208. bindDateChangeAddTwo(e){
  209. var str = e.detail.value + " 00:00:00"
  210. this.setData({
  211. endtime: str
  212. })
  213. },
  214. addUser(){
  215. var cgInfo=this.data.cgInfo
  216. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId,
  217. (callback) => {
  218. if (callback.status == '00') {
  219. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, callback.signKey, (callback1) => {
  220. if (callback1.status == '00') {
  221. ICINLocker.addUserToLock(cgInfo.lockerId, cgInfo.superId, "BLEKEY_8d82e5d527e1", "0o01weit9ti9ti", "00", callback.signKey, "", callback1.commonKey, "00000000", "FFFFFFFF", (callback) => {
  222. console.log(callback)
  223. })
  224. }
  225. })
  226. }
  227. })
  228. },
  229. stringToHex(str){
  230.     var val="";
  231.     for(var i = 0; i < str.length; i++){
  232.       if(val == "")
  233.         val = str.charCodeAt(i).toString(16);
  234.       else
  235.         val += str.charCodeAt(i).toString(16);
  236.     }
  237.     return val;
  238.   },
  239. linkBlue(){
  240. wx.navigateTo({
  241. url: '/pages/addBlueButton/addBlueButton',
  242. })
  243. },
  244. searchBlueButton(e) {
  245. var that = this
  246. var cgInfo=this.data.cgInfo
  247. var comm=this.stringToHex(e.currentTarget.dataset.select.name)
  248. console.log(comm)
  249. var deviceId=e.currentTarget.dataset.select.deviceId
  250. var keyId="0o01weit9ti9ti"
  251. var password="3030000000000000000000000000000000000000"
  252. app.globalData.blueDeviceId = e.currentTarget.dataset.select.name
  253. var blueKeyId=e.currentTarget.dataset.select.name
  254. ICINLocker.connect(deviceId,true) // 此处 deviceId 存起来,当断开连接时使用
  255. .then((res) => {
  256. if (res.status == 0) {
  257. clearInterval(that.data.timer)
  258. this.setData({
  259. bleStatus: '蓝牙已连接',
  260. deviceId: deviceId
  261. })
  262. app.globalData.zgBlueStatus = true
  263. wx.showToast({
  264. title: '连接成功',
  265. icon: "none",
  266. duration: 2000
  267. })
  268. ICINLocker.readBluetoothBuckle(cgInfo.lockerId, comm, callback2 => {
  269. if(callback2.status==0){
  270. ICINLocker.registeBluetoothBuckle(cgInfo.superId, blueKeyId, keyId, password, "", cgInfo.authKey, comm, callback3 => {
  271. if(callback3.status==0){
  272. wx.hideLoading()
  273. wx.showToast({
  274. title: '添加成功',
  275. duration:2000,
  276. icon:"none"
  277. })
  278. }else{
  279. wx.hideLoading()
  280. wx.showToast({
  281. title: '添加成功',
  282. duration:2000,
  283. icon:"none"
  284. })
  285. }
  286. })
  287. }else{
  288. wx.hideLoading()
  289. wx.showToast({
  290. title: '读取失败',
  291. duration:2000,
  292. icon:"none"
  293. })
  294. }
  295. });
  296. } else {
  297. wx.hideLoading()
  298. var msg = ''
  299. switch (res.errCode) {
  300. case 10001:
  301. msg = '调用失败,请打开蓝牙!';
  302. break;
  303. }
  304. wx.showToast({
  305. title: msg,
  306. duration: 2000,
  307. icon: 'none'
  308. })
  309. //此处处理返回值不为成功(0)的情况
  310. }
  311. }).catch((res) => {
  312. wx.hideLoading()
  313. console.log(res, '失败')
  314. // 此处处理未能连接成功问题
  315. })
  316. },
  317. onChange2(event) {
  318. this.setData({
  319. addpassword: event.detail
  320. })
  321. },
  322. onChange(event) {
  323. this.setData({
  324. phone: event.detail
  325. })
  326. },
  327. // 发送临时密码
  328. sendMessage() {
  329. var re = /^1\d{10}$/
  330. if (re.test(this.data.phone)) {
  331. var data = {
  332. code: this.data.TemporaryPassword,
  333. phone: this.data.phone,
  334. device: this.data.deviceinfo.deviceNum,
  335. name: this.data.deviceinfo.roomName
  336. }
  337. WXAPI.sendEmergence(data).then(res => {
  338. if (res.success) {
  339. this.setData({
  340. show1: false
  341. })
  342. wx.showToast({
  343. title: "发送成功",
  344. duration: 2000,
  345. icon: "none"
  346. })
  347. } else {
  348. wx.showToast({
  349. title: "发送失败",
  350. duration: 2000,
  351. icon: "none"
  352. })
  353. }
  354. })
  355. } else {
  356. wx.showToast({
  357. title: "请输入正确的手机号",
  358. duration: 2000,
  359. icon: "none"
  360. })
  361. }
  362. },
  363. // 获取临时密码
  364. getTemporaryPassword() {
  365. var data = {
  366. code: "zg/getEmergence",
  367. signature:wx.getStorageSync('signature'),
  368. cardId:this.data.deviceinfo.cardId,
  369. data: {
  370. lockerId: this.data.deviceinfo.deviceNum
  371. }
  372. }
  373. WXAPI.sendCommandOne(data).then(res => {
  374. if (res.success) {
  375. this.setData({
  376. TemporaryPassword: res.data.data,
  377. show1: true
  378. })
  379. } else {
  380. wx.showToast({
  381. title: "获取失败",
  382. duration: 2000,
  383. icon: "none"
  384. })
  385. }
  386. })
  387. },
  388. // 关闭临时密码弹窗
  389. onClose1() {
  390. this.setData({
  391. show1: false
  392. });
  393. },
  394. // 关闭设置音量
  395. onClose() {
  396. this.setData({
  397. show: false
  398. });
  399. },
  400. processCardNumber(cardNo){
  401. var str1=cardNo.substr(0,8)
  402. var str2=cardNo.substr(8,8)
  403. var num=str2.split("")
  404. var status=num.every(item=> item==0)
  405. console.log(status,num,'numnum',str1,str2)
  406. if(status){
  407. var bbb = str1.split("")
  408. var a, b;
  409. var aIndex = 0;
  410. var bIndex = 1;
  411. var arr = [];
  412. bbb.forEach((str, index) => {
  413. if (index % 2 === 0) {
  414. a = str;
  415. aIndex += 1
  416. } else {
  417. b = str
  418. bIndex += 1
  419. }
  420. if (a&&b&&(bIndex-aIndex === 1)) {
  421. arr.push(a+b)
  422. }
  423. });
  424. console.log(arr)
  425. return arr.join("")
  426. }else{
  427. var ll=str1+str2
  428. return ll
  429. }
  430. },
  431. sendNfc() {
  432. var time3 = new Date(this.data.starttime)
  433. var time4 = new Date(this.data.endtime)
  434. var passwordStartTimecontrast = time3.getTime() / 1000
  435. var passwordEndTimecontrast = time4.getTime() / 1000
  436. if (passwordStartTimecontrast > passwordEndTimecontrast) {
  437. wx.showToast({
  438. title: '开始时间不能大于结束时间',
  439. duration: 2000,
  440. mask:true,
  441. icon: 'none'
  442. })
  443. return
  444. }
  445. wx.showLoading({
  446. title: '正在添加',
  447. mask: true
  448. })
  449. var _this = this
  450. var deviceinfo = this.data.deviceinfo
  451. var info = JSON.parse(this.data.deviceinfo.info)
  452. if (deviceinfo.manufactureId == 101) {
  453. } else if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  454. var cgInfo = this.data.cgInfo
  455. var passwordStartTime = passwordStartTimecontrast
  456. var passwordEndTime = passwordEndTimecontrast
  457. var pzname='',cardName=''
  458. if(pzname==""){
  459. pzname=_this.data.deviceinfo.name+'-蓝牙-NFC'+(_this.data.NfcList.length+1)
  460. cardName=_this.data.deviceinfo.name+'-蓝牙-NFC'+(_this.data.NfcList.length+1)
  461. }else{
  462. pzname=_this.data.deviceinfo.name+'-蓝牙-'+pzname
  463. cardName=_this.data.deviceinfo.name+'-蓝牙-'+pzname
  464. }
  465. var dataPasswod = {
  466. code: "zg/cardOperate",
  467. cardId:deviceinfo.cardId,
  468. data: {
  469. lockerId: deviceinfo.deviceNum,
  470. imei: deviceinfo.imei,
  471. lockerUserId: info.userPassword,
  472. keyId: info.userPassword,
  473. action: 1,
  474. taskStatus: 1,
  475. order: 6210,
  476. startTime: passwordStartTime,
  477. endTime: passwordEndTime,
  478. cardType: 50,
  479. type: ADD_NFC_MODE,
  480. roomName: this.data.deviceinfo.roomName,
  481. cardName: cardName,
  482. operateName:_this.data.deviceinfo.name
  483. },
  484. signature:wx.getStorageSync('signature'),
  485. }
  486. console.log(dataPasswod,'dataPasswod')
  487. WXAPI.sendCommandOne(dataPasswod).then(res => {
  488. console.log(res,'resres')
  489. if (res.success) {
  490. var pwdNo = res.data.index
  491. var passwordIndex = res.data.index
  492. var serialNumber=res.data.serialNumber
  493. pwdNo = pwdNo.toString(16)
  494. if (pwdNo.length < 2) {
  495. pwdNo='0'+pwdNo
  496. }
  497. var startTime = passwordStartTime.toString(16).toUpperCase()
  498. var endTime = passwordEndTime.toString(16).toUpperCase()
  499. info.startTime=startTime
  500. info.endTime=endTime
  501. info.pwdNo = pwdNo
  502. methods.bluetoothOperation_ZH(cgInfo,info,7).then(result=>{
  503. if (result.status == '00') {
  504. let carNoId=this.processCardNumber(result.cardNo)
  505. var datacom = {
  506. code: "zg/bleSendVoucherReply",
  507. cardId:deviceinfo.cardId,
  508. data: {
  509. lockerId: deviceinfo.deviceNum,
  510. serialNumber: serialNumber,
  511. index: passwordIndex,
  512. type: ADD_NFC_MODE,
  513. cardNo: carNoId.toUpperCase(),
  514. result: 1,
  515. operateName:_this.data.deviceinfo.name
  516. },
  517. signature:wx.getStorageSync('signature'),
  518. }
  519. WXAPI.sendCommandOne(datacom).then(res2 => {
  520. if (res2.success) {
  521. var str = {
  522. // cardId: this.personInfo.cardId,
  523. pzname:pzname,
  524. imei: _this.data.deviceinfo.imei,
  525. password: carNoId.toUpperCase(),
  526. blueCardNo:result.cardNo,
  527. userTelephone: info.userTelephone,
  528. operateMode: 10,
  529. userPassword: info.userPassword,
  530. passwordStartTime: passwordStartTime,
  531. passwordEndTime: passwordEndTime,
  532. is: false,
  533. roomName:_this.data.deviceinfo.roomName,
  534. }
  535. var data = {
  536. cardId: _this.data.deviceinfo.cardId,
  537. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  538. deviceNum: _this.data.deviceinfo.deviceNum,
  539. type: 3,
  540. blueCardNo:result.cardNo,
  541. imei: _this.data.deviceinfo.imei,
  542. serial: serialNumber,
  543. startTime: passwordStartTime,
  544. endTime: passwordEndTime,
  545. signature:wx.getStorageSync('signature'),
  546. };
  547. console.log(data, '添加凭证')
  548. var datalist = {
  549. cardId: _this.data.deviceinfo.cardId,
  550. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  551. type: 13,
  552. startTime: passwordStartTime,
  553. endTime: passwordEndTime,
  554. signature:wx.getStorageSync('signature'),
  555. };
  556. WXAPI.tsAddCertificate(datalist).then(res6 => {
  557. console.log(datalist,'NFC',res6)
  558. })
  559. WXAPI.tsAddCertificate(data).then(res3 => {
  560. if (res3.success) {
  561. var updatedata = {
  562. id: res3.data,
  563. status:1,
  564. signature:wx.getStorageSync('signature'),
  565. };
  566. WXAPI.editCertificate(updatedata).then((res2) => {
  567. });
  568. console.log(res3, '添加凭证成功')
  569. _this.setData({
  570. showOne: false
  571. })
  572. _this.getPassWordMehods()
  573. wx.hideLoading()
  574. wx.showToast({
  575. title: '添加成功',
  576. mask:true,
  577. icon: 'none',
  578. duration: 2000
  579. })
  580. } else {
  581. wx.hideLoading()
  582. wx.showToast({
  583. title: '添加失败',
  584. mask:true,
  585. icon: 'none',
  586. duration: 2000
  587. })
  588. }
  589. })
  590. }
  591. })
  592. } else {
  593. wx.hideLoading()
  594. wx.showToast({
  595. title: '添加失败',
  596. mask:true,
  597. icon: 'none',
  598. duration: 2000
  599. })
  600. var datacom = {
  601. code: "zg/bleSendVoucherReply",
  602. cardId:deviceinfo.cardId,
  603. data: {
  604. lockerId: deviceinfo.deviceNum,
  605. serialNumber: serialNumber,
  606. index: passwordIndex,
  607. type: ADD_NFC_MODE,
  608. result: 0
  609. },
  610. signature:wx.getStorageSync('signature'),
  611. }
  612. WXAPI.sendCommandOne(datacom).then(res2 => {
  613. console.log(res2, '失败')
  614. _this.setData({
  615. showOne: false
  616. })
  617. })
  618. }
  619. })
  620. } else {
  621. wx.showToast({
  622. title: res.msg,
  623. duration: 2000,
  624. mask:true,
  625. icon: 'none'
  626. })
  627. }
  628. })
  629. }
  630. },
  631. // 选择设置音量
  632. onSelect(event) {
  633. var volume = '',
  634. volume1 = ''
  635. if (event.detail.name == '静音') {
  636. volume = '00'
  637. volume1 = 0
  638. } else if (event.detail.name == '低音') {
  639. volume = '01'
  640. volume1 = 1
  641. } else if (event.detail.name == '高音') {
  642. volume = '02'
  643. volume1 = 2
  644. }
  645. this.setData({
  646. volume: volume
  647. })
  648. wx.showLoading({
  649. title: "正在设置...",
  650. });
  651. if (this.data.deviceinfo.manufactureId == 201||this.data.deviceinfo.manufactureId == 221) {
  652. this.setVolume(volume)
  653. } else if (this.data.deviceinfo.manufactureId == 101) {
  654. this.setVolume1(volume)
  655. }
  656. },
  657. fingerprintFun() {
  658. this.data.fingerprintId = app.globalData.fingerprintId
  659. },
  660. // 人员管理
  661. personManger() {
  662. wx.navigateTo({
  663. url: '/pages/personManger/personManger',
  664. })
  665. },
  666. openlockfun() {
  667. var that = this
  668. this.data.openlock = app.globalData.openlock
  669. var userInfo=wx.getStorageSync('deviceinfo')
  670. if (app.globalData.openlock == 1) {
  671. var data = {
  672. code: "ld/bleUnlockRecord",
  673. signature:wx.getStorageSync('signature'),
  674. cardId:this.data.deviceinfo.cardId,
  675. data: {
  676. deviceNum: this.data.deviceinfo.deviceNum,
  677. userTelephone: "18270949468",
  678. password: "2021",
  679. roomId:that.data.deviceinfo.roomId,
  680. roomName:that.data.deviceinfo.roomName,
  681. cardName:userInfo.name,
  682. }
  683. }
  684. console.log(data)
  685. WXAPI.sendCommandOne(data).then(res => {
  686. })
  687. } else {
  688. wx.showToast({
  689. title: "开门失败,请重新开门",
  690. duration: 2000,
  691. icon: "none"
  692. })
  693. }
  694. },
  695. getcartcount(val) {
  696. var that = this
  697. let deviceNum = that.data.deviceinfo.deviceNum
  698. if (app.globalData.backdata == 3 && this.data.backstatus) {
  699. that.startFp_29(deviceNum, 0x02)
  700. } else if (app.globalData.backdata == 2 && this.data.backstatus) {
  701. that.startFp_29(deviceNum, 0x01)
  702. } else if (app.globalData.backdata == 1 && this.data.backstatus) {
  703. var data = {
  704. managerTelephone: "18270949468",
  705. managerPassword: "202108",
  706. userTelephone: JSON.parse(that.data.deviceinfo.info).userTelephone,
  707. userPassword: JSON.parse(that.data.deviceinfo.info).userPassword,
  708. startTime: "20210813010101",
  709. endTime: "20680813010101"
  710. }
  711. this.data.backstatus = false
  712. that.startFp_63(data.managerTelephone, data.managerPassword, data.userTelephone, data.userPassword,
  713. data.startTime, data.endTime, 16)
  714. }
  715. },
  716. startFp_63(managerTelephone, managerPassword, userTelephone, userPassword, startTime, endTime, num) {
  717. wx.showLoading({
  718. title: "正在发送...",
  719. });
  720. setTimeout(() => {
  721. wx.hideLoading()
  722. }, 1000);
  723. let cmd = 0x63
  724. let mt = util.stringToUint8Array(managerTelephone)
  725. let mp = util.stringToUint8Array(managerPassword)
  726. let ut = util.stringToUint8Array(userTelephone)
  727. let up = util.stringToUint8Array(userPassword)
  728. let ust = util.time40ToBytes(startTime)
  729. let uet = util.time40ToBytes(endTime)
  730. let fst = util.time40ToBytes(startTime)
  731. let fet = util.time40ToBytes(endTime)
  732. let length = 1 + 11 + 6 + 11 + 6 + 5 + 5 + 4 + 2 + 10 + 5 + 5 + 1 + 2 + 1
  733. let b = new Uint8Array(length)
  734. b[0] = cmd
  735. b.set(mt, 1)
  736. b.set(mp, 12)
  737. b.set(ut, 18)
  738. b.set(up, 29)
  739. b.set(ust, 35)
  740. b.set(uet, 40)
  741. //权限
  742. b[45] = 0x46;
  743. b[46] = 0x46;
  744. b[47] = 0x46;
  745. b[48] = 0x46;
  746. //密码长度 uint16
  747. b[49] = 0
  748. b[50] = 0x0a
  749. //密码数据
  750. b[51] = this.data.fingerprintId
  751. b[52] = 0xff
  752. b[53] = 0xff
  753. b[54] = 0xff
  754. b[55] = 0xff
  755. b[56] = 0xff
  756. b[57] = 0xff
  757. b[58] = 0xff
  758. b[59] = 0xff
  759. b[60] = 0xff
  760. b.set(fst, 61)
  761. b.set(fet, 66)
  762. b[71] = 0xff;
  763. b[72] = 0xff;
  764. b[73] = 0xff;
  765. b[74] = num; //添加指纹
  766. app.globalData.ble.send(cmd, b)
  767. },
  768. delete_63(managerTelephone, managerPassword, userTelephone, userPassword, startTime, endTime, id) {
  769. wx.showLoading({
  770. title: "正在发送...",
  771. });
  772. setTimeout(() => {
  773. wx.hideLoading()
  774. }, 1000);
  775. let cmd = 0x63
  776. let mt = util.stringToUint8Array(managerTelephone)
  777. let mp = util.stringToUint8Array(managerPassword)
  778. let ut = util.stringToUint8Array(userTelephone)
  779. let up = util.stringToUint8Array(userPassword)
  780. let ust = util.time40ToBytes(startTime)
  781. let uet = util.time40ToBytes(endTime)
  782. let fst = util.time40ToBytes(startTime)
  783. let fet = util.time40ToBytes(endTime)
  784. let length = 1 + 11 + 6 + 11 + 6 + 5 + 5 + 4 + 2 + 10 + 5 + 5 + 1 + 2 + 1
  785. let b = new Uint8Array(length)
  786. b[0] = cmd
  787. b.set(mt, 1)
  788. b.set(mp, 12)
  789. b.set(ut, 18)
  790. b.set(up, 29)
  791. b.set(ust, 35)
  792. b.set(uet, 40)
  793. //权限
  794. b[45] = 0x46;
  795. b[46] = 0x46;
  796. b[47] = 0x46;
  797. b[48] = 0x46;
  798. //密码长度 uint16
  799. b[49] = 0
  800. b[50] = 0x0a
  801. //密码数据
  802. b[51] = id
  803. b[52] = 0xff
  804. b[53] = 0xff
  805. b[54] = 0xff
  806. b[55] = 0xff
  807. b[56] = 0xff
  808. b[57] = 0xff
  809. b[58] = 0xff
  810. b[59] = 0xff
  811. b[60] = 0xff
  812. b.set(fst, 61)
  813. b.set(fet, 66)
  814. b[71] = 0xff;
  815. b[72] = 0xff;
  816. b[73] = 0xff;
  817. b[74] = 18; //删除指纹
  818. app.globalData.ble.send(cmd, b)
  819. },
  820. startFp_29(deviceNum, status) {
  821. wx.showLoading({
  822. title: "正在发送...",
  823. });
  824. setTimeout(() => {
  825. wx.hideLoading()
  826. }, 1000);
  827. let cmd = 0x29
  828. let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  829. let length = 1 + 20 + 5 + 1 + 1
  830. let b = new Uint8Array(length)
  831. b[0] = cmd
  832. b.set(dn, 1)
  833. //send data=0x0036000008
  834. b[21] = 0x00;
  835. b[22] = 0x36;
  836. b[23] = 0;
  837. b[24] = 0;
  838. b[25] = 0x08
  839. b[26] = status //status: 0x03, 0x02, 0x01
  840. b[27] = 0x01
  841. app.globalData.ble.send(cmd, b)
  842. },
  843. // 设置密码
  844. permissionsfun() {
  845. wx.navigateTo({
  846. url: "/pages/permissions/permissions"
  847. })
  848. },
  849. // 跳转开锁记录页面
  850. getlogList() {
  851. wx.navigateTo({
  852. url: "/pages/openLockLog/openLockLog?&roomId=" + this.data.deviceinfo.roomId+"&cardId="+this.data.deviceinfo.cardId
  853. })
  854. },
  855. // zg蓝牙连接
  856. openTheDoor() {
  857. // if(this.data.deviceinfo.info){
  858. // JSON.parse(this.data.deviceinfo.info)
  859. // var deviceinfo = this.data.deviceinfo
  860. var userInfo = wx.getStorageSync('deviceinfo')
  861. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, (callback) => {
  862. console.log(callback)
  863. if (callback.status == '00') {
  864. var userSignKey = callback.signKey
  865. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, userSignKey, (callback) => {
  866. console.log(callback)
  867. var commonKey = callback.commonKey
  868. ICINLocker.openTheDoor(this.data.cgInfo.lockerId, this.data.cgInfo.superId, userSignKey, this.data.cgInfo.superId, '', '01', commonKey, (callback) => {
  869. var data = {
  870. code: "zg/bleUnlockRecord",
  871. signature:wx.getStorageSync('signature'),
  872. cardId:this.data.deviceinfo.cardId,
  873. data: {
  874. lockerId: this.data.cgInfo.lockerId,
  875. lockerUserId: this.data.cgInfo.superId,
  876. roomId:this.data.deviceinfo.roomId,
  877. roomName:this.data.deviceinfo.roomName,
  878. cardName:userInfo.name,
  879. operateName:this.data.deviceinfo.name
  880. }
  881. }
  882. WXAPI.sendCommandOne(data).then(res => {
  883. console.log(res)
  884. })
  885. })
  886. })
  887. }
  888. });
  889. // }else{
  890. // wx.showToast({
  891. // title: '请先下发人员',
  892. // duration:2000,
  893. // icon:'none'
  894. // })
  895. // }
  896. },
  897. // 退出登录
  898. loginOut(){
  899. console.log(1111)
  900. wx.removeStorage({
  901. key:"signature"
  902. })
  903. wx.redirectTo({
  904. url:"/pages/login/login"
  905. })
  906. },
  907. // 添加指纹
  908. addFingerPrints() {
  909. var userInfo = JSON.parse(this.data.deviceinfo.info)
  910. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, this.data.cgInfo.authKey, (callback) => {
  911. ICINLocker.addFingerPrints(this.data.cgInfo.lockerId, this.data.cgInfo.superId, userInfo.userPassword, this.data.cgInfo.superId, '', this.data.cgInfo.authKey, '00000000', 'FFFFFFFF', '00', callback.commonKey, (callback) => {
  912. console.log(callback)
  913. })
  914. })
  915. },
  916. // 蓝牙初始化
  917. btntest1(e) {
  918. var event = e.currentTarget.dataset.i
  919. var that = this;
  920. this.data.event = event
  921. var deviceinfo = this.data.deviceinfo
  922. this.setData({
  923. remotePasswordStatus:false
  924. })
  925. if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  926. if (app.globalData.zgBlueStatus) {
  927. if (event == 0) {
  928. this.openTheDoor()
  929. } else if (event == 1) {
  930. this.addPassword()
  931. }else if (event == 3) {
  932. this.addFingerPrints()
  933. } else if (event == 6) {
  934. this.setData({
  935. show: true
  936. })
  937. }else if (event == 11) {
  938. this.setData({
  939. showOne: true
  940. })
  941. }else if (event == 12) {
  942. this.goPasswordList()
  943. }
  944. } else {
  945. that.goBlue()
  946. }
  947. } else if (deviceinfo.manufactureId == 101) {
  948. if (app.globalData.bleStatus == '蓝牙已连接') {
  949. if (event == 0) {
  950. this.btntest2()
  951. } else if (event == 1) {
  952. this.addPassword()
  953. }else if (event == 3) {
  954. this.btntest3()
  955. } else if (event == 6) {
  956. // this.setVoice()
  957. this.setData({
  958. show: true
  959. })
  960. } else if (event == 7) {
  961. wx.showModal({
  962. title: "常开设置",
  963. cancelText: '关闭',
  964. confirmText: '开启',
  965. success: (res) => {
  966. if (res.confirm) {
  967. that.setOpen()
  968. } else if (res.cancel) {
  969. that.setOpen1()
  970. }
  971. }
  972. })
  973. }
  974. } else {
  975. this.startconnect()
  976. }
  977. }
  978. },
  979. goBlue() {
  980. var that = this
  981. wx.showLoading({
  982. title: '连接中',
  983. })
  984. console.log(this.data.deviceinfo.deviceNum, 'this.data.deviceinfo.deviceNum')
  985. ICINLocker.scanDevices(this.data.deviceinfo.deviceNum)
  986. .then((res) => {
  987. console.log(res)
  988. if (res.status == 0) {
  989. var deviceId = res.deviceId
  990. //成功找到蓝牙情况下进行锁连接
  991. app.globalData.blueDeviceId = res.deviceId
  992. ICINLocker.connect(res.deviceId,false) // 此处 deviceId 存起来,当断开连接时使用
  993. .then((res) => {
  994. if (res.status == 0) {
  995. clearInterval(that.data.timer)
  996. this.setData({
  997. bleStatus: '蓝牙已连接',
  998. deviceId: deviceId
  999. })
  1000. app.globalData.zgBlueStatus = true
  1001. wx.hideLoading()
  1002. wx.showToast({
  1003. title: '连接成功',
  1004. icon: "none",
  1005. duration: 2000
  1006. })
  1007. if (this.data.event == 0) {
  1008. this.openTheDoor()
  1009. }else if(this.data.event == 1){
  1010. this.addPassword()
  1011. } else if (this.data.event == 3) {
  1012. this.addFingerPrints()
  1013. } else if (this.data.event == 6) {
  1014. this.setData({
  1015. show: true
  1016. })
  1017. }else if(this.data.event == 11){
  1018. this.setData({
  1019. showOne: true
  1020. })
  1021. }else if (event == 12) {
  1022. this.goPasswordList()
  1023. }
  1024. } else {
  1025. wx.hideLoading()
  1026. var msg = ''
  1027. switch (res.errCode) {
  1028. case 10001:
  1029. msg = '调用失败,请打开蓝牙!';
  1030. break;
  1031. }
  1032. wx.showToast({
  1033. title: msg,
  1034. duration: 2000,
  1035. icon: 'none'
  1036. })
  1037. //此处处理返回值不为成功(0)的情况
  1038. }
  1039. }).catch((res) => {
  1040. wx.hideLoading()
  1041. console.log(res, '失败')
  1042. // 此处处理未能连接成功问题
  1043. })
  1044. }
  1045. })
  1046. .catch((res) => {
  1047. //此处处理未能连接到蓝牙的问题
  1048. if (res.status == 1) {
  1049. if (res.statusReason.errCode == 10001) {
  1050. wx.hideLoading()
  1051. wx.showToast({
  1052. title: '请检查手机蓝牙和定位功能是否打开?',
  1053. duration: 2000,
  1054. icon: 'none'
  1055. })
  1056. } else {
  1057. if (!app.globalData.zgBlueStatus && that.data.bluestatus) {
  1058. that.goBlue()
  1059. } else {
  1060. wx.hideLoading()
  1061. }
  1062. }
  1063. }
  1064. })
  1065. },
  1066. /**
  1067. * *设置音量
  1068. * @param {门锁ID} _lockId
  1069. * @param {用户ID 最多20字节} _userId
  1070. * @param {r 声音选项 00: 静音 01: 低音 02高音} _action
  1071. * @param _commonKey
  1072. * @param {回调方法} callback
  1073. **/
  1074. // 设置音量
  1075. setVolume1(volume) {
  1076. wx.showLoading({
  1077. title: "正在发送...",
  1078. });
  1079. setTimeout(() => {
  1080. wx.hideLoading()
  1081. }, 1000);
  1082. let cmd = 0xF2
  1083. // let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  1084. let length = 2
  1085. let b = new Uint8Array(length)
  1086. b[0] = cmd
  1087. b[1] = volume;
  1088. app.globalData.ble.send(cmd, b, function (res) {
  1089. })
  1090. },
  1091. setVolume(volume) {
  1092. ICINLocker.getSignKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId,
  1093. (callback) => {
  1094. console.log(callback, '-----')
  1095. if (callback.status == '00') {
  1096. ICINLocker.getCommonKey(this.data.cgInfo.lockerId, this.data.cgInfo.superId, this.data.cgInfo.superId, callback.signKey, (callback1) => {
  1097. console.log(callback1, '2222222')
  1098. if (callback1.status == '00') {
  1099. ICINLocker.setVolume(this.data.cgInfo.lockerId, this.data.cgInfo.superId, volume, callback1.commonKey, (callback2) => {
  1100. console.log(callback2, '333333333')
  1101. if (callback2.status == '00') {
  1102. wx.hideLoading()
  1103. wx.showToast({
  1104. title: '设置成功',
  1105. duration: 2000,
  1106. icon: 'none'
  1107. })
  1108. } else {
  1109. wx.hideLoading()
  1110. wx.showToast({
  1111. title: '设置失败',
  1112. duration: 2000,
  1113. icon: 'none'
  1114. })
  1115. }
  1116. })
  1117. } else {
  1118. wx.hideLoading()
  1119. wx.showToast({
  1120. title: '设置失败',
  1121. duration: 2000,
  1122. icon: 'none'
  1123. })
  1124. }
  1125. })
  1126. } else {
  1127. wx.hideLoading()
  1128. wx.showToast({
  1129. title: '设置失败',
  1130. duration: 2000,
  1131. icon: 'none'
  1132. })
  1133. }
  1134. });
  1135. },
  1136. //设置常开
  1137. setOpen() {
  1138. wx.showLoading({
  1139. title: "正在开启...",
  1140. });
  1141. setTimeout(() => {
  1142. wx.hideLoading()
  1143. }, 1000);
  1144. let cmd = 0xF3
  1145. // let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  1146. let length = 2
  1147. let b = new Uint8Array(length)
  1148. b[0] = cmd
  1149. b[1] = 1;
  1150. app.globalData.ble.send(cmd, b, function (res) {})
  1151. },
  1152. setOpen1() {
  1153. wx.showLoading({
  1154. title: "正在关闭...",
  1155. });
  1156. setTimeout(() => {
  1157. wx.hideLoading()
  1158. }, 1000);
  1159. let cmd = 0xF3
  1160. // let dn = util.stringToUint8ArrayWithPadding(deviceNum, 20, 0xff)
  1161. let length = 2
  1162. let b = new Uint8Array(length)
  1163. b[0] = cmd
  1164. b[1] = 0;
  1165. app.globalData.ble.send(cmd, b, function (res) {})
  1166. },
  1167. //设置音量
  1168. setVoice() {
  1169. },
  1170. startconnect() {
  1171. //if(checkWechatVersion())
  1172. // {
  1173. wx.showLoading({
  1174. title: "连接中"
  1175. })
  1176. var deviceinfo = this.data.deviceinfo
  1177. const ble = new BLE(this.data.deviceinfo.deviceNum, emitter)
  1178. app.globalData.ble = ble
  1179. this.watchBLE()
  1180. app.globalData.ble.init()
  1181. // }
  1182. },
  1183. watchBLE() {
  1184. var that = this
  1185. var deviceinfo = this.data.deviceinfo
  1186. if (app.globalData.ble) {
  1187. app.globalData.ble.listen(res => {
  1188. if (res.type == 'connect') {
  1189. if (res.data == "未打开适配器") {
  1190. wx.hideLoading()
  1191. wx.showToast({
  1192. title: '请检查手机蓝牙和定位功能是否打开?',
  1193. duration: 2000,
  1194. icon: 'none'
  1195. })
  1196. } else {
  1197. if (res.data == '蓝牙已连接') {
  1198. this.data.info = res.data
  1199. app.globalData.bleStatus = res.data
  1200. if (this.data.event == 0) {
  1201. this.btntest2()
  1202. } else if(this.data.event == 1){
  1203. this.addPassword()
  1204. }else if (this.data.event == 3) {
  1205. this.btntest3()
  1206. } else if (this.data.event == 6) {
  1207. // this.setVoice()
  1208. this.setData({
  1209. show: true
  1210. })
  1211. } else if (this.data.event == 7) {
  1212. wx.showModal({
  1213. title: "常开设置",
  1214. cancelText: '关闭',
  1215. confirmText: '开启',
  1216. success: (res) => {
  1217. if (res.confirm) {
  1218. that.setOpen()
  1219. } else if (res.cancel) {
  1220. that.setOpen1()
  1221. }
  1222. }
  1223. })
  1224. }
  1225. }
  1226. }
  1227. }
  1228. })
  1229. }
  1230. },
  1231. // 添加密码
  1232. addPassword(){
  1233. this.setData({
  1234. showTwo:true
  1235. })
  1236. },
  1237. async getPassWordMehods(){
  1238. var that=this
  1239. let deviceinfoList = wx.getStorageSync('deviceinfo')
  1240. var data = {
  1241. id:deviceinfoList.cardId,
  1242. signature:wx.getStorageSync('signature'),
  1243. };
  1244. WXAPI.tsGetCertificate(data).then(res=>{
  1245. if(res.success){
  1246. var dataOne=[],dataTwo=[]
  1247. res.data.map(li=>{
  1248. if(li.type == 14){
  1249. li.content=JSON.parse(li.content)
  1250. dataOne.push(li)
  1251. }else if(li.type == 13){
  1252. li.content=JSON.parse(li.content)
  1253. dataTwo.push(li)
  1254. }
  1255. })
  1256. this.setData({
  1257. passwordList:dataOne,
  1258. NfcList:dataTwo
  1259. })
  1260. }else{
  1261. wx.showToast({
  1262. title: '获取失败',
  1263. duration:'2000',
  1264. mask:true,
  1265. icon:'none'
  1266. })
  1267. }
  1268. })
  1269. },
  1270. async sendPassword() {
  1271. var addpassword = this.data.addpassword.toString()
  1272. if(addpassword.length!=6){
  1273. wx.showToast({
  1274. title: '格式错误,密码为6位数字!',
  1275. icon:'none'
  1276. })
  1277. return false;
  1278. }
  1279. var time3 = new Date(this.data.starttime)
  1280. var time4 = new Date(this.data.endtime)
  1281. var passwordStartTimecontrast = time3.getTime() / 1000
  1282. var passwordEndTimecontrast = time4.getTime() / 1000
  1283. let passwordStatus = this.data.passwordStatus
  1284. console.log(time3,time4,passwordStartTimecontrast,passwordEndTimecontrast)
  1285. // await this.getPassWordMehods(this.data.addpassword,this.data.deviceinfo.cardId,14)
  1286. let paaaWd=this.data.passwordList.filter(lt=> lt.content.password == this.data.addpassword)
  1287. if(paaaWd.length > 0){
  1288. passwordStatus = false
  1289. }else{
  1290. passwordStatus = true
  1291. }
  1292. if(this.data.addpassword==''){
  1293. wx.showToast({
  1294. title: '密码不能为空',
  1295. mask:true,
  1296. duration: 2000,
  1297. icon: 'none'
  1298. })
  1299. return
  1300. }
  1301. if(!passwordStatus){
  1302. wx.showToast({
  1303. title: '已存在该密码,请重输',
  1304. duration: 2000,
  1305. mask:true,
  1306. icon: 'none'
  1307. })
  1308. return
  1309. }
  1310. if (passwordStartTimecontrast > passwordEndTimecontrast) {
  1311. wx.showToast({
  1312. title: '开始时间不能大于结束时间',
  1313. duration: 2000,
  1314. mask:true,
  1315. icon: 'none'
  1316. })
  1317. return
  1318. }
  1319. wx.showLoading({
  1320. title: '正在添加',
  1321. mask:true,
  1322. })
  1323. var _this = this
  1324. var deviceinfo = this.data.deviceinfo
  1325. if(this.data.remotePasswordStatus){
  1326. var pzname='',cardName=''
  1327. pzname=_this.data.deviceinfo.name+'-远程-密码'+(_this.data.passwordList.length+1)
  1328. cardName=_this.data.deviceinfo.name+'-远程-密码'+(_this.data.passwordList.length+1)
  1329. let dataObject={
  1330. code: "zg/tempPassword",
  1331. data: {
  1332. lockerId: deviceinfo.deviceNum,
  1333. imei: deviceinfo.imei,
  1334. order: 6207,
  1335. lockerUserId: JSON.parse(deviceinfo.info).userPassword,
  1336. passwordCount: 255,
  1337. keyId: JSON.parse(deviceinfo.info).userPassword,
  1338. passwordStartTime: passwordStartTimecontrast,
  1339. passwordEndTime: passwordEndTimecontrast,
  1340. action: 1,
  1341. password: addpassword,
  1342. cardName: cardName,
  1343. roomName: deviceinfo.roomName
  1344. },
  1345. operateName:_this.data.deviceinfo.name,
  1346. signature:wx.getStorageSync('signature'),
  1347. cardId: deviceinfo.cardId,
  1348. }
  1349. WXAPI.sendCommandOne(dataObject).then(res=>{
  1350. if (res.success) {
  1351. let dataPassword = {
  1352. imei: deviceinfo.imei,
  1353. deviceNum: deviceinfo.deviceNum,
  1354. userTelephone: JSON.parse(deviceinfo.info).userTelephone,
  1355. cardId: deviceinfo.cardId,
  1356. userPassword: JSON.parse(deviceinfo.info).userPassword,
  1357. password: addpassword,
  1358. operateMode: 7,
  1359. order: 6207,
  1360. type: 4,
  1361. passwordStartTime: passwordStartTimecontrast,
  1362. passwordEndTime: passwordEndTimecontrast,
  1363. is: false,
  1364. cardName: cardName,
  1365. roomName: deviceinfo.roomName,
  1366. pzname: pzname,
  1367. pass: false
  1368. };
  1369. var data = {
  1370. cardId: _this.data.deviceinfo.cardId,
  1371. content: JSON.stringify(dataPassword), //operateMode:NFC-10、把人员添加到凭证-1
  1372. deviceNum: _this.data.deviceinfo.deviceNum,
  1373. type: 4,
  1374. imei: _this.data.deviceinfo.imei,
  1375. serial: res.data.serialNumber,
  1376. startTime: passwordStartTimecontrast,
  1377. endTime: passwordEndTimecontrast,
  1378. signature:wx.getStorageSync('signature'),
  1379. };
  1380. var datalist = {
  1381. cardId: _this.data.deviceinfo.cardId,
  1382. content: JSON.stringify(dataPassword), //operateMode:NFC-10、把人员添加到凭证-1
  1383. type: 14,
  1384. startTime: passwordStartTimecontrast,
  1385. endTime: passwordEndTimecontrast,
  1386. signature:wx.getStorageSync('signature'),
  1387. };
  1388. console.log(datalist,'密码11')
  1389. WXAPI.tsAddCertificate(datalist).then(res6 => {
  1390. console.log(datalist,'密码22')
  1391. })
  1392. wx.showToast({
  1393. title: '下发成功',
  1394. icon: 'none',
  1395. mask:true,
  1396. duration: 2000
  1397. })
  1398. WXAPI.tsAddCertificate(data).then(res3 => {
  1399. if (res3.success) {
  1400. // var updatedata = {
  1401. // id: res3.data,
  1402. // status:1,
  1403. // signature:wx.getStorageSync('signature'),
  1404. // };
  1405. // WXAPI.editCertificate(updatedata).then((res2) => {
  1406. // });
  1407. _this.getPassWordMehods()
  1408. _this.setData({
  1409. showTwo: false
  1410. })
  1411. wx.hideLoading()
  1412. wx.showToast({
  1413. title: '下发成功',
  1414. icon: 'none',
  1415. mask:true,
  1416. duration: 2000
  1417. })
  1418. } else {
  1419. wx.hideLoading()
  1420. wx.showToast({
  1421. title: '添加失败',
  1422. mask:true,
  1423. icon: 'none',
  1424. duration: 2000
  1425. })
  1426. }
  1427. })
  1428. }else{
  1429. wx.showToast({
  1430. title: `${res.msg}`,
  1431. duration:2000,
  1432. icon:'none'
  1433. })
  1434. }
  1435. })
  1436. }else{
  1437. if (deviceinfo.manufactureId == 101) {
  1438. var time1 = moment(this.data.starttime).format("YYYYMMDDHHmmss")
  1439. var time2 = moment(this.data.endTime).format("YYYYMMDDHHmmss")
  1440. var time3 = new Date(_this.data.starttime.replace(/-/g, '/'))
  1441. var time4 = new Date(_this.data.endTime.replace(/-/g, '/'))
  1442. var passwordStartTime = time3.getTime() / 1000
  1443. var passwordEndTime = time4.getTime() / 1000
  1444. let info = JSON.parse(_this.data.deviceinfo.info)
  1445. var data1 = {
  1446. managerTelephone: "18270949468",
  1447. managerPassword: '202108',
  1448. userTelephone: info.userTelephone,
  1449. userPassword: info.userPassword,
  1450. password: this.data.addpassword,
  1451. startTime: time1,
  1452. endTime: time2,
  1453. }
  1454. var timestamp = moment().format("x")
  1455. bleall.startFp1_63(data1.managerTelephone, data1.managerPassword, data1.userTelephone,
  1456. data1.userPassword, data1.password, data1.startTime, data1.endTime, 7, timestamp,
  1457. function (res) {
  1458. console.log(res)
  1459. if (res.success) {
  1460. var pzname='',cardName=''
  1461. pzname=_this.data.deviceinfo.name+'-蓝牙-密码'+(_this.data.passwordList.length+1)
  1462. cardName=_this.data.personLi.name+'-蓝牙-密码'+(_this.data.passwordList.length+1)
  1463. var str = {
  1464. // cardId: this.personInfo.cardId,
  1465. pzname:pzname,
  1466. imei: _this.data.deviceinfo.imei,
  1467. password: _this.data.addpassword,
  1468. userTelephone: info.userTelephone,
  1469. operateMode: 7,
  1470. userPassword: info.userPassword,
  1471. passwordStartTime: time1,
  1472. passwordEndTime: time2,
  1473. is: false,
  1474. pass:true
  1475. }
  1476. var data3 = {
  1477. code: "ble/operateUserInfo",
  1478. signature:wx.getStorageSync('signature'),
  1479. cardId:_this.data.deviceinfo.cardId,
  1480. data: {
  1481. deviceNum: _this.data.deviceinfo.deviceNum,
  1482. imei: _this.data.deviceinfo.imei,
  1483. userTelephone: info.userTelephone,
  1484. userPassword: info.userPassword,
  1485. password: _this.data.password,
  1486. userStartTime: time1,
  1487. userEndTime: time2,
  1488. passwordStartTime: time1,
  1489. passwordEndTime: time2,
  1490. operateMode: 7,
  1491. order: 6207,
  1492. timestamp: timestamp,
  1493. managerTelephone: '18270949468',
  1494. managerPassword: '202108',
  1495. passwordLength: 10,
  1496. permission: 4294967295,
  1497. times: 255,
  1498. recycleTime: "65535",
  1499. roomName: _this.data.deviceinfo.roomName,
  1500. cardName: cardName,
  1501. }
  1502. }
  1503. WXAPI.sendCommandOne(data3).then(res3 => {
  1504. if (res3.success) {
  1505. var data4 = {
  1506. result: 1,
  1507. serial: res3.data.serialNumber
  1508. }
  1509. WXAPI.updatePush(data4).then(res4 => {
  1510. })
  1511. var data = {
  1512. cardId: _this.data.deviceinfo.cardId,
  1513. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1514. deviceNum: _this.data.deviceinfo.deviceNum,
  1515. type: 4,
  1516. imei: _this.data.deviceinfo.imei,
  1517. serial: res3.data.serialNumber,
  1518. startTime: passwordStartTime,
  1519. endTime: passwordEndTime,
  1520. signature:wx.getStorageSync('signature'),
  1521. };
  1522. var datalist = {
  1523. cardId: _this.data.deviceinfo.cardId,
  1524. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1525. type: 14,
  1526. startTime: passwordStartTime,
  1527. endTime: passwordEndTime,
  1528. signature:wx.getStorageSync('signature'),
  1529. };
  1530. console.log(datalist,'密码11')
  1531. WXAPI.tsAddCertificate(datalist).then(res6 => {
  1532. console.log(datalist,'密码22')
  1533. })
  1534. WXAPI.tsAddCertificate(data).then(res3 => {
  1535. if (res3.success) {
  1536. var updatedata = {
  1537. id: res3.data,
  1538. status:1,
  1539. signature:wx.getStorageSync('signature'),
  1540. };
  1541. WXAPI.editCertificate(updatedata).then((res2) => {
  1542. });
  1543. _this.getPassWordMehods()
  1544. _this.setData({
  1545. showTwo: false
  1546. })
  1547. wx.hideLoading()
  1548. wx.showToast({
  1549. title: '添加成功',
  1550. icon: 'none',
  1551. mask:true,
  1552. duration: 2000
  1553. })
  1554. } else {
  1555. wx.hideLoading()
  1556. wx.showToast({
  1557. title: '添加失败',
  1558. mask:true,
  1559. icon: 'none',
  1560. duration: 2000
  1561. })
  1562. }
  1563. })
  1564. } else {
  1565. wx.showToast({
  1566. title: res3.msg,
  1567. mask:true,
  1568. icon: 'none',
  1569. duration: 2000
  1570. })
  1571. }
  1572. })
  1573. }else{
  1574. wx.hideLoading()
  1575. if (res.data == "蓝牙功能暂不支持") {
  1576. _this.startconnect()
  1577. }else{
  1578. wx.showToast({
  1579. title: '下发失败',
  1580. mask:true,
  1581. duration: 2000,
  1582. icon: "none"
  1583. })
  1584. }
  1585. }
  1586. })
  1587. }else if(deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221){
  1588. var cgInfo = this.data.cgInfo
  1589. console.log(passwordStartTimecontrast,passwordEndTimecontrast)
  1590. var passwordStartTime = passwordStartTimecontrast
  1591. var passwordEndTime = passwordEndTimecontrast
  1592. var pzname='',cardName=''
  1593. console.log(_this.data.passwordList,_this.data.deviceinfo)
  1594. pzname=_this.data.deviceinfo.name+'-蓝牙-密码'+(_this.data.passwordList.length+1)
  1595. cardName=_this.data.deviceinfo.name+'-蓝牙-密码'+(_this.data.passwordList.length+1)
  1596. let info = JSON.parse(_this.data.deviceinfo.info)
  1597. var dataPasswod = {
  1598. code: "zg/tempPassword",
  1599. cardId:deviceinfo.cardId,
  1600. data: {
  1601. lockerId: deviceinfo.deviceNum,
  1602. imei: deviceinfo.imei,
  1603. passwordCount: 255,
  1604. lockerUserId: info.userPassword,
  1605. keyId: info.userPassword,
  1606. passwordStartTime: passwordStartTime,
  1607. passwordEndTime: passwordEndTime,
  1608. order: 6207,
  1609. action: 1,
  1610. password: this.data.addpassword,
  1611. type: 1,
  1612. roomName: this.data.deviceinfo.roomName,
  1613. cardName: cardName,
  1614. operateName:_this.data.deviceinfo.name
  1615. },
  1616. signature:wx.getStorageSync('signature'),
  1617. }
  1618. console.log(dataPasswod)
  1619. WXAPI.sendCommandOne(dataPasswod).then(res => {
  1620. console.log(res, '获取索引')
  1621. if (res.success) {
  1622. var pwdNo = res.data.index
  1623. var passwordIndex = res.data.index
  1624. // var str = res.data.index
  1625. pwdNo = pwdNo.toString(16)
  1626. if (pwdNo.length < 2) {
  1627. pwdNo='0'+pwdNo
  1628. }
  1629. var startTime = passwordStartTime.toString(16).toUpperCase()
  1630. var endTime = passwordEndTime.toString(16).toUpperCase()
  1631. console.log(startTime,endTime)
  1632. info.startTime=startTime
  1633. info.endTime=endTime
  1634. info.pwdNo=pwdNo
  1635. info.password=_this.data.addpassword
  1636. methods.bluetoothOperation_ZH(cgInfo,info,3).then(result=>{
  1637. console.log(result)
  1638. if (result.status == '00') {
  1639. var datacom = {
  1640. code: "zg/bleSendVoucherReply",
  1641. signature:wx.getStorageSync('signature'),
  1642. cardId:deviceinfo.cardId,
  1643. data: {
  1644. lockerId: deviceinfo.deviceNum,
  1645. serialNumber: res.data.serialNumber,
  1646. index: passwordIndex,
  1647. type: 7,
  1648. result: 1,
  1649. operateName:_this.data.deviceinfo.name
  1650. }
  1651. }
  1652. var str = {
  1653. // cardId: this.personInfo.cardId,
  1654. imei: deviceinfo.imei,
  1655. pzname:pzname,
  1656. password: _this.data.addpassword,
  1657. userTelephone: info.userTelephone,
  1658. operateMode: 7,
  1659. userPassword: info.userPassword,
  1660. passwordStartTime: passwordStartTime,
  1661. passwordEndTime: passwordEndTime,
  1662. is: false,
  1663. pass:true
  1664. }
  1665. var data = {
  1666. cardId: deviceinfo.cardId,
  1667. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1668. deviceNum: deviceinfo.deviceNum,
  1669. type: 4,
  1670. imei: deviceinfo.imei,
  1671. serial: res.data.serialNumber,
  1672. startTime: passwordStartTime,
  1673. endTime: passwordEndTime,
  1674. signature:wx.getStorageSync('signature'),
  1675. };
  1676. var datalist = {
  1677. cardId: deviceinfo.cardId,
  1678. content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
  1679. type: 14,
  1680. startTime: passwordStartTime,
  1681. endTime: passwordEndTime,
  1682. signature:wx.getStorageSync('signature'),
  1683. };
  1684. console.log(datalist,'密码11')
  1685. WXAPI.tsAddCertificate(datalist).then(res6 => {
  1686. console.log(datalist,'密码22',res6)
  1687. })
  1688. console.log(data, '添加凭证')
  1689. WXAPI.tsAddCertificate(data).then(res3 => {
  1690. if (res3.success) {
  1691. var updatedata = {
  1692. id: res3.data,
  1693. status:1,
  1694. signature:wx.getStorageSync('signature'),
  1695. };
  1696. WXAPI.editCertificate(updatedata).then((res2) => {
  1697. });
  1698. WXAPI.sendCommandOne(datacom).then(res2 => {
  1699. if (res2.success) {}
  1700. })
  1701. console.log(res3, '添加凭证成功')
  1702. _this.setData({
  1703. show: false,
  1704. showTwo:false
  1705. })
  1706. _this.getPassWordMehods()
  1707. wx.hideLoading()
  1708. wx.showToast({
  1709. title: '添加成功',
  1710. mask:true,
  1711. icon: 'none',
  1712. duration: 2000
  1713. })
  1714. } else {
  1715. wx.hideLoading()
  1716. wx.showToast({
  1717. title: '添加失败',
  1718. mask:true,
  1719. icon: 'none',
  1720. duration: 2000
  1721. })
  1722. }
  1723. })
  1724. } else {
  1725. wx.showToast({
  1726. title: '添加失败',
  1727. mask:true,
  1728. icon: 'none',
  1729. duration: 2000
  1730. })
  1731. var datacom = {
  1732. code: "zg/bleSendVoucherReply",
  1733. signature:wx.getStorageSync('signature'),
  1734. cardId:deviceinfo.cardId,
  1735. data: {
  1736. lockerId: deviceinfo.deviceNum,
  1737. serialNumber: res.data.serialNumber,
  1738. index: res.data.index,
  1739. type: 7,
  1740. result: 0
  1741. }
  1742. }
  1743. WXAPI.sendCommandOne(datacom).then(res2 => {
  1744. console.log(res2, '失败')
  1745. _this.setData({
  1746. show: false
  1747. })
  1748. })
  1749. }
  1750. })
  1751. // .catch(err=>{
  1752. // wx.hideLoading()
  1753. // wx.showToast({
  1754. // title: '添加失败',
  1755. // icon: 'none',
  1756. // mask:true,
  1757. // duration: 2000
  1758. // })
  1759. // var datacom = {
  1760. // code: "zg/bleSendVoucherReply",
  1761. // signature:wx.getStorageSync('signature'),
  1762. // data: {
  1763. // lockerId: deviceinfo.deviceNum,
  1764. // serialNumber: res.data.serialNumber,
  1765. // index: res.data.index,
  1766. // type: 7,
  1767. // result: 0
  1768. // }
  1769. // }
  1770. // WXAPI.sendCommandOne(datacom).then(res2 => {
  1771. // console.log(res2, '失败')
  1772. // _this.setData({
  1773. // show: false
  1774. // })
  1775. // })
  1776. // })
  1777. } else {
  1778. wx.showToast({
  1779. title: res.msg,
  1780. duration: 2000,
  1781. mask:true,
  1782. icon: 'none'
  1783. })
  1784. }
  1785. })
  1786. }
  1787. }
  1788. },
  1789. closeblue() {
  1790. app.globalData.ble.close()
  1791. this.data.info = ''
  1792. app.globalData.bleStatus = false
  1793. this.data.bleStatus = false,
  1794. this.data.respond = []
  1795. },
  1796. closeblue1() {
  1797. // wx.showLoading({
  1798. // title: "正在停止...",
  1799. // });
  1800. app.globalData.ble.close()
  1801. // setTimeout(() => {
  1802. // wx.hideLoading()
  1803. // }, 1000);
  1804. this.data.info = ''
  1805. app.globalData.bleStatus = false
  1806. this.data.bleStatus = false,
  1807. this.data.respond = []
  1808. },
  1809. btntest3(event) {
  1810. var that = this
  1811. let deviceNum = that.data.deviceinfo.deviceNum
  1812. this.data.backstatus = true
  1813. that.startFp_29(deviceNum, 0x03)
  1814. // setTimeout(() => {
  1815. // that.getcartcount()
  1816. // }, 300)
  1817. },
  1818. btntest2(event) {
  1819. var that = this
  1820. let userTelephone = "18270949468" //JSON.parse(this.data.deviceinfo.info).userTelephone
  1821. let userPassword = "202108" //JSON.parse(this.data.deviceinfo.info).userPassword
  1822. let pwd = "2021110309" //JSON.parse(this.data.deviceinfo.info).userPassword
  1823. let openLockType = 2
  1824. var userInfo=wx.getStorageSync('deviceinfo')
  1825. var timestamp = moment().format("x")
  1826. bleall.openLock(userTelephone, userPassword, pwd, openLockType, timestamp, function (res) {
  1827. if (res.success) {
  1828. var data = {
  1829. code: "ld/bleUnlockRecord",
  1830. signature:wx.getStorageSync('signature'),
  1831. cardId:that.data.deviceinfo.cardId,
  1832. data: {
  1833. deviceNum: that.data.deviceNum,
  1834. userTelephone: userTelephone,
  1835. password: userPassword,
  1836. roomId:that.data.deviceinfo.roomId,
  1837. roomName:that.data.deviceinfo.roomName,
  1838. cardName:userInfo.name,
  1839. }
  1840. }
  1841. WXAPI.sendCommandOne(data).then(res => {
  1842. })
  1843. }
  1844. if (res.data == "蓝牙功能暂不支持") {
  1845. wx.showToast({
  1846. title: '重新连接蓝牙中',
  1847. duration: 2000,
  1848. icon: "none"
  1849. })
  1850. that.startconnect()
  1851. }
  1852. })
  1853. },
  1854. openLock(userTelephone, userPassword, pwd, openLockType) {
  1855. wx.showLoading({
  1856. title: "正在发送...",
  1857. });
  1858. setTimeout(() => {
  1859. wx.hideLoading()
  1860. }, 1000);
  1861. let cmd = 0x41
  1862. console.log(util, userTelephone)
  1863. let ut = util.stringToUint8Array(userTelephone)
  1864. let up = util.stringToUint8Array(userPassword)
  1865. let p = util.hexStringToBytesWithPadding(pwd, 10, 0xff)
  1866. let length = 1 + 11 + 6 + 10 + 1
  1867. let b = new Uint8Array(length)
  1868. b[0] = cmd
  1869. b.set(ut, 1)
  1870. b.set(up, 12)
  1871. b.set(p, 18)
  1872. b[28] = openLockType
  1873. console.log(b)
  1874. app.globalData.ble.send(cmd, b, length)
  1875. },
  1876. //远程开锁
  1877. remoteUnlocking() {
  1878. if (this.data.info == '蓝牙已连接') {
  1879. this.closeblue1()
  1880. }
  1881. var str2 = {
  1882. imei: this.data.deviceinfo.imei,
  1883. openLockType: 2,
  1884. is: true,
  1885. };
  1886. WXAPI.openLock(str2).then(res => {
  1887. if (res.data.success) {
  1888. wx.showToast({
  1889. title: "操作成功",
  1890. icon: "none",
  1891. duration: 2000
  1892. })
  1893. }
  1894. })
  1895. },
  1896. /**
  1897. * 生命周期函数--监听页面初次渲染完成
  1898. */
  1899. onReady: function () {
  1900. app.globalData.zgBlueStatus = false
  1901. // this.btntest1()
  1902. },
  1903. AddressPermissions() {
  1904. wx.openBluetoothAdapter({
  1905. success: function (res) {
  1906. console.log('蓝牙已开启!');
  1907. },
  1908. fail: function (e) {
  1909. console.log(e)
  1910. wx.showToast({
  1911. title: '请打开蓝牙!',
  1912. duration: 2000,
  1913. icon: 'none'
  1914. })
  1915. }
  1916. });
  1917. ICINLocker.getLocationPermission().then((res) => {
  1918. if (res.status == 0) {} else {
  1919. // 连接出现问题
  1920. }
  1921. }).catch((res) => {
  1922. //处理未能获得地理位置情况
  1923. wx.showToast({
  1924. title: '请打开微信定位功能!',
  1925. duration: 2000,
  1926. icon: 'none'
  1927. })
  1928. })
  1929. },
  1930. /**
  1931. * 生命周期函数--监听页面显示
  1932. */
  1933. onShow: function () {
  1934. var deviceinfo = wx.getStorageSync('deviceinfo')
  1935. this.setData({
  1936. deviceinfo:deviceinfo,
  1937. bleStatus: app.globalData.bleStatus
  1938. })
  1939. },
  1940. /**
  1941. * 生命周期函数--监听页面隐藏
  1942. */
  1943. /**
  1944. * 生命周期函数--监听页面卸载
  1945. */
  1946. onUnload: function () {
  1947. if (app.globalData.zgBlueStatus) {
  1948. ICINLocker.disConnect(app.globalData.blueDeviceId);
  1949. this.onReady()
  1950. }
  1951. this.setData({
  1952. bluestatus: false
  1953. })
  1954. this.closeblue()
  1955. },
  1956. onHide() {
  1957. this.closeblue()
  1958. },
  1959. /**
  1960. * 页面相关事件处理函数--监听用户下拉动作
  1961. */
  1962. onPullDownRefresh: function () {
  1963. // this.AddressPermissions()
  1964. var deviceinfo = wx.getStorageSync('deviceinfo')
  1965. app.globalData.deviceNum = deviceinfo.deviceNum
  1966. var userInfo1 = wx.getStorageSync('userInfo')
  1967. if (deviceinfo.manufactureId == 201|| deviceinfo.manufactureId == 221) {
  1968. var data3 = {
  1969. code: "zg/bleRegisterInfo",
  1970. signature:wx.getStorageSync('signature'),
  1971. cardId:deviceinfo.cardId,
  1972. data: {
  1973. lockerId: deviceinfo.deviceNum
  1974. }
  1975. }
  1976. WXAPI.sendCommandOne(data3).then(res1 => {
  1977. if (res1.success) {
  1978. wx.setStorageSync('cgInfo', res1.data)
  1979. this.setData({
  1980. cgInfo: res1.data
  1981. })
  1982. } else {
  1983. }
  1984. })
  1985. }
  1986. if (deviceinfo.roomId) {
  1987. if (userInfo1.type != 3) {
  1988. var data2 = {
  1989. q: JSON.stringify({
  1990. id: deviceinfo.roomId
  1991. }),
  1992. orderBy: "createTime",
  1993. orderType: 'desc'
  1994. }
  1995. WXAPI.getSiteTenant(data2).then(res1 => {
  1996. if (res1.data.list.length > 0) {
  1997. var array = res1.data.list.reverse()
  1998. wx.setStorageSync('info', array[0])
  1999. deviceinfo.info = array[0].info
  2000. this.setData({
  2001. deviceinfo: deviceinfo
  2002. })
  2003. } else {
  2004. wx.showToast({
  2005. title: "还未下发人员,请先下发人员",
  2006. duration: 2000,
  2007. icon: 'none'
  2008. })
  2009. }
  2010. })
  2011. } else if (userInfo1.type == 3) {
  2012. this.setData({
  2013. deviceinfo: deviceinfo
  2014. })
  2015. }
  2016. } else {
  2017. wx.navigateTo({
  2018. url: "../index/index"
  2019. })
  2020. }
  2021. this.setData({
  2022. info: app.globalData.bleStatus,
  2023. deviceinfo: deviceinfo
  2024. })
  2025. wx.stopPullDownRefresh()
  2026. },
  2027. /**
  2028. * 页面上拉触底事件的处理函数
  2029. */
  2030. onReachBottom: function () {
  2031. },
  2032. /**
  2033. * 用户点击右上角分享
  2034. */
  2035. onShareAppMessage: function () {
  2036. }
  2037. })