zuy пре 2 година
родитељ
комит
4879b95457

+ 83 - 49
admin-web/src/views/admin/activity/dialog.vue

@@ -58,7 +58,7 @@
               class="wd200">
           </ext-date-picker>
         </el-form-item>
-        <el-form-item label="优惠方式"  prop="discountType">
+        <el-form-item label="优惠方式" prop="discountType">
           <ext-d-select
               v-model="state.ruleForm.discountType"
               placeholder="优惠方式"
@@ -95,15 +95,15 @@
               class="wd200">
           </el-input>
         </el-form-item>
-        <el-form-item label="活动状态" prop="status">
-          <ext-d-select
-              v-model="state.ruleForm.status"
-              placeholder="活动状态"
-              type="Activity.status"
-              clearable
-              class="wd200 ">
-          </ext-d-select>
-        </el-form-item>
+        <!--        <el-form-item label="活动状态" prop="status">
+                  <ext-d-select
+                      v-model="state.ruleForm.status"
+                      placeholder="活动状态"
+                      type="Activity.status"
+                      clearable
+                      class="wd200 ">
+                  </ext-d-select>
+                </el-form-item>-->
         <el-form-item label="备注" prop="remark" class="w100">
           <el-input
               maxlength="500"
@@ -169,7 +169,7 @@
 
           <el-row :gutter="20">
             <el-col :span="12">
-              <el-form-item label="最小充值金额" prop="amountMin" >
+              <el-form-item label="最小充值金额(元)" prop="amountMin">
                 <el-input-number
                     controls-position="right"
                     v-model.trim="rights.amountMin"
@@ -181,7 +181,7 @@
               </el-form-item>
             </el-col>
             <el-col :span="12">
-              <el-form-item label="最大充值金额" prop="amountMin" >
+              <el-form-item label="最大充值金额(元)" prop="amountMin">
                 <el-input-number
                     controls-position="right"
                     v-model.trim="rights.amountMax"
@@ -196,16 +196,32 @@
           </el-row>
 
 
+          <el-row :gutter="20">
+            <el-col :span="12">
+              <el-form-item label="折扣" prop="amountMin">
+                <el-input-number
+                    :controls="false"
+                    v-model.trim="rights.discount"
+                    placeholder="折扣:100代表无折扣,75代表75折"
+                    clearable
+                    class="wd200">
+                </el-input-number>
+              </el-form-item>
+            </el-col>
+            <el-col :span="12">
+              <el-form-item label="有效期(天)" prop="validity">
+                <el-input-number
+                    :min="1"
+                    :controls="false"
+                    v-model.trim="rights.validity"
+                    placeholder="有效天数"
+                    clearable
+                    class="wd200">
+                </el-input-number>
+              </el-form-item>
+            </el-col>
+          </el-row>
 
-          <el-form-item label="折扣" prop="amountMin" >
-            <el-input
-                type="number"
-                v-model.trim="rights.discount"
-                placeholder="折扣:100代表无折扣,75代表75折"
-                clearable
-                class="wd200">
-            </el-input>
-          </el-form-item>
         </el-card>
 
       </el-form>
@@ -213,7 +229,7 @@
       <template #footer>
         <div class="dialog-footer">
           <el-button @click="onCancel" size="default">取 消</el-button>
-          <el-button v-if="state.action==='add'||state.action==='edit'"  :loading="state.btnLoading" type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
+          <el-button v-if="state.action==='add'||state.action==='edit'" :loading="state.btnLoading" type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
         </div>
       </template>
     </el-dialog>
@@ -234,10 +250,10 @@ const emit = defineEmits(['refresh']);
 const formRef = ref();
 //定义初始变量,重置使用
 const initState = () => ({
-  action:'',
+  action: '',
   ruleForm: {
     id: 0,
-    rechargeRightsList:[] as Array<any>
+    rechargeRightsList: [] as Array<any>
   },
   btnLoading: false,
   dialog: {
@@ -247,15 +263,15 @@ const initState = () => ({
     submitTxt: '',
   },
   rules: {
-    name:[u.validator.required],
-    startTime:[u.validator.required],
-    endTime:[u.validator.required],
-    discountType:[u.validator.required],
-    targetUsers:[u.validator.required],
-    applyStation:[u.validator.required],
-    allowStacke:[u.validator.required],
-    quantity:[u.validator.required],
-    status:[u.validator.required],
+    name: [u.validator.required],
+    startTime: [u.validator.required],
+    endTime: [u.validator.required],
+    discountType: [u.validator.required],
+    targetUsers: [u.validator.required],
+    applyStation: [u.validator.required],
+    allowStacke: [u.validator.required],
+    quantity: [u.validator.required],
+    status: [u.validator.required],
   },
 })
 
@@ -287,17 +303,28 @@ const onCancel = () => {
 // 提交
 const onSubmit = () => {
   let rechargeRightsList = state.ruleForm.rechargeRightsList;
-  if(!u.isEmptyOrNull(rechargeRightsList)){
-    for (let i = 0; i < rechargeRightsList.length; i++){
+  if (!u.isEmptyOrNull(rechargeRightsList)) {
+    for (let i = 0; i < rechargeRightsList.length; i++) {
       const item: any = rechargeRightsList[i];
-      if(item.amountMin>item.amountMax){
-        Msg.message(`权益最小充值金额不能大于最大充值金额`,'error')
+      if (item.amountMax <=0) {
+        Msg.message(`权益最大充值金额不能小于0`, 'error')
+        return false;
+      }
+
+      if (item.amountMin > item.amountMax) {
+        Msg.message(`权益最小充值金额不能大于最大充值金额`, 'error')
         return false;
       }
     }
+
+    state.ruleForm.rechargeRightsList.forEach((rights: any) => {
+      rights.amountMin = rights.amountMin * 100;
+      rights.amountMax = rights.amountMax * 100;
+    })
   }
-  formRef.value.validate((valid:boolean) => {
-    if(valid){
+
+  formRef.value.validate((valid: boolean) => {
+    if (valid) {
       state.btnLoading = true;
       const url = state.ruleForm.id > 0 ? "activity/modify" : "activity/add"
       $body(url, state.ruleForm).then(() => {
@@ -321,30 +348,37 @@ const handleFormChange = (formData: any) => {
 // 初始化表格数据
 const loadData = (id: number) => {
   $get(`activity/${id}`).then((res: any) => {
+    if (res && res.rechargeRightsList) {
+      res.rechargeRightsList.forEach((rights: any) => {
+        rights.amountMin = rights.amountMin / 100;
+        rights.amountMax = rights.amountMax / 100;
+      })
+    }
     state.ruleForm = res;
-    state.ruleForm.rechargeRightsList = res.rechargeRightsList||[]
+    state.ruleForm.rechargeRightsList = res.rechargeRightsList || []
   })
 }
 
-const handleStationChange = (applyStation:number)=>{
+const handleStationChange = (applyStation: number) => {
   console.log(applyStation)
-  if(applyStation==0){
+  if (applyStation == 0) {
     // state.ruleForm.stationIds = [];
   }
 
 }
 
-const handleAddRightsItem = ()=>{
+const handleAddRightsItem = () => {
   state.ruleForm.rechargeRightsList.unshift({
-    rightsDesc:'',
-    amountMin:0,
-    amountMax:0,
-    discount:100,
+    rightsDesc: '',
+    amountMin: 0,
+    amountMax: 0,
+    discount: 100,
+    validity: 0
   })
 }
 
-const handleRemoveRightsItem= (idx:number)=>{
-  state.ruleForm.rechargeRightsList.splice(idx,1)
+const handleRemoveRightsItem = (idx: number) => {
+  state.ruleForm.rechargeRightsList.splice(idx, 1)
 }
 
 // 暴露变量

+ 1 - 1
admin-web/src/views/admin/activity/index.vue

@@ -132,7 +132,7 @@
             </template>
             <template v-else-if="field.prop==='action'">
               <el-button v-auth="'banner.list'" size="small" plain type="success" @click="onRowClick('view',row)">查看</el-button>
-              <el-button v-auth="'banner.modify'" size="small" plain type="danger" @click="onRowTerminal(row)">终止</el-button>
+              <el-button v-auth="'banner.modify'" v-if="row.status==0||row.status==1"  size="small" plain type="danger" @click="onRowTerminal(row)">终止</el-button>
             </template>
             <template v-else>
               <div>{{ row[field.prop] }}</div>