index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import {
  2. visiteeList,
  3. } from '../../../utils/api/api'
  4. import {
  5. getWaterDrop
  6. } from '../../../utils/index/index'
  7. const app = getApp()
  8. Page({
  9. data: {
  10. formPath: null, //从哪个页面来
  11. searchList: [{
  12. name: '姓名',
  13. val: 'name'
  14. },
  15. {
  16. name: '手机号',
  17. val: 'phone'
  18. },
  19. {
  20. name: '身份证',
  21. val: 'idNumber'
  22. },
  23. {
  24. name: '单位',
  25. val: 'company'
  26. },
  27. {
  28. name: '部门',
  29. val: 'unitName'
  30. },
  31. {
  32. name: '楼层',
  33. val: 'floor'
  34. },
  35. {
  36. name: '房间号',
  37. val: 'room'
  38. },
  39. ],
  40. searchForm: {
  41. name: '',
  42. phone: '',
  43. company: '',
  44. unitName: '',
  45. floor: '',
  46. room: '',
  47. },
  48. allList: [],
  49. allListCopy: [],
  50. tableList: [],
  51. total: 0,
  52. pageNum: 0, //总页数
  53. pageSize: 0, //当前页数
  54. sliceStart: 0, //截取数组开始
  55. sliceEnd: 8, //截取数组结束
  56. },
  57. onLoad(e) {
  58. my.hideBackHome();
  59. this.setData({
  60. formPath: e.formPath || null
  61. })
  62. this.data.searchFormCopy = JSON.parse(JSON.stringify(this.data.searchForm));
  63. this.getTable()
  64. },
  65. async getTable(e) {
  66. my.showLoading()
  67. try {
  68. let dto = {
  69. sn: app.globalData.sn,
  70. }
  71. let res = await visiteeList(app.globalData.snDisposition.visiteeUrl, dto)
  72. if (res.data) {
  73. var pageNum = Math.ceil(res.data.length / 8);
  74. let {
  75. sliceEnd,
  76. sliceStart
  77. } = this.data
  78. this.setData({
  79. allList: res.data,
  80. allListCopy: res.data,
  81. tableList: res.data.slice(sliceStart, sliceEnd),
  82. total: res.data.length,
  83. pageNum,
  84. pageSize: res.data.length > 0 ? 1 : 0,
  85. })
  86. }
  87. } catch (error) {
  88. console.log(error);
  89. } finally {
  90. my.hideLoading()
  91. }
  92. },
  93. clickAudio() {
  94. getWaterDrop()
  95. },
  96. getVal(e) {
  97. let key = e.currentTarget.dataset.key
  98. let key1 = `searchForm[${key}]`
  99. this.setData({
  100. [key1]: e.detail.value
  101. })
  102. },
  103. // 查询
  104. inquireFun() {
  105. let {
  106. searchForm,
  107. allList,
  108. allListCopy
  109. } = this.data
  110. allList = JSON.parse(JSON.stringify(allListCopy))
  111. // 根据条件过滤数据
  112. let result = this.filterData(searchForm, allList)
  113. var pageNum = Math.ceil(result.length / 8);
  114. let sliceStart = 0
  115. let sliceEnd = 8
  116. this.setData({
  117. allList: result,
  118. tableList: result.slice(sliceStart, sliceEnd),
  119. sliceEnd,
  120. sliceStart,
  121. total: result.length,
  122. pageNum,
  123. pageSize: result.length > 0 ? 1 : 0,
  124. })
  125. },
  126. // 多条件过滤,参数queryObj(过滤条件对象),list(需要过滤的数组)
  127. filterData(queryObj, list) {
  128. let arr = list
  129. Object.keys(queryObj).forEach(key => {
  130. if (queryObj[key] == undefined || queryObj[key] == '') return arr
  131. arr = arr.filter(p => p[key] !== null && (p[key].indexOf(queryObj[key]) > -1))
  132. })
  133. return arr
  134. },
  135. //清空
  136. clearFun() {
  137. let searchForm = JSON.parse(JSON.stringify(this.data.searchFormCopy));
  138. this.setData({
  139. searchForm
  140. })
  141. this.getTable()
  142. },
  143. // 上一页
  144. previousFun() {
  145. let {
  146. allList,
  147. pageSize,
  148. sliceEnd,
  149. sliceStart
  150. } = this.data
  151. if (pageSize <= 1) {
  152. return
  153. }
  154. this.setData({
  155. tableList: allList.slice(sliceStart - 8, sliceEnd - 8),
  156. sliceStart: sliceStart - 8,
  157. sliceEnd: sliceEnd - 8,
  158. pageSize: pageSize - 1
  159. })
  160. },
  161. // 下一页
  162. nextFun() {
  163. let {
  164. allList,
  165. pageSize,
  166. pageNum,
  167. sliceEnd,
  168. sliceStart
  169. } = this.data
  170. if (pageSize >= pageNum) {
  171. return
  172. }
  173. this.setData({
  174. tableList: allList.slice(sliceStart + 8, sliceEnd + 8),
  175. sliceStart: sliceStart + 8,
  176. sliceEnd: sliceEnd + 8,
  177. pageSize: pageSize + 1
  178. })
  179. },
  180. });