<template>
  <el-dialog :close-on-click-modal="false"
             :title="!this.taskForm.taskId == '' ? $t('处理') : $t('详情')"
             :visible.sync="visible"
             :append-to-body="true"
             width="60%" :close="this.$emit('refreshDataList')">
    <Subitem ref="subitem" v-if="subitemVisible" :sub-id="Number(subId)" :serial-number="sn" :is-approve="isApprove"
             @refreshHisList="afterConfirm"/>
    <span slot="footer" class="dialog-footer">
      <el-button v-if="!this.taskForm.taskId == ''&&isApprove==2" type="primary"
                 @click="dataFormSubmit(0)">通过</el-button>
      <el-button @click="visible = false">{{ $t('返回') }}</el-button>
    </span>
    <div>
      <span>{{ $t('流转详情') }}</span>
      <el-table :data="historyList" border v-loading="historyLoading" style="width: 100%;">
        <el-table-column prop="taskName" header-align="center" align="center"
                         :label="$t('流程进度')"></el-table-column>
        <el-table-column prop="userName" header-align="center" align="center" :label="$t('姓名')"></el-table-column>
        <el-table-column prop="taskCreateTime" header-align="center" align="center"
                         :label="$t('开始时间')"></el-table-column>
        <el-table-column prop="taskEndTime" header-align="center" align="center"
                         :label="$t('结束时间')"></el-table-column>
        <el-table-column prop="comment" header-align="center" align="center"
                         :label="$t('审批意见')"></el-table-column>
      </el-table>
    </div>
  </el-dialog>
</template>

<script>
import {getHistorylist} from "@/api/ehs/approvedanger";
import Subitem from "@/views/pssr/subitem/index.vue";
import {getSubcontent} from "@/api/pssr/subcontent";
import {handlePssrApprove, listApprove} from "@/api/pssr/approve";
import PssrMgrApproveDetail from "@/views/approve/approveDetail/pssrMgrApprove-detail.vue";

export default {
  name: "pssrApprove-detail",
  components: {PssrMgrApproveDetail, Subitem},
  data() {
    return {
      //label样式
      labelStyle: {'width': '200px'},
      isApprove: 1,//0-显示新增等按钮；1-确认人查询（我的待办）；2-28项负责人查询（我的待办）；3-无按钮；4-确认人1；5-确认人2；6-确认人3；
      //流转列表
      historyList: [],
      historyLoading: true,
      submitDisabled: false,
      taskName: '',
      visible: false,
      subitemVisible: false,
      subId: null,
      sn: '',
      taskForm: {
        comment: '',
        taskId: '',
        processId: '',
        condition: '',
        taskName: '',
        processName: '',
        businessKey: '',
        tPssrApprove: {}
      },
      devList: [],
      dataForm: {},
      form: {},
      rules: {},
      flag: false
    }
  },
  methods: {
    init(id, taskId, processId, taskName, sn) {
      console.log("11", sn)
      this.sn = sn;
      this.subitemVisible = false;
      getSubcontent(id).then(res => {
        if (taskName == '检查内容负责人') {
          this.isApprove = 2;
        }
        if (taskName == '确认人1' || taskName == '确认人') {
          this.isApprove = 4;
        }
        if (taskName == '确认人2') {
          this.isApprove = 5;
        }
        if (taskName == '确认人3') {
          this.isApprove = 6;
        }
        console.log(res)
        this.subId = id;
        this.taskForm.taskId = taskId
        this.taskForm.processId = processId
        this.taskForm.taskName = taskName
        if (!taskId) {
          this.isApprove = 3;
        }
        console.log("detail", this.sn)
        this.visible = true;
        this.getHistorylist();
      })
      listApprove({subId: id}).then(res => {
        this.taskForm.tPssrApprove = res.rows[0];
        this.$nextTick(() => {
          this.subitemVisible = true;
        });
        console.log(this.taskForm)
      })
      console.log(this.isApprove)
    },
    getHistorylist() {
      getHistorylist({processId: this.taskForm.processId}).then(response => {
        this.historyLoading = false
        this.historyList = response.rows;
      });
    },
    afterConfirm() {
      this.visible = false;
      this.subitemVisible = false
      this.$emit('refreshDataList')
    },
    dataFormSubmit(val) {
      this.taskForm.condition = val;
      handlePssrApprove(this.taskForm).then(res => {
        this.msgSuccess("审核成功");
        this.visible = false;
        this.$emit('refreshDataList')
      })
    },
  }

}
</script>

<style scoped>

</style>
