排序、状态等

This commit is contained in:
yulixing 2019-10-11 11:00:09 +08:00
parent 9d75a7662c
commit 439f2a0952

View File

@ -48,6 +48,7 @@
<el-select <el-select
v-model="filterForm.gameid" v-model="filterForm.gameid"
placeholder="请选择游戏" placeholder="请选择游戏"
@change="changeGame"
> >
<el-option <el-option
label="所有" label="所有"
@ -61,6 +62,26 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item
label="广告位"
prop="locationid"
>
<el-select
v-model="filterForm.locationid"
placeholder="请选择广告位"
>
<el-option
label="所有"
:value="''"
/>
<el-option
:label="item.label"
:value="item.id"
v-for="(item, index) in locationList"
:key="index"
/>
</el-select>
</el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button
type="primary" type="primary"
@ -75,6 +96,10 @@
<!-- toolbar --> <!-- toolbar -->
<div class="toolbar clearfix"> <div class="toolbar clearfix">
<div class="l fl"> <div class="l fl">
<el-button
type="primary"
@click="addAd"
>新增</el-button>
<el-button <el-button
type="success" type="success"
v-if="batch.show" v-if="batch.show"
@ -107,6 +132,7 @@
class="table mgt-20 mgb-20" class="table mgt-20 mgb-20"
@row-click="rowClick" @row-click="rowClick"
@selection-change="tableSelectionChange" @selection-change="tableSelectionChange"
@sort-change="changeSort"
> >
<el-table-column <el-table-column
v-if="batch.show" v-if="batch.show"
@ -173,11 +199,14 @@
prop="ad_sort" prop="ad_sort"
label="优先级" label="优先级"
show-overflow-tooltip show-overflow-tooltip
width="75" sortable
width="100"
/> />
<el-table-column <el-table-column
prop="status" prop="status"
label="审核状态" label="审核状态"
sortable
width="120"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag <el-tag
@ -259,7 +288,7 @@
</template> </template>
<script> <script>
import {getAd, updateAd, delAd, getAdPos, getAdAreaList} from '@/api/ad' import {getAd, updateAd, delAd, getAdPos} from '@/api/ad'
import {getGameList} from '@/api/game' import {getGameList} from '@/api/game'
import {typeList, modeList} from '@/utils/ad-data' import {typeList, modeList} from '@/utils/ad-data'
import {Promise, reject} from 'q' import {Promise, reject} from 'q'
@ -285,6 +314,7 @@ export default {
filterForm: { filterForm: {
status: '', status: '',
gameid: '', gameid: '',
locationid: '',
}, },
// toolbar // toolbar
batch: { batch: {
@ -318,7 +348,8 @@ export default {
this.platformList[platformKey] = `${item.platform_name}` this.platformList[platformKey] = `${item.platform_name}`
}) })
this.getData() await this.getData()
await this.changeGame()
}, },
methods: { methods: {
// common // common
@ -416,10 +447,42 @@ export default {
// filter // filter
filter() { filter() {
this.currentPage = 1 this.currentPage = 1
this.$router.push({
query: {
status: this.filterForm.status,
gameid: this.filterForm.gameid,
locationid: this.filterForm.locationid,
pageSize: this.pageSize,
currentPage: this.currentPage,
},
})
this.getData() this.getData()
}, },
async changeGame() {
if (this.filterForm.gameid !== '') {
this.filterForm.locationid = ''
const location = await this.getAdPos({
channelid: 6001,
gameid: this.filterForm.gameid,
})
if (!location.message || location.message.length === 0) {
this.locationList = []
return
}
this.locationList = location.message.map(item => {
const area = item.area.split(',')
return {
id: item.id,
label: `${JSON.parse(item.ld_property).title}`,
}
})
}
},
// toolbar // toolbar
addAd() {
this.$router.push('/ad/edit')
},
refreshData() { refreshData() {
this.currentPage = 1 this.currentPage = 1
this.getData() this.getData()
@ -523,15 +586,47 @@ export default {
}, },
// table // table
async getData() { async getData() {
console.log(this.$route.query)
const history = {
status: this.$route.query.status,
gameid: this.$route.query.gameid || '',
locationid: parseInt(this.$route.query.locationid) || '',
}
if(history.status === '0') {
history.status = 0
} else if(history.status) {
history.status = parseInt(history.status)
} else {
history.status = ''
}
console.log(history)
this.filterForm.status = history.status
this.filterForm.gameid = history.gameid
this.filterForm.locationid = history.locationid
this.isLoaded = true this.isLoaded = true
const params = {} const params = {}
if (this.filterForm.status !== '') params.status = this.filterForm.status if (this.filterForm.status !== '') params.status = this.filterForm.status
if (this.filterForm.gameid !== '') params.gameid = parseInt(this.filterForm.gameid) if (this.filterForm.gameid !== '')
params.gameid = parseInt(this.filterForm.gameid)
try { try {
const data = await this.getAd(params) const dataRes = await this.getAd(params)
this.tableData = data.message.sort((a, b) => { let data = dataRes.message
if (this.filterForm.locationid !== '') {
data = data.filter(item => {
const locs = JSON.parse(item.locationid)
return locs.includes(this.filterForm.locationid)
})
}
this.tableData = data.sort((a, b) => {
return b.id - a.id return b.id - a.id
}) })
this.total = this.tableData.length this.total = this.tableData.length
this.sliceData() this.sliceData()
this.isLoaded = false this.isLoaded = false
@ -658,10 +753,56 @@ export default {
this.$message.info('操作已取消!') this.$message.info('操作已取消!')
}) })
}, },
changeSort({column, prop, order}) {
if (prop === 'status') {
this.sortStatus(order)
}
},
sortStatus(order) {
if (order === 'ascending') {
this.tableData = this.tableData.sort(function(a, b) {
if (a.status >= b.status) {
return 1
} else {
return -1
}
})
} else if (order === 'descending') {
this.tableData = this.tableData.sort(function(a, b) {
if (a.status >= b.status) {
return -1
} else {
return 1
}
})
}
this.pageChange(1)
},
sortAdSort(order) {
if (order === 'ascending') {
this.tableData = this.tableData.sort(function(a, b) {
if (a.ad_sort >= b.ad_sort) {
return 1
} else {
return -1
}
})
} else if (order === 'descending') {
this.tableData = this.tableData.sort(function(a, b) {
if (a.ad_sort >= b.ad_sort) {
return -1
} else {
return 1
}
})
}
this.pageChange(1)
},
// pagination // pagination
sizeChange(val) { sizeChange(val) {
this.pageSize = val this.pageSize = val
this.sliceData() this.sliceData()
console.log(this.$route)
}, },
pageChange(val) { pageChange(val) {
this.currentPage = val this.currentPage = val