<template>
|
<div>
|
<list-condition-template ref="table" :form="listQuery" :formLabel="formLabel"
|
:multipleSelected="true" :selectable="selecetInit" dataKey="id"
|
:tableData="tableData" :total="total" @selected="handSelected"
|
@page-info-change="handlePageInfoChange">
|
<template slot="otherElement">
|
<el-col :span="24" :offset="0" class="buttonPosition">
|
<el-button size="mini" type="primary" @click="queryData">查询</el-button>
|
<el-button size="mini" @click="resetQuery">重置</el-button>
|
</el-col>
|
</template>
|
<template slot="operationSection">
|
<el-button size="mini" type="success" @click="addItem">新增</el-button>
|
<el-button size="mini" type="primary" @click="deleteItem">删除</el-button>
|
</template>
|
<template slot="columns">
|
<el-table-column label="套餐编码" prop="code" show-overflow-tooltip></el-table-column>
|
<el-table-column label="套餐名称" prop="name" show-overflow-tooltip></el-table-column>
|
<el-table-column label="适用渠道" prop="belongSource" show-overflow-tooltip>
|
<template slot-scope="scope">
|
{{getLabel(applicableChannels,scope.row.belongSource)}}
|
</template>
|
</el-table-column>
|
<el-table-column label="创建时间" width="180px">
|
<template slot-scope="scope">
|
<span>{{scope.row.createTime}}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="修改时间" width="180px">
|
<template slot-scope="scope">
|
<span>{{scope.row.updateTime}}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="状态" align="center" prop="status" width="150px">
|
<template slot-scope="scope">
|
<span class="statusTag"
|
:style="{ background: scope.row.status === '10' ? '#52c41a' :'#f5222d'}"></span>
|
<span>{{scope.row.status === '10' ? '启用' : '停用'}}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" :width="`${3 * $store.getters.colSize}px`">
|
<template slot-scope="scope">
|
<wly-btn v-if="scope.row.status !== '10'" :type="'primary'"
|
@click="editItem(scope.row,scope.$index)">编辑</wly-btn>
|
<wly-btn @click="detailsInfo(scope.row,scope.$index)">详情</wly-btn>
|
<wly-btn :type="scope.row.status === '10' ? 'warning' : 'success'"
|
@click="updateState(scope.row,scope.$index)">
|
{{scope.row.status === '10' ? '停用' : '启用'}}</wly-btn>
|
</template>
|
</el-table-column>
|
</template>
|
</list-condition-template>
|
</div>
|
</template>
|
<script>
|
import platformPackageApi from '@/api/platformPackage'
|
import applicableChannels from '@/utils/constant/orderSourceArr'
|
import { getArrayLable } from '@/utils/getArrayLable'
|
|
export default {
|
data () {
|
return {
|
applicableChannels,
|
tableData: [],
|
total: 0,
|
listQuery: {
|
name: null,
|
codeLike: null,
|
belongSource: null,
|
status: null,
|
startDate: null,
|
endDate: null
|
},
|
formLabel: [
|
{
|
model: 'codeLike',
|
label: '套餐编码',
|
type: 'input',
|
rule: /[^\w]/g // 可输入数字字母
|
},
|
{
|
model: 'name',
|
label: '套餐名称',
|
type: 'input'
|
},
|
{
|
model: 'belongSource',
|
label: '适用渠道',
|
type: 'select',
|
opts: applicableChannels
|
},
|
{
|
model: 'status',
|
label: '状态',
|
type: 'select',
|
opts: [
|
{
|
id: '10',
|
name: '启用'
|
},
|
{
|
id: '00',
|
name: '停用'
|
}
|
]
|
}
|
// {
|
// model: 'startDate',
|
// label: '创建时间',
|
// type: 'date',
|
// pickerOptions: {
|
// disabledDate: (time) => {
|
// return this.listQuery.endDate && time.getTime() >= new Date(this.listQuery.endDate).getTime() + 86400000
|
// }
|
// }
|
// },
|
// {
|
// model: 'endDate',
|
// label: '-',
|
// type: 'date',
|
// pickerOptions: {
|
// disabledDate: (time) => {
|
// return this.listQuery.startDate && time.getTime() <= new Date(this.listQuery.startDate).getTime() - 86400000
|
// }
|
// }
|
// }
|
],
|
rows: []
|
}
|
},
|
/*
|
* 数据变化后刷新列表
|
*/
|
activated () {
|
this.queryList(this.$refs.table.getPageInfo())
|
},
|
methods: {
|
/**
|
* 获取数组的label
|
*/
|
getLabel (array, id) {
|
let str = ''
|
id.split(',').forEach((item, index, arr) => {
|
const endTag = arr.length !== index + 1 ? ',' : ''
|
str += getArrayLable(array, item) + endTag
|
})
|
return str
|
},
|
/**
|
* 初始化表格
|
*/
|
initTable () {
|
this.$refs.table.reloadCurrent()
|
this.rows = []
|
},
|
/**
|
* 批量删除
|
*/
|
async deleteItem () {
|
if (!this.rows.length) {
|
this.$message({
|
message: '请选择需要删除的数据',
|
type: 'info'
|
})
|
return
|
}
|
this.$confirm('确认删除数据吗?', '删除', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}).then(async () => {
|
try {
|
const ids = this.rows.map(item => item.id).join()
|
console.log(ids)
|
const res = await platformPackageApi.deleteItem({ ids })
|
if (res.code === '0') {
|
this.$message({
|
message: '删除成功',
|
type: 'success'
|
})
|
this.initTable()
|
}
|
} catch (error) {
|
}
|
}).catch(() => { })
|
},
|
/**
|
*
|
*获取勾选的表格数据
|
*/
|
handSelected (val) {
|
this.rows = val
|
},
|
/**
|
* 初始化复选框
|
*/
|
selecetInit (row, index) {
|
if (row.status === '10') {
|
return false // 不可勾选
|
} else {
|
return true // 可勾选
|
}
|
},
|
/**
|
* 启用/停用
|
*/
|
async updateState (row, index) {
|
console.log(row.status)
|
if (row.status === '00') {
|
this.enablePackage(row.id)
|
} else if (row.status === '10') {
|
this.disablePackage(row.id)
|
}
|
},
|
/**
|
* 启用
|
*/
|
async enablePackage (id) {
|
const res = await platformPackageApi.enableStatus(id)
|
if (res.code === '0') {
|
this.$message({
|
message: '启用成功',
|
type: 'success'
|
})
|
this.initTable()
|
}
|
},
|
/**
|
* 禁用
|
*/
|
async disablePackage (id) {
|
const res = await platformPackageApi.disabledStatus(id)
|
if (res.code === '0') {
|
this.$message({
|
message: '禁用成功',
|
type: 'success'
|
})
|
this.initTable()
|
}
|
},
|
/**
|
* 新增
|
*/
|
addItem () {
|
this.$router.push({ name: 'platformPgAdd' })
|
},
|
/**
|
* 编辑
|
*/
|
editItem (row, index) {
|
this.$router.push({ name: 'platformPgEdit', query: { id: row.id } })
|
},
|
/**
|
* 详情
|
*/
|
detailsInfo (row, index) {
|
this.$router.push({ name: 'platformPgInfo', query: { id: row.id } })
|
},
|
/**
|
* '分页信息改变时查询列表
|
*/
|
handlePageInfoChange (pageInfo) {
|
this.queryList(pageInfo)
|
},
|
|
/**
|
* 重置
|
*/
|
resetQuery () {
|
this.$refs.table.reloadCurrent()
|
},
|
/**
|
* 点击查询按钮
|
*/
|
queryData () {
|
this.$refs.table.changeCondition()
|
},
|
/**
|
* 查询列表
|
*/
|
async queryList (pageInfo = { pageNum: 1, pageSize: 10 }) {
|
try {
|
const res = await platformPackageApi.getList({ ...this.listQuery, ...pageInfo })
|
if (res.code === '0') {
|
this.tableData = res.data.list
|
this.total = res.data.total
|
}
|
} catch (error) {
|
}
|
}
|
}
|
}
|
</script>
|
<style lang="scss">
|
.statusTag {
|
width: 6px;
|
height: 6px;
|
border-radius: 50%;
|
display: inline-block;
|
margin-right: 4px;
|
position: relative;
|
bottom: 2px;
|
}
|
</style>
|