123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <template>
- <div>
- <van-search
- v-model="value"
- placeholder="姓名、部门、类型模糊查询"
- input-align="center"
- left-icon=""
- show-action
- shape="round"
- @search="onSearch"
- >
- <template #action>
- <div @click="onSearch"><van-icon name="search" />搜索</div>
- </template>
- </van-search>
- <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
- <van-list
- v-model="loading"
- :finished="finished"
- finished-text="没有更多了"
- @load="onLoad"
- >
- <van-cell style="background-color: #ca8caf">
- <template #title>
- <van-row>
- <van-col
- v-for="(column, idx) in columns"
- :key="column.name + idx"
- :span="24 / columns.length"
- >
- {{ column.name }}
- <van-icon :name="column.icon" @click="onSort(column.key)" />
- </van-col>
- </van-row>
- </template>
- </van-cell>
- <van-cell v-for="item in list" :key="item">
- <template #title>
- <van-row>
- <van-col
- v-for="(column, idx) in columns"
- :key="column.key + idx"
- :span="24 / columns.length"
- >
- {{ item[column.key] }}
- </van-col>
- </van-row>
- </template>
- </van-cell>
- </van-list>
- </van-pull-refresh>
- </div>
- </template>
- <script>
- import { mapGetters } from 'vuex'
- export default {
- name: 'FireTable',
- props: {
- queryType: {
- type: String,
- default: '1'
- },
- allColumns: {
- type: Boolean,
- default: true
- }
- },
- data() {
- return {
- value: '',
- list: [],
- loading: false,
- finished: false,
- refreshing: false,
- page: 1,
- sorts: ['', 'desc', 'asc'],
- icons: ['sort', 'descending', 'ascending'],
- columns: [
- {
- name: '部门',
- key: 'bm',
- sort: '',
- icon: 'sort'
- },
- {
- name: '姓名',
- key: 'xm',
- sort: '',
- icon: 'sort'
- },
- {
- name: '类型',
- key: 'lx',
- sort: '',
- icon: 'sort'
- },
- {
- name: '签到时间',
- key: 'qdrq',
- sort: '',
- icon: 'sort'
- }
- ]
- }
- },
- computed: {
- ...mapGetters(['gValue'])
- },
- watch: {
- gValue: function (n, o) {
- if (n) {
- this.finished = false
- this.loading = true
- this.onLoad(1)
- }
- }
- },
- mounted() {
- if (!this.allColumns) {
- this.columns = [
- {
- name: '部门',
- key: 'bm',
- sort: '',
- icon: 'sort'
- },
- {
- name: '姓名',
- key: 'xm',
- sort: '',
- icon: 'sort'
- },
- {
- name: '类型',
- key: 'lx',
- sort: '',
- icon: 'sort'
- }
- ]
- }
- },
- methods: {
- onLoad(page) {
- if (!this.gValue) {
- this.finished = true
- this.loading = false
- return
- }
- if (page) {
- this.page = page
- }
- page = this.page
- this.page += 1
- let sort = ''
- this.columns.forEach(function (v) {
- if (v.sort) {
- sort += v.key + ' ' + v.sort
- }
- })
- // 查询类型 queryType
- // 演习id=gValue
- // 排序情况= columns . sort
- // 搜索情况 this.value
- const postData = {
- yxid: this.gValue,
- cxlx: this.queryType,
- sort: sort,
- gjz: this.value,
- page: page
- }
- this.$apis.requestBase('list', postData).then(res => {
- if (res.data && res.data.length > 0) {
- if (page === 1) {
- this.list = res.data
- } else {
- this.list.push(res.data)
- }
- } else {
- if (page === 1) {
- this.list = []
- }
- this.finished = true
- }
- this.loading = false
- if (this.refreshing) {
- this.refreshing = false
- }
- })
- },
- onRefresh() {
- this.finished = false
- this.loading = true
- this.onLoad(1)
- },
- onSearch() {
- this.finished = false
- this.loading = true
- this.onLoad(1)
- },
- onSort(key) {
- const _this = this
- this.columns.forEach(function (v) {
- if (v.key === key) {
- let idx = _this.sorts.indexOf(v.sort) + 1
- if (idx > 2) {
- idx = 0
- }
- v.sort = _this.sorts[idx]
- v.icon = _this.icons[idx]
- } else {
- v.sort = _this.sorts[0]
- v.icon = _this.icons[0]
- }
- })
- this.finished = false
- this.loading = true
- this.onLoad(1)
- }
- }
- }
- </script>
- <style scoped></style>
|