<template >
  <div class="app-container">
    <el-table v-loading="loading" :data="approvedangerList" @selection-change="handleSelectionChange" :height="clientHeight" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column :label="$t('流程') + $t('ID')" align="center" prop="processId" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('流程') + $t('名称')" align="center" prop="processName" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('流程') + $t('创建时间')" align="center" prop="processCreateTime" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('申请人') + $t('姓名')" align="center" prop="apName" :show-overflow-tooltip="true"/>
<!--      <el-table-column :label="$t('隐患级别')" align="center" prop="tApprove.hiddendangerLevel" :show-overflow-tooltip="true"/>-->
      <el-table-column :label="$t('申请编号')" align="center" prop="apNo" :show-overflow-tooltip="true"/>
      <el-table-column
        prop="isEnd"
        header-align="center"
        align="center"
        :label="$t('是否结束')">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.end? 'success' : 'danger'"
            disable-transitions>{{scope.row.end? $t('是') : $t('否')}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >{{ $t('查看') }}</el-button>
          <el-button
            size="mini"
            type="text"
            @click="processImg(scope.row.processId)"
          >{{ $t('流程图') }}</el-button>
        </template>
      </el-table-column>
      </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 弹窗, 查看 -->
<!--    <div v-if="addOrUpdateVisible">-->
<!--      <el-dialog v-dialogDrag :visible.sync="addOrUpdateVisible" :destroy-on-close="true">-->
<!--        <add-or-update :info="approveInfo"></add-or-update>-->
<!--      </el-dialog>-->
<!--    </div>-->
    <process-img v-if="processImgVisible" ref="processImg" @refreshDataList="getList"></process-img>
    <add-or-update v-if="specDealVisible" ref="specDeal" @refreshDataList="getList"></add-or-update>
    <spec-modify v-if="specModifyDealVisible" ref="specModifyDeal" @refreshDataList="getList"></spec-modify>
    <spec-training-plan v-if="specTrainingPlanVisible" ref="specTrainingPlan" @refreshDataList="getList"></spec-training-plan>
    <spec-maintenance v-if="specMaintenanceVisible" ref="specMaintenance" @refreshDataList="getList"></spec-maintenance>
    <intact-detail v-if="intactDetailVisible" ref="intactDetail" @refreshDataList="getList"></intact-detail>
    <kekao-detail v-if="kekaoDetailVisible" ref="kekaoDetail" @refreshDataList="getList"></kekao-detail>
    <invoice-detail v-if="invoiceDetailVisible" ref="invoiceDetail" @refreshDataList="getList"></invoice-detail>
    <offlinevalve-detail v-if="offlinevalveDetailVisible" ref="offlinevalveDetail" @refreshDataList="getList"></offlinevalve-detail>
    <safetychange-detail v-if="safetychangeDetailVisible" ref="safetychangeDetail" @refreshDataList="getList"></safetychange-detail>
    <sai-apply-detail v-if="saiApplyVisible" ref="saiApplyDetail" @refreshDataList="getList"></sai-apply-detail>
  </div>
</template>

<script>
  import { getTaskdonelist } from "@/api/ehs/approvedanger";
  import AddOrUpdate from '../approveDetail/spec-detail';
  import { treeselect } from "@/api/system/dept";
  import { getToken } from "@/utils/auth";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import ProcessImg from "../processImg/index";
  import SpecModify from '../approveDetail/specModify-detail';
  import SpecTrainingPlan from '../approveDetail/specTrainingPlan-detaill';
  import SpecMaintenance from "@/views/approve/approveDetail/specMaintenance-detail";
  import IntactDetail from "@/views/approve/approveDetail/intact-detail";
  import KekaoDetail from "@/views/approve/approveDetail/kekao-detail";
  import InvoiceDetail from "@/views/approve/approveDetail/invoice-detail";
  import OfflinevalveDetail from "@/views/approve/approveDetail/offlinevalve-detail";
  import SafetychangeDetail from "@/views/approve/approveDetail/safetychange-detail";
  import SaiApplyDetail from "@/views/approve/approveDetail/sai-apply-detail";

  export default {
    name: "Taskdone",
    components: {
      SaiApplyDetail,
      SafetychangeDetail,
      OfflinevalveDetail,
      Treeselect, AddOrUpdate,ProcessImg,SpecModify,SpecTrainingPlan,SpecMaintenance,IntactDetail,KekaoDetail,InvoiceDetail
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        processImgVisible: false,
        specDealVisible: false,
        specModifyDealVisible: false,
        specTrainingPlanVisible: false,
        specMaintenanceVisible: false,
        intactDetailVisible:false,
        kekaoDetailVisible:false,
        invoiceDetailVisible:false,
        offlinevalveDetailVisible:false,
        safetychangeDetailVisible:false,
        saiApplyVisible:false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: false,
        // 总条数
        total: 0,
        // 我的申请表格数据
        approvedangerList: [],
        // 弹出层标题
        title: "",
        // 部门树选项
        deptOptions: undefined,
        clientHeight:300,
        // 是否显示弹出层
        open: false,
        // 装置名称字典
        plantCodeOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          plantCode: null,
          recorderId: null,
          hiddendangerLevel: null,
          hiddendangerContent: null,
          measures: null,
          completeTime: null,
          status: null,
          creattime: null,
          endtime: null,
          processId: null,
          approveNo: null,
          deptId: null,
        },
        // 表单参数
        form: {},
        //处理数据传输
        approveInfo: null,
        //弹窗界面是否开启
        addOrUpdateVisible: false,
      };
    },
    watch: {
      // 根据名称筛选部门树
      deptName(val) {
        this.$refs.tree.filter(val);
      }
    },
    created() {
      //设置表格高度对应屏幕高度
      this.$nextTick(() => {
        this.clientHeight = document.body.clientHeight -250
      })
      this.getList();
      this.getTreeselect();
      this.getDicts("PLANT_DIVIDE").then(response => {
        this.plantCodeOptions = response.data;
      });
    },
    methods: {
      /** 查询隐患申请列表 */
      getList() {
        this.loading = true;
        getTaskdonelist(this.queryParams).then(response => {
          this.approvedangerList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      /** 查看操作 */
      handleView (row) {
        if (row.processName == "特种设备审核"){
          this.specDealVisible = true
          this.$nextTick(() => {
            console.log(row.taskName)
            this.$refs.specDeal.init(row.specApprove.id, row.taskId, row.processId,row.taskName)
          })
        }else if (row.processName == "年度检查报告申请"){
          this.specDealVisible = true
          this.$nextTick(() => {
            console.log(row.taskName)
            this.$refs.specDeal.init(row.specApprove.id, row.taskId, row.processId,row.taskName)
          })
        }else if (row.processName == "月度检查"){
          this.specDealVisible = true
          this.$nextTick(() => {
            console.log(row.taskName)
            this.$refs.specDeal.init(row.specApprove.id, row.taskId, row.processId,row.taskName)
          })
        }else if (row.processName == "设备修改/删除审核" || row.processName == "设备新增/删除审核"){
          this.specModifyDealVisible = true
          this.$nextTick(() => {
            console.log(row.taskName)
            this.$refs.specModifyDeal.init(row.approveSpecModify.id, row.taskId, row.processId,row.taskName)
          })
        }else if (row.processName == "专项培训计划审核"){
          this.specTrainingPlanVisible = true
          this.$nextTick(() => {
            console.log(row.taskName)
            this.$refs.specTrainingPlan.init(row.approveObject.id, row.taskId, row.processId,row.taskName)
          })
        }else if (row.processName == "设备维修审批流程") {
          this.specMaintenanceVisible = true
          this.$nextTick(() => {
            console.log(row.taskName)
            this.$refs.specMaintenance.init(row.approveObject.id, row.taskId, row.processId, row.taskName)
          })
        }else if (row.processName == "设备变更申请") {
          this.intactDetailVisible = true
          this.$nextTick(() => {
            console.log(row.taskName)
            this.$refs.intactDetail.init(row.approveObject.id, row.taskId, row.processId, row.taskName)
          })
        }else if (row.processName == "可靠性管理申请") {
          this.kekaoDetailVisible = true
          this.$nextTick(() => {
            console.log(row.taskName)
            this.$refs.kekaoDetail.init(row.approveObject.id, row.taskId, row.processId, row.taskName)
          })
        }else if (row.processName == "预约开票审批流程"){
          this.invoiceDetailVisible = true
          this.$nextTick(() => {
            console.log(row)
            console.log(row.approveObj)
            this.$refs.invoiceDetail.init(row.approveObject.id, row.taskId, row.processId,row.taskName)
          })
        } else if (row.processName == "安全阀离线/切出申请流程") {
          this.offlinevalveDetailVisible = true
          this.$nextTick(() => {
            this.$refs.offlinevalveDetail.init(row.approveObject.id, row.taskId, row.processId, row.taskName)
          })
        } else if (row.processName == "组织保护措施状态变更申请流程") {
          this.safetychangeDetailVisible = true
          this.$nextTick(() => {
            this.$refs.safetychangeDetail.init(row.approveObject.id, row.taskId, row.processId, row.taskName)
          })
        } else if (row.processName == "SAI开项申请流程") {
          this.saiApplyVisible = true
          this.$nextTick(() => {
            this.$refs.saiApplyDetail.init(row.approveObject.saiApplyId, row.taskId, row.processId, row.taskName)
          })
        } else {
          this.approveInfo = row;
          this.infoTaskName = row.taskName;
          this.infoprocessName = row.processName;
          this.addOrUpdateVisible = true;
        }
      },
      // 装置名称字典翻译
      plantCodeFormat(row, column) {
        return this.selectDictLabel(this.plantCodeOptions, row.plantCode);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          plantCode: null,
          recorderId: null,
          hiddendangerLevel: null,
          hiddendangerContent: null,
          measures: null,
          completeTime: null,
          status: 0,
          creattime: null,
          endtime: null,
          processId: null,
          approveNo: null,
          deptId: null,
          delFlag: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      processImg (processId) {
        this.processImgVisible = true
        this.$nextTick(() => {
          this.$refs.processImg.init(processId)
        })
      },
    }
  };
</script>
