index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import {
  2. getDate,
  3. getWaterDrop,
  4. } from '../../../utils/index/index'
  5. import {
  6. visitorReportPageList,
  7. visitorSignOut
  8. } from '../../../utils/api/api'
  9. const app = getApp()
  10. Page({
  11. data: {
  12. formPath: null, //从哪个页面来
  13. tableList: [],
  14. searchForm: {
  15. data: {
  16. name: '',
  17. phone: '',
  18. idNumber: '',
  19. startTime: '',
  20. endTime: '',
  21. sn: '',
  22. },
  23. pageNum: 1,
  24. pageSize: 9,
  25. },
  26. total: null,
  27. allPageNum: 0,
  28. notDesensitizedColumn: [],
  29. signOutList: [{
  30. id: true,
  31. name: '已签离'
  32. },
  33. {
  34. id: false,
  35. name: '未签离'
  36. },
  37. ]
  38. },
  39. onLoad(e) {
  40. my.hideBackHome();
  41. this.setData({
  42. formPath: e.formPath || null,
  43. notDesensitizedColumn: app.globalData.snDisposition.notDesensitizedColumn
  44. })
  45. this.data.searchFormCopy = JSON.parse(JSON.stringify(this.data.searchForm));
  46. this.getTable()
  47. },
  48. async getTable() {
  49. let {
  50. searchForm,
  51. } = this.data;
  52. searchForm.data.sn = app.globalData.sn
  53. my.showLoading()
  54. try {
  55. let res = await visitorReportPageList(searchForm)
  56. this.setData({
  57. tableList: res.data.list,
  58. total: res.data.total,
  59. allPageNum: Math.ceil(res.data.total / searchForm.pageSize)
  60. })
  61. my.hideLoading();
  62. } catch (error) {
  63. my.hideLoading();
  64. }
  65. },
  66. clickAudio() {
  67. getWaterDrop()
  68. },
  69. //签离
  70. async signOff(e) {
  71. let item = e.currentTarget.dataset.item
  72. let data = {
  73. sn: app.globalData.sn,
  74. userVisitorListDetailId: item.userVisitorListDetailId,
  75. }
  76. let res = await visitorSignOut(data)
  77. my.showToast({
  78. content: '签离成功',
  79. duration: 2000
  80. });
  81. this.getTable()
  82. },
  83. getVal(e) {
  84. let key = e.currentTarget.dataset.key
  85. let key1 = `searchForm.data[${key}]`
  86. let signOutList = this.data.signOutList
  87. switch (key) {
  88. case 'isSignOut':
  89. this.setData({
  90. 'searchForm.data.isSignOut': signOutList[e.detail.value].id,
  91. 'searchForm.data.isSignOutName': signOutList[e.detail.value].name,
  92. })
  93. break;
  94. default:
  95. this.setData({
  96. [key1]: e.detail.value
  97. })
  98. break;
  99. }
  100. },
  101. // 获取日期
  102. datePicker(e) {
  103. my.datePicker({
  104. format: 'yyyy-MM-dd HH:mm:ss', //返回的日期格式
  105. currentDate: getDate(), //初始选择的日期时间,默认当前时间
  106. startDate: '2012-01-01 11:11:11', //最小日期时间
  107. endDate: getDate(), //最大日期时间
  108. success: res => {
  109. let key = e.currentTarget.dataset.key
  110. switch (key) {
  111. case 'startTime':
  112. this.setData({
  113. 'searchForm.data.startTime': res.date
  114. })
  115. break;
  116. case 'endTime':
  117. this.setData({
  118. 'searchForm.data.endTime': res.date
  119. })
  120. break;
  121. default:
  122. break;
  123. }
  124. },
  125. });
  126. },
  127. //清空
  128. clearFun() {
  129. let searchForm = JSON.parse(JSON.stringify(this.data.searchFormCopy));
  130. this.setData({
  131. searchForm
  132. })
  133. this.getTable()
  134. },
  135. // 上一页
  136. previousFun() {
  137. let {
  138. searchForm,
  139. } = this.data
  140. if (searchForm.pageNum <= 1) {
  141. return
  142. }
  143. this.setData({
  144. 'searchForm.pageNum': searchForm.pageNum - 1,
  145. })
  146. this.getTable()
  147. },
  148. // 下一页
  149. nextFun() {
  150. let {
  151. searchForm,
  152. allPageNum,
  153. } = this.data
  154. if (searchForm.pageNum >= allPageNum) {
  155. return
  156. }
  157. this.setData({
  158. 'searchForm.pageNum': searchForm.pageNum + 1,
  159. })
  160. this.getTable()
  161. },
  162. // 关闭
  163. closeFun() {
  164. let url = this.data.formPath ? '/pages/home/index' : '/pages/settings/index/index'
  165. my.reLaunch({
  166. url: url
  167. });
  168. },
  169. });