From 1cc2bba0c5cfd27e0744f1df8c5bbd41135ae817 Mon Sep 17 00:00:00 2001
From: Your Name <123456>
Date: 星期三, 28 九月 2022 16:02:53 +0800
Subject: [PATCH] Merge branch 'master' of https://sinanoaq.cn:8888/r/gtqt

---
 src/views/specialWorkSystem/foundationSet/material/index.vue |  209 +++++++++++++++++++++++-----------------------------
 1 files changed, 93 insertions(+), 116 deletions(-)

diff --git a/src/views/specialWorkSystem/foundationSet/material/index.vue b/src/views/specialWorkSystem/foundationSet/material/index.vue
index 2de6ce6..93ea978 100644
--- a/src/views/specialWorkSystem/foundationSet/material/index.vue
+++ b/src/views/specialWorkSystem/foundationSet/material/index.vue
@@ -80,7 +80,7 @@
                 <div class="main-card">
                     <el-row class="cardTop">
                         <el-col :span="12" class="mainCardBtn">
-                            <el-button type="primary" :icon="Plus" size="default" @click="dialogAddRecord = true">新增</el-button>
+                            <el-button type="primary" :icon="Plus" size="default" @click="addRecordBtn">新增</el-button>
                             <!--						<el-button type="warning" :icon="Edit" size="default" plain>修改</el-button>-->
 <!--                            <el-button type="danger" :icon="Delete" size="default" plain @click="deleteBatchBtn">删除</el-button>-->
                         </el-col>
@@ -125,7 +125,7 @@
                         <div>必选</div>
                         <div>
                             <div v-if="mustList.length>0" v-for="(i,index) in mustList" :key="index">
-                                {{i.materialName}}:默认值:{{i.defaultVal}},{{i.consumables?'耗材':'费耗材'}}
+                                {{i.materialName}}:默认值:{{i.defaultVal}},{{i.consumables?'耗材':'非耗材'}}
                             </div>
                             <div v-else>
                                 无
@@ -136,7 +136,7 @@
                         <div>可选</div>
                         <div>
                             <div v-if="chooseList.length>0" v-for="(i,index) in chooseList" :key="index">
-                                {{i.materialName}}:默认值:{{i.defaultVal}},{{i.consumables?'耗材':'费耗材'}}
+                                {{i.materialName}}:默认值:{{i.defaultVal}},{{i.consumables?'耗材':'非耗材'}}
                             </div>
                             <div v-else>
                                 无
@@ -156,6 +156,9 @@
                     </div>
                     </div>
                 </el-form-item>
+                <el-form-item label="描述">
+                    <el-input v-model="details.info" type="textarea" autosize readonly />
+                </el-form-item>
                 <el-form-item label="创建人">
                     <el-input v-model="details.createUname" readonly />
                 </el-form-item>
@@ -170,7 +173,7 @@
                 </el-form-item>
             </el-form>
         </el-dialog>
-        <el-dialog v-model="dialogAddRecord" title="作业物资标准编辑" @close="closeAdd" @open="openAdd">
+        <el-dialog v-model="dialogAddRecord" title="作业物资标准编辑" @close="closeAdd" @open="openAdd" center>
             <el-form :model="addRecord" label-width="150px" ref="addRef" :rules="addRules">
                 <el-form-item label="作业物资标准名称" prop="name">
                     <el-input v-model="addRecord.name"> </el-input>
@@ -223,38 +226,39 @@
                 <el-form-item label="物资标准配置">
                     <el-tabs tab-position="left" class="demo-tabs" type="border-card">
                         <el-tab-pane v-for="(item,index) in allList" :label="item.materialTypeName" :key="index">
-                            <div v-for="(i,x) in item.list" :key="x">
-                            <el-checkbox :label="i.name" v-model="checkData[index].list[x].checked">
-                                <div>{{i.name}}</div>
-                                <div><span>默认值:</span><el-input size="small" v-model="checkData[index].list[x].defaultVal"/></div>
-                                <div>
-                                    <span>配置级别:</span>
-                                    <el-select size="small" v-model="checkData[index].list[x].configurationLevel">
+                            <div class="tab-i" v-for="(i,x) in item.list" :key="x">
+                            <el-checkbox :label="i.materialName" v-model="checkData[index].list[x].checked">
+                            </el-checkbox>
+                            <el-form v-if="checkData[index].list[x].checked" :model="checkData[index].list[x]" label-width="100px" ref="addListRef" :rules="addListRules">
+                                <el-form-item label="默认值" prop="defaultVal"><el-input v-model="checkData[index].list[x].defaultVal"/></el-form-item>
+                                <el-form-item label="配置级别" prop="configurationLevel">
+                                    <el-select v-model="checkData[index].list[x].configurationLevel">
                                         <el-option key="0" label="必选" value="0"/>
                                         <el-option key="1" label="可选" value="1"/>
                                         <el-option key="2" label="高配" value="2"/>
                                     </el-select>
-                                </div>
-                                <div>
-                                    <span>是否耗材:</span>
-                                    <el-radio-group v-model="checkData[index].list[x].consumables" class="ml-4">
-                                        <el-radio label="1">是</el-radio>
-                                        <el-radio label="2">否</el-radio>
+                                </el-form-item>
+                                <el-form-item label="是否耗材" prop="consumables">
+                                    <el-radio-group v-model="checkData[index].list[x].consumables">
+                                        <el-radio :label=true>是</el-radio>
+                                        <el-radio :label=false>否</el-radio>
                                     </el-radio-group>
-                                </div>
-                            </el-checkbox>
+                                </el-form-item>
+                            </el-form>
                             </div>
                         </el-tab-pane>
                     </el-tabs>
                 </el-form-item>
-                <el-form-item label="描述" prop="describe">
-                    <el-input v-model="addRecord.describe" type="textarea" autosize :rows="2"/>
-                </el-form-item>
-                <el-form-item>
-                    <el-button type="warning" @click="dialogAddRecord = false" size="default" plain>取消</el-button>
-                    <el-button type="primary" @click="confirmAddRecord(addRef)" size="default">确认</el-button>
+                <el-form-item label="描述" prop="info">
+                    <el-input v-model="addRecord.info" type="textarea" autosize :rows="2"/>
                 </el-form-item>
             </el-form>
+            <template #footer>
+                <span class="dialog-footer">
+                    <el-button type="warning" @click="dialogAddRecord = false" size="default" plain>取消</el-button>
+                    <el-button type="primary" @click="confirmAddRecord(addRef)" size="default">确认</el-button>
+                </span>
+            </template>
         </el-dialog>
         <el-dialog v-model="deleteDialog" title="提示" width="30%" center @close="indexClear">
             <span>您确定要删除该条记录吗?</span>
@@ -288,6 +292,7 @@
 import type { FormInstance, FormRules } from 'element-plus'
 import { teamManageApi } from '/@/api/systemManage/basicDateManage/personShiftManage/teamManage';
 import { materialApi } from '/@/api/specialWorkSystem/material';
+import {a} from "pinia-plugin-persistedstate/dist/types-374a3a36";
 
 // 定义接口来定义对象的类型
 interface stateType {
@@ -524,16 +529,21 @@
         // };
 
         const addRef = ref<FormInstance>();
+        const addListRef = ref<FormInstance>();
         const addRules = reactive<FormRules>({
             name: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
             workType: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
             workLevel: [{ required: true, message: '该内容不能为空', trigger: 'blur' }]
         });
+        const addListRules = reactive<FormRules>({
+            defaultVal: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
+            configurationLevel: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
+            consumables: [{ required: true, message: '该内容不能为空', trigger: 'blur' }]
+        });
 
         // 页面载入时执行方法
         onMounted(() => {
-            getListByPage();
-            getList();
+            getListByPage()
         });
 
         const toType = (row, column, cellValue, index) => {
@@ -541,14 +551,18 @@
         };
 
         const toLevel = (row, column, cellValue, index) => {
-            if(row.workLevel <= 3){
-                return state.fireLevel.find((item) => item.value === row.workLevel)?.label;
-            }else if(row.workLevel>3 && row.workLevel<=7){
-                return state.heightLevel.find((item) => item.value === row.workLevel)?.label;
-            }else if(row.workLevel>8 && row.workLevel<=10){
-                return state.hoistLevel.find((item) => item.value === row.workLevel)?.label;
+            if(row.workLevel == null){
+                return '无'
             }else{
-                return state.plateLevel.find((item) => item.value === row.workLevel)?.label;
+                if(row.workLevel <= 3){
+                    return state.fireLevel.find((item) => item.value === row.workLevel)?.label;
+                }else if(row.workLevel>3 && row.workLevel<=7){
+                    return state.heightLevel.find((item) => item.value === row.workLevel)?.label;
+                }else if(row.workLevel>8 && row.workLevel<=10){
+                    return state.hoistLevel.find((item) => item.value === row.workLevel)?.label;
+                }else{
+                    return state.plateLevel.find((item) => item.value === row.workLevel)?.label;
+                }
             }
         };
 
@@ -556,25 +570,12 @@
             let res = await materialApi().getRecordList();
             if (res.data.code === '200') {
                 state.allList  = JSON.parse(JSON.stringify(res.data.data))
-                // const test = [{id:1,name:'1',children:[{one:1,two:'1'},]},{id:2,name:'2',children:[{one:2,two:'2'},]}]
-                // test.map(item => {
-                //     item.children.map(i =>{
-                //         debugger
-                //         return {
-                //             three:true
-                //         }
-                //         const obj = i
-                //         console.log(obj);
-                //     })
-                //     return item
-                // })
-                // console.log(test);
                 for(let i in state.allList){
                     state.allList[i].list = state.allList[i].list?.map((item:any) => {
                         const obj = {
                             checked: false,
                             materialName: item.name,
-                            consumables: false,
+                            consumables: null,
                             defaultVal: null,
                             configurationLevel: null,
                             materialType: item.materialType,
@@ -585,37 +586,12 @@
                     })
                 }
                 state.checkData = JSON.parse(JSON.stringify(state.allList))
-                // state.checkData = state.allList.map((item)=>{
-                //     if(item.list && item.list != null){
-                //         console.log('1111111111111')
-                //         item.list.map((i)=>{
-                //             i.checked = false
-                //             i.defaultVal = null
-                //             i.configurationLevel = null
-                //             i.consumables = false
-                //             debugger
-                //             const obj = {
-                //                 checked: i.checked,
-                //                 materialName: i.name,
-                //                 consumables: i.consumables,
-                //                 defaultVal: i.defaultVal,
-                //                 configurationLevel: i.configurationLevel,
-                //                 materialType: i.materialType,
-                //                 materialTypeName: i.materialTypeName,
-                //                 emergencyMaterialId: i.id
-                //             }
-                //             return {...obj}
-                //         })
-                //     }
-                //     return item
-                // })
             } else {
                 ElMessage({
                     type: 'warning',
                     message: res.data.msg
                 });
             }
-            console.log(state.checkData,'state.checkData')
         }
 
         // 分页获取物资标准列表
@@ -673,6 +649,11 @@
             getListByPage();
         };
 
+        const addRecordBtn = () =>{
+            getList()
+            state.dialogAddRecord = true
+        }
+
         // 添加方法
         const addRecord = async (data: any) => {
             let res = await materialApi().addRecord(data);
@@ -692,13 +673,15 @@
 
         // 修改方法
         const editRecordBtn = async (index, row) => {
+            getList()
             state.addRecord = JSON.parse(JSON.stringify(row));
+            console.log(state.addRecord,'state.addRecord')
             state.dialogAddRecord = true;
             state.chosenIndex = index;
         };
 
         const editRecord = async (data: any) => {
-            let res = await teamManageApi().updateRecord(data);
+            let res = await materialApi().updateRecord(data);
             if (res.data.code === '200') {
                 ElMessage({
                     type: 'success',
@@ -718,32 +701,41 @@
             if (!formEl) return;
             await formEl.validate(async (valid, fields) => {
                 if (valid) {
+                    state.addRecord.materialDetailList = []
+                    for(let i in state.checkData){
+                        if(state.checkData[i].list && state.checkData[i].list.length>0){
+                            for(let j=0;j<state.checkData[i].list.length;j++){
+                                if(state.checkData[i].list[j].checked){
+                                    // delete state.checkData[i].list[j].checked
+                                    // state.checkData[i].list[j].checked
+                                    let { checked,...checkObj } = state.checkData[i].list[j]
+                                    state.addRecord.materialDetailList.push(checkObj)
+                                }
+                            }
+                        }
+                    }
                     const data = {
                         name: state.addRecord.name,
                         workType: state.addRecord.workType,
                         workLevel: state.addRecord.workLevel,
-                        describe: state.addRecord.describe,
-                        materialDetailList: []
+                        info: state.addRecord.info,
+                        materialDetailList: state.addRecord.materialDetailList
                     };
-                    // for(let i=0;i<state.checkData.length;i++){
-                    //     if(state.checkData[i].list !=null && state.checkData[i].list.length>0){
-                    //         for(let j=0;j<state.checkData[i].list.length;j++){
-                    //             if(state.checkData[i].list[j].checked){
-                    //                 let {materialName,consumables,defaultVal,configurationLevel,materialType,materialTypeName,id} = state.checkData[i].list[j]
-                    //                 const newObj = {materialName,consumables,defaultVal,configurationLevel,materialType,materialTypeName,id}
-                    //                 data.materialDetailList.push({ materialName, consumables, defaultVal, configurationLevel, materialType, materialTypeName, id})
-                    //             }
-                    //         }
-                    //     }
-                    // }
-                    console.log(data,'data>>>>>>>>>')
-                    // if (state.chosenIndex == null) {
-                    //     await addRecord(data);
-                    // } else {
-                    //     data.groupId = JSON.stringify(state.addRecord.groupId);
-                    //     await editRecord(data);
-                    // }
-                    state.dialogAddRecord = false;
+                    console.log(data.materialDetailList,'data.materialDetailList')
+                    if(data.materialDetailList.length==0 || data.materialDetailList.some((e) => e.defaultVal == null) || data.materialDetailList.some((e) => e.configurationLevel == null) || data.materialDetailList.some((e) => e.consumables == null)){
+                        ElMessage({
+                            type: 'warning',
+                            message: '请完善物资配置必填数据'
+                        });
+                    }else{
+                        if (state.chosenIndex == null) {
+                            await addRecord(data);
+                        } else {
+                            data.id = state.addRecord.id;
+                            await editRecord(data);
+                        }
+                        state.dialogAddRecord = false;
+                    }
                 } else {
                     console.log('error submit!', fields);
                 }
@@ -845,7 +837,6 @@
 
                 }
             }
-            console.log(state.mustList,state.chooseList,state.highList,'666666666')
             state.dialogDetails = true;
         };
 
@@ -881,12 +872,15 @@
         };
         return {
             addRef,
+            addListRef,
             addRules,
+            addListRules,
             View,
             Edit,
             Delete,
             Refresh,
             Plus,
+            addRecordBtn,
             toType,
             toLevel,
             searchRecord,
@@ -1029,28 +1023,11 @@
     width: 100% !important;
 }
 
-.el-checkbox{
-    width: 100%;
+.tab-i{
     margin-bottom: 20px;
-    display: flex;
-    align-items: flex-start;
-    height: auto;
-    ::v-deep(.el-checkbox__label){
+
+    .el-form-item{
         margin-bottom: 20px;
-        &>div{
-            width: 100%;
-            margin-bottom: 10px;
-            &>span{
-                display: inline-block;
-                width: 30%;
-            }
-            .el-input {
-                width: 100% !important;
-            }
-            .el-select {
-                width: 100% !important;
-            }
-        }
     }
 }
 </style>

--
Gitblit v1.9.2