<template>
  <el-dialog  :close-on-click-modal="false"
              :title="!this.taskForm.taskId == '' ? $t('处理') : $t('详情')"

              width="70%"
              :visible.sync="visible">
    <el-form ref="form" :model="form" label-width="80px">
      <el-row>
        <el-col :span="12">
          <el-form-item  label-width="150px" label="周排查日期" prop="checkDate">
            <el-date-picker clearable size="small" style="width: 200px"
                            :disabled="true"
                            v-model="dataForm.checkDate"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择检查日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label-width="150px" label="周" prop="weekNo">
            <el-input v-model="dataForm.weekNo" placeholder="请输入周" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label-width="150px" label="上周安全风险隐患问题整改核实情况" prop="lastWeekRisk">
        <el-input v-model="dataForm.lastWeekRisk" type="textarea" placeholder="请输入内容"/>
      </el-form-item>
      <el-form-item label-width="150px" label="本周主要安全风险隐患和整改情况" prop="thisWeekRisk">
        <el-input v-model="dataForm.thisWeekRisk" type="textarea" placeholder="请输入内容" :disabled="true"/>
      </el-form-item>
      <el-form-item label-width="150px" label="本周安全管理情况评价">
        <el-radio-group v-model="dataForm.safeCondition" >
          <el-radio label="安全风险可控，无较大（质量）安全风险隐患">安全风险可控，无较大（质量）安全风险隐患</el-radio>
          <el-radio label="存在安全风险隐患，需尽快采取防范措施">存在安全风险隐患，需尽快采取防范措施</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label-width="150px" label="下周工作重点" prop="nextWeekWork">
        <el-input v-model="dataForm.nextWeekWork" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label-width="150px" label="安全管理员" prop="safeAdminId">
        <el-input v-model="dataForm.safeAdminName" placeholder="请输入安全管理员" :disabled="true" />
      </el-form-item>
      <el-form-item label-width="150px" label="安全管理员意见" prop="safeAdminSug">
        <el-input v-model="dataForm.safeAdminSug" type="textarea" placeholder="请输入内容" :disabled="true" />
      </el-form-item>
      <el-form-item label-width="150px" label="安全总监" prop="safeDirId">
        <el-input v-model="dataForm.safeDirName" placeholder="请输入安全总监" :disabled="true" />
      </el-form-item>
      <div style="margin-bottom: 20px">
        <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-form-item label-width="150px" label="安全总监意见" prop="safeDirSug">
        <el-input v-model="dataForm.safeDirSug" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <form ref="downloadForm" :action="downloadAction" target="FORMSUBMIT">
      <input name="approveId" v-model="dataForm.id"  hidden  />
      <input name="processId" v-model="dataForm.processId"  hidden  />
    </form>
    <span slot="footer" class="dialog-footer">
      <el-button v-if="this.taskForm.taskId == ''" @click="visible = false">{{$t('message.return')}}</el-button>
      <el-button v-if="!this.taskForm.taskId == ''" type="primary" @click="dataFormSubmit(1)" :disabled="submitDisabled">{{$t('通过')}}</el-button>
      <el-button v-if="!this.taskForm.taskId == ''" type="danger" @click="dataFormSubmit(0)" :disabled="submitDisabled">{{$t('拒绝')}}</el-button>
    </span>

  </el-dialog>
</template>

<script>
import {getToken} from "@/utils/auth";
import {getHistorylist} from "@/api/ehs/approvedanger";
import {getWeekcheck , handle} from "@/api/sems/safecheck/weekcheck";

export default {
  name: "semsWeekCheck-detail",
  data() {
    return {
      loading: true,
      // 总条数
      total: 0,
      approvedangerList: [],
      recordVisible: false,
      // 遮罩层
      historyLoading: false,
      //显示详细列表
      IfDataIndex: false,
      //流转列表
      historyList: [],
      visible: false,
      devList: [],
      recordList: [],
      dataList: [],
      fileTips: '',
      showDelay: false,
      submitDisabled: false,
      dataListLoading:true,
      taskName: '',
      dataForm: {
      },
      taskForm: {
        comment: '',
        taskId: '',
        files: '',
        govDate: '',
        govFileList: []
      },
      // 查询参数
      queryParams: {
        processId: null,
      },
      doc: {
        file: "",
        // 是否显示弹出层（报告附件）
        open: false,
        // 弹出层标题（报告附件）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 报告附件上传位置编号
        ids: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/sems/specfile/uploadFile",
        commonfileList: null,
        pType: 'traning',
        pId: null
      },
      dataRule: {
      },
      downloadAction: process.env.VUE_APP_BASE_API +'/sems/approve/exportPDF',
      approveOption: [],
      devTypeOption: [],
      belong: '',
      fileList: [],
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {

  },
  methods: {
    init (id, taskId, processId,taskName) {
      this.taskName = taskName
      this.taskForm.taskId = taskId
      this.dataForm.id = id || 0
      this.visible = true
      this.queryParams.processId = processId;
      getHistorylist(this.queryParams).then(response => {
        this.historyList = response.rows;
        this.historyLoading = false
      });
      getWeekcheck(id).then(response => {
        this.dataForm = response.data;
        if (!this.dataForm.safeDirSug && !this.taskForm.taskId == '') {
          this.dataForm.safeDirSug = '同意'
        }
      });
    },

    // 取消按钮
    cancel() {
      this.visible = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        devId: null,
        devType: null,
        approveType: null,
        content: null,
        fileUrls: null,
        reUrls: null,
        status: 0,
        creattime: null,
        endtime: null,
        processId: null,
        govDate: null,
        delayDate: null,
        delayReason: null,
        delayMeasure: null,
        delayNotice: null,
        apNo: null,
        checkDate: null,
        reportId: null,
        monthId: null,
        delFlag: null,
        deptId: null
      };
      this.resetForm("form");
    },

    /** 提交按钮 */
    // 表单提交
    dataFormSubmit (val) {
      this.submitDisabled = true

      this.taskForm.condition = val
      this.taskForm.comment = this.dataForm.safeDirSug
      this.taskForm.businessKey = this.dataForm.id
      this.taskForm.approveObject = this.dataForm
      handle(this.taskForm).then(response => {
        this.submitDisabled = false
        this.msgSuccess(this.$t('处理成功'));
        this.visible = false;
        this.$emit('refreshDataList')
      });
      this.$nextTick(function () {
        this.comment = ''
      })
    },
  }
}


</script>

<style>
.el-textarea.is-disabled .el-textarea__inner {
  color: #404040;
}
.el-input.is-disabled .el-input__inner {
  color: #404040;
}

.el-radio__input.is-disabled.is-checked .el-radio__inner {
  background-color: #404040;
  border-color: #404040;
}
.el-radio__input.is-disabled + span.el-radio__label {
  color: #404040;
}

</style>
