Browse Source

物料基础档案详情界面效期管理否,有效期和近效期预警天数还是必填

002390 1 year ago
parent
commit
6aa76c534b
2 changed files with 120 additions and 22 deletions
  1. 99 21
      src/views/material/basicFile/details.vue
  2. 21 1
      src/views/material/basicFile/init/index.js

+ 99 - 21
src/views/material/basicFile/details.vue

@@ -142,7 +142,12 @@
                       <template v-if="f.show">
 
                         <!-- 多选框 -->
-                        <el-form-item v-if="f.attribute == 'checkbox'" style="text-align: left;" :prop="f.prop">
+                        <el-form-item 
+                          v-if="f.attribute == 'checkbox'" 
+                          style="text-align: left;" 
+                          :prop="f.prop"
+                          :key="f.required"
+                        >
 
                           <el-checkbox
                             :label="f.name" name="type"
@@ -159,6 +164,7 @@
                         <el-form-item v-else-if="f.attribute == 'select'"
                           :id="(updateButtonGroup && f.apiUrl) ? 'selected' : ''"
                           :prop="f.apiUrl ? `${f.prop}Name` : f.prop"
+                          :key="f.required"
                           :rules="[{ required: f.required ,message: `请选择${f.name}`, trigger: 'change' }]"
                         >
                           <template slot="label">
@@ -210,7 +216,7 @@
                         </el-form-item>
 
                         <!--attribute 文本 数字 文本域 为null -->
-                        <el-form-item v-else :prop="f.prop">
+                        <el-form-item v-else :prop="f.prop" :key="f.required">
                           <template slot="label">
                             <el-tooltip class="item" effect="dark" placement="top-start" :disabled="f.name.length < 10">
                               <span>{{ f.name }}</span>
@@ -220,8 +226,10 @@
                             </el-tooltip>
                           </template>
 
-                          <el-input size="mini" v-model="basicData.value[f.prop]" :type="f.attribute || 'text'"
-                                    :readonly="handleJudge(f)">
+                          <el-input size="mini" 
+                            v-model="basicData.value[f.prop]" 
+                            :type="f.attribute || 'text'"
+                            :readonly="handleJudge(f)">
                           </el-input>
                         </el-form-item>
 
@@ -261,6 +269,7 @@
                     <el-form v-if="activeViceTab == 'material_medcine'" 
                       :inline="true" 
                       label-position="right"
+                      ref="medcineRef"
                       :model="medcineData.value" 
                       class="md-vice-content"
                       :rules="medcineRules"
@@ -649,7 +658,7 @@
   import materialApi from '@/api/material/basic';
   import {getDicts as getDicts} from '@/api/system/dict/data'
   import arrayUtils from '../tools/arrayUtils';
-  import { initRules} from './init/index';
+  import { initRules, initParams} from './init/index';
   import { getDetail } from '@/api/classify/basic';
 
   export default {
@@ -816,23 +825,33 @@
           return !(this.updateButtonGroup && attribute.edit && this.basicData.value['isInventoryStatus'] == '0');
         }
           // 效期管理(expiryDateManagerment):控制一下几个是否可编辑
-        // expiryUnitId 效期单位  usefulLife 有效期 usefulLifeUnitId 有效期至单位  "recentWarningPeriod" 近效期预警天数
+        // expiryUnitId 效期单位  usefulLife 有效期 usefulLifeUnitId 有效期至单位  
 
         else if (attribute.prop == 'expiryUnitId'
           || attribute.prop == 'usefulLife'
           || attribute.prop == 'usefulLifeUnitId'
-          || attribute.prop == 'recentWarningPeriod'
+          // || attribute.prop == 'recentWarningPeriod'
         ) {
           if (this.basicData.value['expiryDateManagerment'] == '2') {
 
             this.basicData.value['expiryUnitId'] = '';
             this.basicData.value['usefulLife'] = '';
             this.basicData.value['usefulLifeUnitId'] = '';
-            this.basicData.value['recentWarningPeriod'] = '';
+            // this.basicData.value['recentWarningPeriod'] = '';
           }
 
           return !(this.updateButtonGroup && attribute.edit && this.basicData.value['expiryDateManagerment'] == '0');
         }
+        //  近效期管理:nearOnsetManagerment 控制   "recentWarningPeriod" 近效期预警天数
+        else if(attribute.prop == 'recentWarningPeriod'){
+
+          if (this.basicData.value['nearOnsetManagerment'] == '2') {
+            this.basicData.value['recentWarningPeriod'] = '';
+          }
+
+          return !(this.updateButtonGroup && attribute.edit && this.basicData.value['nearOnsetManagerment'] == '0');
+
+        }
         // 默认采购组织:purchasingOrganization  业务部门:businessDepartment
         else if (attribute.prop == 'businessDepartment') {
           return !(this.updateButtonGroup && attribute.edit && this.basicData.value['purchasingOrganization']);
@@ -1026,7 +1045,7 @@
           let {code, data} = res;
           if (code == 200) {
 
-            _this.basicData.value = data.data;
+            _this.basicData.value ={... _this.basicData.value,...data.data};
 
             for (const key in data.data) {
               _this.basicData.value[key] = (typeof data.data[key] === 'number') ? String(data.data[key]) : data.data[key];
@@ -1446,49 +1465,49 @@
           // 基本信息
           case 'material':
             this.getTagList('material', (form) => {
-              this.basicData.form = form;
+              this.basicData.form = [...form];
               this.getMaterialDetails(this.materialId, 'material');
             })
             break;
           // 财物信息
           case 'material_finance':
             this.getTagList('material_finance', (form) => {
-              this.mainMsg.form = form;
+              this.mainMsg.form = [...form];
               this.getFinanceList(this.materialId);
             });
             break;
           // 利润中心信息
           case 'profit_center':
             this.getTagList('profit_center', (form) => {
-              this.mainMsg.form = form;
+              this.mainMsg.form = [...form];
               this.getCenterList(this.materialId);
             });
             break;
           // 采购信息
           case 'material_purchase':
             this.getTagList('material_purchase', (form) => {
-              this.mainMsg.form = form;
+              this.mainMsg.form = [...form];
               this.getPurchaseList(this.materialId);
             });
             break;
           // 库存信息
           case 'material_inventory':
             this.getTagList('material_inventory', (form) => {
-              this.mainMsg.form = form;
+              this.mainMsg.form = [...form];
               this.getInventoryList(this.materialId);
             });
             break;
           // 计划信息
           case 'material_plan':
             this.getTagList('material_plan', (form) => {
-              this.mainMsg.form = form;
+              this.mainMsg.form = [...form];
               this.getPlanList(this.materialId);
             });
             break;
           // 成本信息
           case 'material_cost':
             this.getTagList('material_cost', (form) => {
-              this.mainMsg.form = form;
+              this.mainMsg.form = [...form];
               this.getCostList(this.materialId);
             });
             break;
@@ -1525,6 +1544,9 @@
       // 刷新
       handleRefresh() {
         console.log('刷新');
+
+        this.$refs.basicMessageRef.clearValidate();
+        this.$refs.medcineRef.clearValidate();
         this.handleRest();
       },
       // 过滤
@@ -1814,7 +1836,7 @@
         console.log('更新导入');
       },
       // 确认弹窗操作
-      handleComfirmOption() {
+      async handleComfirmOption() {
         console.log('确认弹窗操作');
 
         this.optionDialog.show = false;
@@ -1822,7 +1844,12 @@
         // 取消基本信息修改
         if (this.updateButtonGroup) {
           this.updateButtonGroup = false;
-          this.handleRest();
+          // this.handleRest();
+          await this.getMaterialDetails(this.materialId, 'material');
+       
+          await this.getMedcineDetails(this.materialId, 'material_medcine');
+          this.$refs.basicMessageRef.clearValidate();
+          this.$refs.medcineRef.clearValidate();
 
         }
 
@@ -2096,14 +2123,37 @@
         })
       },
 
+      judgeIsRequriedByProps(message){
+        // condiition:条件,tergetNames:目标porps数组,formName:表单,formRef:表单ref名,
+
+        this[message.formName].form.forEach(formItem => {
+
+          let target = message.tergetNames.filter(t => t === formItem.prop);
+
+          if(target && target.length){
+
+            (formItem.required = message.condiition ? false : true);
+          }
+
+        })
+
+        this.rules = initRules(this[message.formName].form);
+
+        this.$nextTick( ()=> {
+
+          message.condiition && this.$refs[message.formRef].clearValidate(message.tergetNames);
+        })
+
+      },
 
       // 重新加载
       async handleRest() {
         this.loading = true;
         // 基本信息
         await this.getTagList('material', (form) => {
-          this.basicData.form = form;
+          this.basicData.form = [...form];
           this.rules = initRules(form);
+          this.basicData.value = initParams(this.basicData.form,'prop')
           this.getMaterialDetails(this.materialId, 'material');
         })
         // 医疗行业
@@ -2112,12 +2162,13 @@
             this.medcineData.value[item.prop] = ''
           })
           this.medcineData.form = form;
+          this.medcineData.value = initParams(this.medcineData.form,'prop')
           this.medcineRules = initRules(form);
           this.getMedcineDetails(this.materialId, 'material_medcine');
         })
 
       },
-
+      
     },
 
     watch: {
@@ -2156,7 +2207,7 @@
 
           this.basicData.form = this.basicData.form.map(formItem => {
 
-            if (formItem.prop === "businessLine") {
+            if (formItem.prop === "businessLine" && nVal) {
 
               if ( nVal.includes('介入耗材&5') || nVal.includes('骨科耗材&2') ||
                   nVal.includes('普通耗材&3') || nVal.includes('医用设备&1') ||
@@ -2202,7 +2253,34 @@
         },
         deep: true,
       },
+      // 效期管理 expiryDateManagerment 控制 expiryUnitId 效期单位  usefulLife 有效期 usefulLifeUnitId 有效期至单位 必填
+      "basicData.value.expiryDateManagerment":{
+
+        handler(nVal, oVal) {
+
+          this.judgeIsRequriedByProps({
+            condiition:(nVal === '2'),
+            tergetNames:['expiryUnitId','usefulLife','usefulLifeUnitId'],
+            formName:'basicData',
+            formRef:'basicMessageRef',
+          })
+        },
+        deep: true,
+      },
+      // 近效期管理 nearOnsetManagerment 控制 "recentWarningPeriod" 近效期预警天数 必填
+      "basicData.value.nearOnsetManagerment":{
 
+        handler(nVal, oVal) {
+
+          this.judgeIsRequriedByProps({
+            condiition:(nVal === '2'),
+            tergetNames:['recentWarningPeriod'],
+            formName:'basicData',
+            formRef:'basicMessageRef',
+          })
+        },
+        deep: true,
+      }, 
     },
 
     created() {

+ 21 - 1
src/views/material/basicFile/init/index.js

@@ -10,4 +10,24 @@ export const initRules = (prop) => {
       ];
     });
   return rules;
-};
+};
+
+export const initParams = (prop, key = "key", value = "value") =>
+  Object.fromEntries(prop.map((item) => [item[key], item[value]]));
+
+// export const initParams = (prop, key = "key", value = "value") => {
+//   // get params
+//   const object1 = Object.fromEntries(
+//     prop.map(({ item, attr }) => [item[key], attr[value]])
+//   );
+//   // get mapping params
+//   const object2 = {};
+//   prop
+//     .filter((item) => item.attr.dataMapping)
+//     .map(({ attr: { dataMapping } }) => {
+//       for (let key in dataMapping) {
+//         object2[key] = null;
+//       }
+//     });
+//   return { ...object1, ...object2 };
+// };