<!--
 * @Author: ysh
 * @Date: 2024-04-08 13:56:14
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-04-30 11:27:44
-->
<template>
  <div class="app-container">
    <h2 style="text-align:center;">经营审核</h2>
    <el-form :model="form" :rules="rules" label-width="100px" :disabled="disabled">
      <el-form-item label="审核意见：" prop="jyComment">
        <el-input type="textarea" :rows="4" placeholder="请输入审核意见" v-model="form.jyComment">
        </el-input>
      </el-form-item>
      <el-form-item label="签名：">
        <span class="auditor">{{ form.jyApproverName }}</span>
      </el-form-item>
      <el-form-item label="审核时间：">
        {{ form.jyApprovalTime }}
      </el-form-item>
      <el-form-item>
        <p style="text-align:center;"><el-button type="primary" @click="confirm">确认审核</el-button></p>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import { parseTime } from "@/utils/ruoyi";
import { complete, rejectTask, returnList, returnTask, getNextFlowNode, delegate, flowTaskForm } from "@/api/flowable/todo";
import { getProjectComment, addProjectComment } from "@/api/oa/project/projectComment"
import { listProject, getProject, addProject, updateProject, delProject, submitProject, modifyProject } from "@/api/oa/project/project";
import { getUsersManageLeaderByDept } from '@/api/system/post'
export default {
  computed: {
    ...mapGetters(['name', 'userId']),
  },
  props: {
    disabled: {
      type: Boolean,
      require: true,
    },
    taskForm: {
      type: Object,
      required: true,
    },
    taskName: {
      type: String,
      required: true,
    }
  },
  data() {
    return {
      form: {
        jyApprover: '',
        jyApproverName: '',
        jyApprovalTime: ''
      },
      rules: {
        jyComment: [{ required: true, message: "请输入审核意见", trigger: "blur" }]
      },
      jyApprovalTime: "",
      managerList: []
    }
  },
  created() {
    if (this.$route.query.taskName != '项目登记' && this.$route.query.taskName != '项目安排') {
      this.initForm();
    }
  },
  mounted() {
    if (this.$route.query.taskName != '项目登记' && this.$route.query.taskName != '项目安排') {
      this.getDeptManageLeader()
    }
  },
  methods: {
    initForm() {
      getProjectComment(this.taskForm.formId).then(res => {
        if (res.data) {
          this.form = res.data
          if (this.form.jyUser) {
            this.form.jyApproverName = this.form.jyUser.nickName
          }
        } else {
          if (this.taskName == '经营审核') {
            this.form.jyApproverName = this.name;
            this.form.jyApprover = this.userId;
            this.form.jyApprovalTime = parseTime(new Date(), '{y}-{m}-{d}')
          } else {
            this.form.jyApprover = '';
            this.form.jyApprovalTime = '';
          }
        }
      })
    },
    getDeptManageLeader() {
      getProject(this.taskForm.formId).then(res => {
        let deptId = res.data.undertakingDept.split(',');
        this.$store.commit('SET_UNDERDEPTID', deptId);
        for (let d of deptId) {
          getUsersManageLeaderByDept({ deptId: Number(d) }).then(resopnse => {
            if (resopnse.data) {
              this.managerList.push(resopnse.data.userId)
            }
          })
        }
      })
    },
    confirm() {
      this.form.projectId = this.taskForm.formId
      addProjectComment({ projectId: this.taskForm.formId, jyComment: this.form.jyComment })
      const params = { taskId: this.taskForm.taskId };
      // 获取下一个流程节点
      getNextFlowNode(params).then(res => {
        this.managerList.push(10)
        this.managerList.push(7)
        this.managerList = Array.from(new Set(this.managerList));
        this.$set(this.taskForm.variables, "approvalList", this.managerList);
        complete(this.taskForm).then(response => {
          this.$modal.msgSuccess(response.msg);
          this.$emit("goBack");
        });
      });
    },
  },
}
</script>

<style lang="scss" scoped>
.auditor {
  font-family: '华文行楷';
  font-size: 20px;
}
::v-deep .el-textarea.is-disabled .el-textarea__inner {
  color: #121212 !important;
}
</style>