|
@@ -30,7 +30,36 @@
|
|
|
</el-radio-group>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="优惠设置">
|
|
|
- <!-- TODO 待实现!这个实现下哈 -->
|
|
|
+ <template v-for="(item,index) in formData.rules" :key="index">
|
|
|
+ <el-row type="flex">
|
|
|
+ <el-col :span="24" style="font-weight: bold;display: flex;">活动层级{{ index+1 }}<el-button link type="danger" style="margin-left: auto;" v-if="index!=0" @click="deleteStratum(index)">删除</el-button></el-col>
|
|
|
+ <e-form :ref="'formRef'+index" :model="item" >
|
|
|
+ <el-form-item label="优惠门槛:" prop="limit" label-width="100px" style="padding-left: 50px;">满<el-input style="width: 150px;padding:0 10px;" v-model="item.limit" type='number' placeholder="" /> 元
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="优惠内容:" label-width="100px" style="padding-left: 50px;">
|
|
|
+ <el-checkbox-group v-model="rules[index]" style="width:100%">
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-checkbox label="订单金额优惠" name="type" />
|
|
|
+ <el-form-item v-if="rules[index].includes('订单金额优惠')">
|
|
|
+ 减<el-input style="width: 150px;padding:0 20px;" v-model="item.discountPrice" type='number' placeholder="" />元
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24"><el-checkbox v-model="item.freeDelivery" label="包邮" name="type" /></el-col>
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-checkbox label="送积分" name="type" />
|
|
|
+ <el-form-item v-if="rules[index].includes('送积分')">
|
|
|
+ 送<el-input style="width: 150px;padding:0 20px;" v-model="item.point" type='number' placeholder="" />积分
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <!-- 优惠券待处理 也可以参考优惠劵的SpuShowcase-->
|
|
|
+ <!-- TODO 待实现!-->
|
|
|
+ <el-col :span="24"><el-checkbox label="送优惠券" name="type" /></el-col>
|
|
|
+ </el-checkbox-group>
|
|
|
+ </el-form-item>
|
|
|
+ </e-form>
|
|
|
+ </el-row>
|
|
|
+ </template>
|
|
|
+ <el-button type="primary" @click="addStratum">添加活动层级</el-button>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="活动商品" prop="productScope">
|
|
|
<el-radio-group v-model="formData.productScope">
|
|
@@ -78,7 +107,7 @@
|
|
|
import { getSpuSimpleList } from '@/api/mall/product/spu'
|
|
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
|
|
import { CommonStatusEnum } from '@/utils/constants'
|
|
|
-import * as ProductBrandApi from '@/api/mall/product/brand'
|
|
|
+import * as RewardActivityApi from '@/api/mall/promotion/reward/rewardActivity'
|
|
|
import {
|
|
|
PromotionConditionTypeEnum,
|
|
|
PromotionProductScopeEnum,
|
|
@@ -112,8 +141,19 @@ const formData = ref({
|
|
|
remark: undefined,
|
|
|
productScope: PromotionProductScopeEnum.ALL.scope,
|
|
|
productSpuIds: undefined,
|
|
|
- rules: undefined
|
|
|
+ rules: [{
|
|
|
+ limit: undefined,
|
|
|
+ discountPrice: undefined,
|
|
|
+ freeDelivery: undefined,
|
|
|
+ point: undefined,
|
|
|
+ couponIds: [],
|
|
|
+ couponCounts: []
|
|
|
+ }],
|
|
|
})
|
|
|
+// 优惠设置
|
|
|
+let rules=reactive([]);
|
|
|
+// 优惠券列表
|
|
|
+
|
|
|
const formRules = reactive({
|
|
|
name: [{ required: true, message: '活动名称不能为空', trigger: 'blur' }],
|
|
|
startAndEndTime: [{ required: true, message: '活动时间不能为空', trigger: 'blur' }],
|
|
@@ -121,7 +161,7 @@ const formRules = reactive({
|
|
|
productScope: [{ required: true, message: '商品范围不能为空', trigger: 'blur' }],
|
|
|
productSpuIds: [{ required: true, message: '商品范围不能为空', trigger: 'blur' }]
|
|
|
})
|
|
|
-const formRef = ref() // 表单 Ref
|
|
|
+const formRef = ref([]) // 表单 Ref
|
|
|
|
|
|
/** 打开弹窗 */
|
|
|
const open = async (type: string, id?: number) => {
|
|
@@ -133,19 +173,23 @@ const open = async (type: string, id?: number) => {
|
|
|
if (id) {
|
|
|
formLoading.value = true
|
|
|
try {
|
|
|
- // formData.value = await ProductBrandApi.getBrand(id)
|
|
|
- formData.value = {
|
|
|
- conditionType: 10,
|
|
|
- description: '',
|
|
|
- id: undefined,
|
|
|
- name: '测试活动',
|
|
|
- picUrl: '',
|
|
|
- productScope: 2,
|
|
|
- productSpuIds: [634],
|
|
|
- remark: '测试备注',
|
|
|
- startAndEndTime: [new Date(), new Date('2023-12-31')],
|
|
|
- status: 0
|
|
|
+ let data= await RewardActivityApi.getReward(id);
|
|
|
+ data.startAndEndTime=[new Date(data.startTime), new Date(data.endTime)];
|
|
|
+ rules.splice(0,rules.length);
|
|
|
+ data.rules.forEach((item)=>{
|
|
|
+ let ars:string[]=reactive([]);
|
|
|
+ if(item.freeDelivery){
|
|
|
+ ars.push('包邮')
|
|
|
+ }
|
|
|
+ if(item.point){
|
|
|
+ ars.push('送积分')
|
|
|
+ }
|
|
|
+ if(item.discountPrice){
|
|
|
+ ars.push('订单金额优惠')
|
|
|
}
|
|
|
+ rules.push(ars)
|
|
|
+ })
|
|
|
+ formData.value=data
|
|
|
} finally {
|
|
|
formLoading.value = false
|
|
|
}
|
|
@@ -160,18 +204,33 @@ const submitForm = async () => {
|
|
|
if (!formRef) return
|
|
|
const valid = await formRef.value.validate()
|
|
|
if (!valid) return
|
|
|
- console.log(formData.value)
|
|
|
- message.success('已在控制台打印数据')
|
|
|
- return
|
|
|
+ // 处理下数据兼容接口
|
|
|
+ formData.value.startTime= +new Date(formData.value.startAndEndTime[0])
|
|
|
+ formData.value.endTime=+new Date(formData.value.startAndEndTime[1])
|
|
|
+ console.log(rules)
|
|
|
+ rules.forEach((item,index)=>{
|
|
|
+ if(item.includes('包邮')){
|
|
|
+ formData.value.rules[index].freeDelivery=true;
|
|
|
+ }else{
|
|
|
+ formData.value.rules[index].freeDelivery=false;
|
|
|
+ }
|
|
|
+ if(!item.includes('送积分')){
|
|
|
+ formData.value.rules[index].point=undefined;
|
|
|
+ }
|
|
|
+ if(!item.includes('订单金额优惠')){
|
|
|
+ formData.value.rules[index].discountPrice=undefined;
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
// 提交请求
|
|
|
formLoading.value = true
|
|
|
try {
|
|
|
- const data = formData.value as ProductBrandApi.BrandVO
|
|
|
+ const data = formData.value as RewardActivityApi.DiscountActivityVO
|
|
|
if (formType.value === 'create') {
|
|
|
- await ProductBrandApi.createBrand(data)
|
|
|
+ await RewardActivityApi.createRewardActivity(data)
|
|
|
message.success(t('common.createSuccess'))
|
|
|
} else {
|
|
|
- await ProductBrandApi.updateBrand(data)
|
|
|
+ await RewardActivityApi.updateRewardActivity(data)
|
|
|
message.success(t('common.updateSuccess'))
|
|
|
}
|
|
|
dialogVisible.value = false
|
|
@@ -182,15 +241,50 @@ const submitForm = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+const addStratum =()=>{
|
|
|
+ formData.value.rules.push({
|
|
|
+ limit: undefined,
|
|
|
+ discountPrice: undefined,
|
|
|
+ freeDelivery: undefined,
|
|
|
+ point: undefined,
|
|
|
+ couponIds: [],
|
|
|
+ couponCounts: []
|
|
|
+ })
|
|
|
+ rules.push([]);
|
|
|
+ console.log(rules)
|
|
|
+}
|
|
|
+
|
|
|
+const deleteStratum=(index)=>{
|
|
|
+ formData.value.rules.splice(index,1)
|
|
|
+ rules.splice(index,1)
|
|
|
+}
|
|
|
+
|
|
|
/** 重置表单 */
|
|
|
const resetForm = () => {
|
|
|
formData.value = {
|
|
|
id: undefined,
|
|
|
- name: '',
|
|
|
- picUrl: '',
|
|
|
- status: CommonStatusEnum.ENABLE,
|
|
|
- description: ''
|
|
|
+ name: undefined,
|
|
|
+ startAndEndTime: undefined,
|
|
|
+ startTime: undefined,
|
|
|
+ endTime: undefined,
|
|
|
+ conditionType: PromotionConditionTypeEnum.PRICE.type,
|
|
|
+ remark: undefined,
|
|
|
+ productScope: PromotionProductScopeEnum.ALL.scope,
|
|
|
+ productSpuIds: undefined,
|
|
|
+ rules: [{
|
|
|
+ limit: undefined,
|
|
|
+ discountPrice: undefined,
|
|
|
+ freeDelivery: undefined,
|
|
|
+ point: undefined,
|
|
|
+ couponIds: [],
|
|
|
+ couponCounts: []
|
|
|
+ }],
|
|
|
}
|
|
|
+ rules.splice(0,rules.length);
|
|
|
+ rules.push(reactive([]));
|
|
|
+ // 解决下有时刷新页面第一次点编辑报错
|
|
|
+ nextTick(()=>{
|
|
|
formRef.value?.resetFields()
|
|
|
+ })
|
|
|
}
|
|
|
</script>
|