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.

1231 lines
42 KiB

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