Newer
Older
KaiFengPC / src / views / project / ProjectProcessAdministration / completionAcceptancea / operate.vue
@zhangdeliang zhangdeliang on 12 Jun 18 KB update
<template>
  <div class="operate" v-loading.fullscreen.lock="loading" element-loading-text="加载中..." element-loading-background="rgba(0, 0, 0, 0.6)">
    <el-steps :active="active" finish-status="success" align-center class="steps">
      <el-step title="验收申请提交" />
      <el-step title="验收审查" />
      <el-step title="验收合格" />
    </el-steps>
    <el-form ref="ruleForm" :model="form" :rules="rules" :disabled="opts.type === 'view'">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="项目名称:" prop="projectNo" class="formItem110">
            <el-select v-model="form.projectNo" placeholder="请选择项目名称" style="width: 100%" @change="projectChange">
              <el-option v-for="dict in projectList" :key="dict.projectNo" :label="dict.projectName" :value="dict.projectNo" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目编码:" prop="projectNo" class="formItem110">
            <el-input v-model="form.projectNo" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目类型:" prop="projectTypeId" class="formItem110">
            <el-input v-model="form.projectTypeIdName" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="联系人:" prop="chargeUser" class="formItem110">
            <el-input v-model="form.chargeUser" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="联系电话:" prop="phone" class="formItem110">
            <el-input v-model="form.phone" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="建设单位:" prop="chargeDepartment" class="formItem110">
            <el-input v-model="form.chargeDepartment" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="设计单位:" prop="designUnit" class="formItem110">
            <el-input v-model="form.designUnitName" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="施工单位:" prop="constructUnit" class="formItem110">
            <el-input v-model="form.constructUnitName" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="监理单位:" prop="supervisorUnit" class="formItem110">
            <el-select v-model="form.supervisorUnit" placeholder="请选择监理单位" style="width: 100%" :disabled="opts.type === 'audit'">
              <el-option v-for="dict in props.companyList" :key="dict.id" :label="dict.unitName" :value="dict.id" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="雨水资源利用量:" prop="rainwaterUtilization" class="formItem110">
            <el-input v-model="form.rainwaterUtilization" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="可渗透地面面积:" prop="permeableFloorArea" class="formItem110">
            <el-input v-model="form.permeableFloorArea" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-divider content-position="left">建设内容</el-divider>
      <div class="pl20">
        <el-form-item label="建设指标达成情况:" prop="achievementTarget" class="formItem140">
          <el-input v-model="form.achievementTarget" type="textarea" resize="none" :disabled="opts.type === 'audit'" />
        </el-form-item>
        <el-form-item label="海绵设施类型及规模:" prop="spongeTypeScale" class="formItem140">
          <el-input v-model="form.spongeTypeScale" type="textarea" resize="none" :disabled="opts.type === 'audit'" />
        </el-form-item>
        <el-form-item label="其他情况说明:" prop="otherDescription" class="formItem140">
          <el-input v-model="form.otherDescription" type="textarea" resize="none" :disabled="opts.type === 'audit'" />
        </el-form-item>
      </div>
      <el-divider content-position="left">验收资料上传</el-divider>
      <div class="box" v-for="(item, i) in form.projectProcessAttachmentSaveRequestList">
        <el-row :gutter="24">
          <el-col :span="12">
            <!-- 必填   :rules="opts.type === 'add' || (i < 10 && opts.type === 'audit') ? rules['filieDescription'] : []" -->
            <el-form-item
              :label="`${item.name}:`"
              :prop="'projectProcessAttachmentSaveRequestList.' + i + '.' + 'filieDescription'"
              class="formItem300"
            >
              <el-input
                v-model="item.filieDescription"
                placeholder="请输入资料说明"
                style="width: 200px"
                :disabled="i < 10 && opts.type === 'audit'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <ImageFileUpload
              listType="text"
              :limit="10"
              :saveFileArr="item.fileList"
              :refType="item.dictType"
              :refField="item.dictData"
              :fileType="['pdf', 'doc', 'docx', 'xlsx', 'xls', 'txt']"
              :disabled="i < 10 && opts.type === 'audit'"
            />
          </el-col>
        </el-row>
      </div>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="指定处理人:" prop="dealUsers" class="formItem110">
            <el-select v-model="form.dealUsers" placeholder="请选择指定处理人" style="width: 100%" :disabled="opts.type === 'audit'">
              <el-option v-for="dict in userLists" :key="dict.userId" :label="dict.nickName" :value="dict.userId" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="流程抄送人:" prop="pushUsers" class="formItem110">
            <el-select v-model="form.pushUsers" placeholder="请选择流程抄送人" style="width: 100%" :disabled="opts.type === 'audit'">
              <el-option v-for="dict in userLists" :key="dict.userId" :label="dict.nickName" :value="dict.userId" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="验收意见:" prop="inGoodCondition" class="formItem110">
            <el-select v-model="form.inGoodCondition" placeholder="请选择" style="width: 100%" :disabled="opts.type === 'audit'">
              <el-option label="正常办理、验收通过" value="1" />
              <el-option label="容缺办理、原则通过" value="0" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="审核意见:" prop="approveComment" class="formItem110" v-if="opts.type === 'audit'">
        <el-input v-model="form.approveComment" type="textarea" resize="none" />
      </el-form-item>

      <el-divider content-position="left" v-if="form.status && form.status !== 'start'">流程日志</el-divider>
      <div class="stapesBox" v-if="form.status && form.status !== 'start'">
        <el-steps direction="vertical" :active="stapesDate.length">
          <el-step v-for="i in stapesDate" :title="i.activityName" style="width: 300px">
            <template #description>
              <div class="direction">时间:{{ i.endTime }}</div>
              <div class="direction">分配人:{{ i.assigneeName }}</div>
              <div class="direction">任务备注:{{ i.comment }}</div>
            </template>
          </el-step>
        </el-steps>
      </div>
    </el-form>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue';
import { required } from '@/utils/validate-helper';
import { inheritAttr } from '@/utils/v3';
import { getProjectInfoNewList, getDicts } from '@/api/project/projectApproval';
import { projectInfoNewDetail } from '@/api/project/projectInformationNew';
import ImageFileUpload from '@/components/ImageFileUpload/index.vue'; //图片文件上传
import {
  projectCompletionAcceptanceeAdd,
  projectCompletionAcceptanceeEdit,
  projectCompletionAcceptanceeStartWorkFlow,
  projectCompletionAcceptanceeDetail,
  projectCompletionAcceptanceApprove,
} from '@/api/project/completionAcceptance';
import { workflowProcess, userList } from '@/api/project/constructionPermits';
import useUserStore from '@/store/modules/user';
const { proxy } = getCurrentInstance();
const emit = defineEmits(['close']);
const props = defineProps({
  curRow: {
    type: Object,
    default: () => ({}),
  },
  opts: {
    type: Object,
    default: () => ({}),
  },
  types: {
    type: Array,
    default: [],
  },
  companyList: {
    type: Array,
    default: () => [],
  },
});
const { acceptance_material } = proxy.useDict('acceptance_material');
const { curRow, opts } = props;
const loading = ref(false);
const active = ref(0);
const form = reactive({
  projectName: '',
  projectNo: '',
  projectTypeId: '',
  projectTypeIdName: '',
  chargeUser: '',
  phone: '',
  chargeDepartment: '',
  designUnit: '',
  designUnitName: '',
  constructUnit: '',
  constructUnitName: '',
  rainwaterUtilization: '',
  permeableFloorArea: '',
  supervisorUnit: '',
  supervisorUnitName: '',
  achievementTarget: '',
  spongeTypeScale: '',
  otherDescription: '',
  projectProcessAttachmentSaveRequestList: [],
  fileSaveRequestList: [],
  dealUsers: '',
  pushUsers: '',
  status: '',
  approveComment: '',
  inGoodCondition: '0',
  workflowInstanceId: '',
});

const rules = reactive({
  projectName: required('项目名称'),
  projectNo: required('项目编码'),
  projectTypeId: required('项目类型'),
  chargeUser: required('联系人'),
  phone: required('联系电话'),
  chargeDepartment: required('建设单位'),
  designUnit: required('设计单位'),
  constructUnit: required('施工单位'),
  supervisorUnit: required('监理单位'),
  achievementTarget: required('建设指标达成情况'),
  spongeTypeScale: required('海绵设施类型及规模'),
  otherDescription: required('其他情况说明'),
  filieDescription: required('内容'),
  approveComment: required('审核意见'),
});

const stapesDate = ref([]);

const projectList = ref([]);
const userLists = ref([]);
const showDetail = ref(false);
const fileObj = ref({});

// 选择附件上传,对应动态参数添加
function uploadGo(item, index) {
  fileObj.value.refType = item.dictType;
  fileObj.value.refField = item.dictData;
  fileObj.value.fileList = item.fileList;
  fileObj.value.index = index; //动态的第几个
  showDetail.value = true;
}
// 文件列表删除
function deleteGG(list, index) {
  list.splice(index, 1);
}
// 确定之后选择的附件
const closeGGDialog = e => {
  form.projectProcessAttachmentSaveRequestList[fileObj.value.index].fileList = e;
  showDetail.value = false;
};

const getUserList = async () => {
  const res = await userList();
  if (res?.code !== 200) return;
  userLists.value = res?.data || [];
};

const getProjectList = async () => {
  const res = await getProjectInfoNewList();
  if (res?.code !== 200) return;
  projectList.value = res?.data || [];
  if (opts.type === 'add' && projectList.value.length) {
    projectChange(projectList.value[0].projectNo);
    fileObj.value.refId = projectList.value[0].id; //项目返回的id值
  }
};

const projectChange = async val => {
  const res = await projectInfoNewDetail(val);
  if (res?.code !== 200) return;
  fileObj.value.refId = res.data.id; //项目返回的id值
  inheritAttr(res.data, form);
  form.projectTypeIdName = props.types.find(it => it.id === form.projectTypeId)?.projectTypeName;
  form.designUnitName = props.companyList.find(it => it.id === form.designUnit)?.unitName || '';
  form.constructUnitName = props.companyList.find(it => it.id === form.constructUnit)?.unitName || '';

  form.achievementTarget = '';
  form.spongeTypeScale = '';
  form.otherDescription = '';
  form.dealUsers = '';
  form.pushUsers = '';
  getDictMaps('acceptance_material');
};

const getDictMaps = async dictType => {
  const res = await getDicts(dictType);
  if (res?.code !== 200) return;
  if (res?.data) {
    form.projectProcessAttachmentSaveRequestList = [];
    for (const item of res.data) {
      form.projectProcessAttachmentSaveRequestList.push({
        fileList: [],
        dictData: item.dictValue,
        dictType: item.dictType,
        filieDescription: '',
        projectNo: '',
        name: item.dictLabel,
      });
    }
    form.projectProcessAttachmentSaveRequestList = form.projectProcessAttachmentSaveRequestList.slice(0, 10);
  }

  setTimeout(() => {
    if (proxy.$refs.ruleForm) {
      proxy.$refs.ruleForm.clearValidate();
    }
  });
};

const getProjectTypeFileList = async (fileGroup, type, list, filterList) => {
  for (const key in fileGroup) {
    if (key === type) {
      if (Object.hasOwnProperty.call(fileGroup, key)) {
        const element = fileGroup[key];
        for (const item of element) {
          const info = filterList.value.find(it => it.value === item.dictData);
          if (!info) continue;
          list.push({
            fileList: item.fileList,
            dictData: item.dictData,
            dictType: item.dictType,
            filieDescription: item.filieDescription,
            projectNo: item.projectNo,
            name: info.label,
          });
        }
      }
    }
  }
};

const getDetail = async () => {
  const res = await projectCompletionAcceptanceeDetail(curRow.id);
  if (res?.code !== 200) return;
  fileObj.value.refId = res.data.projectId; //项目返回的id值
  inheritAttr(res.data, form);
  form.projectTypeIdName = props.types.find(it => it.id === form.projectTypeId)?.projectTypeName;
  form.designUnitName = props.companyList.find(it => it.id === form.designUnit)?.unitName || '';
  form.constructUnitName = props.companyList.find(it => it.id === form.constructUnit)?.unitName || '';
  form.dealUsers = form.dealUsers * 1 || '';
  form.pushUsers = form.pushUsers * 1 || '';

  const fileGroup = res.data.fileGroup;
  form.projectProcessAttachmentSaveRequestList = [];
  getProjectTypeFileList(fileGroup, 'acceptance_material', form.projectProcessAttachmentSaveRequestList, acceptance_material);

  if (form.status && form.status !== 'start') {
    workflowProcessM(res.data.id);
    if (form.status === 'acceptanceReview') {
      active.value = 1;
    } else if (form.status === 'end') {
      active.value = 3;
    }
  }

  if (opts.type === 'audit') {
    const res = await getDicts('acceptance_material');
    if (res?.code !== 200) return;
    if (res?.data) {
      res.data = res.data.slice(10);
      for (const item of res.data) {
        form.projectProcessAttachmentSaveRequestList.push({
          fileList: [],
          dictData: item.dictValue,
          dictType: item.dictType,
          filieDescription: '',
          projectNo: '',
          name: item.dictLabel,
        });
      }
    }
  }
};

const submit = type => {
  proxy.$refs.ruleForm.validate(async (valid, fields) => {
    if (valid) {
      if (type === 2) {
        if (!form.dealUsers) return proxy.$modal.msgError('请指定处理人!');
        if (!form.pushUsers) return proxy.$modal.msgError('请指定抄送人!');
      }
      loading.value = true;
      const params = JSON.parse(JSON.stringify(form));
      for (const item of params.projectProcessAttachmentSaveRequestList) {
        item.projectNo = params.projectNo;
        for (const it of item.fileList) {
          params.fileSaveRequestList.push(it);
        }
      }
      console.log(params);
      let methed = '';
      if (type === 1) {
        if (curRow?.id) {
          params.id = curRow.id;
          methed = projectCompletionAcceptanceeEdit;
        } else {
          methed = projectCompletionAcceptanceeAdd;
        }
      } else {
        if (curRow?.id) {
          params.id = curRow.id;
        }
        methed = projectCompletionAcceptanceeStartWorkFlow;
      }
      const res = await methed(params);
      loading.value = false;
      if (res?.code !== 200) return;
      proxy.$modal.msgSuccess('操作成功!');
      emit('close');
    } else {
      console.log('error submit!', fields);
    }
  });
};

const handleAudit = result => {
  proxy.$refs.ruleForm.validate(async (valid, fields) => {
    if (valid) {
      const params = JSON.parse(JSON.stringify(form));
      delete params.list1;
      params.fileSaveRequestList = [];
      for (let i = 0; i < params.projectProcessAttachmentSaveRequestList.length; i++) {
        if (opts.type === 'audit' && i < 10) continue;
        const item = params.projectProcessAttachmentSaveRequestList[i];
        if (result === 'true' && !item.filieDescription) {
          return proxy.$modal.msgError(`${item.name}文件说明不能为空!`);
        }
        item.projectNo = params.projectNo;
        for (const it of item.fileList) {
          params.fileSaveRequestList.push(it);
        }
      }
      loading.value = true;
      if (opts.type === 'audit') {
        params.projectProcessAttachmentSaveRequestList = params.projectProcessAttachmentSaveRequestList.slice(10);
      }
      params.approveResult = result;
      params.submitUserId = useUserStore().userId;
      params.id = curRow.id;
      console.log(params);
      try {
        const res = await projectCompletionAcceptanceApprove(params);
        loading.value = false;
        if (res?.code !== 200) return;
        proxy.$modal.msgSuccess('操作成功!');
        emit('close');
      } catch (error) {
        loading.value = false;
      }
    } else {
      console.log('error submit!', fields);
    }
  });
};

//获取流程日志
const workflowProcessM = async id => {
  let params = {
    businessKey: id,
    workflowKey: 'proProjectCompletionAcceptance',
    workflowUserId: '',
  };
  let { data } = await workflowProcess(params);
  stapesDate.value = data;
};

onMounted(() => {
  getProjectList();
  getUserList();
  if (curRow?.id) {
    getDetail();
  }
});

defineExpose({
  submit,
  handleAudit,
});
</script>

<style lang="scss" scoped>
.operate {
  .steps {
    margin-bottom: 20px;
  }

  .pl20 {
    padding-left: 20px;
  }

  .tips {
    margin-left: 10px;
    line-height: 30px;
  }

  .mb5 {
    margin-bottom: 5px;
  }

  .mb0 {
    margin-bottom: 0;
  }

  .fileSaveRequestList {
    .file-item {
      white-space: nowrap;
      display: flex;
      align-items: center;
      .del {
        flex-shrink: 0;
        color: #f56c6c;
        cursor: pointer;
        margin-left: 10px;
      }
    }
  }
  .box {
    margin-bottom: 10px;
  }

  .direction {
    min-width: 190px;
  }

  .stapesBox {
    min-height: 100px;
    margin-bottom: 30px;
    margin-left: 30px;
  }
}
</style>