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.

1230 lines
42 KiB

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. 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 starttime = moment().format('YYYY-MM-DD HH:mm:ss')
  562. let endtime = moment().add(30,'days').format('YYYY-MM-DD HH:mm:ss')
  563. // wx.setStorageSync('minDate',starttime)
  564. // wx.setStorageSync('minDate1',endtime)
  565. this.setData({
  566. personList: res1.data.list,
  567. roomId: roomId,
  568. starttime,
  569. endtime,
  570. // minDate,minDate1
  571. })
  572. } else {
  573. this.setData({
  574. personList: []
  575. })
  576. wx.showToast({
  577. title: "还未下发人员,请先下发人员",
  578. mask:true,
  579. duration: 2000,
  580. icon: 'none'
  581. })
  582. }
  583. })
  584. },
  585. onChange(event) {
  586. this.setData({
  587. searchValue: event.detail
  588. })
  589. },
  590. onClick(e) {
  591. var data2 = {
  592. q: JSON.stringify({
  593. id: this.data.roomId,
  594. name: this.data.searchValue
  595. }),
  596. orderBy: "createTime",
  597. orderType: 'desc'
  598. }
  599. WXAPI.getSiteTenant(data2).then(res1 => {
  600. if (res1.data.list.length > 0) {
  601. let minDate = res1.data.list[0].startTime
  602. let minDate1 = res1.data.list[0].endTime
  603. let starttime = moment(minDate).format('YYYY-MM-DD HH:mm:ss')
  604. let endtime = moment(minDate1).format('YYYY-MM-DD HH:mm:ss')
  605. wx.setStorageSync('minDate',starttime)
  606. wx.setStorageSync('minDate1',endtime)
  607. this.setData({
  608. personList: res1.data.list,
  609. starttime,
  610. endtime,
  611. minDate,minDate1
  612. })
  613. } else {
  614. wx.showToast({
  615. title: "未发现该人员",
  616. mask:true,
  617. duration: 2000,
  618. icon: 'none'
  619. })
  620. }
  621. })
  622. },
  623. //选择已存在人员
  624. personnelCheckin(){
  625. wx.navigateTo({
  626. url: '/pages/selectPersonnel/selectPersonnel',
  627. })
  628. },
  629. // 添加人员
  630. addperson(e) {
  631. var deviceinfo = this.data.deviceinfo
  632. var current = e.currentTarget.dataset.current
  633. this.setData({
  634. current: current
  635. })
  636. if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 221) {
  637. if (app.globalData.zgBlueStatus) {
  638. this.setData({
  639. show: true
  640. })
  641. } else {
  642. this.goBlue()
  643. }
  644. } else if (deviceinfo.manufactureId == 101) {
  645. if (app.globalData.bleStatus == '蓝牙已连接') {
  646. this.setData({
  647. show: true
  648. })
  649. } else {
  650. this.startconnect()
  651. }
  652. }else if (deviceinfo.manufactureId == 1201) {
  653. this.setData({
  654. show: true
  655. })
  656. }else if (deviceinfo.manufactureId == 1241) {
  657. this.setData({
  658. show: true
  659. })
  660. }
  661. },
  662. addperson1(e) {
  663. wx.showLoading({
  664. title: '加载中...',
  665. })
  666. var deviceinfo = this.data.deviceinfo
  667. var that = this
  668. var cgInfo = wx.getStorageSync('cgInfo')
  669. var current = e.currentTarget.dataset.current
  670. var index = e.currentTarget.dataset.index
  671. var personLi = that.data.personList[index]
  672. wx.setStorageSync('personLi', that.data.personList[index])
  673. this.setData({
  674. current: current,
  675. index: index
  676. })
  677. // wx.navigateTo({
  678. // url: '/pages/addperson/addperson?current=' + current,
  679. // })
  680. // return
  681. if (deviceinfo.manufactureId == 201||deviceinfo.manufactureId == 201) {
  682. if (app.globalData.zgBlueStatus) {
  683. if (current == 1) {
  684. wx.hideLoading()
  685. wx.navigateTo({
  686. url: '/pages/addperson/addperson?current=' + current,
  687. })
  688. } else if (current == 2) {
  689. wx.hideLoading()
  690. wx.showModal({
  691. title: '是否删除',
  692. success(res) {
  693. if (res.confirm) {
  694. wx.showLoading({
  695. title: '加载中...',
  696. })
  697. var info = JSON.parse(that.data.personList[that.data.index].info)
  698. var personLi = that.data.personList[that.data.index]
  699. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId,
  700. (callback) => {
  701. if(callback.status=='00'){
  702. var signKey = callback.signKey
  703. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, signKey, (callback1) => {
  704. if(callback1.status=='00'){
  705. var commonKey = callback1.commonKey
  706. ICINLocker.deleteUser(cgInfo.lockerId, cgInfo.superId, info.userId, cgInfo.superId, '', signKey, commonKey, (callback2) => {
  707. if (callback2.status == '00') {
  708. var data = {
  709. lockerId: deviceinfo.deviceNum,
  710. imei: deviceinfo.imei,
  711. lockerUserId: info.userId,
  712. keyId: info.userId,
  713. role: '00',
  714. action: 2,
  715. order: 6203,
  716. type: 3,
  717. result: 1,
  718. cardName:personLi.name,
  719. roomName:deviceinfo.roomName
  720. };
  721. WXAPI.ZGduserOperation(data).then(res => {
  722. if(res.code==200){
  723. var data3 = {
  724. result: 1,
  725. serial: res.data.serialNumber
  726. }
  727. setTimeout(()=>{
  728. WXAPI.updatePush(data3).then(res4 => {
  729. })
  730. },1000)
  731. }else{
  732. var data3 = {
  733. result: 702,
  734. serial: res.data.serialNumber
  735. }
  736. setTimeout(()=>{
  737. WXAPI.updatePush(data3).then(res4 => {
  738. })
  739. },1000)
  740. }
  741. })
  742. var str = [{
  743. cardId: personLi.cardId,
  744. siteId: that.data.deviceinfo.roomId,
  745. }]
  746. WXAPI.unbindCard(str).then(res => {
  747. if (res.success) {
  748. that.getSiteTenant(that.data.roomId)
  749. }
  750. })
  751. wx.hideLoading()
  752. } else {
  753. wx.hideLoading()
  754. wx.showToast({
  755. title: '删除失败',
  756. duration: 2000,
  757. mask:true,
  758. icon: 'none'
  759. })
  760. }
  761. })
  762. }else{
  763. wx.hideLoading()
  764. wx.showToast({
  765. title: '连接失败',
  766. duration: 2000,
  767. mask:true,
  768. icon: 'none'
  769. })
  770. }
  771. })
  772. }else{
  773. wx.hideLoading()
  774. wx.showToast({
  775. title: '连接失败',
  776. duration: 2000,
  777. mask:true,
  778. icon: 'none'
  779. })
  780. }
  781. })
  782. } else if (res.cancel) {
  783. console.log('用户点击取消')
  784. }
  785. }
  786. })
  787. }
  788. } else {
  789. wx.hideLoading()
  790. this.goBlue()
  791. }
  792. } else if (deviceinfo.manufactureId == 101) {
  793. wx.hideLoading()
  794. if (app.globalData.bleStatus == '蓝牙已连接') {
  795. if (current == 1) {
  796. wx.navigateTo({
  797. url: '/pages/addperson/addperson?current=' + current,
  798. })
  799. } else if (current == 2) {
  800. wx.hideLoading()
  801. wx.showModal({
  802. title: '是否删除',
  803. success(res) {
  804. if (res.confirm) {
  805. wx.showLoading({
  806. title: '加载中...',
  807. })
  808. var info = JSON.parse(that.data.personList[that.data.index].info)
  809. var personLi = that.data.personList[that.data.index]
  810. var data1 = {
  811. managerTelephone: "18270949468",
  812. managerPassword: '202108',
  813. userTelephone: info.userTelephone,
  814. userPassword: info.userPassword,
  815. password: info.userPassword,
  816. startTime: "20210813010101",
  817. endTime: "20680813010101"
  818. }
  819. var timestamp= moment().format("x")
  820. bleall.startFp1_63(data1.managerTelephone, data1.managerPassword, data1.userTelephone,
  821. data1.userPassword, data1.password, data1.startTime, data1.endTime, 3,timestamp,
  822. function (res) {
  823. if (res.success) {
  824. var data3 = {
  825. code: "ble/operateUserInfo",
  826. data: {
  827. deviceNum: that.data.deviceinfo.deviceNum,
  828. imei: that.data.deviceinfo.imei,
  829. userTelephone: info.userTelephone,
  830. userPassword: info.userPassword,
  831. password: info.userPassword,
  832. userStartTime: '20210813010101',
  833. userEndTime: '20680813010101',
  834. passwordStartTime: '20210813010101',
  835. passwordEndTime: '20680813010101',
  836. operateMode: 3,
  837. order: 6203,
  838. timestamp:timestamp,
  839. roomName:deviceinfo.roomName,
  840. cardName:'蓝牙'+personLi.name,
  841. managerTelephone: '18270949468',
  842. managerPassword: '202108',
  843. passwordLength: 10,
  844. permission: 4294967295,
  845. times: 255,
  846. recycleTime: "65535",
  847. }
  848. }
  849. WXAPI.sendCommand(data3).then(res => {
  850. console.log(res)
  851. if(res.success){
  852. var data4 = {
  853. result: 1,
  854. serial: res.data.serialNumber
  855. }
  856. setTimeout(()=>{
  857. WXAPI.updatePush(data4).then(res4 => {
  858. })
  859. },1000)
  860. var str = [{
  861. cardId: personLi.cardId,
  862. siteId: that.data.deviceinfo.roomId,
  863. }]
  864. WXAPI.unbindCard(str).then(res => {
  865. if (res.success) {
  866. that.getSiteTenant(that.data.roomId)
  867. }
  868. })
  869. }
  870. })
  871. }
  872. if (res.data == "蓝牙功能暂不支持") {
  873. wx.showLoading({
  874. title: '重连中',
  875. })
  876. that.startconnect()
  877. }
  878. })
  879. }
  880. }
  881. })
  882. }
  883. } else {
  884. this.startconnect()
  885. }
  886. }else if(deviceinfo.manufactureId == 1201 || deviceinfo.manufactureId == 1241){
  887. if (current == 1) {
  888. wx.navigateTo({
  889. url: '/pages/addperson/addperson?current=' + current,
  890. })
  891. } else if (current == 2) {
  892. wx.hideLoading()
  893. wx.showModal({
  894. title: '是否删除',
  895. success(res) {
  896. if (res.confirm) {
  897. var str = [{
  898. cardId: personLi.cardId,
  899. siteId: that.data.deviceinfo.roomId,
  900. }]
  901. WXAPI.unbindCard(str).then(res => {
  902. if (res.success) {
  903. that.getSiteTenant(that.data.roomId)
  904. }
  905. })
  906. }
  907. }
  908. })
  909. }
  910. }
  911. },
  912. goBlue() {
  913. var that = this
  914. var cgInfo = wx.getStorageSync('cgInfo')
  915. wx.showLoading({
  916. title: '连接蓝牙中',
  917. })
  918. ICINLocker.scanDevices(this.data.deviceinfo.deviceNum)
  919. .then((res) => {
  920. console.log(res)
  921. if (res.status == 0) {
  922. var deviceId = res.deviceId
  923. //成功找到蓝牙情况下进行锁连接
  924. app.globalData.blueDeviceId = res.deviceId
  925. ICINLocker.connect(res.deviceId) // 此处 deviceId 存起来,当断开连接时使用
  926. .then((res) => {
  927. if (res.status === 0) {
  928. clearInterval(that.data.timer)
  929. this.setData({
  930. bleStatus: '蓝牙已连接',
  931. deviceId: deviceId
  932. })
  933. app.globalData.zgBlueStatus = true
  934. wx.hideLoading()
  935. wx.showToast({
  936. title: '连接成功',
  937. mask:true,
  938. icon: "none",
  939. duration: 2000
  940. })
  941. if (that.data.current === 0) {
  942. this.setData({
  943. show: true
  944. })
  945. } else if (that.data.current == 1) {
  946. wx.navigateTo({
  947. url: '/pages/addperson/addperson?current=' + that.data.current,
  948. })
  949. } else if (that.data.current == 2) {
  950. var info = JSON.parse(that.data.personList[that.data.index].info)
  951. var personLi = that.data.personList[that.data.index]
  952. ICINLocker.getSignKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId,
  953. (callback) => {
  954. var signKey = callback.signKey
  955. console.log(signKey, 'signKey')
  956. ICINLocker.getCommonKey(cgInfo.lockerId, cgInfo.superId, cgInfo.superId, signKey, (callback) => {
  957. var commonKey = callback.commonKey
  958. console.log(commonKey, 'commonKey')
  959. ICINLocker.deleteUser(cgInfo.lockerId, cgInfo.superId, info.userId, cgInfo.superId, '', signKey, commonKey, (callback) => {
  960. console.log(callback, "删除人员")
  961. if (callback.status == '00') {
  962. var str = [{
  963. cardId: personLi.cardId,
  964. siteId: that.data.deviceinfo.roomId,
  965. }]
  966. console.log(str, 'str')
  967. WXAPI.unbindCard(str).then(res => {
  968. if (res.success) {
  969. that.getSiteTenant(that.data.roomId)
  970. }
  971. })
  972. } else {
  973. wx.showToast({
  974. title: '删除失败',
  975. mask:true,
  976. duration: 2000,
  977. icon: 'none'
  978. })
  979. }
  980. })
  981. })
  982. })
  983. }
  984. } else {
  985. wx.hideLoading()
  986. var msg = ''
  987. switch (res.errCode) {
  988. case 10001:
  989. msg = '调用失败,请打开蓝牙!';
  990. break;
  991. }
  992. wx.showToast({
  993. title: msg,
  994. duration: 2000,
  995. mask:true,
  996. icon: 'none'
  997. })
  998. //此处处理返回值不为成功(0)的情况
  999. }
  1000. }).catch((res) => {
  1001. wx.hideLoading()
  1002. console.log(res, '失败')
  1003. // 此处处理未能连接成功问题
  1004. })
  1005. }
  1006. })
  1007. .catch((res) => {
  1008. //此处处理未能连接到蓝牙的问题
  1009. if (res.status == 1) {
  1010. if (res.statusReason.errCode == 10001) {
  1011. wx.hideLoading()
  1012. wx.showModal({
  1013. title: "提示",
  1014. content: "请检查手机蓝牙和定位功能是否打开?",
  1015. showCancel: false,
  1016. confirmText: "确定",
  1017. success(res) {}
  1018. });
  1019. } else {
  1020. if (!app.globalData.zgBlueStatus) {
  1021. that.goBlue()
  1022. } else {
  1023. wx.hideLoading()
  1024. }
  1025. }
  1026. }
  1027. })
  1028. },
  1029. startconnect() {
  1030. //if(checkWechatVersion())
  1031. // {
  1032. wx.showLoading({
  1033. title: "连接蓝牙中"
  1034. })
  1035. var deviceinfo = this.data.deviceinfo
  1036. const ble = new BLE(this.data.deviceinfo.deviceNum, emitter)
  1037. app.globalData.ble = ble
  1038. this.watchBLE()
  1039. app.globalData.ble.init()
  1040. // }
  1041. },
  1042. watchBLE() {
  1043. var that = this
  1044. if (app.globalData.ble) {
  1045. app.globalData.ble.listen(res => {
  1046. if (res.type == 'connect') {
  1047. if (res.data == "未打开适配器") {
  1048. wx.hideLoading()
  1049. wx.showModal({
  1050. title: "提示",
  1051. content: "请检查手机蓝牙和定位功能是否打开?",
  1052. showCancel: false,
  1053. confirmText: "确定",
  1054. success(res) {}
  1055. });
  1056. } else {
  1057. if (res.data == '蓝牙已连接') {
  1058. app.globalData.bleStatus = res.data
  1059. if (that.data.current == 0) {
  1060. this.setData({
  1061. show: true
  1062. })
  1063. } else if (that.data.current == 1) {
  1064. wx.navigateTo({
  1065. url: '/pages/addperson/addperson?current=' + that.data.current,
  1066. })
  1067. } else if (that.data.current == 2) {
  1068. wx.showModal({
  1069. title: '是否删除',
  1070. success(res) {
  1071. if (res.confirm) {
  1072. wx.showLoading({
  1073. title: '加载中...',
  1074. })
  1075. var info = JSON.parse(that.data.personList[that.data.index].info)
  1076. var personLi = that.data.personList[that.data.index]
  1077. var data1 = {
  1078. managerTelephone: "18270949468",
  1079. managerPassword: '202108',
  1080. userTelephone: info.userTelephone,
  1081. userPassword: info.userPassword,
  1082. password: info.userPassword,
  1083. startTime: "20210813010101",
  1084. endTime: "20680813010101"
  1085. }
  1086. var timestamp= moment().format("x")
  1087. bleall.startFp1_63(data1.managerTelephone, data1.managerPassword, data1.userTelephone,
  1088. data1.userPassword, data1.password, data1.startTime, data1.endTime, 3,timestamp,
  1089. function (res) {
  1090. if (res.success) {
  1091. var data3 = {
  1092. code: "ble/operateUserInfo",
  1093. data: {
  1094. deviceNum: that.data.deviceinfo.deviceNum,
  1095. imei: that.data.deviceinfo.imei,
  1096. userTelephone: info.userTelephone,
  1097. userPassword: info.userPassword,
  1098. password: info.userPassword,
  1099. userStartTime: '20210813010101',
  1100. userEndTime: '20680813010101',
  1101. passwordStartTime: '20210813010101',
  1102. passwordEndTime: '20680813010101',
  1103. operateMode: 3,
  1104. order: 6203,
  1105. timestamp: timestamp,
  1106. managerTelephone: '18270949468',
  1107. managerPassword: '202108',
  1108. passwordLength: 10,
  1109. permission: 4294967295,
  1110. times: 255,
  1111. recycleTime: "65535",
  1112. }
  1113. }
  1114. WXAPI.sendCommand(data3).then(res => {
  1115. })
  1116. var str = [{
  1117. cardId: personLi.cardId,
  1118. siteId: that.data.deviceinfo.roomId,
  1119. }]
  1120. WXAPI.unbindCard(str).then(res => {
  1121. if (res.success) {
  1122. that.getSiteTenant(that.data.roomId)
  1123. }
  1124. })
  1125. }
  1126. if (res.data == "蓝牙功能暂不支持") {
  1127. wx.showLoading({
  1128. title: '重连中',
  1129. })
  1130. that.startconnect()
  1131. }
  1132. })
  1133. }
  1134. }
  1135. })
  1136. }
  1137. }
  1138. }
  1139. }
  1140. })
  1141. }
  1142. },
  1143. //普通用户获取 signk
  1144. getUserSignKey(data, callback) {
  1145. // ICINLocker.getUserSignKey(data.lockId, data.superAdminId, data.usrId, data.keyId, data.authUserSignKeyOrAuthKey, data.accessType, (callback1) => {
  1146. // console.log(callback1)
  1147. // callback(callback1)
  1148. // })
  1149. ICINLocker.getSignKey(data.lockId, data.usrId, data.keyId, (callback1) => {
  1150. console.log(callback1)
  1151. callback(callback1)
  1152. })
  1153. },
  1154. // 协商通讯密钥
  1155. getCommonKey(data, callback) {
  1156. ICINLocker.getCommonKey(data.lockId, data.usrId, data.keyId, data.userSignKey, (callback2) => {
  1157. console.log(callback2)
  1158. callback(callback2)
  1159. })
  1160. },
  1161. // 删除用户
  1162. ZGdeleteUser(data, callback) {
  1163. ICINLocker.deleteUser(data.lockId, data.superAdminId, data.usrId, data.keyId, data.delUserToken, data.signkey, data.commonKey, (callback1) => {
  1164. console.log(callback1)
  1165. callback(callback1)
  1166. });
  1167. },
  1168. /**
  1169. * 生命周期函数--监听页面初次渲染完成
  1170. */
  1171. onReady: function () {
  1172. },
  1173. /**
  1174. * 生命周期函数--监听页面显示
  1175. */
  1176. onShow: function () {
  1177. var deviceinfo = wx.getStorageSync('deviceinfo')
  1178. // this.getSiteTenant(deviceinfo.roomId)
  1179. },
  1180. /**
  1181. * 生命周期函数--监听页面隐藏
  1182. */
  1183. onHide: function () {
  1184. },
  1185. /**
  1186. * 生命周期函数--监听页面卸载
  1187. */
  1188. onUnload: function () {
  1189. },
  1190. /**
  1191. * 页面相关事件处理函数--监听用户下拉动作
  1192. */
  1193. onPullDownRefresh: function () {
  1194. },
  1195. /**
  1196. * 页面上拉触底事件的处理函数
  1197. */
  1198. onReachBottom: function () {
  1199. },
  1200. /**
  1201. * 用户点击右上角分享
  1202. */
  1203. onShareAppMessage: function () {
  1204. }
  1205. })