morphone1995 4 jaren geleden
bovenliggende
commit
7506bc89e8
2 gewijzigde bestanden met toevoegingen van 263 en 118 verwijderingen
  1. 39 18
      src/components/icss/bill/AddBill.vue
  2. 224 100
      src/components/icss/bill/ConditionForm1.vue

+ 39 - 18
src/components/icss/bill/AddBill.vue

@@ -120,7 +120,7 @@ export default {
     return {
       form: {
         ruleName: '',
-        ruleType: '',
+        ruleType: 2,
         conceptType: '',
         conceptName: '',
         concept: {
@@ -156,9 +156,9 @@ export default {
           { required: true, validator: checkFrequency, trigger: 'blur' },
           { validator: checkFrequency2, trigger: 'change' }
         ],
-        conditionName: [
-          { required: true, message: '请输入条件明细', trigger: 'change' }
-        ]
+        // conditionName: [
+        //   { required: true, message: '请输入条件明细', trigger: 'change' }
+        // ]
       },
       saveDisable: false, //保存按钮禁止点击
       isEdit: false, // 是否处于编辑页面 false--新增   true--编辑
@@ -168,7 +168,7 @@ export default {
   },
   created() {
     const { isEdit, data } = this.$route.params;
-    console.log(data, '编辑页传递的data');
+    // console.log(data, '编辑页传递的data');
     if (isEdit) {
       this.isEdit = true;
       this.form.ruleName = data.ruleName;
@@ -186,7 +186,6 @@ export default {
 
   methods: {
     splitRuleName(val) {
-      // console.log(val, '======val');
       this.form.ruleName = val.name + '开单' + this.form.conceptName;
       this.form.condition.conditionLabel = val.conditionLabel;
       this.form.condition.id = val.id;
@@ -194,15 +193,17 @@ export default {
       this.form.condition.name = val.name;
     },
     changeWord(val) {
+      if (val === '') return;
       let concept = this.conceptList.find(item => (item.name = val));
       this.form.concept.conceptLabel = concept.conceptLabel;
       this.form.concept.id = concept.id;
       this.form.concept.name = concept.name;
       this.form.concept.status = concept.status;
-      // console.log(this.form.concept, '===========this.form.concept');
+      this.form.ruleName =
+        this.form.condition.name + '开单' + this.form.concept.name;
     },
     handleInput(data) {
-      console.log(data, '父组件接受的数据');
+      // console.log(data, '父组件接受的数据');
       if (data.type === 'minValue') {
         this.form.condition.minValue = data.value;
       } else if (data.type === 'maxValue') {
@@ -210,8 +211,6 @@ export default {
       } else if (data.type === 'unit') {
         this.form.condition.unit = data.value;
       }
-
-      // console.log(this.form.condition, 'this.form.condition');
     },
 
     // 获取焦点
@@ -253,6 +252,7 @@ export default {
     // 处理参数
     _getParams() {
       const { concept, condition, ruleType, ruleName } = this.form;
+      // console.log(condition, '=condition');
       let params = {
         concept: {
           conceptLabel: concept.conceptLabel,
@@ -263,8 +263,9 @@ export default {
         condition: {
           conditionLabel: condition.conditionLabel,
           id: condition.id,
-          maxValue: condition.maxValue,
-          minValue: condition.minValue,
+          maxValue: condition.maxValue === '' ? '' : +condition.maxValue,
+          minValue: condition.minValue === '' ? '' : +condition.minValue,
+          // minValue: !null && +condition.minValue,
           name: condition.name,
           range: condition.range,
           status: condition.status,
@@ -277,18 +278,29 @@ export default {
         // ruleName: 'string',
         // type: 0
       };
-      console.log(params,'params');
+      // console.log(params,'params');
       return params;
     },
 
     onSubmit() {
-      // this.$refs.subForm.$refs.form.validate(valid => {
-      //   if (valid) {
-      //     // console.log(this.$refs.subForm.$refs.form,'=========');
-      //   }
-      // });
+      let goOn = true;
+      this.$refs.subForm.$refs.form.validate(valid => {
+        if (valid) {
+          // console.log(this.$refs.subForm.$refs.form, '=========');
+        } else {
+          goOn = false;
+        }
+      });
+      this.$refs.subForm.$refs.ruleForm.validate(valid => {
+        if (valid) {
+          // console.log(this.$refs.subForm.$refs.form, '=========');
+        } else {
+          goOn = false;
+        }
+      });
       this.$refs.outForm.validate(valid => {
         if (valid) {
+          if (!goOn) return;
           this.saveDisable = true;
           let params = this._getParams();
           if (this.isEdit) {
@@ -300,6 +312,7 @@ export default {
               type: this.form.conceptType
             };
           }
+
           api.saveBillmanRecord(params).then(res => {
             if (res.data.code === '0') {
               this.$message({
@@ -322,10 +335,18 @@ export default {
                 type: 'error',
                 duration: 1000
               });
+            } else {
+              this.$message({
+                showClose: true,
+                message: res.data.msg,
+                type: 'error',
+                duration: 1000
+              });
             }
             this.saveDisable = false;
           });
         } else {
+          goOn = false;
         }
       });
     }

+ 224 - 100
src/components/icss/bill/ConditionForm1.vue

@@ -1,37 +1,17 @@
 <template>
-  <el-form :model="form" ref="form" class="sub-form" :validate-on-rule-change="false">
-    <!-- 文本类型 -->
-    <el-form-item label="条件明细" label-width="80px" v-if="ruleType==1">
-      <el-select
-        style="width:100%;minWidth: 240px"
-        v-model="form.name"
-        filterable
-        remote
-        clearable
-        :loading="showDrop"
-        loading-text="加载中..."
-        @change="changeWord"
-        @visible-change="handleVisible"
-        placeholder="搜索开单项目"
-        :remote-method="searchCondition"
-        reserve-keyword
-        ref="conditionListName"
+  <el-row>
+    <el-col :span="8">
+      <el-form
+        :model="form"
+        ref="form"
+        class="sub-form"
+        :validate-on-rule-change="false"
+        :rules="rules"
       >
-        <el-option
-          v-for="item in conditionList"
-          :key="item.id + item.name"
-          :label="item.name"
-          :value="item.name"
-          :title="item.name"
-        ></el-option>
-      </el-select>
-    </el-form-item>
-
-    <el-row v-if="ruleType==2">
-      <el-col :span="8">
-        <el-form-item label="条件明细" label-width="80px" v-if="ruleType==2">
+        <!-- 文本类型 -->
+        <el-form-item label="条件明细" label-width="80px" v-if="ruleType==1" prop="condition">
           <el-select
-            style="width:100%"
+            style="width:100%;minWidth: 240px"
             v-model="form.name"
             filterable
             remote
@@ -54,34 +34,76 @@
             ></el-option>
           </el-select>
         </el-form-item>
-        <el-form-item label label-width="0px" v-if="ruleType==2&&isOpen">
-          <span class="font">1</span>
-        </el-form-item>
-      </el-col>
 
-      <el-col :span="16" v-for="(item,index) in ruleForm" :key="index">
+        <el-row v-if="ruleType==2">
+          <el-form-item label="条件明细" label-width="80px" v-if="ruleType==2" prop="condition">
+            <el-select
+              style="width:100%"
+              v-model="form.name"
+              filterable
+              remote
+              clearable
+              :loading="showDrop"
+              loading-text="加载中..."
+              @change="changeWord"
+              @visible-change="handleVisible"
+              placeholder="搜索开单项目"
+              :remote-method="searchCondition"
+              reserve-keyword
+              ref="conditionListName"
+            >
+              <el-option
+                v-for="item in conditionList"
+                :key="item.id + item.name"
+                :label="item.name"
+                :value="item.name"
+                :title="item.name"
+              ></el-option>
+            </el-select>
+          </el-form-item>
+          <el-form-item label label-width="0px" v-if="ruleType==2&&isOpen">
+            <span class="font">1</span>
+          </el-form-item>
+        </el-row>
+      </el-form>
+    </el-col>
+    <el-form :rules="rules1" ref="ruleForm" :model="ruleForm">
+      <el-col :span="16" v-for="(item,index) in ruleForm.ruleForm" :key="index">
         <el-row>
           <el-col :span="8">
-            <el-select v-model="item.compare" placeholder="请输入比较" style="width: 100%">
-              <el-option label="大于" value=">"></el-option>
-              <el-option label="大于等于" value=">="></el-option>
-              <el-option label="小于" value="<"></el-option>
-              <el-option label="小于等于" value="<="></el-option>
-            </el-select>
+            <el-form-item label-width="0px" prop="compare">
+              <el-select
+                v-model="item.compare"
+                placeholder="请输入比较"
+                style="width: 100%"
+                ref="compare"
+              >
+                <el-option label="大于" value=">"></el-option>
+                <el-option label="大于等于" value=">="></el-option>
+                <el-option label="小于" value="<"></el-option>
+                <el-option label="小于等于" value="<="></el-option>
+              </el-select>
+            </el-form-item>
           </el-col>
           <el-col :span="8">
-            <el-form-item label-width="0px">
+            <el-form-item label-width="0px" :prop="index===0?'amount0':'amount1'">
               <el-input
                 v-model="item.value"
                 placeholder="填写数值"
                 @blur="handleValue('value',index)"
                 :disabled="item.compare ==''"
+                :ref="index===0?'amount0':'amount1'"
               ></el-input>
             </el-form-item>
           </el-col>
           <el-col :span="8">
-            <el-form-item label-width="0px">
-              <el-input v-model="item.unit" placeholder="填写单位" @blur="handleValue('unit',index)"></el-input>
+            <el-form-item label-width="0px" :prop="index===0?'unit0':'unit1'">
+              <el-input
+                v-model="item.unit"
+                placeholder="填写单位"
+                @blur="handleValue('unit',index)"
+                :ref="index===0?'unit0':'unit1'"
+              ></el-input>
             </el-form-item>
           </el-col>
           <el-col :span="1" class="operation">
@@ -92,8 +114,8 @@
           </el-col>
         </el-row>
       </el-col>
-    </el-row>
-  </el-form>
+    </el-form>
+  </el-row>
 </template>
 
 <script>
@@ -102,6 +124,46 @@ export default {
   name: 'ConditionForm',
   props: ['data', 'type', 'conceptName', 'ruleType'],
   data() {
+    let checkFrequency = (rule, value, callback) => {
+      let conditionListName = this.$refs.conditionListName.value;
+      if (conditionListName === '') {
+        callback('请输入开单项目');
+      } else {
+        callback();
+      }
+    };
+    let checkFrequency1 = (rule, value, callback) => {
+      let amount0 = this.$refs['amount0'][0].value;
+      if (amount0 === '') {
+        callback('请输入数值');
+      } else {
+        callback();
+      }
+    };
+    let checkFrequency2 = (rule, value, callback) => {
+      let amount1 = this.$refs['amount1'][0].value;
+      if (amount1 === '') {
+        callback('请输入数值');
+      } else {
+        callback();
+      }
+    };
+    let checkFrequency3 = (rule, value, callback) => {
+      let unit0 = this.$refs['unit0'][0].value;
+      if (unit0 === '') {
+        callback('请输入单位');
+      } else {
+        callback();
+      }
+    };
+    let checkFrequency4 = (rule, value, callback) => {
+      let unit1 = this.$refs['unit1'][0].value;
+      if (unit1 === '') {
+        callback('请输入单位');
+      } else {
+        callback();
+      }
+    };
     return {
       showDrop: false,
       conditionList: [],
@@ -115,18 +177,59 @@ export default {
         status: '',
         unit: ''
       },
-      ruleForm: [
-        {
-          compare: '',
-          value: '',
-          unit: ''
-        }
-      ]
+      ruleForm: {
+        ruleForm: [
+          {
+            compare: '',
+            value: '',
+            unit: ''
+          }
+        ]
+      },
+      rules: {
+        condition: [
+          {
+            required: true,
+            validator: checkFrequency,
+            trigger: ['blur', 'change']
+          }
+        ]
+      },
+      rules1: {
+        amount0: [
+          {
+            required: true,
+            validator: checkFrequency1,
+            trigger: 'change'
+          }
+        ],
+        amount1: [
+          {
+            required: true,
+            validator: checkFrequency2,
+            trigger: 'change'
+          }
+        ],
+        unit0: [
+          {
+            required: true,
+            validator: checkFrequency3,
+            trigger: 'change'
+          }
+        ],
+        unit1: [
+          {
+            required: true,
+            validator: checkFrequency4,
+            trigger: 'change'
+          }
+        ]
+      }
     };
   },
   computed: {
     isOpen() {
-      if (this.ruleForm.length === 2) {
+      if (this.ruleForm.ruleForm.length === 2) {
         return true;
       } else {
         return false;
@@ -134,52 +237,72 @@ export default {
     }
   },
   created() {
-    this.form = { ...this.data };
-    const { maxValue, minValue, unit } = this.form;
-    if (minValue !== null && maxValue !== null) {
-      this.ruleForm = [
-        {
-          compare: '>=',
-          value: minValue,
-          unit: unit
-        },
-        {
-          compare: '<=',
-          value: maxValue,
-          unit: unit
-        }
-      ];
-    } else if (minValue === null && maxValue !== null) {
-      this.ruleForm = [
-        {
-          compare: '<=',
-          value: maxValue,
-          unit: unit
-        }
-      ];
-    } else if (minValue !== null && maxValue === null) {
-      this.ruleForm = [
-        {
-          compare: '>=',
-          value: minValue,
-          unit: unit
-        }
-      ];
-    } else {
-      this.ruleForm = [
-        {
-          compare: '',
-          value: '',
-          unit: ''
-        }
-      ];
-    }
+    this._initData();
   },
+  mounted() {},
   methods: {
+    _initData() {
+      this.form = { ...this.data };
+      const { maxValue, minValue, unit } = this.form;
+      console.log(maxValue, 'maxValue', minValue, 'minValue');
+      if (minValue === null && maxValue === null) {
+        this.ruleForm.ruleForm = [
+          {
+            compare: '',
+            value: '',
+            unit: ''
+          }
+        ];
+      } else if (minValue === null && maxValue !== null) {
+        this.ruleForm.ruleForm = [
+          {
+            compare: '<=',
+            value: maxValue,
+            unit: unit
+          }
+        ];
+      } else if (minValue !== null && maxValue === null) {
+        this.ruleForm.ruleForm = [
+          {
+            compare: '>=',
+            value: minValue,
+            unit: unit
+          }
+        ];
+      } else if (minValue !== '' && maxValue !== '') {
+        this.ruleForm.ruleForm = [
+          {
+            compare: '>=',
+            value: minValue,
+            unit: unit
+          },
+          {
+            compare: '<=',
+            value: maxValue,
+            unit: unit
+          }
+        ];
+      } else {
+        this.ruleForm.ruleForm = [
+          {
+            compare: '',
+            value: '',
+            unit: ''
+          }
+        ];
+      }
+    },
     changeWord(val) {
+      if (val === '') return;
       let condition = this.conditionList.find(item => item.name == val);
       this.$emit('split', condition);
     },
+
+    // handleSelectChange(val) {
+    //   console.log(val, '===========');
+    //   this.$refs.form.clearValidate();
+    //   this.rules.compare = this.rules.compare.slice(0, 1);
+    // },
     handleVisible(flag) {
       if (!flag) {
         this.conceptList = [];
@@ -208,7 +331,7 @@ export default {
     },
     // 编辑规则
     handleValue(from, idx) {
-      let item = this.ruleForm.find((item, index) => index == idx);
+      let item = this.ruleForm.ruleForm.find((item, index) => index == idx);
       if ((item.compare == '>' || item.compare == '>=') && from == 'value') {
         this.form.minValue = item.value;
         this.$emit('handleInput', {
@@ -235,7 +358,8 @@ export default {
 
     // 新增表单
     addForm() {
-      this.ruleForm.push({
+      if (this.ruleForm.ruleForm.length === 2) return;
+      this.ruleForm.ruleForm.push({
         compare: '',
         value: '',
         unit: ''
@@ -243,8 +367,8 @@ export default {
     },
     // 减少表单
     cutForm(i) {
-      let item = this.ruleForm.find((item, index) => index == i);
-      console.log(item,'==========');
+      let item = this.ruleForm.ruleForm.find((item, index) => index == i);
+      // console.log(item, '==========');
       if (item.compare == '>' || item.compare == '>=') {
         this.form.minValue = '';
         this.$emit('handleInput', {
@@ -258,7 +382,7 @@ export default {
           value: this.form.maxValue
         });
       }
-      this.ruleForm.splice(i, 1);
+      this.ruleForm.ruleForm.splice(i, 1);
     }
   }
 };