فهرست منبع

服务管理 mixin文件

DESKTOP-O04BTUJ\muzen 3 سال پیش
والد
کامیت
dc56fd8c81
1فایلهای تغییر یافته به همراه50 افزوده شده و 16 حذف شده
  1. 50 16
      src/views/service/mixin/index.js

+ 50 - 16
src/views/service/mixin/index.js

@@ -14,7 +14,7 @@ const mixin = {
         value: 1,
         label: '上架'
       }, {
-        value: 2,
+        value: 4,
         label: '下架'
       }]
     }
@@ -142,9 +142,37 @@ import {
 } from '@/api/service/musicPackage'
 const detailMixin = {
   data() {
+    let checkedPrice = (rule, value, callback) => {
+      if (Number(value) > 500) {
+        callback(new Error('原价不得超过500'))
+      } else {
+        if (this.form.discount !== undefined) {
+          this.$refs.form.validateField('discount')
+        }
+        callback()
+      }
+    }
+    let checkedDiscount = (rule, value, callback) => {
+      if (Number(value) > Number(this.form.price)) {
+        callback(new Error('活动价不得大于原价!'))
+      } else {
+        callback()
+      }
+    }
     return {
       // 关联设备
-      deviceIds: []
+      deviceIds: [],
+      // 校验
+      rules: {
+        price: [{
+          validator: checkedPrice,
+          trigger: 'blur'
+        }],
+        discount: [{
+          validator: checkedDiscount,
+          trigger: 'blur'
+        }]
+      }
     }
   },
   watch: {
@@ -170,21 +198,27 @@ const detailMixin = {
     },
     // 提交
     getSubmit() {
-      if (this.form.id) {
-        edit(this.form).then(res => {
-          if (res.code === 0) {
-            this.$message.success('修改成功!')
-            this.cancel()
-          }
-        })
-      } else {
-        create(this.form).then(res => {
-          if (res.code === 0) {
-            this.$message.success('新增成功!')
-            this.cancel()
+      this.$refs.form.validate((valid) => {
+        if (valid) {
+          if (this.form.id) {
+            edit(this.form).then(res => {
+              if (res.code === 0) {
+                this.$message.success('修改成功!')
+                this.cancel()
+              }
+            })
+          } else {
+            create(this.form).then(res => {
+              if (res.code === 0) {
+                this.$message.success('新增成功!')
+                this.cancel()
+              }
+            })
           }
-        })
-      }
+        } else {
+          return false
+        }
+      })
     }
   }
 }