<template>
|
<div class="table-list">
|
<!-- 搜索相关 -->
|
<el-form ref="searchForm" :model="searchForm" class="search-form" inline>
|
<el-form-item label="团购活动">
|
<el-select v-model="searchForm.active_id" placeholder="请选择团购活动" clearable>
|
<el-option
|
v-for="item in activeList"
|
:key="item.groupbuy_active_id"
|
:label="item.active_name"
|
:value="item.groupbuy_active_id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="商品名称">
|
<el-input v-model="searchForm.product_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_product_id" label="ID" width="100" />
|
<el-table-column prop="product.product_name" label="商品名称" min-width="200" />
|
<el-table-column prop="active.active_name" label="团购活动" width="200" />
|
<el-table-column prop="groupbuy_num" label="成团人数" width="100" />
|
<el-table-column prop="groupbuySku.groupbuy_price" label="团购价格" width="100" />
|
<el-table-column prop="stock" label="库存" width="100" />
|
<el-table-column prop="total_sales" label="销量" width="100" />
|
<el-table-column prop="status" label="状态" width="100">
|
<template slot-scope="scope">
|
<el-tag :type="scope.row.status === 0 ? 'success' : 'danger'">
|
{{ scope.row.status === 0 ? '启用' : '禁用' }}
|
</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" width="200">
|
<template slot-scope="scope">
|
<el-button size="mini" @click="onEdit(scope.row)">编辑</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: 'GroupbuyProduct',
|
data() {
|
return {
|
loading: false,
|
list: [],
|
activeList: [],
|
searchForm: {
|
active_id: '',
|
product_name: '',
|
status: ''
|
},
|
pageInfo: {
|
page: 1,
|
limit: 20,
|
total: 0
|
}
|
}
|
},
|
created() {
|
this.getList()
|
this.getActiveList()
|
},
|
methods: {
|
// 获取列表
|
getList() {
|
this.loading = true
|
const params = {
|
page: this.pageInfo.page,
|
list_rows: this.pageInfo.limit,
|
...this.searchForm
|
}
|
PlusApi.productList(params).then(res => {
|
this.list = res.data.list.data
|
this.pageInfo.total = res.data.list.total
|
}).finally(() => {
|
this.loading = false
|
})
|
},
|
// 获取活动列表
|
getActiveList() {
|
PlusApi.activeList({}).then(res => {
|
this.activeList = res.data.list.data
|
})
|
},
|
// 搜索
|
onSearch() {
|
this.pageInfo.page = 1
|
this.getList()
|
},
|
// 重置
|
onReset() {
|
this.searchForm = {
|
active_id: '',
|
product_name: '',
|
status: ''
|
}
|
this.pageInfo.page = 1
|
this.getList()
|
},
|
// 新增
|
onAdd() {
|
this.$router.push('/plus/groupbuy/product/add')
|
},
|
// 编辑
|
onEdit(row) {
|
this.$router.push(`/plus/groupbuy/product/edit/?groupbuy_product_id=${row.groupbuy_product_id}`)
|
},
|
// 删除
|
onDelete(row) {
|
this.$confirm('确认删除该团购商品?', '提示', {
|
type: 'warning'
|
}).then(() => {
|
PlusApi.deleteProduct({ groupbuy_product_id: row.groupbuy_product_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>
|