|
@@ -3,20 +3,31 @@
|
|
|
<div class="discountCodePage flex-col">
|
|
|
<s-header :name="$t('discountCode.applDiscCode')" :noback="false"></s-header>
|
|
|
<div class="discountCodeBox flex-col">
|
|
|
+ <van-field name="radio" :label="$t('discountCode.addMode')">
|
|
|
+ <template #input>
|
|
|
+ <van-radio-group v-model="addMode" direction="horizontal">
|
|
|
+ <van-radio name="1">{{ $t('discountCode.randomAdd') }}</van-radio>
|
|
|
+ <van-radio name="2">{{ $t('discountCode.oneceAdd') }}</van-radio>
|
|
|
+ </van-radio-group>
|
|
|
+ </template>
|
|
|
+ </van-field>
|
|
|
<van-form @submit="onSubmit">
|
|
|
<van-field v-model="number" name="number" :label="$t('discountCode.numberOfDiscountCodesLabel')"
|
|
|
- :placeholder="$t('discountCode.numberOfDiscountCodesPlaceholder')">
|
|
|
+ :placeholder="$t('discountCode.numberOfDiscountCodesPlaceholder')" v-if="addMode == '1'">
|
|
|
<template #button>
|
|
|
<span>{{ $t('discountCode.aSingleGenerationCannotExceed') }}</span>
|
|
|
</template>
|
|
|
</van-field>
|
|
|
+ <van-field v-if='addMode === "2"' v-model="codeNum" type="number" :label="$t('discountCode.codeNum')"
|
|
|
+ maxlength="6" :placeholder="$t('discountCode.codeNumPlaceholder')">
|
|
|
+ </van-field>
|
|
|
<van-field v-model="month" name="number" :label="$t('discountCode.termOfValidity')"
|
|
|
:placeholder="$t('discountCode.pleaseEnterTheValidityPeriod')">
|
|
|
<template #button>
|
|
|
<span>{{ $t('discountCode.Months') }}<span>{{ $t('discountCode.noMoreThanMonths') }}</span></span>
|
|
|
</template>
|
|
|
</van-field>
|
|
|
- <van-field readonly v-model="validDays" :label="$t('discountCode.validDays')" placeholder="" />
|
|
|
+ <!-- <van-field readonly v-model="validDays" :label="$t('discountCode.validDays')" placeholder="" /> -->
|
|
|
<div class="van-cell van-field">
|
|
|
<div class="van-cell__title van-field__label"><span>{{ $t('discountCode.type') }}</span></div>
|
|
|
<div class="van-cell__value van-field__value radioBox">
|
|
@@ -26,13 +37,13 @@
|
|
|
</van-radio-group>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <van-field v-if='type === "1"' v-model="discount" name="number" :label="$t('discountCode.deductionPriceLabdel')"
|
|
|
- :placeholder="$t('discountCode.deductionPricePlaceholder')">
|
|
|
+ <van-field v-if='type === "1"' v-model="discount" type="number" name="number"
|
|
|
+ :label="$t('discountCode.deductionPriceLabdel')" :placeholder="$t('discountCode.deductionPricePlaceholder')">
|
|
|
</van-field>
|
|
|
- <van-field v-if='type === "0"' v-model="discount" name="number" :label="$t('discountCode.discount')"
|
|
|
- :placeholder="$t('discountCode.enterNumber')">
|
|
|
- <template #button>
|
|
|
- <span>0-10</span>
|
|
|
+ <van-field v-if='type === "0"' v-model="discount" type="number" name="number"
|
|
|
+ :label="$t('discountCode.discount') + '(0-10)'" :placeholder="$t('discountCode.enterNumber')">
|
|
|
+ <template #button v-if="user.ifForeign === '1' && discount != ''">
|
|
|
+ <span>{{ $t('discountCode.sameAs') + (10 - discount) * 10 }}% off</span>
|
|
|
</template>
|
|
|
</van-field>
|
|
|
<div class="van-cell van-field" v-if='type === "0" && discount === "0" && promoCodeOpen != "0"'>
|
|
@@ -46,7 +57,7 @@
|
|
|
</div>
|
|
|
<van-row justify="space-around" style="padding: 1em;">
|
|
|
<van-button span="5" round type="primary" style="height: 2em; padding: 0 2em;" native-type="submit">{{
|
|
|
- $t('discountCode.apply') }}</van-button>
|
|
|
+ $t('discountCode.apply') }}</van-button>
|
|
|
</van-row>
|
|
|
</van-form>
|
|
|
</div>
|
|
@@ -64,7 +75,11 @@
|
|
|
import sHeader from "@/components/SimpleHeader";
|
|
|
import { onMounted, reactive, toRefs, ref, watch } from "vue";
|
|
|
import { getLoginUser, Format_calcuDecial, styleUrl } from "@/common/js/utils";
|
|
|
-import { showFailToast, showSuccessToast } from "vant";
|
|
|
+import {
|
|
|
+ showFailToast,
|
|
|
+ showSuccessToast,
|
|
|
+ showToast
|
|
|
+} from "vant";
|
|
|
import { addCode } from "@/service/discountCode";
|
|
|
import { useRouter } from "vue-router";
|
|
|
import { useI18n } from "vue-i18n";
|
|
@@ -77,6 +92,8 @@ export default {
|
|
|
const { t } = useI18n();
|
|
|
const router = useRouter();
|
|
|
let payParams = reactive({
|
|
|
+ addMode: '1', // 生成方式
|
|
|
+ codeNum: '', // 优惠码
|
|
|
number: '', // 优惠码个数
|
|
|
month: '', // 有效期
|
|
|
type: '1', // 优惠卷类型
|
|
@@ -86,7 +103,7 @@ export default {
|
|
|
const payCodeType = ref(false);
|
|
|
const ewmObj = ref(null);
|
|
|
const promoCodeOpen = ref(''); // 0折优惠码开通状态
|
|
|
-
|
|
|
+ const user = getLoginUser();
|
|
|
|
|
|
// 初始化页面
|
|
|
onMounted(async () => {
|
|
@@ -98,30 +115,36 @@ export default {
|
|
|
payParams.type = '1';
|
|
|
payParams.discount = '';
|
|
|
payParams.frpCode = 'WEIXIN_NATIVE';
|
|
|
- const user = getLoginUser();
|
|
|
- if (user) {
|
|
|
+ if (user) {
|
|
|
payParams.adminId = user.id;
|
|
|
promoCodeOpen.value = user.promoCodeOpen;
|
|
|
// console.log("promoCodeOpen",promoCodeOpen.value);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 提交搜索表单触发搜索
|
|
|
+ // 申请优惠码
|
|
|
const onSubmit = async () => {
|
|
|
- if (payParams.number === '') { showFailToast(t('discountCode.numberOfDiscountCodesPlaceholder')); return; }
|
|
|
- if (payParams.month === '') { showFailToast(t('discountCode.pleaseEnterTheValidityPeriod')); return; }
|
|
|
- if (payParams.type === '1' && payParams.discount === '') { showFailToast(t('discountCode.deductionPricePlaceholder')); return; }
|
|
|
- if (payParams.type === '0' && payParams.discount === '') { showFailToast(t('discountCode.pleaseEnterDiscount')); return; }
|
|
|
- if (parseInt(payParams.number) > 200) { showFailToast(t('discountCode.theNumberOfDiscountCodesCannotExceed')); return; }
|
|
|
- if (parseInt(payParams.month) > 3) { showFailToast(t('discountCode.theValidityPeriodCannotExceedMonths')); return; }
|
|
|
- if (payParams.type === '0' && parseInt(payParams.discount) > 10) { showFailToast(t('discountCode.discountCannotBeGreaterThan')); return; }
|
|
|
+ if (payParams.addMode === '1') {
|
|
|
+ payParams.codeNum = '';
|
|
|
+ if (payParams.number === '') { showToast(t('discountCode.numberOfDiscountCodesPlaceholder')); return; }
|
|
|
+ } else {
|
|
|
+ payParams.number = "1";
|
|
|
+ if (payParams.codeNum.length != 6) { showToast(t('discountCode.codeNumPlaceholder')); return; }
|
|
|
+ }
|
|
|
+ if (payParams.month === '') { showToast(t('discountCode.pleaseEnterTheValidityPeriod')); return; }
|
|
|
+ if (payParams.type === '1' && payParams.discount === '') { showToast(t('discountCode.deductionPricePlaceholder')); return; }
|
|
|
+ if (payParams.type === '0' && payParams.discount === '') { showToast(t('discountCode.pleaseEnterDiscount')); return; }
|
|
|
+ if (parseInt(payParams.number) > 200) { showToast(t('discountCode.theNumberOfDiscountCodesCannotExceed')); return; }
|
|
|
+ if (parseInt(payParams.month) > 3) { showToast(t('discountCode.theValidityPeriodCannotExceedMonths')); return; }
|
|
|
+ if (payParams.type === '0' && parseInt(payParams.discount) > 10) { showToast(t('discountCode.discountCannotBeGreaterThan')); return; }
|
|
|
+ console.log("payParams", payParams);
|
|
|
const { data } = await addCode(Object.assign({}, payParams));
|
|
|
if (payParams.type === '0' && payParams.discount === '0' && promoCodeOpen.value != '0') {
|
|
|
- // console.log("data", data);
|
|
|
+ console.log("data", data);
|
|
|
ewmObj.value = data.data;
|
|
|
payCodeType.value = true;
|
|
|
} else {
|
|
|
- // console.log("data", data);
|
|
|
+ console.log("data", data);
|
|
|
if (data.code === '00000') {
|
|
|
showSuccessToast(t('discountCode.successfulProductionOfDiscountCode'));
|
|
|
// router.push({ path: '/discountCode' });
|
|
@@ -129,7 +152,11 @@ export default {
|
|
|
router.go(-1);
|
|
|
}, 1500);
|
|
|
} else {
|
|
|
- showFailToast(data.message);
|
|
|
+ if (data.code === 'A0002') {
|
|
|
+ showFailToast(t('discountCode.existsCode'));
|
|
|
+ } else {
|
|
|
+ showFailToast(data.message);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -138,7 +165,7 @@ export default {
|
|
|
router.go(-1);
|
|
|
}
|
|
|
// 有效天数
|
|
|
- const validDays = ref('0'+ t('discountCode.days'));
|
|
|
+ const validDays = ref('0' + t('discountCode.days'));
|
|
|
// 监听有效期,计算有效天数
|
|
|
watch(() => payParams.month, (newVal) => {
|
|
|
validDays.value = Format_calcuDecial(newVal, 30) + t('discountCode.days');
|
|
@@ -150,7 +177,8 @@ export default {
|
|
|
onSubmit,
|
|
|
payCodeClose,
|
|
|
validDays,
|
|
|
- promoCodeOpen
|
|
|
+ promoCodeOpen,
|
|
|
+ user,
|
|
|
};
|
|
|
},
|
|
|
};
|