payCode.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <!-- 购买优惠码 -->
  3. <div class="discountCodePage flex-col">
  4. <s-header :name="$t('discountCode.applDiscCode')" :noback="false"></s-header>
  5. <div class="discountCodeBox flex-col">
  6. <van-form @submit="onSubmit">
  7. <van-field v-model="number" name="number" :label="$t('discountCode.numberOfDiscountCodesLabel')"
  8. :placeholder="$t('discountCode.numberOfDiscountCodesPlaceholder')">
  9. <template #button>
  10. <span>{{ $t('discountCode.aSingleGenerationCannotExceed') }}</span>
  11. </template>
  12. </van-field>
  13. <van-field v-model="month" name="number" :label="$t('discountCode.termOfValidity')"
  14. :placeholder="$t('discountCode.pleaseEnterTheValidityPeriod')">
  15. <template #button>
  16. <span>{{ $t('discountCode.Months') }}<span>{{ $t('discountCode.noMoreThanMonths') }}</span></span>
  17. </template>
  18. </van-field>
  19. <van-field readonly v-model="validDays" :label="$t('discountCode.validDays')" placeholder="" />
  20. <div class="van-cell van-field">
  21. <div class="van-cell__title van-field__label"><span>{{ $t('discountCode.type') }}</span></div>
  22. <div class="van-cell__value van-field__value radioBox">
  23. <van-radio-group v-model="type" direction="horizontal">
  24. <van-radio name="1" icon-size="18px">{{ $t('discountCode.deductionRoll') }}</van-radio>
  25. <van-radio name="0" icon-size="18px">{{ $t('discountCode.discount2') }}</van-radio>
  26. </van-radio-group>
  27. </div>
  28. </div>
  29. <van-field v-if='type === "1"' v-model="discount" name="number" :label="$t('discountCode.deductionPriceLabdel')"
  30. :placeholder="$t('discountCode.deductionPricePlaceholder')">
  31. </van-field>
  32. <van-field v-if='type === "0"' v-model="discount" name="number" :label="$t('discountCode.discount')"
  33. :placeholder="$t('discountCode.enterNumber')">
  34. <template #button>
  35. <span>0-10</span>
  36. </template>
  37. </van-field>
  38. <div class="van-cell van-field" v-if='type === "0" && discount === "0"'>
  39. <div class="van-cell__title van-field__label"><span>{{ $t('discountCode.paymentMethod') }}</span></div>
  40. <div class="van-cell__value van-field__value radioBox">
  41. <van-radio-group v-model="frpCode" direction="horizontal">
  42. <van-radio name="WEIXIN_NATIVE" icon-size="18px">{{ $t('discountCode.weChat') }}</van-radio>
  43. <van-radio name="ALIPAY_NATIVE" icon-size="18px">{{ $t('discountCode.alipay') }}</van-radio>
  44. </van-radio-group>
  45. </div>
  46. </div>
  47. <van-row justify="space-around" style="padding: 1em;">
  48. <van-button span="5" round type="primary" style="height: 2em; padding: 0 2em;"
  49. native-type="submit">{{ $t('discountCode.apply') }}</van-button>
  50. </van-row>
  51. </van-form>
  52. </div>
  53. <van-popup v-model:show="payCodeType" round class="payCodePopup" @close="payCodeClose">
  54. <div style="text-align: center; font-size: 14px; padding: 1em; line-height: 1.8;">
  55. <div>price: {{ ewmObj.price || '' }}</div>
  56. <div>sn: {{ ewmObj.sn || '' }}</div>
  57. <img :src="ewmObj.image" />
  58. </div>
  59. </van-popup>
  60. </div>
  61. </template>
  62. <script>
  63. import sHeader from "@/components/SimpleHeader";
  64. import { onMounted, reactive, toRefs, ref, watch } from "vue";
  65. import { getLoginUser, Format_calcuDecial, styleUrl } from "@/common/js/utils";
  66. import { Toast } from "vant";
  67. import { addCode } from "@/service/discountCode";
  68. import { useRouter } from "vue-router";
  69. import { useI18n } from "vue-i18n";
  70. export default {
  71. name: "payCode",
  72. components: { sHeader },
  73. setup() {
  74. // 引入语言
  75. const { t } = useI18n();
  76. const router = useRouter();
  77. let payParams = reactive({
  78. number: '', // 优惠码个数
  79. month: '', // 有效期
  80. type: '1', // 优惠卷类型
  81. discount: '', // 折扣
  82. frpCode: 'WEIXIN_NATIVE', // 支付方式
  83. });
  84. const payCodeType = ref(false);
  85. const ewmObj = ref(null);
  86. // 初始化页面
  87. onMounted(async () => {
  88. //加载样式
  89. styleUrl('discountCode');
  90. payCodeType.value = false;
  91. payParams.number = '';
  92. payParams.month = '';
  93. payParams.type = '1';
  94. payParams.discount = '';
  95. payParams.frpCode = 'WEIXIN_NATIVE';
  96. const user = getLoginUser();
  97. if (user) { payParams.adminId = user.id; }
  98. });
  99. // 提交搜索表单触发搜索
  100. const onSubmit = async () => {
  101. if (payParams.number === '') { Toast.fail(t('discountCode.numberOfDiscountCodesPlaceholder')); return; }
  102. if (payParams.month === '') { Toast.fail(t('discountCode.pleaseEnterTheValidityPeriod')); return; }
  103. if (payParams.type === '1' && payParams.discount === '') { Toast.fail(t('discountCode.deductionPricePlaceholder')); return; }
  104. if (payParams.type === '0' && payParams.discount === '') { Toast.fail(t('discountCode.pleaseEnterDiscount')); return; }
  105. if (parseInt(payParams.number) > 200) { Toast.fail(t('discountCode.theNumberOfDiscountCodesCannotExceed')); return; }
  106. if (parseInt(payParams.month) > 3) { Toast.fail(t('discountCode.theValidityPeriodCannotExceedMonths')); return; }
  107. if (payParams.type === '0' && parseInt(payParams.discount) > 10) { Toast.fail(t('discountCode.discountCannotBeGreaterThan')); return; }
  108. const { data } = await addCode(Object.assign({}, payParams));
  109. if (payParams.type === '0') {
  110. ewmObj.value = data.data;
  111. payCodeType.value = true;
  112. } else {
  113. if (data.code === '00000') {
  114. Toast.success(t('discountCode.successfulProductionOfDiscountCode'));
  115. router.push({ path: '/discountCode' });
  116. } else {
  117. Toast.fail(data.message);
  118. }
  119. }
  120. }
  121. const payCodeClose = () => { router.push({ path: '/discountCode' }); }
  122. // 有效天数
  123. const validDays = ref('0天');
  124. // 监听有效期,计算有效天数
  125. watch(() => payParams.month, (newVal) => {
  126. validDays.value = Format_calcuDecial(newVal, 30) + '天';
  127. }, { immediate: true, deep: true });
  128. return {
  129. ...toRefs(payParams),
  130. payCodeType,
  131. ewmObj,
  132. onSubmit,
  133. payCodeClose,
  134. validDays,
  135. };
  136. },
  137. };
  138. </script>
  139. <style lang="less" scoped>
  140. @import "../../common/style/common.less";
  141. </style>