适配重构促销

This commit is contained in:
paulGao
2021-12-11 13:50:58 +08:00
parent fd1d32d431
commit edef393535
40 changed files with 2532 additions and 1486 deletions

View File

@@ -0,0 +1,310 @@
<template>
<div>
<Card>
<Form ref="form" :model="form" :label-width="120">
<div class="base-info-item">
<h4>基本信息</h4>
<div class="form-item-view">
<FormItem label="活动名称" prop="promotionName">
<Input
type="text"
v-model="form.promotionName"
disabled
placeholder="活动名称"
clearable
style="width: 260px"
/>
</FormItem>
<FormItem label="活动时间" prop="rangeTime">
<DatePicker
type="datetimerange"
v-model="form.rangeTime"
disabled
format="yyyy-MM-dd HH:mm:ss"
placeholder="请选择"
:options="options"
style="width: 320px"
>
</DatePicker>
</FormItem>
<FormItem label="活动描述" prop="description">
<Input
v-model="form.description"
disabled
type="textarea"
:rows="4"
clearable
style="width: 260px"
/>
</FormItem>
</div>
<h4>优惠设置</h4>
<div class="form-item-view">
<FormItem label="优惠门槛" prop="fullMoney">
<Input
type="text"
v-model="form.fullMoney"
disabled
placeholder="优惠门槛"
clearable
style="width: 260px"
/>
<span class="describe">消费达到当前金额可以参与优惠</span>
</FormItem>
<FormItem label="优惠方式">
<RadioGroup type="button" button-style="solid" v-model="form.discountType">
<Radio label="isFullMinus" disabled>减现金</Radio>
<Radio label="isFullRate" disabled>打折</Radio>
</RadioGroup>
</FormItem>
<FormItem
v-if="form.discountType == 'isFullMinus'"
label="优惠金额"
prop="fullMinus"
>
<Input
type="text"
disabled
v-model="form.fullMinus"
placeholder="优惠金额"
clearable
style="width: 260px"
/>
</FormItem>
<FormItem
v-if="form.discountType == 'isFullRate'"
label="优惠折扣"
prop="fullRate"
>
<Input
type="text"
v-model="form.fullRate"
placeholder="优惠折扣"
disabled
clearable
style="width: 260px"
/>
<span class="describe">优惠折扣为0-10之间数字可有一位小数</span>
</FormItem>
<FormItem label="额外赠送">
<Checkbox v-model="form.isFreeFreight" disabled>免邮费</Checkbox>&nbsp;
<Checkbox v-model="form.isCoupon" disabled>送优惠券</Checkbox>&nbsp;
<Checkbox v-model="form.isGift" disabled>送赠品</Checkbox>&nbsp;
<Checkbox v-model="form.isPoint" disabled>送积分</Checkbox>
</FormItem>
<FormItem v-if="form.isCoupon" label="赠送优惠券" prop="couponId">
<Select
v-model="form.couponId"
filterable
:remote-method="getCouponList"
placeholder="输入优惠券名称搜索"
disabled
:loading="couponLoading"
style="width: 260px"
>
<Option v-for="item in couponList" :value="item.id" :key="item.id">{{
item.couponName
}}</Option>
</Select>
</FormItem>
<FormItem v-if="form.isGift" label="赠品" prop="giftId">
<Select
v-model="form.giftId"
filterable
:remote-method="getGiftList"
placeholder="输入赠品名称搜索"
disabled
:loading="giftLoading"
style="width: 260px"
>
<Option v-for="item in giftList" :value="item.id" :key="item.id">{{
item.goodsName
}}</Option>
</Select>
</FormItem>
<FormItem v-if="form.isPoint" label="赠积分" prop="point">
<Input v-model="form.point" type="number" disabled style="width: 260px" />
</FormItem>
<FormItem label="使用范围" prop="scopeType">
<RadioGroup type="button" button-style="solid" v-model="form.scopeType">
<Radio label="ALL" disabled>全品类</Radio>
<Radio label="PORTION_GOODS" disabled>指定商品</Radio>
</RadioGroup>
</FormItem>
<FormItem style="width: 100%" v-if="form.scopeType == 'PORTION_GOODS'">
<Table border :columns="columns" :data="form.promotionGoodsList">
<template slot-scope="{ row }" slot="goodsName">
<div>
<a class="mr_10" @click="linkTo(row.goodsId, row.skuId)">{{
row.goodsName
}}</a>
<Poptip trigger="hover" title="扫码在手机中查看" transfer>
<div slot="content">
<vue-qr
:text="wapLinkTo(row.goodsId, row.skuId)"
:margin="0"
colorDark="#000"
colorLight="#fff"
:size="150"
></vue-qr>
</div>
<img
src="../../../assets/qrcode.svg"
style="vertical-align: middle"
class="hover-pointer"
width="20"
height="20"
alt=""
/>
</Poptip>
</div>
</template>
</Table>
</FormItem>
<div>
<Button @click="$router.push({ name: 'fullCut' })">返回</Button>
</div>
</div>
</div>
</Form>
</Card>
</div>
</template>
<script>
import { getPlatformCouponList, getFullDiscountById } from "@/api/promotion";
import { getGoodsSkuData } from "@/api/goods";
import vueQr from "vue-qr";
export default {
name: "add-full-discount",
components: {
"vue-qr": vueQr,
},
data() {
return {
form: {
// 表单
discountType: "isFullMinus",
scopeType: "ALL",
promotionGoodsList: [],
},
id: this.$route.query.id, // 活动id
couponList: [], // 优惠券列表
giftList: [], // 赠品列表
giftLoading: false, // 赠品加载状态
columns: [
{
type: "selection",
width: 60,
align: "center",
},
{
title: "商品名称",
slot: "goodsName",
minWidth: 120,
},
{
title: "商品价格",
key: "price",
minWidth: 40,
render: (h, params) => {
return h("div", this.$options.filters.unitPrice(params.row.price, "¥"));
},
},
{
title: "库存",
key: "quantity",
minWidth: 40,
},
],
options: {
disabledDate(date) {
return date && date.valueOf() < Date.now() - 86400000;
},
},
};
},
async mounted() {
if (this.id) {
this.getDetail();
}
this.getCouponList();
this.getGiftList();
},
methods: {
getDetail() {
// 获取活动详情
getFullDiscountById(this.id).then((res) => {
let data = res.result;
if (!data.scopeType === "ALL") {
data.promotionGoodsList = [];
}
if (data.isFullMinus) {
data.discountType = "isFullMinus";
delete data.isFullMinus;
} else {
data.discountType = "isFullMinus";
delete data.isFullRate;
}
data.rangeTime = [];
data.rangeTime.push(new Date(data.startTime), new Date(data.endTime));
this.form = data;
});
},
getCouponList(query) {
// 优惠券列表
let params = {
pageSize: 10,
pageNumber: 0,
couponName: query,
promotionStatus: "START",
};
this.couponLoading = true;
getPlatformCouponList(params).then((res) => {
this.couponLoading = false;
if (res.success) {
this.couponList = res.result.records;
}
});
},
getGiftList(query) {
// 赠品列表
let params = {
pageSize: 10,
pageNumber: 1,
goodsName: query,
};
this.giftLoading = true;
getGoodsSkuData(params).then((res) => {
this.giftLoading = false;
if (res.success) {
this.giftList = res.result.records;
}
});
},
},
};
</script>
<style lang="scss" scoped>
h4 {
margin-bottom: 10px;
padding: 0 10px;
border: 1px solid #ddd;
background-color: #f8f8f8;
font-weight: bold;
color: #333;
font-size: 14px;
line-height: 40px;
text-align: left;
}
.describe {
font-size: 12px;
margin-left: 10px;
color: #999;
}
</style>

View File

@@ -0,0 +1,246 @@
<template>
<div class="full-cut">
<Card>
<Row>
<Form
ref="searchForm"
:model="searchForm"
inline
:label-width="70"
class="search-form"
>
<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>
<Button
@click="handleSearch"
type="primary"
class="search-btn"
icon="ios-search"
>搜索</Button
>
</Form>
</Row>
<Table
:loading="loading"
border
:columns="columns"
:data="data"
ref="table"
class="mt_10"
sortable="custom"
>
<template slot-scope="{ row }" slot="applyEndTime">
{{ unixDate(row.applyEndTime) }}
</template>
<template slot-scope="{ row }" slot="promotionType">
{{ row.isFullMinus ? "满减" : "满折" }}
</template>
<template slot-scope="{ row }" slot="hours">
<Tag v-for="item in unixHours(row.hours)" :key="item">{{ item }}</Tag>
</template>
<template slot-scope="{ row }" slot="action">
<div>
<Button type="info" size="small" @click="view(row)">查看</Button>
<Button
type="error"
v-if="row.promotionStatus === 'START'"
style="margin-left: 5px"
size="small"
@click="openOrClose(row)"
>关闭</Button
>
<Button
type="success"
v-if="row.promotionStatus === 'CLOSE' || row.promotionStatus === 'NEW'"
style="margin-left: 5px"
size="small"
@click="openOrClose(row)"
>开启</Button
>
</div>
</template>
</Table>
<Row type="flex" justify="end" class="mt_10">
<Page
:current="searchForm.pageNumber"
: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>
import { getFullDiscountList, updateFullDiscount } from "@/api/promotion.js";
import { promotionsStatusRender } from "@/utils/promotions";
export default {
data() {
return {
selectDate: [],
total: 0,
loading: false, // 表单加载状态
searchForm: {
// 请求参数
pageNumber: 1,
pageSize: 10,
sort: "startTime",
order: "desc",
},
columns: [
// 表头
{
title: "活动名称",
key: "promotionName",
minWidth: 120,
},
{
title: "开始时间",
key: "startTime",
width: 170,
},
{
title: "结束时间",
key: "endTime",
width: 170,
},
{
title: "店铺名称",
key: "storeName",
minWidth: 60,
},
{
title: "活动类型",
slot: "promotionType",
minWidth: 60,
},
{
title: "活动状态",
key: "promotionStatus",
minWidth: 60,
render: (h, params) => {
return promotionsStatusRender(h, params);
},
},
{
title: "操作",
slot: "action",
align: "center",
width: 140,
},
],
data: [], // 列表数据
};
},
methods: {
// 初始化数据
init() {
this.getDataList();
},
// 开启或关闭活动
openOrClose(row) {
let name = "开启";
let status = "START";
if (row.promotionStatus === "START") {
name = "关闭";
status = "CLOSE";
}
this.$Modal.confirm({
title: "提示",
// 记得确认修改此处
content: `确认${name}此活动吗?需要一定时间才能生效,请耐心等待`,
loading: true,
onOk: () => {
// 删除
updateFullDiscount(row.id, status).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success(`${name}成功`);
this.getDataList();
}
});
},
});
},
changePage(v) {
// 改变页数
this.searchForm.pageNumber = v;
this.getDataList();
},
changePageSize(v) {
// 改变页码
this.searchForm.pageNumber = 1;
this.searchForm.pageSize = v;
this.getDataList();
},
handleSearch() {
// 搜索
this.searchForm.pageNumber = 1;
this.searchForm.pageSize = 10;
this.getDataList();
},
// 获取列表数据
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;
}
getFullDiscountList(this.searchForm).then((res) => {
this.loading = false;
if (res.success) {
this.data = res.result.records;
this.total = res.result.total;
}
});
},
view(row) {
// 查看
this.$router.push({ name: "full-discount-detail", query: { id: row.id } });
},
},
mounted() {
this.init();
},
};
</script>