359 lines
10 KiB
Vue
Raw Normal View History

2021-05-13 10:56:04 +08:00
<template>
<div class="pintuan">
2021-05-13 10:56:04 +08:00
<Card>
<Row>
2021-12-11 13:50:58 +08:00
<Form
ref="searchForm"
:model="searchForm"
inline
:label-width="70"
class="search-form"
>
2021-05-13 10:56:04 +08:00
<Form-item label="活动名称" prop="promotionName">
<Input
type="text"
v-model="searchForm.promotionName"
placeholder="请输入活动名称"
clearable
style="width: 200px"
/>
</Form-item>
<Form-item label="活动状态" prop="promotionStatus">
<Select
v-model="searchForm.promotionStatus"
placeholder="请选择"
clearable
style="width: 200px"
>
<Option value="NEW">未开始</Option>
<Option value="START">已开始/上架</Option>
<Option value="END">已结束/下架</Option>
<Option value="CLOSE">紧急关闭/作废</Option>
</Select>
</Form-item>
<Form-item label="活动时间">
<DatePicker
v-model="selectDate"
type="daterange"
clearable
placeholder="选择起始时间"
style="width: 200px"
></DatePicker>
</Form-item>
2021-12-11 13:50:58 +08:00
<Button
@click="handleSearch"
type="primary"
class="search-btn"
icon="ios-search"
>搜索</Button
>
<Button @click="handleReset" class="search-btn">重置</Button>
2021-05-13 10:56:04 +08:00
</Form>
</Row>
<Row class="operation padding-row">
<Button @click="newAct" type="primary">添加</Button>
</Row>
2021-12-11 13:50:58 +08:00
<Table :loading="loading" border :columns="columns" :data="data" ref="table">
2021-05-27 16:37:00 +08:00
<template slot-scope="{ row }" slot="action">
2021-12-11 13:50:58 +08:00
<div class="row">
<Button
type="default"
size="small"
v-if="row.promotionStatus == 'NEW'"
@click="edit(row)"
>编辑</Button
2021-12-29 19:50:24 +08:00
>
2021-12-11 13:50:58 +08:00
<Button
type="info"
v-if="row.promotionStatus == 'NEW'"
size="small"
@click="manage(row, 'manager')"
>管理</Button
2021-12-29 19:50:24 +08:00
>
2021-12-11 13:50:58 +08:00
<Button
type="info"
2021-12-29 19:50:24 +08:00
v-if="row.promotionStatus !== 'NEW' && row.promotionStatus !== 'CLOSE'"
2021-12-11 13:50:58 +08:00
size="small"
@click="manage(row, 'view')"
>查看</Button
2021-12-29 19:50:24 +08:00
>
2021-12-11 13:50:58 +08:00
<Button
type="error"
size="small"
v-if="row.promotionStatus != 'START'"
@click="remove(row)"
>删除</Button
2021-12-29 19:50:24 +08:00
>
2021-12-11 13:50:58 +08:00
<Button
type="success"
2021-12-29 19:50:24 +08:00
v-if="row.promotionStatus == 'CLOSE'"
2021-12-11 13:50:58 +08:00
size="small"
@click="open(row)"
>开启</Button
>
<Button
type="warning"
v-if="row.promotionStatus == 'START'"
size="small"
@click="close(row)"
>关闭</Button
>
2021-06-23 18:08:22 +08:00
</div>
2021-05-27 16:37:00 +08:00
</template>
</Table>
2021-07-31 15:49:54 +08:00
<Row type="flex" justify="end" class="mt_10">
2021-05-13 10:56:04 +08:00
<Page
:current="searchForm.pageNumber + 1"
:total="total"
:page-size="searchForm.pageSize"
@on-change="changePage"
@on-page-size-change="changePageSize"
:page-size-opts="[10, 20, 50]"
size="small"
show-total
show-elevator
show-sizer
></Page>
</Row>
</Card>
</div>
</template>
<script>
2021-12-11 13:50:58 +08:00
import { getPintuanList, deletePintuan, editPintuanStatus } from "@/api/promotion";
2021-05-13 10:56:04 +08:00
export default {
name: "pintuan",
data() {
return {
loading: true, // 表单加载状态
searchForm: {
// 搜索框初始化对象
pageNumber: 0, // 当前页数
pageSize: 10, // 页面大小
sort: "startTime", // 默认排序字段
order: "desc", // 默认排序方式
},
selectDate: null, // 选择的时间
columns: [
{
title: "活动名称",
key: "promotionName",
2021-12-11 13:50:58 +08:00
minWidth: 120,
2021-05-13 10:56:04 +08:00
},
{
title: "活动开始时间",
key: "startTime",
},
{
title: "活动结束时间",
key: "endTime",
},
{
title: "状态",
key: "promotionStatus",
2021-05-24 18:14:06 +08:00
width: 100,
2021-05-13 10:56:04 +08:00
render: (h, params) => {
let text = "未知",
color = "default";
if (params.row.promotionStatus == "NEW") {
text = "未开始";
color = "default";
} else if (params.row.promotionStatus == "START") {
text = "已开始";
color = "green";
} else if (params.row.promotionStatus == "END") {
text = "已结束";
color = "blue";
} else if (params.row.promotionStatus == "CLOSE") {
text = "已关闭";
color = "red";
}
return h("div", [h("Tag", { props: { color: color } }, text)]);
},
},
{
title: "操作",
slot: "action",
align: "center",
width: 250,
},
],
data: [], // 表单数据
total: 0, // 表单数据总数
};
},
methods: {
// 初始化数据
2021-05-13 10:56:04 +08:00
init() {
this.getDataList();
},
// 改变页码
2021-05-13 10:56:04 +08:00
changePage(v) {
this.searchForm.pageNumber = v - 1;
this.getDataList();
},
// 改变页数
2021-05-13 10:56:04 +08:00
changePageSize(v) {
this.searchForm.pageSize = v;
this.getDataList();
},
// 搜索
2021-05-13 10:56:04 +08:00
handleSearch() {
this.searchForm.pageNumber = 0;
this.searchForm.pageSize = 10;
this.getDataList();
},
// 重置
handleReset() {
this.searchForm = {
// 搜索框初始化对象
pageNumber: 0, // 当前页数
pageSize: 10, // 页面大小
sort: "startTime",
order: "desc", // 默认排序方式
};
2021-12-11 13:50:58 +08:00
this.selectDate = "";
this.getDataList();
},
// 时间段分别赋值
2021-05-13 10:56:04 +08:00
selectDateRange(v) {
if (v) {
this.searchForm.startDate = v[0];
this.searchForm.endDate = v[1];
}
},
// 获取列表数据
2021-05-13 10:56:04 +08:00
getDataList() {
this.loading = true;
if (this.selectDate && this.selectDate[0] && this.selectDate[1]) {
this.searchForm.startTime = this.selectDate[0].getTime();
this.searchForm.endTime = this.selectDate[1].getTime();
} else {
this.searchForm.startTime = null;
this.searchForm.endTime = null;
}
getPintuanList(this.searchForm).then((res) => {
this.loading = false;
if (res.success) {
this.data = res.result.records;
this.total = res.result.total;
}
});
},
// 新建拼团
2021-05-13 10:56:04 +08:00
newAct() {
2021-12-11 13:50:58 +08:00
this.$router.push({ name: "pintuan-edit" });
2021-05-13 10:56:04 +08:00
},
// 编辑拼团
2021-05-13 10:56:04 +08:00
edit(v) {
2021-12-11 13:50:58 +08:00
this.$router.push({ name: "pintuan-edit", query: { id: v.id } });
2021-05-13 10:56:04 +08:00
},
// 管理拼团商品
2021-05-17 15:38:31 +08:00
manage(v, status) {
this.$options.filters.customRouterPush({name: "pintuan-goods", query: { id: v.id, status: status }} )
2021-05-13 10:56:04 +08:00
},
// 手动开启拼团活动
2021-05-13 10:56:04 +08:00
open(v) {
2021-12-11 13:50:58 +08:00
let sTime = new Date();
sTime.setMinutes(sTime.getMinutes() + 10);
let eTime = new Date(new Date().setHours(0, 0, 0, 0) + 24 * 60 * 60 * 1000 - 1);
this.openStartTime = sTime.getTime();
this.openEndTime = eTime.getTime();
2021-05-13 10:56:04 +08:00
this.$Modal.confirm({
2021-12-11 13:50:58 +08:00
title: "确认开启(默认为当前时间的十分钟之后)",
2021-05-13 10:56:04 +08:00
content: "您确认要开启此拼团活动?",
onOk: () => {
let params = {
startTime: this.openStartTime,
endTime: this.openEndTime,
};
2021-12-11 13:50:58 +08:00
editPintuanStatus(v.id, params).then((res) => {
2021-05-13 10:56:04 +08:00
this.$Modal.remove();
if (res.success) {
this.$Message.success("开启活动成功");
this.getDataList();
}
});
},
render: (h) => {
return h("div", [
h("DatePicker", {
props: {
type: "datetimerange",
placeholder: "请选择开始时间和结束时间",
2021-12-11 13:50:58 +08:00
value: [sTime, eTime],
2021-05-13 10:56:04 +08:00
},
style: {
width: "350px",
},
on: {
input: (val) => {
if (val[0]) {
this.openStartTime = val[0].getTime();
}
if (val[1]) {
this.openEndTime = val[1].getTime();
}
},
},
}),
]);
},
});
},
// 关闭拼团活动
2021-05-13 10:56:04 +08:00
close(v) {
this.$Modal.confirm({
title: "确认关闭",
content: "您确认要关闭此拼团活动?",
loading: true,
onOk: () => {
2021-12-11 13:50:58 +08:00
editPintuanStatus(v.id).then((res) => {
2021-05-13 10:56:04 +08:00
this.$Modal.remove();
if (res.success) {
this.$Message.success("关闭活动成功");
this.getDataList();
}
});
},
});
},
// 删除拼团活动
2021-05-13 10:56:04 +08:00
remove(v) {
this.$Modal.confirm({
title: "确认删除",
content: "您确认要删除此拼团活动?",
loading: true,
onOk: () => {
// 删除
deletePintuan(v.id).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("操作成功");
this.getDataList();
}
});
},
});
},
},
2021-07-31 15:49:54 +08:00
mounted() {
2021-05-13 10:56:04 +08:00
this.init();
},
2021-07-31 15:49:54 +08:00
// 页面缓存处理从该页面离开时修改KeepAlive为false保证进入该页面是刷新
beforeRouteLeave(to, from, next) {
2021-12-11 13:50:58 +08:00
from.meta.keepAlive = false;
next();
},
2021-05-13 10:56:04 +08:00
};
</script>
<style lang="scss">
@import "@/styles/table-common.scss";
2021-12-29 19:50:24 +08:00
.row Button {
margin-right: 4px;
}
2021-05-13 10:56:04 +08:00
</style>