lct
Your Name
2022-08-20 52cdea9a329e0835fc30ef8c3ebb7263658cf38d
src/views/goalManagement/safetyAssessment/component/Dailog.vue
@@ -1,13 +1,15 @@
<template>
   <el-dialog v-model="dialogVisible" :fullscreen="full" title="目标考核" width="70%" draggable @close="closeDialog">
   <el-dialog v-model="dialogVisible" :before-close="resetForm" :fullscreen="full" title="目标分解" width="60%" draggable>
      <el-button @click="toggleFullscreen" size="small" class="pot" :icon="FullScreen"></el-button>
      <el-form :model="form" label-width="120px">
         <el-row>
            <el-col :span="11">
               <el-form-item label="安全目标指标" size="default">
                  <el-input v-model="form.qName" :disabled="disabled">
                     <template #append> <el-button :icon="Search" @click="daiInpt" /> </template
                  ></el-input>
                     <template #append>
                        <el-button :icon="Search" @click="daiInpt" />
                     </template>
                  </el-input>
               </el-form-item>
            </el-col>
            <el-col :span="11" :offset="2">
@@ -29,167 +31,187 @@
            </el-col>
         </el-row>
      </el-form>
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
      <el-tabs v-model="activeName" class="demo-tabs">
         <el-tab-pane label="目标指标分解" name="1">
        <el-button type="primary" size="default" @click="daiAdd('新增')" :disabled="disabled">新增</el-button>
      </el-tab-pane>
            <!-- <el-button type="primary" size="default" @click="daiAdd('新增')" :disabled="disabled">新增</el-button> -->
         </el-tab-pane>
      </el-tabs>
      <el-table :data="formUp.examineList" style="width: 100%">
         <el-table-column align="center" type="index" label="序号" width="70" />
         <el-table-column align="center" prop="dutyDepartmentName" label="责任部门" />
         <el-table-column align="center" prop="examineValue" label="考核指标" />
         <el-table-column align="center" prop="makerDepartmentName" label="制定部门" />
         <el-table-column align="center" prop="makeDate" label="制定日期" />
         <el-table-column align="center" prop="uploadValue" label="上报值" />
         <el-table-column align="center" prop="uploadDate" label="上报时间" />
         <el-table-column align="center" prop="examineResult" label="考核结果" >
            <template #default="scope">
               <div v-if="scope.row.examineResult==1">
                  合格
               </div>
               <div v-if="scope.row.examineResult==2">
                  不合格
               </div>
            </template>
         </el-table-column>
         <el-table-column align="center" prop="examinePersonName" label="考核人" />
         <el-table-column align="center" prop="examineDate" label="考核时间" />
      <el-table :data="formUp.targetDivideDetailList" style="width: 100%">
         <el-table-column align="center" property="dutyDepartmentName" label="责任部门" width="180" />
         <el-table-column align="center" property="value" label="考核指标" width="180" />
         <el-table-column align="center" property="makerDepartmentName" label="制定人部门" />
         <el-table-column align="center" property="makeDate" :formatter="timeDate" label="制定日期" />
         <el-table-column align="center" property="commitPersonName" label="上报人" />
         <el-table-column align="center" label="操作">
            <template #default="scope">
               <el-button link type="primary" @click="daiAdd('查看', scope.row)">查看</el-button>
               <el-button link type="primary" @click="daiAdd('修改', scope.row)">修改</el-button>
               <el-button link type="primary" @click="Delete(scope.row)">删除</el-button>
               <el-button link :disabled="disabled" type="primary" @click="daiAdd('修改', scope.row)">考核</el-button>
            </template>
         </el-table-column>
      </el-table>
      <template #footer>
         <span class="dialog-footer">
            <el-button @click="closeDialog" size="default">关闭</el-button>
            <el-button type="primary" @click="submitForm" size="default">确定</el-button>
            <el-button @click="resetForm" size="default">关闭</el-button>
            <el-button type="primary" v-if="disabled == false" @click="submitForm" size="default">确定</el-button>
         </span>
      </template>
   </el-dialog>
   <DailogAdd ref="Show" @onAdd="add"></DailogAdd>
   <DailogSearch ref="Shows" @backNum="onNumber"></DailogSearch>
  <DailogAdd ref="Show" @onAdd="add"></DailogAdd>
</template>
<script lang="ts">
import { defineComponent, ref, reactive } from 'vue';
import { timeDate } from '/@/assets/index.ts';
import { Search, FullScreen } from '@element-plus/icons-vue';
import DailogAdd from './DailogAdd.vue';
import { ElMessageBox, ElMessage, ElButton, ElInput, TabsPaneContext } from 'element-plus';
import DailogSearch from '../../../../components/DailogSearch/DailogSearch.vue';
import DailogAdd from './DailogAdd.vue';
import { goalManagementApi } from '/@/api/goalManagement';
import {deepClone} from "/@/utils/other";
import { emit } from 'process';
import { deepClone } from '/@/utils/other';
export default defineComponent({
   components: { DailogSearch ,DailogAdd},
   setup() {
   components: { DailogAdd, DailogSearch },
   setup(props, { emit }) {
      const dialogVisible = ref<boolean>(false);
      const form = ref({});
      const form = ref({
         qName: '',
         indexNum: '',
         year: '',
         value: '',
         targetDivideDetailList: [],
      });
      const targetType = ref();
      const disabled = ref(false);
      const titles = ref();
      const numId=ref()
      const openDailog = (title: string, type: any, id: number) => {
         dialogVisible.value = true;
         titles.value = title;
         targetType.value = type;
         disabled.value = title == '查看' ? true : false;
         if (title == '查看' || title == '修改') {
            goalManagementApi()
               .gettargetExamineDetail(id)
               .getTargetMngDetail(id)
               .then((res) => {
                  if (res.data.code == 200) {
                     form.value = res.data.data;
                     formUp.examineList = res.data.data.examineList
                     formUp.targetDivideDetailList = form.value.targetDivideDetailList;
                     for(let i=0;i<formUp.targetDivideDetailList.length;i++){
                        formUp.targetDivideDetailList[i].makeDate=timeC(formUp.targetDivideDetailList[i].makeDate)
                     }
                  } else {
                     ElMessage.error(res.data.msg);
                  }
               });
         }
         numId.value=id
      };
      const closeDialog = () => {
         form.value = {}
         formUp.examineList = []
         dialogVisible.value = false
      const timeC = (timestamp: any) => {
         let a = new Date(timestamp).getTime();
         const date = new Date(a);
         const Y = date.getFullYear() + '-';
         const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
         const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '  ';
         const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
         const m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
         const s = date.getSeconds(); // 秒
         const dateString = Y + M + D + h + m +`:${s}`;
         // console.log('dateString', dateString); // > dateString 2021-07-06 14:23
         return dateString;
      };
      const submitForm = () => {
         // formUp.delTargetDivideDetails = arr.value.toString();
         // formUp.targetId = form.value.id;
         dialogVisible.value = false;
         for(let i=0;i<formUp.examineList.length;i++){
            delete formUp.examineList[i].dutyDepartmentName
            delete formUp.examineList[i].makerDepartmentName
         }
         formUp.id = form.value.id
         formUp.delIds = arr.value.toString();
         goalManagementApi()
               .gettargetExamineAddOrUpdate(formUp)
               .then((res) => {
                  if (res.data.code == 200) {
                     ElMessage({
                        message: res.data.msg,
                        type: 'success',
                     });
                     emit('addList');
                  } else {
                     ElMessage.error(res.data.msg);
                  }
               });
         form.value = {
            qName: '',
            indexNum: '',
            year: '',
            value: '',
            examineList: [],
         };
         tableData.value = [];
         formUp.targetId = '';
         formUp.delTargetDivideDetails = '';
         formUp.examineList = [];
      };
      const arr = ref([]);
      // 删除
      const Delete = (data: any) => {
         formUp.examineList.splice(form.value.examineList.indexOf(data), 1);
         arr.value.push(data.id);
      };
      const onNumber = (e: object) => {
         form.value = e;
      const onNumber = (val: object) => {
         form.value = val;
      };
      // 导航
      const activeName = ref('1');
      // 表格
      const tableData = ref([]);
      // 新增弹窗
      const index = ref<any>();
      const Show = ref();
      const daiAdd = (title: string, data: any) => {
         index.value = formUp.targetDivideDetailList.indexOf(data);
         Show.value.openDailog(title, data);
      };
      const formUp = reactive({
         targetId: '', //关联的目标指标/外键
         delTargetDivideDetails: '', //要删除的目标指标分解ID,多个用逗号隔开
         targetDivideDetailList: [], //目标指标分解列表
      });
      const add = (val: any) => {
            goalManagementApi()
               .getTargetMngDetail(numId.value)
               .then((res) => {
                  if (res.data.code == 200) {
                     form.value = res.data.data;
                     formUp.targetDivideDetailList = form.value.targetDivideDetailList;
                     for(let i=0;i<formUp.targetDivideDetailList.length;i++){
                        formUp.targetDivideDetailList[i].makeDate=timeC(formUp.targetDivideDetailList[i].makeDate)
                     }
                  } else {
                     ElMessage.error(res.data.msg);
                  }
               });
         // let obj=JSON.parse(JSON.stringify(form.value))
      };
      // 新增
      const submitForm = () => {
         formUp.delTargetDivideDetails = arr.value.toString();
         formUp.targetId = form.value.id;
         dialogVisible.value = false;
         for(let i=0;i<formUp.targetDivideDetailList.length;i++){
            delete formUp.targetDivideDetailList[i].dutyDepartmentName
            delete formUp.targetDivideDetailList[i].makerDepartmentName
         }
         goalManagementApi()
            .gettargetDivideDetail(formUp)
            .then((res) => {
               if (res.data.code == 200) {
                  ElMessage({
                     message: res.data.msg,
                     type: 'success',
                  });
                  emit('addList');
               } else {
                  ElMessage.error(res.data.msg);
               }
            });
         form.value = {
            qName: '',
            indexNum: '',
            year: '',
            value: '',
            targetDivideDetailList: [],
         };
         tableData.value = [];
         formUp.targetId = '';
         formUp.delTargetDivideDetails = '';
         formUp.targetDivideDetailList = [];
      };
      const arr = ref([]);
      // 安全目标指标弹窗
      const Shows = ref();
      const daiInpt = () => {
         Shows.value.openDailog(targetType.value);
      };
      // 新增弹窗
      const index=ref<any>()
      const Show = ref();
      const daiAdd = (title: string, data: any) => {
        index.value = formUp.examineList.indexOf(data);
        Show.value.openDailog(title, data);
      // 关闭
      const resetForm = () => {
         dialogVisible.value = false;
         form.value = {
            qName: '',
            indexNum: '',
            year: '',
            value: '',
            targetDivideDetailList: [],
         };
         tableData.value = [];
         formUp.targetId = '';
         formUp.delTargetDivideDetails = '';
         formUp.targetDivideDetailList = [];
      };
      const formUp = reactive({
        targetId: '', //关联的目标指标/外键
        delTargetDivideDetails: '', //要删除的目标指标分解ID,多个用逗号隔开
        examineList: [], //目标指标分解列表
      });
      const add = (val: any) => {
        const item = deepClone(val)
        if(index.value==-1){
         formUp.examineList.push(item);
        }else{
         formUp.examineList[index.value] = item;
        }
         console.log(formUp)
        // let obj=JSON.parse(JSON.stringify(form.value))
      };
      //全屏
      const full = ref(false);
      const toggleFullscreen = () => {
@@ -199,30 +221,38 @@
            full.value = false;
         }
      };
      // 时间格式处理
      // const timeDate = (data: any) => {
      //    let result = new Date(data).getTime();
      //    return result;
      // };
      return {
         timeC,
         index,
         timeDate,
         arr,
         form,
         dialogVisible,
         openDailog,
         targetType,
         onNumber,
         disabled,
         titles,
         activeName,
         tableData,
         Show,
         daiAdd,
         Shows,
         daiInpt,
         Search,
         full,
         toggleFullscreen,
         FullScreen,
          daiAdd,
          index,
          Show,
          formUp,
          add,
         closeDialog,
         onNumber,
         targetType,
         disabled,
         resetForm,
         titles,
         add,
         formUp,
         submitForm,
         Delete
         numId
      };
   },
});