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.

479 lines
12 KiB

1 year ago
1 year ago
  1. // pages/openLockLog/openLockLog.js
  2. const app = getApp()
  3. const WXAPI = require('../../utils/request')
  4. var util = require('../../utils/util');
  5. import moment from "../../utils/moment"
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. locklogList: [],
  12. locklogListOne:[],
  13. locklogListTwo:[],
  14. pageNum: 1,
  15. pageNumOne:1,
  16. pageNumTwo:1,
  17. pageSize: 10,
  18. roomId: '',
  19. cardId:'',
  20. stoppull: false,
  21. active:0,
  22. openType:0,
  23. bottomroolTwo:true,
  24. bottomroolOne:true
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. if (options.roomId && !options.cardId) {
  31. this.data.roomId = options.roomId
  32. this.getopenlocklog(options.roomId)
  33. }else{
  34. this.data.roomId = options.roomId
  35. this.data.cardId = options.cardId
  36. this.minGetopenlocklog()
  37. }
  38. },
  39. onChange(event){
  40. this.setData({
  41. active:event.detail.name
  42. })
  43. if(this.data.cardId){
  44. this.minGetopenlocklog()
  45. }else{
  46. if(event.detail.name==0){
  47. this.getopenlocklog(this.data.roomId)
  48. }else if(event.detail.name==1){
  49. this.getopenlocklogOne(this.data.roomId)
  50. }else if(event.detail.name==2){
  51. this.getopenlocklogTwo(this.data.roomId)
  52. }
  53. }
  54. },
  55. timestampToTime(cjsj) {
  56. if (cjsj.toString().length == 10) {
  57. cjsj = cjsj * 1000
  58. }
  59. var date = new Date(cjsj); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  60. var Y = date.getFullYear() + "-";
  61. var M =
  62. (date.getMonth() + 1 < 10 ?
  63. "0" + (date.getMonth() + 1) :
  64. date.getMonth() + 1) + "-";
  65. var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
  66. var h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
  67. var m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":";
  68. var s = (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds());
  69. return Y + M + D + h + m + s;
  70. },
  71. getopenlocklogTwo(roomId){
  72. let operUrl="",q={}
  73. var carname=wx.getStorageSync('username')
  74. var deviceinfo=wx.getStorageSync('deviceinfo')
  75. operUrl="/v1/device/isp/openLock"
  76. q= util.searchParaProcess({
  77. operUrl:operUrl,
  78. roomIds:[this.data.roomId],
  79. request:[carname],
  80. })
  81. var dataq = {
  82. pageNum: this.data.pageNumTwo,
  83. pageSize: 30,
  84. orderType: "desc",
  85. orderBy:"createAt",
  86. q: q
  87. };
  88. WXAPI.getOperateList(dataq).then(res=>{
  89. if(res.success){
  90. var data = [];
  91. if(res.data.total<30){
  92. this.setData({
  93. bottomroolTwo:false
  94. })
  95. }
  96. res.data.list.map((li, index) => {
  97. var operRequ=JSON.parse(li.operRequ).param[0]
  98. let path="",compli=""
  99. if(operRequ.hasOwnProperty("data")){
  100. path=deviceinfo.roomName
  101. li.roomName = path?path:operRequ.data.roomName?operRequ.data.roomName:'';
  102. li.roomId = operRequ.data.roomId;
  103. li.name=operRequ.data.cardName
  104. li.deviceNum=operRequ.data.lockerId?operRequ.data.lockerId:operRequ.data.deviceNum;
  105. }else{
  106. li.roomName = operRequ.roomName
  107. li.name=operRequ.cardName
  108. li.deviceNum=operRequ.deviceNum || operRequ.imei
  109. }
  110. li.openType="远程开锁"
  111. li.openTime = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss");
  112. });
  113. var locklogListTwo=this.data.locklogListTwo.concat(res.data.list)
  114. this.setData({
  115. locklogListTwo:locklogListTwo
  116. })
  117. }
  118. })
  119. },
  120. getopenlocklogOne(roomId){
  121. let operUrl="",q={}
  122. var carname=wx.getStorageSync('username')
  123. operUrl="/v1/device/send/bleCommand"
  124. q= util.searchParaProcess({
  125. operRequ: "bleUnlockRecord",
  126. // operUrl:operUrl,
  127. roomIds:[this.data.roomId],
  128. request:[carname],
  129. })
  130. var dataq = {
  131. pageNum: this.data.pageNumOne,
  132. pageSize: 30,
  133. orderType: "desc",
  134. orderBy:"createAt",
  135. q: q
  136. };
  137. WXAPI.getOperateList(dataq).then(res=>{
  138. if(res.success){
  139. if(res.data.total<30){
  140. this.setData({
  141. bottomroolOne:false
  142. })
  143. }
  144. var data = [];
  145. res.data.list.map((li, index) => {
  146. var operRequ=JSON.parse(li.operRequ).param[0]
  147. let path="",compli=""
  148. if(operRequ.hasOwnProperty("data")){
  149. path=wx.getStorageSync('deviceinfo').roomName
  150. li.roomName = path?path:operRequ.data.roomName?operRequ.data.roomName:'';
  151. li.roomId = operRequ.data.roomId;
  152. li.name=operRequ.data.cardName
  153. li.deviceNum=operRequ.data.lockerId?operRequ.data.lockerId:operRequ.data.deviceNum;
  154. }else{
  155. li.roomName = operRequ.roomName
  156. li.name=operRequ.cardName
  157. li.deviceNum=operRequ.deviceNum || operRequ.imei
  158. }
  159. li.openType="蓝牙开锁"
  160. li.openTime = moment(li.createAt).format("YYYY-MM-DD HH:mm:ss");
  161. });
  162. var locklogListOne=this.data.locklogListOne.concat(res.data.list)
  163. this.setData({
  164. locklogListOne:locklogListOne
  165. })
  166. }
  167. })
  168. },
  169. // 租客获取开锁记录
  170. minGetopenlocklog(){
  171. var q = {
  172. // roomId: this.data.roomId,
  173. cardId:this.data.cardId
  174. }
  175. var data1 = {
  176. param:{
  177. pageNum: this.data.pageNum,
  178. pageSize: this.data.pageSize,
  179. orderBy:"open_time desc",
  180. q: JSON.stringify(q)
  181. },
  182. signature:wx.getStorageSync('signature')
  183. }
  184. let deviceinfo = wx.getStorageSync('deviceinfo')
  185. let data2={
  186. param:{
  187. pageNum: 1,
  188. pageSize:10,
  189. orderType: "desc",
  190. orderBy:"createAt",
  191. q: JSON.stringify({
  192. operateName:deviceinfo.name,
  193. roomId:deviceinfo.roomId
  194. })
  195. },
  196. signature:wx.getStorageSync('signature')
  197. }
  198. WXAPI.getBleUnlockRecord(data2).then(res2=>{
  199. if(res2.success){
  200. this.setData({
  201. locklogListOne:res2.data.list
  202. })
  203. }
  204. })
  205. WXAPI.minGetOpenLocks(data1).then(res=>{
  206. if (res.success) {
  207. if (res.data.list.length<10) {
  208. this.data.stoppull = true
  209. this.data.pageNum = 1
  210. wx.showToast({
  211. title: '暂无更多数据!',
  212. duration:2000,
  213. icon:'none'
  214. })
  215. }
  216. res.data.list.map((li, index) => {
  217. var str = ""
  218. switch (li.openType) {
  219. case 1:
  220. str = "指纹开锁";
  221. break;
  222. case 2:
  223. str = "数字键盘开锁";
  224. break;
  225. case 3:
  226. str = "NFC开锁";
  227. break;
  228. case 4:
  229. str = "机械钥匙开锁";
  230. break;
  231. case 5:
  232. str = "蓝牙开锁";
  233. break;
  234. case 6:
  235. str = "NB开锁";
  236. break;
  237. case 7:
  238. str = "身份证";
  239. break;
  240. case 8:
  241. str = "单机密码开锁";
  242. break;
  243. case 9:
  244. str = "人脸开锁";
  245. break;
  246. default:
  247. break;
  248. }
  249. li.openTime = this.timestampToTime(li.openTime)
  250. li.openType = str
  251. })
  252. var locklogList=this.data.locklogList.concat(res.data.list)
  253. console.log(locklogList)
  254. this.setData({
  255. locklogList:locklogList
  256. })
  257. }
  258. })
  259. },
  260. getopenlocklog(roomId) {
  261. var q = {
  262. roomId: roomId
  263. }
  264. var data1 = {
  265. pageNum: this.data.pageNum,
  266. pageSize: this.data.pageSize,
  267. orderBy:"open_time desc",
  268. q: JSON.stringify(q)
  269. }
  270. WXAPI.getOpenRecord(data1).then(res=>{
  271. console.log(res);
  272. if (res.success) {
  273. if (res.data.length<10) {
  274. this.data.stoppull = true
  275. }
  276. res.data.list.map((li, index) => {
  277. var str = ""
  278. switch (li.openType) {
  279. case 1:
  280. str = "指纹开锁";
  281. break;
  282. case 2:
  283. str = "数字键盘开锁";
  284. break;
  285. case 3:
  286. str = "NFC开锁";
  287. break;
  288. case 4:
  289. str = "机械钥匙开锁";
  290. break;
  291. case 5:
  292. str = "蓝牙开锁";
  293. break;
  294. case 6:
  295. str = "NB开锁";
  296. break;
  297. case 7:
  298. str = "身份证";
  299. break;
  300. case 8:
  301. str = "单机密码开锁";
  302. break;
  303. case 9:
  304. str = "人脸开锁";
  305. break;
  306. default:
  307. break;
  308. }
  309. li.openTime = this.timestampToTime(li.openTime)
  310. li.openType = str
  311. })
  312. var locklogList=this.data.locklogList.concat(res.data.list)
  313. console.log(locklogList)
  314. this.setData({
  315. locklogList:locklogList
  316. })
  317. }
  318. })
  319. },
  320. getopenlocklog1() {
  321. var data1 = {
  322. pageNum: this.data.pageNum,
  323. pageSize: this.data.pageSize,
  324. orderBy: "open_time desc",
  325. q: JSON.stringify({
  326. roomId: this.data.roomId
  327. }),
  328. };
  329. WXAPI.getOpenRecord(data1).then(res=>{
  330. if (res.success) {
  331. if (res.data.list.length<10) {
  332. this.data.stoppull = true
  333. }
  334. res.data.list.map((li, index) => {
  335. var str = ""
  336. switch (li.openType) {
  337. case 1:
  338. str = "指纹开锁";
  339. break;
  340. case 2:
  341. str = "数字键盘开锁";
  342. break;
  343. case 3:
  344. str = "NFC开锁";
  345. break;
  346. case 4:
  347. str = "机械钥匙开锁";
  348. break;
  349. case 5:
  350. str = "蓝牙开锁";
  351. break;
  352. case 6:
  353. str = "NB开锁";
  354. break;
  355. case 7:
  356. str = "身份证";
  357. break;
  358. case 8:
  359. str = "单机密码开锁";
  360. break;
  361. case 9:
  362. str = "人脸开锁";
  363. break;
  364. default:
  365. break;
  366. }
  367. li.openTime = this.timestampToTime(li.openTime)
  368. li.openType = str
  369. })
  370. var array = []
  371. var locklogList = array.concat(this.data.locklogList, res.data.list)
  372. this.setData({
  373. locklogList
  374. })
  375. }
  376. })
  377. },
  378. /**
  379. * 生命周期函数--监听页面初次渲染完成
  380. */
  381. onReady: function () {
  382. },
  383. /**
  384. * 生命周期函数--监听页面显示
  385. */
  386. onShow: function () {
  387. },
  388. /**
  389. * 生命周期函数--监听页面隐藏
  390. */
  391. onHide: function () {
  392. },
  393. /**
  394. * 生命周期函数--监听页面卸载
  395. */
  396. onUnload: function () {
  397. },
  398. /**
  399. * 页面相关事件处理函数--监听用户下拉动作
  400. */
  401. onPullDownRefresh: function () {
  402. },
  403. /**
  404. * 页面上拉触底事件的处理函数
  405. */
  406. onReachBottom: function () {
  407. if(this.data.cardId){
  408. // this.getopenlocklogOne()
  409. let pageNum = this.data.pageNum+1
  410. this.setData({
  411. pageNum
  412. })
  413. this.minGetopenlocklog()
  414. }else{
  415. if(this.data.active==0){
  416. if (!this.data.stoppull) {
  417. this.data.pageNum = this.data.pageNum + 1
  418. this.getopenlocklog1()
  419. setTimeout(() => {
  420. wx.stopPullDownRefresh()
  421. })
  422. } else {
  423. wx.showToast({
  424. title: "暂无更多数据!",
  425. icon: "none",
  426. duration: 2000
  427. })
  428. }
  429. }else if(this.data.active==1){
  430. if (!this.data.bottomroolOne) {
  431. this.data.pageNumOne = this.data.pageNumOne + 1
  432. this.getopenlocklogOne(this.data.roomId)
  433. setTimeout(() => {
  434. wx.stopPullDownRefresh()
  435. })
  436. } else {
  437. wx.showToast({
  438. title: "暂无更多数据!",
  439. icon: "none",
  440. duration: 2000
  441. })
  442. }
  443. }else if(this.data.active==2){
  444. if (!this.data.bottomroolTwo) {
  445. this.data.pageNumTwo = this.data.pageNumTwo + 1
  446. this.getopenlocklogTwo(this.data.roomId)
  447. setTimeout(() => {
  448. wx.stopPullDownRefresh()
  449. })
  450. } else {
  451. wx.showToast({
  452. title: "暂无更多数据!",
  453. icon: "none",
  454. duration: 2000
  455. })
  456. }
  457. }
  458. }
  459. },
  460. /**
  461. * 用户点击右上角分享
  462. */
  463. onShareAppMessage: function () {
  464. }
  465. })