| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <template>
- <div class="white-box">
- <el-table
- :key="tableKey"
- v-loading="listLoading"
- :data="list"
- border
- fit
- highlight-current-row
- style="width: 100%;"
- >
- <el-table-column :label="$t('ad.ad')" prop="id" align="center" :class-name="getSortClass('id')">
- <template slot-scope="{row}">
- <span>{{ row.LOCATION_NAME }}</span>
- </template>
- </el-table-column>
- <el-table-column :label="$t('ad.description')" prop="id" align="center" :class-name="getSortClass('id')">
- <template slot-scope="{row}">
- <span>{{ row.REMARK }}</span>
- </template>
- </el-table-column>
- <el-table-column :label="$t('ad.type')" align="center"> <!-- 类型 -->
- <template slot-scope="{row}">
- <template v-if="row.TYPE === '1'">
- <el-tag type="success">Slideshow</el-tag> <!-- 外链 -->
- </template>
- <template v-else-if="row.TYPE === '2'">
- <el-tag>Image</el-tag> <!-- 文章 -->
- </template>
- </template>
- </el-table-column>
- <el-table-column :label="$t('ad.creator')" prop="id" align="center" width="80" :class-name="getSortClass('id')">
- <template slot-scope="{row}">
- <span>{{ row.CREATE_ADMIN_NAME }}</span>
- </template>
- </el-table-column>
- <el-table-column :label="$t('ad.createTime')" align="center">
- <template slot-scope="{row}">
- <span>{{ row.CREATED_AT | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
- </template>
- </el-table-column>
- <el-table-column :label="$t('ad.action')" align="center" class-name="small-padding fixed-width">
- <template slot-scope="{row}">
- <el-button type="primary" size="mini" @click="handleView(row)">
- {{ $t('ad.view') }}
- </el-button>
- <!-- <router-link :to="'/ad/list/'+ row.id" class="link-type">
- <el-button type="primary" size="small" icon="el-icon-edit">
- {{ $t('ad.view') }}
- </el-button>
- </router-link> -->
- </template>
- </el-table-column>
- </el-table>
- <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
- </div>
- </div></template>
- <script>
- import { fetchList } from '@/api/ad'
- import waves from '@/directive/waves' // waves directive
- import { parseTime } from '@/utils'
- import Pagination from '@/components/Pagination' // secondary package based on el-pagination
- const calendarTypeOptions = [
- { key: 'CN', display_name: 'China' },
- { key: 'US', display_name: 'USA' }
- ]
- // arr to obj, such as { CN : "China", US : "USA" }
- const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
- acc[cur.key] = cur.display_name
- return acc
- }, {})
- export default {
- name: 'ComplexTable',
- components: { Pagination },
- directives: { waves },
- filters: {
- statusFilter(status) {
- const statusMap = {
- published: 'success',
- draft: 'info',
- deleted: 'danger'
- }
- return statusMap[status]
- },
- typeFilter(type) {
- return calendarTypeKeyValue[type]
- }
- },
- data() {
- return {
- tableKey: 0,
- list: null,
- total: 0,
- listLoading: true,
- listQuery: {
- page: 1,
- limit: 20
- },
- importanceOptions: [1, 2, 3],
- calendarTypeOptions,
- sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
- statusOptions: ['published', 'draft', 'deleted'],
- showReviewer: false,
- temp: {
- id: undefined,
- importance: 1,
- remark: '',
- timestamp: new Date(),
- title: '',
- type: '',
- status: 'published'
- },
- dialogFormVisible: false,
- dialogStatus: '',
- textMap: {
- update: 'Edit',
- create: 'Create'
- },
- dialogPvVisible: false,
- pvData: [],
- rules: {
- type: [{ required: true, message: 'type is required', trigger: 'change' }],
- timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
- title: [{ required: true, message: 'title is required', trigger: 'blur' }]
- },
- downloadLoading: false
- }
- },
- created() {
- this.getList()
- },
- methods: {
- getList() {
- this.listLoading = true
- fetchList(this.listQuery).then(response => {
- this.list = response.data.list
- this.total = response.data.totalCount
- // Just to simulate the time of the request
- setTimeout(() => {
- this.listLoading = false
- }, 1.5 * 1000)
- })
- },
- handleFilter() {
- this.listQuery.page = 1
- this.getList()
- },
- resetTemp() {
- this.temp = {
- id: undefined,
- importance: 1,
- remark: '',
- timestamp: new Date(),
- title: '',
- status: 'published',
- type: ''
- }
- },
- handleView(row) {
- this.$router.push(`/ad/list/${row.ID}`)
- },
- formatJson(filterVal) {
- return this.list.map(v => filterVal.map(j => {
- if (j === 'timestamp') {
- return parseTime(v[j])
- } else {
- return v[j]
- }
- }))
- },
- getSortClass: function(key) {
- const sort = this.listQuery.sort
- return sort === `+${key}` ? 'ascending' : 'descending'
- }
- }
- }
- </script>
|