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.

1247 lines
43 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. // pages/personManger/personManger.js
  2. const app = getApp()
  3. const WXAPI = require('../../utils/request')
  4. import ICINLocker from "../../utils/ICINPakage/ICINLocker"
  5. var methods = require('../../utils/methods.js');
  6. var md5 = require('../../utils/md5.js');
  7. var bleall = require('../../utils/bleall');
  8. import {
  9. BLE
  10. } from "../../utils/btls/ble";
  11. const emitter = app.globalData.emitter
  12. // ArrayBuffer转16进度字符串示例
  13. function ab2hex(buffer) {
  14. var hexArr = Array.prototype.map.call(
  15. new Uint8Array(buffer),
  16. function (bit) {
  17. return ('00' + bit.toString(16)).slice(-2)
  18. }
  19. )
  20. return hexArr.join(',');
  21. }
  22. import moment from "../../utils/moment"
  23. function CurentTime() {
  24. var now = new Date();
  25. var year = now.getFullYear(); //年
  26. var month = now.getMonth() + 1; //月
  27. var day = now.getDate(); //日
  28. var hh = now.getHours(); //时
  29. var mm = now.getMinutes(); //分
  30. var clock = year + "-";
  31. if (month < 10)
  32. clock += "0";
  33. clock += month + "-";
  34. if (day < 10)
  35. clock += "0";
  36. clock += day + " ";
  37. // if (hh < 10)
  38. // clock += "0";
  39. // clock += '00' + ":";
  40. // // if (mm < 10) clock += '0';
  41. clock += '00:00:00';
  42. return (clock);
  43. }
  44. function CurentTime1() {
  45. var now = new Date();
  46. var year = now.getFullYear() + 3; //年
  47. var month = now.getMonth() + 1; //月
  48. var day = now.getDate(); //日
  49. var hh = now.getHours(); //时
  50. var mm = now.getMinutes(); //分
  51. var clock = year + "-";
  52. if (month < 10)
  53. clock += "0";
  54. clock += month + "-";
  55. if (day < 10)
  56. clock += "0";
  57. clock += day + " ";
  58. // if (hh < 10)
  59. // clock += "0";
  60. // clock += hh + ":";
  61. // if (mm < 10) clock += '0';
  62. // clock += mm;
  63. clock += '23:59:59';
  64. return (clock);
  65. }
  66. Page({
  67. /**
  68. * 页面的初始数据
  69. */
  70. data: {
  71. datetimerange: [CurentTime(), CurentTime1()],
  72. endtime: '',
  73. starttime: '',
  74. personList: [],
  75. searchValue: '',
  76. deviceinfo: [],
  77. roomId: [],
  78. current: '',
  79. index: '',
  80. show: false,
  81. phone: '',
  82. name: '',
  83. cgInfo: {},
  84. number:"",
  85. minDate: '',
  86. minDate1: ''
  87. },
  88. bindDateChange: function (e) {
  89. var str = e.detail.value + " 00:00:00"
  90. this.data.datetimerange[0] = str
  91. this.setData({
  92. starttime: str
  93. })
  94. },
  95. bindDateChange1: function (e) {
  96. var str = e.detail.value + " 00:00:00"
  97. this.data.datetimerange[1] = str
  98. this.setData({
  99. endtime: str
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面加载
  104. */
  105. onLoad: function (options) {
  106. console.log(moment().format("x"))
  107. var deviceinfo = wx.getStorageSync('deviceinfo')
  108. var cgInfo = wx.getStorageSync('cgInfo')
  109. let starttime = moment().format('YYYY-MM-DD HH:mm:ss')
  110. let endtime = moment().add(365,'days').format('YYYY-MM-DD HH:mm:ss')
  111. if(deviceinfo.roomId){
  112. this.getSiteTenant(deviceinfo.roomId)
  113. }
  114. this.setData({
  115. deviceinfo: deviceinfo,
  116. roomId: deviceinfo.roomId,
  117. cgInfo: cgInfo,
  118. starttime,
  119. endtime,
  120. minDate: starttime,
  121. minDate1: endtime
  122. })
  123. },
  124. onChange1(event) {
  125. // event.detail 为当前输入的值
  126. console.log(event.detail);
  127. this.setData({
  128. name: event.detail
  129. })
  130. },
  131. onChange3(event) {
  132. this.setData({
  133. number: event.detail
  134. })
  135. },
  136. onChange2(event) {
  137. // event.detail 为当前输入的值
  138. console.log(event.detail);
  139. var str = event.detail
  140. if (str.length > 11) {
  141. wx.showToast({
  142. title: '手机号为11位数字,请输入正确手机号',
  143. duration: 2000,
  144. mask:true,
  145. icon: 'none'
  146. })
  147. str = str.substr(1, 11)
  148. this.setData({
  149. phone: str
  150. })
  151. } else {
  152. this.setData({
  153. phone: event.detail
  154. })
  155. }
  156. },
  157. // 添加用户
  158. adduser() {
  159. var _this = this
  160. wx.showLoading({
  161. title: '正在添加',
  162. mask:true
  163. })
  164. var time1 = moment(this.data.datetimerange[0]).format("YYYYMMDDHHmmss")
  165. var time2 = moment(this.data.datetimerange[1]).format("YYYYMMDDHHmmss")
  166. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  167. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  168. var passwordStartTime = time3.getTime() / 1000
  169. var passwordEndTime = time4.getTime() / 1000
  170. if(passwordStartTime>passwordEndTime){
  171. wx.showToast({
  172. title: '开始时间不能大于结束时间',
  173. duration: 2000,
  174. mask:true,
  175. icon: 'none'
  176. })
  177. return
  178. }
  179. if (this.data.phone == '') {
  180. wx.showToast({
  181. title: '请填写手机号',
  182. duration: 2000,
  183. mask:true,
  184. icon: 'none'
  185. })
  186. }else if(this.data.name == ''){
  187. wx.showToast({
  188. title: '请填写名称',
  189. duration: 2000,
  190. mask:true,
  191. icon: 'none'
  192. })
  193. }else if(this.data.number == ''){
  194. wx.showToast({
  195. title: '请填写学号',
  196. duration: 2000,
  197. mask:true,
  198. icon: 'none'
  199. })
  200. }else if(this.data.phone.length !=11){
  201. wx.showToast({
  202. title: '手机号格式错误',
  203. duration: 2000,
  204. mask:true,
  205. icon: 'none'
  206. })
  207. } else {
  208. var userInfo = wx.getStorageSync('userInfo')
  209. var deviceinfo = this.data.deviceinfo
  210. if (deviceinfo.manufactureId == 101) {
  211. var time1 = moment(this.data.datetimerange[0]).format("YYYYMMDDHHmmss")
  212. var time2 = moment(this.data.datetimerange[1]).format("YYYYMMDDHHmmss")
  213. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  214. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  215. var passwordStartTime = time3.getTime() / 1000
  216. var passwordEndTime = time4.getTime() / 1000
  217. var userPassword = JSON.stringify(this.data.phone).substring(this.data.phone.length - 6, this.data.phone.length)
  218. var data = {
  219. managerTelephone: "18270949468",
  220. managerPassword: "202108",
  221. userTelephone: this.data.phone,
  222. password: userPassword,
  223. userPassword: userPassword,
  224. startTime: time1,
  225. endTime: time2
  226. }
  227. var str = md5(this.data.phone)
  228. var usrID = userPassword//str.substr(str.length - 7, str.length).toUpperCase()
  229. var timestamp= moment().format("x")
  230. bleall.startFp1_63(data.managerTelephone, data.managerPassword, data.userTelephone,
  231. data.userPassword, data.password, data.startTime, data.endTime, 1,timestamp,
  232. function (res) {
  233. console.log(res)
  234. if (res.success) {
  235. bleall.startFp1_63(data.managerTelephone, data.managerPassword, data.userTelephone,
  236. data.userPassword, data.password,
  237. data.startTime, data.endTime, 4,timestamp,
  238. function (res1) {
  239. if (res1.success) {
  240. let loginKey = WXAPI.setCode("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXKHkNKieiGOTjXZJ0lFBjhRCa\nZTaAebTIfB9nnnVmNVIp//yCfyFXSlxbAj58CQwCVhwy109ROYf3BcsQNMZz7Djo\n8a5V0JThNye4ihxLiYLawLRjb2y2/IhzV0/JZiFtaM83xUt0tbqTKxD00Up7dy8c\n9OXc0h//0uQSraf6JwIDAQAB", userPassword)
  241. var infostr = {
  242. userTelephone: _this.data.phone,
  243. userPassword: userPassword,
  244. loginKey:loginKey,
  245. userId: usrID,
  246. keyId: usrID,
  247. pass:true
  248. };
  249. var data1 = {
  250. cardId: _this.data.number,
  251. cardState: 1,
  252. info: JSON.stringify(infostr),
  253. name: _this.data.name,
  254. number: _this.data.number,
  255. phone: _this.data.phone,
  256. sex: 1,
  257. type: 0,
  258. };
  259. WXAPI.addCard(data1).then(res => {
  260. if (res.success) {
  261. var data2 = [{
  262. cardId: res.data,
  263. siteId: _this.data.deviceinfo.roomId,
  264. startTime: time3,
  265. endTime: time4
  266. }]
  267. WXAPI.bindCard(data2).then(res2 => {
  268. var data3 = {
  269. code: "ble/operateUserInfo",
  270. data: {
  271. deviceNum: _this.data.deviceinfo.deviceNum,
  272. imei: _this.data.deviceinfo.imei,
  273. userTelephone: _this.data.phone,
  274. userPassword: userPassword,
  275. userStartTime: time1,
  276. userEndTime: time2,
  277. password: userPassword,
  278. passwordStartTime: time1,
  279. passwordEndTime: time2,
  280. operateMode: 1,
  281. order: 6226,
  282. roomName:_this.data.deviceinfo.roomName,
  283. cardName:'蓝牙'+_this.data.name,
  284. timestamp: timestamp,
  285. managerTelephone: '18270949468',
  286. managerPassword: '202108',
  287. passwordLength: 10,
  288. permission: 4294967295,
  289. times: 255,
  290. recycleTime: "65535",
  291. }
  292. }
  293. wx.hideLoading()
  294. wx.showToast({
  295. title: '添加成功',
  296. icon: 'none',
  297. mask:true,
  298. duration: 2000
  299. })
  300. // wx.setStorageSync('minDate', data.startTime)
  301. // wx.setStorageSync('minDate1', data.endTime)
  302. WXAPI.sendCommand(data3).then(res6 => {
  303. if(res6.success){
  304. var data4 = {
  305. result: 1,
  306. serial: res6.data.serialNumber
  307. }
  308. setTimeout(()=>{
  309. WXAPI.updatePush(data4).then(res4 => {
  310. })
  311. },1000)
  312. }
  313. // var result='',serial=''
  314. // WXAPI.editStatusBySerial('',`/v1/device/editStatus/bySerial/${result}/${serial}`).then(res2=>{
  315. // })
  316. })
  317. _this.setData({
  318. show: false
  319. })
  320. _this.getSiteTenant(_this.data.roomId)
  321. })
  322. }else{
  323. wx.hideLoading()
  324. wx.showToast({
  325. title: '添加失败',
  326. duration:2000,
  327. icon:'none'
  328. })
  329. }
  330. })
  331. }else{
  332. wx.hideLoading()
  333. wx.showToast({
  334. title: '添加失败',
  335. duration:2000,
  336. icon:'none'
  337. })
  338. }
  339. })
  340. }
  341. if (res.data == "蓝牙功能暂不支持") {
  342. wx.showLoading({
  343. title: '重连中',
  344. })
  345. _this.startconnect()
  346. }
  347. })
  348. } else if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  349. var time1 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  350. var time2 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  351. var passwordStartTime = time1.getTime() / 1000
  352. var passwordEndTime = time2.getTime() / 1000
  353. var startTime = passwordStartTime.toString(16).toUpperCase()
  354. var endTime = passwordEndTime.toString(16).toUpperCase()
  355. var str = md5(this.data.phone)
  356. var usrID = str.substr(str.length - 7, str.length).toUpperCase()
  357. var userPassword = JSON.stringify(this.data.phone).substring(this.data.phone.length - 6, this.data.phone.length)
  358. wx.showLoading({
  359. title: '正在添加',
  360. })
  361. let info={
  362. usrID:userPassword,
  363. startTime:startTime,
  364. endTime:endTime
  365. }
  366. methods.bluetoothOperation_ZH(this.data.cgInfo,info,1).then(result=>{
  367. console.log("373",result);
  368. if (result.status == '00') {
  369. var dataPasswod = {
  370. lockerId: this.data.deviceinfo.deviceNum,
  371. imei: this.data.deviceinfo.imei,
  372. lockerUserId: userPassword,
  373. keyId: userPassword,
  374. role: 0,
  375. order: 6226,
  376. action: 1,
  377. roomName:this.data.deviceinfo.roomName,
  378. cardName:'蓝牙'+this.data.name,
  379. type: 1,
  380. result: 1
  381. }
  382. let loginKey = WXAPI.setCode("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXKHkNKieiGOTjXZJ0lFBjhRCa\nZTaAebTIfB9nnnVmNVIp//yCfyFXSlxbAj58CQwCVhwy109ROYf3BcsQNMZz7Djo\n8a5V0JThNye4ihxLiYLawLRjb2y2/IhzV0/JZiFtaM83xUt0tbqTKxD00Up7dy8c\n9OXc0h//0uQSraf6JwIDAQAB", userPassword)
  383. var infostr = {
  384. userTelephone: _this.data.phone,
  385. userPassword: userPassword,
  386. loginKey:loginKey,
  387. userId: userPassword,
  388. keyId: userPassword,
  389. pass:true
  390. };
  391. var data1 = {
  392. cardId: this.data.number,
  393. cardState: 1,
  394. info: JSON.stringify(infostr),
  395. name: this.data.name,
  396. number: this.data.number,
  397. phone: this.data.phone,
  398. enterpriseId: userInfo.enterpriseId,
  399. sex: 1,
  400. type: 0
  401. }
  402. WXAPI.addCard(data1).then(res => {
  403. if (res.success) {
  404. var data2 = [{
  405. cardId: res.data,
  406. siteId: this.data.deviceinfo.roomId,
  407. startTime: time1,
  408. endTime: time2
  409. }]
  410. this.setData({
  411. name:'',
  412. phone:'',
  413. number:''
  414. })
  415. WXAPI.bindCard(data2).then(res2 => {
  416. if (res2.success) {
  417. WXAPI.ZGduserOperation(dataPasswod).then(res6 => {
  418. console.log(res6)
  419. if (res6.success) {
  420. wx.hideLoading()
  421. this.setData({
  422. name:'',
  423. phone:'',
  424. number:''
  425. })
  426. wx.showToast({
  427. title: '添加成功',
  428. icon: 'none',
  429. mask:true,
  430. duration: 2000
  431. })
  432. // wx.setStorageSync('minDate', data.startTime)
  433. // wx.setStorageSync('minDate1', data.endTime)
  434. } else {
  435. wx.hideLoading()
  436. wx.showToast({
  437. title: '添加失败',
  438. icon: 'none',
  439. mask:true,
  440. duration: 2000
  441. })
  442. }
  443. })
  444. this.getSiteTenant(this.data.roomId)
  445. this.setData({
  446. show: false
  447. })
  448. wx.showToast({
  449. title: '绑定成功',
  450. mask:true,
  451. icon: 'none',
  452. })
  453. } else {
  454. wx.hideLoading()
  455. wx.showToast({
  456. title: '添加失败',
  457. mask:true,
  458. icon: 'none'
  459. })
  460. }
  461. })
  462. } else {
  463. wx.hideLoading()
  464. wx.showToast({
  465. title: '添加失败',
  466. mask:true,
  467. icon: 'none'
  468. })
  469. }
  470. })
  471. } else {
  472. wx.hideLoading()
  473. wx.showToast({
  474. title: '添加失败',
  475. mask:true,
  476. duration: 2000,
  477. icon: 'none'
  478. })
  479. }
  480. })
  481. }else if(deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241){
  482. var time1 = moment(this.data.datetimerange[0]).format("YYYYMMDDHHmmss")
  483. var time2 = moment(this.data.datetimerange[1]).format("YYYYMMDDHHmmss")
  484. var time3 = new Date(this.data.datetimerange[0].replace(/-/g, '/'))
  485. var time4 = new Date(this.data.datetimerange[1].replace(/-/g, '/'))
  486. var passwordStartTime = time3.getTime() / 1000
  487. var passwordEndTime = time4.getTime() / 1000
  488. var userPassword = JSON.stringify(this.data.phone).substring(this.data.phone.length - 6, this.data.phone.length)
  489. var data = {
  490. userTelephone: this.data.phone,
  491. password: userPassword,
  492. userPassword: userPassword,
  493. startTime: time1,
  494. endTime: time2
  495. }
  496. let loginKey = WXAPI.setCode("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXKHkNKieiGOTjXZJ0lFBjhRCa\nZTaAebTIfB9nnnVmNVIp//yCfyFXSlxbAj58CQwCVhwy109ROYf3BcsQNMZz7Djo\n8a5V0JThNye4ihxLiYLawLRjb2y2/IhzV0/JZiFtaM83xUt0tbqTKxD00Up7dy8c\n9OXc0h//0uQSraf6JwIDAQAB", userPassword)
  497. var infostr = {
  498. userTelephone: _this.data.phone,
  499. userPassword: userPassword,
  500. loginKey:loginKey,
  501. userId: userPassword,
  502. keyId: userPassword,
  503. pass:true
  504. };
  505. var data1 = {
  506. cardId: _this.data.number,
  507. cardState: 1,
  508. info: JSON.stringify(infostr),
  509. name: _this.data.name,
  510. number: _this.data.number,
  511. phone: _this.data.phone,
  512. sex: 1,
  513. type: 0,
  514. };
  515. WXAPI.addCard(data1).then(res => {
  516. if (res.success) {
  517. var data2 = [{
  518. cardId: res.data,
  519. siteId: _this.data.deviceinfo.roomId,
  520. startTime: time3,
  521. endTime: time4
  522. }]
  523. WXAPI.bindCard(data2).then(res2 => {
  524. if(res2.success){
  525. _this.setData({
  526. show: false
  527. })
  528. wx.showToast({
  529. title: '人员绑定成功',
  530. icon: 'none',
  531. duration: 2000
  532. })
  533. // wx.setStorageSync('minDate', data.startTime)
  534. // wx.setStorageSync('minDate1', data.endTime)
  535. _this.getSiteTenant(_this.data.roomId)
  536. }else{
  537. wx.hideLoading()
  538. wx.showToast({
  539. title: '人员绑定失败',
  540. duration:2000,
  541. icon:'none'
  542. })
  543. }
  544. })
  545. }else{
  546. wx.hideLoading()
  547. wx.showToast({
  548. title: '添加失败',
  549. duration:2000,
  550. icon:'none'
  551. })
  552. }
  553. })
  554. }
  555. }
  556. },
  557. // 关闭添加人员弹窗
  558. onClose() {
  559. this.setData({
  560. show: false
  561. });
  562. },
  563. // 获取入住人员
  564. getSiteTenant(roomId) {
  565. var data2 = {
  566. q: JSON.stringify({
  567. id: roomId
  568. }),
  569. orderBy: "createTime",
  570. orderType: 'desc'
  571. }
  572. WXAPI.getSiteTenant(data2).then(res1 => {
  573. if (res1.data.list.length > 0) {
  574. let starttime = moment().format('YYYY-MM-DD HH:mm:ss')
  575. let endtime = moment().add(30,'days').format('YYYY-MM-DD HH:mm:ss')
  576. // wx.setStorageSync('minDate',starttime)
  577. // wx.setStorageSync('minDate1',endtime)
  578. this.setData({
  579. personList: res1.data.list,
  580. roomId: roomId,
  581. starttime,
  582. endtime,
  583. // minDate,minDate1
  584. })
  585. } else {
  586. this.setData({
  587. personList: []
  588. })
  589. wx.showToast({
  590. title: "还未下发人员,请先下发人员",
  591. mask:true,
  592. duration: 2000,
  593. icon: 'none'
  594. })
  595. }
  596. })
  597. },
  598. onChange(event) {
  599. this.setData({
  600. searchValue: event.detail
  601. })
  602. },
  603. onClick(e) {
  604. var data2 = {
  605. q: JSON.stringify({
  606. id: this.data.roomId,
  607. name: this.data.searchValue
  608. }),
  609. orderBy: "createTime",
  610. orderType: 'desc'
  611. }
  612. WXAPI.getSiteTenant(data2).then(res1 => {
  613. if (res1.data.list.length > 0) {
  614. let minDate = res1.data.list[0].startTime
  615. let minDate1 = res1.data.list[0].endTime
  616. let starttime = moment(minDate).format('YYYY-MM-DD HH:mm:ss')
  617. let endtime = moment(minDate1).format('YYYY-MM-DD HH:mm:ss')
  618. // wx.setStorageSync('minDate',starttime)
  619. // wx.setStorageSync('minDate1',endtime)
  620. this.setData({
  621. personList: res1.data.list,
  622. starttime,
  623. endtime,
  624. // minDate,minDate1
  625. })
  626. } else {
  627. wx.showToast({
  628. title: "未发现该人员",
  629. mask:true,
  630. duration: 2000,
  631. icon: 'none'
  632. })
  633. }
  634. })
  635. },
  636. //选择已存在人员
  637. personnelCheckin(){
  638. wx.navigateTo({
  639. url: '/pages/selectPersonnel/selectPersonnel',
  640. })
  641. },
  642. // 添加人员
  643. addperson(e) {
  644. var deviceinfo = this.data.deviceinfo
  645. var current = e.currentTarget.dataset.current
  646. this.setData({
  647. current: current
  648. })
  649. if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  650. if (app.globalData.zgBlueStatus) {
  651. this.setData({
  652. show: true
  653. })
  654. } else {
  655. this.goBlue()
  656. }
  657. } else if (deviceinfo.manufactureId == 101) {
  658. if (app.globalData.bleStatus == '蓝牙已连接') {
  659. this.setData({
  660. show: true
  661. })
  662. } else {
  663. this.startconnect()
  664. }
  665. }else if (deviceinfo.manufactureId == 1201) {
  666. this.setData({
  667. show: true
  668. })
  669. }else if (deviceinfo.manufactureId == 1241) {
  670. this.setData({
  671. show: true
  672. })
  673. }
  674. },
  675. addperson1(e) {
  676. wx.showLoading({
  677. title: '加载中...',
  678. })
  679. var deviceinfo = this.data.deviceinfo
  680. var that = this
  681. var cgInfo = wx.getStorageSync('cgInfo')
  682. var current = e.currentTarget.dataset.current
  683. var index = e.currentTarget.dataset.index
  684. var personLi = that.data.personList[index]
  685. wx.setStorageSync('personLi', that.data.personList[index])
  686. this.setData({
  687. current: current,
  688. index: index
  689. })
  690. // wx.navigateTo({
  691. // url: '/pages/addperson/addperson?current=' + current,
  692. // })
  693. // return
  694. if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  695. if (app.globalData.zgBlueStatus) {
  696. if (current == 1) {
  697. wx.hideLoading()
  698. wx.navigateTo({
  699. url: '/pages/addperson/addperson?current=' + current,
  700. })
  701. } else if (current == 2) {
  702. wx.hideLoading()
  703. wx.showModal({
  704. title: '是否删除',
  705. success(res) {
  706. if (res.confirm) {
  707. wx.showLoading({
  708. title: '加载中...',
  709. })
  710. var info = JSON.parse(that.data.personList[that.data.index].info)
  711. var personLi = that.data.personList[that.data.index]
  712. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId,
  713. (callback) => {
  714. if(callback.status=='00'){
  715. var signKey = callback.signKey
  716. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, signKey, (callback1) => {
  717. if(callback1.status=='00'){
  718. var commonKey = callback1.commonKey
  719. ICINLocker.deleteUser(cgInfo.lockerId, cgInfo.superId, info.userId, cgInfo.superId, '', signKey, commonKey, (callback2) => {
  720. if (callback2.status == '00') {
  721. var data = {
  722. lockerId: deviceinfo.deviceNum,
  723. imei: deviceinfo.imei,
  724. lockerUserId: info.userId,
  725. keyId: info.userId,
  726. role: '00',
  727. action: 2,
  728. order: 6203,
  729. type: 3,
  730. result: 1,
  731. cardName:personLi.name,
  732. roomName:deviceinfo.roomName
  733. };
  734. WXAPI.ZGduserOperation(data).then(res => {
  735. if(res.code==200){
  736. var data3 = {
  737. result: 1,
  738. serial: res.data.serialNumber
  739. }
  740. setTimeout(()=>{
  741. WXAPI.updatePush(data3).then(res4 => {
  742. })
  743. },1000)
  744. }else{
  745. var data3 = {
  746. result: 702,
  747. serial: res.data.serialNumber
  748. }
  749. setTimeout(()=>{
  750. WXAPI.updatePush(data3).then(res4 => {
  751. })
  752. },1000)
  753. }
  754. })
  755. var str = [{
  756. cardId: personLi.cardId,
  757. siteId: that.data.deviceinfo.roomId,
  758. }]
  759. WXAPI.unbindCard(str).then(res => {
  760. if (res.success) {
  761. that.getSiteTenant(that.data.roomId)
  762. }
  763. })
  764. wx.hideLoading()
  765. } else {
  766. wx.hideLoading()
  767. wx.showToast({
  768. title: '删除失败',
  769. duration: 2000,
  770. mask:true,
  771. icon: 'none'
  772. })
  773. }
  774. })
  775. }else{
  776. wx.hideLoading()
  777. wx.showToast({
  778. title: '连接失败',
  779. duration: 2000,
  780. mask:true,
  781. icon: 'none'
  782. })
  783. }
  784. })
  785. }else{
  786. wx.hideLoading()
  787. wx.showToast({
  788. title: '连接失败',
  789. duration: 2000,
  790. mask:true,
  791. icon: 'none'
  792. })
  793. }
  794. })
  795. } else if (res.cancel) {
  796. console.log('用户点击取消')
  797. }
  798. }
  799. })
  800. }
  801. } else {
  802. wx.hideLoading()
  803. this.goBlue()
  804. }
  805. } else if (deviceinfo.manufactureId == 101) {
  806. wx.hideLoading()
  807. if (app.globalData.bleStatus == '蓝牙已连接') {
  808. if (current == 1) {
  809. wx.navigateTo({
  810. url: '/pages/addperson/addperson?current=' + current,
  811. })
  812. } else if (current == 2) {
  813. wx.hideLoading()
  814. wx.showModal({
  815. title: '是否删除',
  816. success(res) {
  817. if (res.confirm) {
  818. wx.showLoading({
  819. title: '加载中...',
  820. })
  821. var info = JSON.parse(that.data.personList[that.data.index].info)
  822. var personLi = that.data.personList[that.data.index]
  823. var data1 = {
  824. managerTelephone: "18270949468",
  825. managerPassword: '202108',
  826. userTelephone: info.userTelephone,
  827. userPassword: info.userPassword,
  828. password: info.userPassword,
  829. startTime: "20210813010101",
  830. endTime: "20680813010101"
  831. }
  832. var timestamp= moment().format("x")
  833. bleall.startFp1_63(data1.managerTelephone, data1.managerPassword, data1.userTelephone,
  834. data1.userPassword, data1.password, data1.startTime, data1.endTime, 3,timestamp,
  835. function (res) {
  836. if (res.success) {
  837. var data3 = {
  838. code: "ble/operateUserInfo",
  839. data: {
  840. deviceNum: that.data.deviceinfo.deviceNum,
  841. imei: that.data.deviceinfo.imei,
  842. userTelephone: info.userTelephone,
  843. userPassword: info.userPassword,
  844. password: info.userPassword,
  845. userStartTime: '20210813010101',
  846. userEndTime: '20680813010101',
  847. passwordStartTime: '20210813010101',
  848. passwordEndTime: '20680813010101',
  849. operateMode: 3,
  850. order: 6203,
  851. timestamp:timestamp,
  852. roomName:deviceinfo.roomName,
  853. cardName:'蓝牙'+personLi.name,
  854. managerTelephone: '18270949468',
  855. managerPassword: '202108',
  856. passwordLength: 10,
  857. permission: 4294967295,
  858. times: 255,
  859. recycleTime: "65535",
  860. }
  861. }
  862. WXAPI.sendCommand(data3).then(res => {
  863. console.log(res)
  864. if(res.success){
  865. var data4 = {
  866. result: 1,
  867. serial: res.data.serialNumber
  868. }
  869. setTimeout(()=>{
  870. WXAPI.updatePush(data4).then(res4 => {
  871. })
  872. },1000)
  873. var str = [{
  874. cardId: personLi.cardId,
  875. siteId: that.data.deviceinfo.roomId,
  876. }]
  877. WXAPI.unbindCard(str).then(res => {
  878. if (res.success) {
  879. that.getSiteTenant(that.data.roomId)
  880. }
  881. })
  882. }
  883. })
  884. }
  885. if (res.data == "蓝牙功能暂不支持") {
  886. wx.showLoading({
  887. title: '重连中',
  888. })
  889. that.startconnect()
  890. }
  891. })
  892. }
  893. }
  894. })
  895. }
  896. } else {
  897. this.startconnect()
  898. }
  899. }else if(deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241){
  900. if (current == 1) {
  901. wx.navigateTo({
  902. url: '/pages/addperson/addperson?current=' + current,
  903. })
  904. } else if (current == 2) {
  905. wx.hideLoading()
  906. wx.showModal({
  907. title: '是否删除',
  908. success(res) {
  909. if (res.confirm) {
  910. var str = [{
  911. cardId: personLi.cardId,
  912. siteId: that.data.deviceinfo.roomId,
  913. }]
  914. WXAPI.unbindCard(str).then(res => {
  915. if (res.success) {
  916. that.getSiteTenant(that.data.roomId)
  917. }
  918. })
  919. }
  920. }
  921. })
  922. }else if(current == 3){
  923. wx.navigateTo({
  924. url: '/pagesA/facepeople/facepeople',
  925. })
  926. }
  927. }
  928. },
  929. goBlue() {
  930. var that = this
  931. var cgInfo = wx.getStorageSync('cgInfo')
  932. wx.showLoading({
  933. title: '连接蓝牙中',
  934. })
  935. ICINLocker.scanDevices(this.data.deviceinfo.deviceNum)
  936. .then((res) => {
  937. console.log(res)
  938. if (res.status == 0) {
  939. var deviceId = res.deviceId
  940. //成功找到蓝牙情况下进行锁连接
  941. app.globalData.blueDeviceId = res.deviceId
  942. ICINLocker.connect(res.deviceId) // 此处 deviceId 存起来,当断开连接时使用
  943. .then((res) => {
  944. if (res.status === 0) {
  945. clearInterval(that.data.timer)
  946. this.setData({
  947. bleStatus: '蓝牙已连接',
  948. deviceId: deviceId
  949. })
  950. app.globalData.zgBlueStatus = true
  951. wx.hideLoading()
  952. wx.showToast({
  953. title: '连接成功',
  954. mask:true,
  955. icon: "none",
  956. duration: 2000
  957. })
  958. if (that.data.current === 0) {
  959. this.setData({
  960. show: true
  961. })
  962. } else if (that.data.current == 1) {
  963. wx.navigateTo({
  964. url: '/pages/addperson/addperson?current=' + that.data.current,
  965. })
  966. } else if (that.data.current == 2) {
  967. var info = JSON.parse(that.data.personList[that.data.index].info)
  968. var personLi = that.data.personList[that.data.index]
  969. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId,
  970. (callback) => {
  971. var signKey = callback.signKey
  972. console.log(signKey, 'signKey')
  973. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, signKey, (callback) => {
  974. var commonKey = callback.commonKey
  975. console.log(commonKey, 'commonKey')
  976. ICINLocker.deleteUser(cgInfo.lockerId, cgInfo.superId, info.userId, cgInfo.superId, '', signKey, commonKey, (callback) => {
  977. console.log(callback, "删除人员")
  978. if (callback.status == '00') {
  979. var str = [{
  980. cardId: personLi.cardId,
  981. siteId: that.data.deviceinfo.roomId,
  982. }]
  983. console.log(str, 'str')
  984. WXAPI.unbindCard(str).then(res => {
  985. if (res.success) {
  986. that.getSiteTenant(that.data.roomId)
  987. }
  988. })
  989. } else {
  990. wx.showToast({
  991. title: '删除失败',
  992. mask:true,
  993. duration: 2000,
  994. icon: 'none'
  995. })
  996. }
  997. })
  998. })
  999. })
  1000. }
  1001. } else {
  1002. wx.hideLoading()
  1003. var msg = ''
  1004. switch (res.errCode) {
  1005. case 10001:
  1006. msg = '调用失败,请打开蓝牙!';
  1007. break;
  1008. }
  1009. wx.showToast({
  1010. title: msg,
  1011. duration: 2000,
  1012. mask:true,
  1013. icon: 'none'
  1014. })
  1015. //此处处理返回值不为成功(0)的情况
  1016. }
  1017. }).catch((res) => {
  1018. wx.hideLoading()
  1019. console.log(res, '失败')
  1020. // 此处处理未能连接成功问题
  1021. })
  1022. }
  1023. })
  1024. .catch((res) => {
  1025. //此处处理未能连接到蓝牙的问题
  1026. if (res.status == 1) {
  1027. if (res.statusReason.errCode == 10001) {
  1028. wx.hideLoading()
  1029. wx.showModal({
  1030. title: "提示",
  1031. content: "请检查手机蓝牙和定位功能是否打开?",
  1032. showCancel: false,
  1033. confirmText: "确定",
  1034. success(res) {}
  1035. });
  1036. } else {
  1037. if (!app.globalData.zgBlueStatus) {
  1038. that.goBlue()
  1039. } else {
  1040. wx.hideLoading()
  1041. }
  1042. }
  1043. }
  1044. })
  1045. },
  1046. startconnect() {
  1047. //if(checkWechatVersion())
  1048. // {
  1049. wx.showLoading({
  1050. title: "连接蓝牙中"
  1051. })
  1052. var deviceinfo = this.data.deviceinfo
  1053. const ble = new BLE(this.data.deviceinfo.deviceNum, emitter)
  1054. app.globalData.ble = ble
  1055. this.watchBLE()
  1056. app.globalData.ble.init()
  1057. // }
  1058. },
  1059. watchBLE() {
  1060. var that = this
  1061. if (app.globalData.ble) {
  1062. app.globalData.ble.listen(res => {
  1063. if (res.type == 'connect') {
  1064. if (res.data == "未打开适配器") {
  1065. wx.hideLoading()
  1066. wx.showModal({
  1067. title: "提示",
  1068. content: "请检查手机蓝牙和定位功能是否打开?",
  1069. showCancel: false,
  1070. confirmText: "确定",
  1071. success(res) {}
  1072. });
  1073. } else {
  1074. if (res.data == '蓝牙已连接') {
  1075. app.globalData.bleStatus = res.data
  1076. if (that.data.current == 0) {
  1077. this.setData({
  1078. show: true
  1079. })
  1080. } else if (that.data.current == 1) {
  1081. wx.navigateTo({
  1082. url: '/pages/addperson/addperson?current=' + that.data.current,
  1083. })
  1084. } else if (that.data.current == 2) {
  1085. wx.showModal({
  1086. title: '是否删除',
  1087. success(res) {
  1088. if (res.confirm) {
  1089. wx.showLoading({
  1090. title: '加载中...',
  1091. })
  1092. var info = JSON.parse(that.data.personList[that.data.index].info)
  1093. var personLi = that.data.personList[that.data.index]
  1094. var data1 = {
  1095. managerTelephone: "18270949468",
  1096. managerPassword: '202108',
  1097. userTelephone: info.userTelephone,
  1098. userPassword: info.userPassword,
  1099. password: info.userPassword,
  1100. startTime: "20210813010101",
  1101. endTime: "20680813010101"
  1102. }
  1103. var timestamp= moment().format("x")
  1104. bleall.startFp1_63(data1.managerTelephone, data1.managerPassword, data1.userTelephone,
  1105. data1.userPassword, data1.password, data1.startTime, data1.endTime, 3,timestamp,
  1106. function (res) {
  1107. if (res.success) {
  1108. var data3 = {
  1109. code: "ble/operateUserInfo",
  1110. data: {
  1111. deviceNum: that.data.deviceinfo.deviceNum,
  1112. imei: that.data.deviceinfo.imei,
  1113. userTelephone: info.userTelephone,
  1114. userPassword: info.userPassword,
  1115. password: info.userPassword,
  1116. userStartTime: '20210813010101',
  1117. userEndTime: '20680813010101',
  1118. passwordStartTime: '20210813010101',
  1119. passwordEndTime: '20680813010101',
  1120. operateMode: 3,
  1121. order: 6203,
  1122. timestamp: timestamp,
  1123. managerTelephone: '18270949468',
  1124. managerPassword: '202108',
  1125. passwordLength: 10,
  1126. permission: 4294967295,
  1127. times: 255,
  1128. recycleTime: "65535",
  1129. }
  1130. }
  1131. WXAPI.sendCommand(data3).then(res => {
  1132. })
  1133. var str = [{
  1134. cardId: personLi.cardId,
  1135. siteId: that.data.deviceinfo.roomId,
  1136. }]
  1137. WXAPI.unbindCard(str).then(res => {
  1138. if (res.success) {
  1139. that.getSiteTenant(that.data.roomId)
  1140. }
  1141. })
  1142. }
  1143. if (res.data == "蓝牙功能暂不支持") {
  1144. wx.showLoading({
  1145. title: '重连中',
  1146. })
  1147. that.startconnect()
  1148. }
  1149. })
  1150. }
  1151. }
  1152. })
  1153. }
  1154. }
  1155. }
  1156. }
  1157. })
  1158. }
  1159. },
  1160. //普通用户获取 signk
  1161. getUserSignKey(data, callback) {
  1162. // ICINLocker.getUserSignKey(data.lockId, data.superAdminId, data.usrId, data.keyId, data.authUserSignKeyOrAuthKey, data.accessType, (callback1) => {
  1163. // console.log(callback1)
  1164. // callback(callback1)
  1165. // })
  1166. ICINLocker.getSignKey(data.lockId, data.usrId, data.keyId, (callback1) => {
  1167. console.log(callback1)
  1168. callback(callback1)
  1169. })
  1170. },
  1171. // 协商通讯密钥
  1172. getCommonKey(data, callback) {
  1173. ICINLocker.getCommonKey(data.lockId, data.usrId, data.keyId, data.userSignKey, (callback2) => {
  1174. console.log(callback2)
  1175. callback(callback2)
  1176. })
  1177. },
  1178. // 删除用户
  1179. ZGdeleteUser(data, callback) {
  1180. ICINLocker.deleteUser(data.lockId, data.superAdminId, data.usrId, data.keyId, data.delUserToken, data.signkey, data.commonKey, (callback1) => {
  1181. console.log(callback1)
  1182. callback(callback1)
  1183. });
  1184. },
  1185. /**
  1186. * 生命周期函数--监听页面初次渲染完成
  1187. */
  1188. onReady: function () {
  1189. },
  1190. /**
  1191. * 生命周期函数--监听页面显示
  1192. */
  1193. onShow: function () {
  1194. var deviceinfo = wx.getStorageSync('deviceinfo')
  1195. // this.getSiteTenant(deviceinfo.roomId)
  1196. },
  1197. /**
  1198. * 生命周期函数--监听页面隐藏
  1199. */
  1200. onHide: function () {
  1201. },
  1202. /**
  1203. * 生命周期函数--监听页面卸载
  1204. */
  1205. onUnload: function () {
  1206. },
  1207. /**
  1208. * 页面相关事件处理函数--监听用户下拉动作
  1209. */
  1210. onPullDownRefresh: function () {
  1211. },
  1212. /**
  1213. * 页面上拉触底事件的处理函数
  1214. */
  1215. onReachBottom: function () {
  1216. },
  1217. /**
  1218. * 用户点击右上角分享
  1219. */
  1220. onShareAppMessage: function () {
  1221. }
  1222. })