Your Name
2022-10-13 902a537974ce0374d68d9e717febab7157a69286
src/views/specialWorkSystem/workTicket/apply/components/fire.vue
对比新文件
@@ -0,0 +1,502 @@
<template>
   <div class="home-container">
      <div style="height: 100%">
      <el-form :model="form" label-width="150px" :rules="applyRules" ref="ruleFormRef">
         <div class="homeCard">
         <el-row>
            <el-col :span="12">
               <el-form-item label="作业人" prop="operatorUids">
                  <el-select v-model="form.operatorUids" multiple>
                     <el-option
                           v-for="item in workerList"
                           :key="item.uid"
                           :label="item.username"
                           :value="item.uid"
                     />
                  </el-select>
               </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="作业时间" prop="workTimeLine">
                  <el-date-picker
                        v-model="form.workTimeLine"
                        format="YYYY-MM-DD HH:mm"
                        value-format="YYYY-MM-DD HH:mm:00"
                        type="datetimerange"
                        range-separator="至"
                        start-placeholder="开始时间"
                        end-placeholder="结束时间"
                  />
               </el-form-item>
            </el-col>
         </el-row>
         <el-row>
            <el-col :span="12">
               <el-form-item label="作业等级" prop="workLevel">
                  <el-select v-model="form.workLevel">
                     <el-option
                           v-for="item in workLevelList"
                           :key="item.value"
                           :label="item.label"
                           :value="item.value"
                     />
                  </el-select>
               </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="作业内容" prop="workContent">
                  <el-input
                        v-model="form.workContent"
                        autosize
                        type="textarea"
                        placeholder="请输入作业内容"
                  />
               </el-form-item>
            </el-col>
         </el-row>
         <el-row>
            <el-col :span="12">
               <el-form-item label="作业地址" prop="workLocation">
                  <el-input
                        v-model="form.workLocation"
                        autosize
                        type="textarea"
                        placeholder="请输入作业地址"
                  />
               </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="危害辨识" prop="hazardIdentification">
                  <el-input
                        v-model="form.hazardIdentification"
                        placeholder="请输入危害辨识"
                  />
               </el-form-item>
            </el-col>
         </el-row>
            <el-divider border-style="dashed"/>
         <el-row>
            <el-col :span="12">
               <el-form-item label="动火方式" prop="workDetail.hotMethod">
                  <el-input
                        v-model="form.workDetail.hotMethod"
                        autosize
                        type="textarea"
                        placeholder="请输入动火方式"
                  />
               </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="关联作业" prop="workDetail.otherSpecialWork">
                  <el-select v-model="form.workDetail.otherSpecialWork" multiple>
                     <el-option
                           v-for="item in otherWorkList"
                           :key="item.value"
                           :label="item.label"
                           :value="item.value"
                     />
                  </el-select>
               </el-form-item>
            </el-col>
         </el-row>
         <el-row>
            <el-col :span="12">
               <el-form-item label="选择关联物资">
                  <el-button type="primary" @click="getMaList">选择物资标准</el-button>
               </el-form-item>
            </el-col>
         </el-row>
         </div>
      </el-form>
      <el-dialog v-model="equipmentDialog" title="关联物资标准" width="40%" center @close="closeMaterial">
         <el-tabs tab-position="left" class="demo-tabs" type="border-card">
            <el-tab-pane v-for="(item,index) in materialList" :label="item.materialTypeName" :key="index">
               <div style="margin-bottom: 20px">
                  <el-form label-width="150px" label-position="top">
                     <div v-if="item.mustList.length>0" style="width: 100%;border-bottom: 1px solid #ccc;padding-bottom: 6px;margin-bottom: 10px;font-weight: bolder">必选</div>
                     <el-form-item v-if="item.mustList.length>0" class="tab-i" v-for="(i,x) in item.mustList" :key="x" :label="item.mustList[x].materialName + ':'" prop="defaultVal" :rules="[{ type: 'defaultVal', required: true, message: '该内容不能为空', trigger: 'blur'}]">
                        <el-input size="default" type="number" v-model="item.mustList[x].value" @change="(val)=>toZero(val,index,'mustList',x)" placeholder="请输入配置数量,空值默认为0">
                           <template #append>{{'库存:' + item.mustList[x].stock}}</template>
                        </el-input>
                     </el-form-item>
                     <div v-if="item.unList.length>0" style="width: 100%;border-bottom: 1px solid #ccc;padding-bottom: 6px;margin-bottom: 10px;font-weight: bolder">其他</div>
                     <el-form-item v-if="item.unList.length>0" class="tab-i" v-for="(i,x) in item.unList" :key="x" :label="item.unList[x].materialName + ':'">
                        <el-input size="default" type="number" v-model="item.unList[x].value" @change="(val)=>toZero(val,index,'unList',x)" placeholder="请输入配置数量,空值默认为0">
                           <template #append>{{'库存:' + item.unList[x].stock}}</template>
                        </el-input>
                     </el-form-item>
                  </el-form>
               </div>
            </el-tab-pane>
         </el-tabs>
         <template #footer>
            <span class="dialog-footer">
               <el-button @click="equipmentDialog = false" size="default">取消</el-button>
               <el-button type="primary" @click="conFirmDevices" size="default">确认</el-button>
            </span>
         </template>
      </el-dialog>
      <div class="applyBtn">
         <el-button type="primary" size="large" plain @click="submitForm(ruleFormRef)">发起申请</el-button>
      </div>
   </div>
   </div>
</template>
<script lang="ts">
   import { toRefs, reactive, defineComponent, ref, defineAsyncComponent, onMounted } from 'vue';
   import { storeToRefs } from 'pinia';
   import { initBackEndControlRoutes } from '/@/router/backEnd';
   import {useUserInfo} from "/@/stores/userInfo";
   import { Session } from '/@/utils/storage';
   import { Search } from '@element-plus/icons-vue'
   import { ElMessage, ElMessageBox } from 'element-plus'
   import type { FormInstance, FormRules } from 'element-plus'
   import { workApplyApi } from '/@/api/specialWorkSystem/workApply';
   interface stateType {
      form: Object,
      workLevelList: Array<any>,
      otherWorkList: Array<any>,
      equipmentDialog: boolean,
      materialList: Array<any>
   }
   export default defineComponent({
      name: 'fireForm',
      components: {},
      props:['workerList'],
      setup() {
         const userInfo = useUserInfo()
         const { userInfos } = storeToRefs(userInfo);
         const state  = reactive<stateType>({
            equipmentDialog: false,
            materialList: [],
            form: {
               operatorUids: [],
               workType: 1,
               workLevel: null,
               workContent: '',
               workLocation: '',
               hazardIdentification: '',
               workDetail:{
                  hotMethod: '',
                  otherSpecialWork: []
               },
               wmAddReqDTOList: [],
               workTimeLine: [],
               expStartTime: '',
               expEndTime: ''
            },
            workLevelList: [
               {
                  label: "一级动火作业",
                  value: 1
               },
               {
                  label: "二级动火作业",
                  value: 2
               },
               {
                  label: "特级动火作业",
                  value: 3
               }
            ],
            otherWorkList: [
               {
                  label: "动火作业",
                  value: 1
               },
               {
                  label: "受限空间作业",
                  value: 2
               },
               {
                  label: "吊装作业",
                  value: 3
               },
               {
                  label: "动土作业",
                  value: 4
               },
               {
                  label: "断路作业",
                  value: 5
               },
               {
                  label: "高处作业",
                  value: 6
               },
               {
                  label: "临时用电作业",
                  value: 7
               },
               {
                  label: "盲板抽堵作业",
                  value: 8
               }
            ]
         });
         const ruleFormRef = ref<FormInstance>()
         const applyRules = reactive<FormRules>({
            operatorUids: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
            workType: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
            workLevel: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
            workContent: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
            workLocation: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
            hazardIdentification: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
            workTimeLine: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
            "workDetail.hotMethod": [{ required: true, message: '该内容不能为空', trigger: 'blur' }]
         });
         // 页面载入时执行方法
         onMounted(() => {
         });
         const toZero = (value: string | number,index: number,name: string,x:number) =>{
            if(!value){
               state.materialList[index][name][x].value = 0
            }
         }
         const submitForm = async (formEl: FormInstance | undefined) => {
            if (!formEl) return
            await formEl.validate(async (valid, fields) => {
               if (valid) {
                  if (state.materialList.length == 0){
                     ElMessage({
                        type: 'warning',
                        message: '请确认关联物资的配置'
                     });
                     return
                  }
                  for(let i in state.materialList){
                     for(let j in state.materialList[i].mustList){
                        if(state.materialList[i].mustList[j].value>state.materialList[i].mustList[j].stock){
                           ElMessage({
                              type: 'warning',
                              message: '部分物资库存不足,请重新配置数量。'
                           });
                           return
                        }
                     }
                     for(let j in state.materialList[i].unList){
                        if(state.materialList[i].unList[j].value>state.materialList[i].unList[j].stock){
                           ElMessage({
                              type: 'warning',
                              message: '部分物资库存不足,请重新配置数量。'
                           });
                           return
                        }
                     }
                     state.materialList[i].mustList = state.materialList[i].mustList.map((item:any)=>{
                        const obj = {
                           defaultVal: item.value,
                           id: item.id
                        }
                        return {...obj}
                     })
                     state.materialList[i].unList = state.materialList[i].unList.map((item:any)=>{
                        const obj = {
                           defaultVal: item.value,
                           id: item.id
                        }
                        return {...obj}
                     })
                     state.materialList[i].postList = [...state.materialList[i].mustList,...state.materialList[i].unList]
                     state.form.wmAddReqDTOList = [...state.form.wmAddReqDTOList,...state.materialList[i].postList]
                  }
                  state.form.expStartTime = JSON.parse(JSON.stringify(state.form.workTimeLine))[0]
                  state.form.expEndTime = JSON.parse(JSON.stringify(state.form.workTimeLine))[1]
                  let { workTimeLine, ...data } = JSON.parse(JSON.stringify(state.form))
                  data.workDetail.otherSpecialWork = data.workDetail.otherSpecialWork.join(',')
                  const res = await workApplyApi().postFireApply(data)
                  if (res.data.code === '200') {
                        ElMessage({
                           type: 'success',
                           message: '提交成功!'
                        });
                        formEl.resetFields()
                  } else {
                     ElMessage({
                        type: 'warning',
                        message: res.data.msg
                     });
                  }
                  state.materialList = []
               } else {
                  console.log('error submit!', fields)
               }
            })
         }
         // 确认物资标准
         const getMaList = async() =>{
            if(state.materialList.length == 0){
               const data = {workType: 1,workLevel: state.form.workLevel}
               const res = await workApplyApi().getMaterial(data)
               if (res.data.code === '200') {
                  if(res.data.data.materialTypeList && res.data.data.materialTypeList!=null&&res.data.data.materialTypeList.length>0){
                     state.materialList = JSON.parse(JSON.stringify(res.data.data.materialTypeList))
                     for(let i in state.materialList){
                        state.materialList[i].mustList = []
                        state.materialList[i].unList = []
                        state.materialList[i].mdList = state.materialList[i].mdList?.map((item:any) => {
                           if(item.configurationLevel == 0){
                              state.materialList[i].mustList.push(item)
                              return
                           }else{
                              state.materialList[i].unList.push(item)
                              return
                           }
                        })
                        state.materialList[i].mustList = state.materialList[i].mustList.map((item:any)=>{
                           const obj = {
                              value: item.defaultVal,
                              materialName: item.materialName,
                              configurationLevel: item.configurationLevel,
                              id: item.id,
                              stock: item.stock
                           }
                           return {...obj}
                        })
                        state.materialList[i].unList = state.materialList[i].unList.map((item:any)=>{
                           const obj = {
                              value: item.defaultVal,
                              materialName: item.materialName,
                              configurationLevel: item.configurationLevel,
                              id: item.id,
                              stock: item.stock
                           }
                           return {...obj}
                        })
                     }
                     state.equipmentDialog = true
                  }else{
                     ElMessage({
                        type: 'warning',
                        message: '暂时查询不到物资标准信息'
                     });
                  }
               } else {
                  ElMessage({
                     type: 'warning',
                     message: res.data.msg
                  });
               }
            }else{
               state.materialList = state.materialList
               state.equipmentDialog = true
            }
         }
         const conFirmDevices = ()=>{
            for(let i in state.materialList){
               for(let j in state.materialList[i].mustList){
                  if(state.materialList[i].mustList[j].value>state.materialList[i].mustList[j].stock){
                     ElMessage({
                        type: 'warning',
                        message: '部分物资库存不足,请重新配置数量。'
                     });
                     return
                  }
               }
               for(let j in state.materialList[i].unList){
                  if(state.materialList[i].unList[j].value>state.materialList[i].unList[j].stock){
                     ElMessage({
                        type: 'warning',
                        message: '部分物资库存不足,请重新配置数量。'
                     });
                     return
                  }
               }
            }
            ElMessageBox.confirm('是否确认物资及数量配置?')
               .then(() => {
                  state.equipmentDialog = false
               })
               .catch(() => {
                  // catch error
               })
         }
         const closeMaterial = ()=>{
         }
         // 折线图
         const renderMenu = async (value: string) => {
            Session.set('projectId',value)
            userInfos.value.projectId = value
            await initBackEndControlRoutes();
         };
         return {
            renderMenu,
            Search,
            ruleFormRef,
            applyRules,
            toZero,
            getMaList,
            conFirmDevices,
            closeMaterial,
            submitForm,
            ...toRefs(state),
         };
      },
   });
</script>
<style scoped lang="scss">
   .home-container {
      height: 100%;
      overflow: hidden;
      position: relative;
      .homeCard{
         width: 100%;
         padding: 20px;
         box-sizing: border-box;
         background: #fff;
         border-radius: 4px;
         margin-bottom: 20px;
      }
      .applyBtn{
         width: 100%;
         background: #fff;
         padding-top: 15px;
         z-index: 5;
         box-shadow: 0 -3px 8px rgba(150,150,150,.1);
         display: flex;
         align-items: center;
         justify-content: center;
      }
      .el-row{
         margin-bottom: 20px;
      }
      .el-row:last-child {
         margin-bottom: 0;
      }
      .el-input{
         width: 100% !important;
      }
      .el-date-editor::v-deep{
         width: 100%;
      }
      .el-select{
         width: 100%;
      }
      .el-cascader{
         width: 100% !important;
      }
   }
   .tab-i{
      margin-bottom: 15px;
      &:last-of-type{
         margin-bottom: 0;
      }
      ::v-deep(.el-form-item){
         .el-form-item__label{
            margin-bottom: 4px;
         }
      }
   }
</style>