FireTable.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div>
  3. <van-search
  4. v-model="value"
  5. placeholder="姓名、部门、类型模糊查询"
  6. input-align="center"
  7. left-icon=""
  8. show-action
  9. shape="round"
  10. @search="onSearch"
  11. >
  12. <template #action>
  13. <div @click="onSearch"><van-icon name="search" />搜索</div>
  14. </template>
  15. </van-search>
  16. <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  17. <van-list
  18. v-model="loading"
  19. :finished="finished"
  20. finished-text="没有更多了"
  21. @load="onLoad"
  22. >
  23. <van-cell style="background-color: #ca8caf">
  24. <template #title>
  25. <van-row>
  26. <van-col
  27. v-for="(column, idx) in columns"
  28. :key="column.name + idx"
  29. :span="24 / columns.length"
  30. >
  31. {{ column.name }}
  32. <van-icon :name="column.icon" @click="onSort(column.key)" />
  33. </van-col>
  34. </van-row>
  35. </template>
  36. </van-cell>
  37. <van-cell v-for="item in list" :key="item">
  38. <template #title>
  39. <van-row>
  40. <van-col
  41. v-for="(column, idx) in columns"
  42. :key="column.key + idx"
  43. :span="24 / columns.length"
  44. >
  45. {{ item[column.key] }}
  46. </van-col>
  47. </van-row>
  48. </template>
  49. </van-cell>
  50. </van-list>
  51. </van-pull-refresh>
  52. </div>
  53. </template>
  54. <script>
  55. import { mapGetters } from 'vuex'
  56. export default {
  57. name: 'FireTable',
  58. props: {
  59. queryType: {
  60. type: String,
  61. default: '1'
  62. },
  63. allColumns: {
  64. type: Boolean,
  65. default: true
  66. }
  67. },
  68. data() {
  69. return {
  70. value: '',
  71. list: [],
  72. loading: false,
  73. finished: false,
  74. refreshing: false,
  75. page: 1,
  76. sorts: ['', 'desc', 'asc'],
  77. icons: ['sort', 'descending', 'ascending'],
  78. columns: [
  79. {
  80. name: '部门',
  81. key: 'bm',
  82. sort: '',
  83. icon: 'sort'
  84. },
  85. {
  86. name: '姓名',
  87. key: 'xm',
  88. sort: '',
  89. icon: 'sort'
  90. },
  91. {
  92. name: '类型',
  93. key: 'lx',
  94. sort: '',
  95. icon: 'sort'
  96. },
  97. {
  98. name: '签到时间',
  99. key: 'qdrq',
  100. sort: '',
  101. icon: 'sort'
  102. }
  103. ]
  104. }
  105. },
  106. computed: {
  107. ...mapGetters(['gValue'])
  108. },
  109. watch: {
  110. gValue: function (n, o) {
  111. if (n) {
  112. this.finished = false
  113. this.loading = true
  114. this.onLoad(1)
  115. }
  116. }
  117. },
  118. mounted() {
  119. if (!this.allColumns) {
  120. this.columns = [
  121. {
  122. name: '部门',
  123. key: 'bm',
  124. sort: '',
  125. icon: 'sort'
  126. },
  127. {
  128. name: '姓名',
  129. key: 'xm',
  130. sort: '',
  131. icon: 'sort'
  132. },
  133. {
  134. name: '类型',
  135. key: 'lx',
  136. sort: '',
  137. icon: 'sort'
  138. }
  139. ]
  140. }
  141. },
  142. methods: {
  143. onLoad(page) {
  144. if (!this.gValue) {
  145. this.finished = true
  146. this.loading = false
  147. return
  148. }
  149. if (page) {
  150. this.page = page
  151. }
  152. page = this.page
  153. this.page += 1
  154. let sort = ''
  155. this.columns.forEach(function (v) {
  156. if (v.sort) {
  157. sort += v.key + ' ' + v.sort
  158. }
  159. })
  160. // 查询类型 queryType
  161. // 演习id=gValue
  162. // 排序情况= columns . sort
  163. // 搜索情况 this.value
  164. const postData = {
  165. yxid: this.gValue,
  166. cxlx: this.queryType,
  167. sort: sort,
  168. gjz: this.value,
  169. page: page
  170. }
  171. this.$apis.requestBase('list', postData).then(res => {
  172. if (res.data && res.data.length > 0) {
  173. if (page === 1) {
  174. this.list = res.data
  175. } else {
  176. this.list.push(res.data)
  177. }
  178. } else {
  179. if (page === 1) {
  180. this.list = []
  181. }
  182. this.finished = true
  183. }
  184. this.loading = false
  185. if (this.refreshing) {
  186. this.refreshing = false
  187. }
  188. })
  189. },
  190. onRefresh() {
  191. this.finished = false
  192. this.loading = true
  193. this.onLoad(1)
  194. },
  195. onSearch() {
  196. this.finished = false
  197. this.loading = true
  198. this.onLoad(1)
  199. },
  200. onSort(key) {
  201. const _this = this
  202. this.columns.forEach(function (v) {
  203. if (v.key === key) {
  204. let idx = _this.sorts.indexOf(v.sort) + 1
  205. if (idx > 2) {
  206. idx = 0
  207. }
  208. v.sort = _this.sorts[idx]
  209. v.icon = _this.icons[idx]
  210. } else {
  211. v.sort = _this.sorts[0]
  212. v.icon = _this.icons[0]
  213. }
  214. })
  215. this.finished = false
  216. this.loading = true
  217. this.onLoad(1)
  218. }
  219. }
  220. }
  221. </script>
  222. <style scoped></style>