<template>
|
<div class="table-list">
|
<!-- 搜索相关 -->
|
<el-form ref="searchForm" :model="searchForm" class="search-form" inline>
|
<el-form-item label="活动名称">
|
<el-input v-model="searchForm.active_name" placeholder="请输入活动名称" />
|
</el-form-item>
|
<el-form-item label="状态">
|
<el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
|
<el-option label="启用" :value="1"></el-option>
|
<el-option label="禁用" :value="0"></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" @click="onSearch">查询</el-button>
|
<el-button @click="onReset">重置</el-button>
|
<el-button type="primary" @click="onAdd">新增团购活动</el-button>
|
</el-form-item>
|
</el-form>
|
|
<!-- 表格 -->
|
<el-table
|
:data="list"
|
v-loading="loading"
|
style="width: 100%">
|
<el-table-column prop="groupbuy_active_id" label="ID" width="100" />
|
<el-table-column prop="active_name" label="活动名称" min-width="200" />
|
<el-table-column label="活动封面" width="120">
|
<template slot-scope="scope">
|
<el-image
|
v-if="scope.row.file && scope.row.file.file_path"
|
:src="scope.row.file.file_path"
|
class="table-image"
|
fit="cover" />
|
</template>
|
</el-table-column>
|
<el-table-column prop="start_time" label="开始时间" width="160" />
|
<el-table-column prop="end_time" label="结束时间" width="160" />
|
<el-table-column prop="together_time" label="成团时限(小时)" width="130" />
|
<el-table-column prop="status" label="状态" width="100">
|
<template slot-scope="scope">
|
<el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
|
{{ scope.row.status === 1 ? '启用' : '禁用' }}
|
</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" width="250">
|
<template slot-scope="scope">
|
<el-button size="mini" @click="onEdit(scope.row)">编辑</el-button>
|
<el-button size="mini" type="success" @click="onToggleStatus(scope.row)">
|
{{ scope.row.status === 1 ? '禁用' : '启用' }}
|
</el-button>
|
<el-button size="mini" type="danger" @click="onDelete(scope.row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<!-- 分页 -->
|
<div class="pagination">
|
<el-pagination
|
@size-change="handleSizeChange"
|
@current-change="handleCurrentChange"
|
:current-page="pageInfo.page"
|
:page-size="pageInfo.limit"
|
layout="total, prev, pager, next, jumper"
|
:total="pageInfo.total">
|
</el-pagination>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import PlusApi from '@/api/plus/groupbuy'
|
|
export default {
|
name: 'GroupbuyActive',
|
data() {
|
return {
|
loading: false,
|
list: [],
|
searchForm: {
|
active_name: '',
|
status: ''
|
},
|
pageInfo: {
|
page: 1,
|
limit: 20,
|
total: 0
|
}
|
}
|
},
|
created() {
|
this.getList()
|
},
|
methods: {
|
// 获取列表
|
getList() {
|
this.loading = true
|
const params = {
|
page: this.pageInfo.page,
|
list_rows: this.pageInfo.limit,
|
...this.searchForm
|
}
|
PlusApi.activeList(params).then(res => {
|
this.list = res.data.list.data
|
this.pageInfo.total = res.data.list.total
|
}).finally(() => {
|
this.loading = false
|
})
|
},
|
// 搜索
|
onSearch() {
|
this.pageInfo.page = 1
|
this.getList()
|
},
|
// 重置
|
onReset() {
|
this.searchForm = {
|
active_name: '',
|
status: ''
|
}
|
this.pageInfo.page = 1
|
this.getList()
|
},
|
// 新增
|
onAdd() {
|
this.$router.push('/plus/groupbuy/active/add')
|
},
|
// 编辑
|
onEdit(row) {
|
this.$router.push(`/plus/groupbuy/active/edit?groupbuy_active_id=${row.groupbuy_active_id}`)
|
},
|
// 切换状态
|
onToggleStatus(row) {
|
const newStatus = row.status === 1 ? 0 : 1
|
this.$confirm(`确认${newStatus === 1 ? '启用' : '禁用'}该团购活动?`, '提示', {
|
type: 'warning'
|
}).then(() => {
|
PlusApi.updateActiveStatus({
|
groupbuy_active_id: row.groupbuy_active_id,
|
status: newStatus
|
}).then(res => {
|
this.$message.success(`${newStatus === 1 ? '启用' : '禁用'}成功`)
|
this.getList()
|
})
|
})
|
},
|
// 删除
|
onDelete(row) {
|
this.$confirm('确认删除该团购活动?', '提示', {
|
type: 'warning'
|
}).then(() => {
|
PlusApi.deleteActive({ groupbuy_active_id: row.groupbuy_active_id }).then(res => {
|
this.$message.success('删除成功')
|
this.getList()
|
})
|
})
|
},
|
// 分页相关
|
handleSizeChange(val) {
|
this.pageInfo.limit = val
|
this.pageInfo.page = 1
|
this.getList()
|
},
|
handleCurrentChange(val) {
|
this.pageInfo.page = val
|
this.getList()
|
}
|
}
|
}
|
</script>
|