<!--
 * @Author: ysh
 * @Date: 2024-02-27 14:49:15
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-01-22 14:29:46
-->

<template>
  <div class="project-wrapper">
    <div class="mt20 mb20" v-if="showAlter">
      <el-alert title="任务被退回，请修改后重新提交" type="error" :closable="false">
        <return-comment :taskForm="taskForm" @isReturn="isReturn"></return-comment>
      </el-alert>
    </div>
    <el-row :gutter="20">
      <el-col :xs="24" :md="18">
        <el-tabs tabPosition="left" type="card" class="tabs-border" v-model="activeName">
          <el-tab-pane label="项目登记" name="项目登记">
            <addproject :taskForm="taskForm" :taskName="taskName" :disabled="taskName != '项目登记'" @goBack="goBack">
            </addproject>
          </el-tab-pane>
          <el-tab-pane label="核定工作" name="核定工作">
            <assess-work :taskForm="taskForm" :taskName="taskName" :disabled="taskName != '核定工作'"
              @goBack="goBack" @returnBack="returnOpen = true"></assess-work>
          </el-tab-pane>
          <el-tab-pane label="项目安排" name="项目安排">
            <arrangeProject :taskForm="taskForm" :taskName="'项目安排'" :disabled="taskName != '项目安排'" @goBack="goBack" @returnBack="returnOpen = true">
            </arrangeProject>
          </el-tab-pane>
          <el-tab-pane label="经营审核" name="经营审核">
            <business-review :taskForm="taskForm" :taskName="taskName" :disabled="taskName != '经营审核'"
              @goBack="goBack" @returnBack="returnOpen = true"></business-review>
          </el-tab-pane>
          <el-tab-pane label="分管审核" name="分管审核">
            <manage-review :taskForm="taskForm" :taskName="taskName" :disabled="taskName != '分管审核'"
              @goBack="goBack" @returnBack="returnOpen = true"></manage-review>
          </el-tab-pane>
          <!-- <el-tab-pane label="生产确认" name="生产确认">
            <sc-confirm :taskForm="taskForm" :taskName="taskName" :disabled="taskName != '生产确认'"
              @goBack="goBack"></sc-confirm>
          </el-tab-pane> -->
          <el-tab-pane label="项目生产" name="项目生产">
            <in-progress :taskForm="taskForm" :taskName="taskName" :disabled="taskName != '项目生产'"
              @goBack="goBack" @returnBack="returnOpen = true"></in-progress>
          </el-tab-pane>
          <el-tab-pane label="项目预算" name="项目预算">
            <budget-tab :taskForm="taskForm" @goBack="goBack"></budget-tab>
          </el-tab-pane>
          <el-tab-pane label="安全交底" name="安全交底">
            <safe-tab :taskForm="taskForm" @goBack="goBack"></safe-tab>
          </el-tab-pane>
          <el-tab-pane label="技术交底" name="技术交底">
            <technical-tab :taskForm="taskForm" @goBack="goBack"></technical-tab>
          </el-tab-pane>
          <el-tab-pane label="技术方案" name="技术方案">
            <plan-tab :taskForm="taskForm" :taskName="taskName" @goBack="goBack"></plan-tab>
          </el-tab-pane>
        </el-tabs>
      </el-col>
      <el-col :xs="24" :md="6">
        <el-card>
          <h2 style="text-align: center;">流程进度</h2>
          <div>
            <flow :flowData="flowData" />
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-dialog title="退回" :visible.sync="returnOpen" width="40%" append-to-body>
      <return-btn :taskForm="taskForm" @goBack="$emit('goBack')" @cancel="returnOpen = false"></return-btn>
    </el-dialog>
  </div>
</template>

<script>
import { listProject, submitProject, modifyProject, delProject } from "@/api/oa/project/project"
import { listDept } from '@/api/system/dept'
import { listUser, getUser } from '@/api/system/user'
import addproject from "./addproject.vue"
import arrangeProject from "./arrangeProject.vue"
import businessReview from "./businessReview.vue"
import flow from '@/views/flowable/task/todo/detail/flow'
import { flowXmlAndNode } from "@/api/flowable/definition";
import ManageReview from './manageReview.vue'
import ScConfirm from './scConfirm.vue'
import InProgress from './inProgress.vue'
import BudgetTab from './budgetTab.vue'
import planTab from './planTab.vue'
import SafeTab from './safeTab.vue'
import technicalTab from './technicalTab.vue'
import AssessWork from './assessWork.vue'
import ReturnComment from '@/views/flowable/form/components/flowBtn/returnComment.vue';
import ReturnBtn from '@/views/flowable/form/components/flowBtn/returnBtn.vue';
export default {
  props: {
    taskName: {
      type: String
    },
    taskForm: {
      type: Object,
    }
  },
  components: {
    addproject, arrangeProject, businessReview, flow, ManageReview, ScConfirm, InProgress, BudgetTab, planTab, SafeTab, technicalTab, AssessWork, ReturnComment,
    ReturnBtn
  },
  data() {
    return {
      activeName: '项目登记',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectNumber: '',
        projectLeader: '',
        projectLeaderName: undefined,
        projectName: '',
      },
      projectList: [],
      total: 0,
      loading: true,
      addOpen: false,
      modifyOpen: false,
      title: '',
      addForm: {},
      rules: {
        projectNumber: [{ required: true, message: '请输入项目编号', trigger: 'blur' }],
        projectName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }]
      },
      peopleVisible: false,
      peopleForm: {
        deptId: '',
        deptList: [],
        userId: '',
        userList: []
      },
      workList: [{
        content: '',
        scale: '',
        unit: '',
        workload: '',
        deadline: '',
        remark: ''
      }],
      flowData: {},
      showAlter: true,
      returnOpen:false,
    }
  },
  created() {
    if (this.taskName != '' && this.taskName != undefined && this.taskName != null) {
      this.activeName = this.taskName;
    }
    this.getList();
    this.getDeptList();
    flowXmlAndNode({ procInsId: this.taskForm.procInsId, deployId: this.taskForm.deployId }).then(res => {
      this.flowData = res.data;
    })
  },
  methods: {
    // 查询项目列表
    getList() {
      this.loading = true
      listProject(this.queryParams).then(response => {
        this.projectList = [];
        for (let p of response.rows) {
          if (p.projectLeader != null) {
            getUser(Number(p.projectLeader)).then(res => {
              p.projectLeaderName = res.data.nickName;
            })
          }
          this.projectList.push(p);
        }
        this.total = response.total;
        this.loading = false;
      })
    },
    getDeptList() {
      listDept({
        deptName: undefined,
        status: undefined
      }).then(res => {
        this.peopleForm.deptList = res.data
      })
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleAdd() {
      this.title = '新增项目'
      this.addOpen = true
    },
    handleUpdate(row) {
      this.addForm = row;
      this.title = '修改项目信息';
      this.addOpen = true;
    },
    handleDelete(row) {
      const projectIds = row.projectId || this.ids;
      const projectNumbers = row.projectNumber || this.ids;
      this.$modal.confirm('是否确认删除项目编号为"' + projectNumbers + '"的数据项？').then(function () {
        return delProject(projectIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    // 人员选择
    choosePeople() {
      this.peopleVisible = true;
    },
    // 改变部门选择
    handleChangeDept(deptId) {
      this.peopleForm.userId = '';
      listUser({ pageSize: 999999, deptId }).then(res => {
        this.peopleForm.userList = res.rows
      })
    },
    // 确定项目负责人
    confirmPeople() {
      this.addForm.projectLeader = this.peopleForm.userId;
      this.addForm.projectLeaderName = this.tagLeader()
      this.peopleVisible = false
    },
    tagLeader() {
      if (this.addForm.projectLeader == '' || this.addForm.projectLeader == undefined || this.addForm.projectLeader == null) {
        return undefined
      } else {
        for (let user of this.peopleForm.userList) {
          if (this.addForm.projectLeader == user.userId) {
            return user.nickName
          }
        }
      }
    },
    cancel() {
      this.peopleForm.deptId = '';
      this.peopleForm.userId = '';
      this.addOpen = false;
      this.addForm = {}
    },
    addWorkList() {
      this.workList.push({
        content: '',
        scale: '',
        unit: '',
        workload: '',
        deadline: '',
        remark: ''
      });
    },
    deletWorkItem(index) {
      let arr = this.workList
      if (arr.length == 1) {
        return
      }
      if (index >= 0 && index < arr.length) {
        arr.splice(index, 1);
      }
    },
    cancelChoosePeople() {
      this.peopleForm.deptId = '';
      this.peopleForm.userId = '';
      this.peopleVisible = false;
    },
    goBack() {
      this.$emit('goBack')
    },
    isReturn(val) {
      this.showAlter = val
    },
  },
}
</script>

<style lang="scss" scoped>
@import "@/assets/styles/element-reset.scss";

.project-wrapper {
  padding: 25px;
}

.table-header {
  background-color: #f5f5f5;
}

.card-header {
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
}

table {
  /*居中*/
  margin: 0 auto;
  /*边框*/
  /* border: 1px solid black; */
  text-align: center;
  border-collapse: collapse;
  /*设置背景颜色*/
  /* background-color: #bfa; */
}

.tabs-border {
  border: 1px solid #DCDFE6;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
}


::v-deep .el-tabs__item {
  line-height: 60px;
  height: 60px;
}
</style>./arrangeProject.vue