<template>
  <el-dialog
    :title="!this.taskForm.taskId == '' ? $t('处理') : $t('详情')"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="taskForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="" label-width="80px">
      <el-form-item :label="$t('设备')">
        <el-table
          v-show="dataForm.approveType != 7 && dataForm.devType == 1"
          :data="devList"
          border
          style="width: 100%; height: 95px" >
          <el-table-column
            prop="plantCode"
            header-align="center"
            align="center"
            :label="$t('装置名称')">
          </el-table-column>
          <el-table-column
            prop="devno"
            header-align="center"
            align="center"
            :label="$t('位号')">
          </el-table-column>
          <el-table-column
            prop="devname"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="150"
            :label="$t('设备名称')">
          </el-table-column>
          <el-table-column
            prop="useno"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('使用证编号')">
          </el-table-column>
          <el-table-column
            prop="medium"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('介质')">
          </el-table-column>
          <el-table-column
            prop="desPressure"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('设计压力')+'(MPa)'">
          </el-table-column>
          <el-table-column
            prop="desTemp"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('设计温度')+'(℃)'">
          </el-table-column>
        </el-table>
        <el-table
          v-show="dataForm.approveType != 7 && dataForm.devType == 2"
          :data="devList"
          border
          style="width: 100%; height: 95px">
          <el-table-column
            prop="plantCode"
            header-align="center"
            align="center"
            width="100"
            :label="$t('装置名称')">
          </el-table-column>
          <el-table-column
            prop="devno"
            header-align="center"
            align="center"
            width="120"
            :label="$t('位号')">
          </el-table-column>
<!--          <el-table-column-->
<!--            prop="starting"-->
<!--            header-align="center"-->
<!--            align="center"-->
<!--            width="100"-->
<!--            :show-overflow-tooltip="true"-->
<!--            :label="$t('起点')">-->
<!--          </el-table-column>-->
<!--          <el-table-column-->
<!--            prop="ending"-->
<!--            header-align="center"-->
<!--            align="center"-->
<!--            width="100"-->
<!--            :show-overflow-tooltip="true"-->
<!--            :label="$t('终点')">-->
<!--          </el-table-column>-->
          <el-table-column
            prop="medium"
            header-align="center"
            align="center"
            width="100"
            :show-overflow-tooltip="true"
            :label="$t('介质')">
          </el-table-column>
          <el-table-column
            prop="desPressure"
            header-align="center"
            align="center"
            :label="$t('设计压力')">
          </el-table-column>
          <el-table-column
            prop="desTemp"
            header-align="center"
            align="center"
            :label="$t('设计温度')">
          </el-table-column>
          <el-table-column
            prop="optPressure"
            header-align="center"
            align="center"
            :label="$t('工作压力')">
          </el-table-column>
          <el-table-column
            prop="optTemp"
            header-align="center"
            align="center"
            width="100"
            :show-overflow-tooltip="true"
            :label="$t('工作温度')">
          </el-table-column>
        </el-table>
        <el-table
          v-show="dataForm.devType == 3"
          :data="devList"
          border
          style="width: 100%; height: 95px">
          <el-table-column
            prop="plantCode"
            header-align="center"
            align="center"
            :label="$t('装置名称')">
          </el-table-column>
          <el-table-column
            prop="docno"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('档案号')">
          </el-table-column>
          <el-table-column
            prop="devname"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="150"
            :label="$t('设备名称')">
          </el-table-column>
          <el-table-column
            prop="capacity"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('起吊重量')+'(ton)'">
          </el-table-column>
          <el-table-column
            prop="location"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('使用地点')">
          </el-table-column>
        </el-table>
        <el-table
          v-show="dataForm.devType == 4"
          :data="devList"
          border
          style="width: 100%; height: 95px">
          <el-table-column
            prop="plantCode"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('装置名称')">
          </el-table-column>
          <el-table-column
            prop="devno"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('位号')">
          </el-table-column>
          <el-table-column
            prop="devname"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="120"
            :label="$t('设备名称')">
          </el-table-column>
          <el-table-column
            prop="useno"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('使用证编号')">
          </el-table-column>
          <el-table-column
            prop="desTemp"
            header-align="center"
            align="center"
            :label="$t('设计温度')+'(℃)'">
          </el-table-column>
          <el-table-column
            prop="desPressure"
            header-align="center"
            align="center"
            :label="$t('设计压力')+'(MPa)'">
          </el-table-column>
        </el-table>
        <el-table
          v-show="dataForm.devType == 5"
          :data="devList"
          border
          style="width: 100%; height: 95px">
          <el-table-column
            prop="plantCode"
            header-align="center"
            align="center"
            :label="$t('装置名称')">
          </el-table-column>
          <el-table-column
            prop="docno"
            header-align="center"
            align="center"
            :label="$t('docNo')">
          </el-table-column>
          <el-table-column
            prop="devname"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="150"
            :label="$t('设备名称')">
          </el-table-column>
          <el-table-column
            prop="model"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="120"
            :label="$t('型号')">
          </el-table-column>
          <el-table-column
            prop="location"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            :label="$t('使用地点')">
          </el-table-column>
        </el-table>
        <el-table
          v-show="dataForm.devType == 6"
          :data="devList"
          border
          style="width: 100%; height: 95px">
          <el-table-column
            prop="plantCode"
            header-align="center"
            align="center"
            :label="$t('装置名称')">
          </el-table-column>
          <el-table-column
            prop="useDept"
            header-align="center"
            align="center"
            :label="$t('dept')">
          </el-table-column>
          <el-table-column
            prop="carNo"
            header-align="center"
            align="center"
            :label="$t('plateNo')">
          </el-table-column>
          <el-table-column
            prop="docno"
            header-align="center"
            align="center"
            :label="$t('docNo')">
          </el-table-column>
          <el-table-column
            prop="model"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="120"
            :label="$t('model')">
          </el-table-column>
        </el-table>
        <el-table
          v-show="dataForm.devType == 7"
          :data="devList"
          border
          style="width: 100%; height: 95px">
          <el-table-column
            prop="plantCode"
            header-align="center"
            align="center"
            :label="$t('装置名称')">
          </el-table-column>
          <el-table-column
            prop="unit"
            header-align="center"
            align="center"
            :label="$t('单元')">
          </el-table-column>
          <el-table-column
            prop="devno"
            header-align="center"
            align="center"
            :label="$t('位号')">
          </el-table-column>
          <el-table-column
            prop="devname"
            header-align="center"
            align="center"
            :label="$t('名称')">
          </el-table-column>
          <el-table-column
            prop="createno"
            header-align="center"
            align="center"
            :label="$t('制造编号')">
          </el-table-column>
          <el-table-column
            prop="indiameter"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="120"
            :label="$t('内径')+' mm'">
          </el-table-column>
          <el-table-column
            prop="height"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="120"
            :label="$t('高(长)')+' mm'">
          </el-table-column>
          <el-table-column
            prop="chickness"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="120"
            :label="$t('壁厚(mm)')">
          </el-table-column>
          <el-table-column
            prop="volume"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="120"
            :label="$t('容积mm³')">
          </el-table-column>
          <el-table-column
            prop="medium"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="120"
            :label="$t('介质')">
          </el-table-column>
          <el-table-column
            prop="material"
            header-align="center"
            align="center"
            :show-overflow-tooltip="true"
            width="120"
            :label="$t('材料')">
          </el-table-column>
        </el-table>
        <el-button @click="recordHandle(devList,dataForm)" type="text" v-if="devList.length >1">{{$t('更多条目')}}</el-button>
      </el-form-item>
      <el-row>
        <el-col :span="8" v-if="dataForm.approveType != 8">
          <el-form-item :label="$t('设备类型')" prop="devType">
            <el-select v-model="dataForm.devType" :placeholder="$t('message.select')" disabled>
              <el-option
                v-for="dict in devTypeOption"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="parseInt(dict.dictValue)">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('申请类型')" prop="approveType">
            <el-select v-model="dataForm.approveType" :placeholder="$t('message.select')" disabled>
              <el-option>
                维修
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item :label="$t('申请时间')" prop="creattime">
        <el-input v-model="dataForm.creattime" disabled></el-input>
      </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>
<!--    <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>-->
    <record v-if="recordVisible" ref="recordDeal"></record>
  </el-dialog>
</template>

<script>
  import {getToken} from "@/utils/auth";
  import {getHistorylist} from "@/api/ehs/approvedanger";
  import {getApproveInfo, handleApprove} from "@/api/intact/approve_dev";
  import record from "./spec-itemDetail";


  export default {
  name: "spec-maintenance",
  components: {record},
  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: {
        id: 0,
        userId: '',
        devId: '',
        devType: '',
        approveType: '',
        content: '',
        fileUrls: '',
        reUrls: '',
        status: '',
        creattime: '',
        plantCode: '',
        unit: '',
        devname: '',
        devno: '',
        files: [],
        delayDate: '',
        delayReason: '',
        delayMeasure: '',
        delayNotice: ''
      },
      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: {
        approveType: [
          { required: true, message: this.$t('approveType') + this.$t('notEmpty'), trigger: 'blur' }
        ],
        content: [
          { required: true, message: this.$t('content') + this.$t('notEmpty'), trigger: 'blur' }
        ]
      },
      downloadAction: process.env.VUE_APP_BASE_API +'/sems/approve/exportPDF',
      approveOption: [],
      devTypeOption: [{dictValue:1,dictLabel:'工业炉'},{dictValue:2,dictLabel:'压缩机'},{},{}],
      belong: '',
      fileList: [],
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {

  },
  methods: {
    init (id, taskId, processId,taskName) {
      this.getDicts("INTACT_APPROVE_TYPE").then(response => {
        this.approveOption = response.data;
      });
      this.getDicts("INTACT_DEVTYPE").then(response => {
        // this.devTypeOption = response.data;
      });
      this.dataForm.processId = processId
      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
      });
      getApproveInfo(id).then(response => {
        this.taskForm.businessKey = response.data.id
        this.dataForm.userId = response.data.userId
        this.dataForm.devId = response.data.devId
        this.dataForm.devType = response.data.devType
         this.dataForm.approveType = response.data.approveType

        this.dataForm.content = response.data.content
        this.dataForm.fileUrls = response.data.fileUrls
        this.dataForm.reUrls = response.data.reUrls
        this.dataForm.status = response.data.status
        this.dataForm.creattime = response.data.creattime
        this.dataForm.plantCode = response.data.plantCode
        this.dataForm.unit = response.data.unit
        this.dataForm.devname = response.data.devname
        this.dataForm.devno = response.data.devno
        this.dataForm.files = response.data.files
        this.devList = response.data.devList
        this.dataForm.delayDate = response.data.delayDate
        this.dataForm.delayReason = response.data.delayReason
        this.dataForm.delayMeasure = response.data.delayMeasure
        this.dataForm.delayNotice = response.data.delayNotice
      });

    },
    // 设备类型：字典翻译
    devTypeFormat(row, column) {
      // return this.selectDictLabel(this.devTypeOptions, row.devType);
    },
    // 审批类型字典翻译
    approveTypeFormat(row, column) {
      return this.selectDictLabel(this.approveTypeOptions, row.approveType);
    },

    // 取消按钮
    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
      console.log(this.taskForm.govFileList)
      this.dataForm.files = []
      if (this.taskForm.govFileList.length > 0) {
        for (let i = 0; i < this.taskForm.govFileList.length; i++) {
          let obj = {}
          obj.fileName = this.taskForm.govFileList[i].response.fileName
          obj.fileUrl = this.taskForm.govFileList[i].response.url
          this.dataForm.files.push(obj)
        }
      }
      this.taskForm.condition = val
      this.taskForm.govFiles = this.dataForm.files
      handleApprove(this.taskForm).then(response => {
        this.submitDisabled = false
        this.msgSuccess(this.$t('处理成功'));
        this.visible = false;
        this.$emit('refreshDataList')
      });
      this.$nextTick(function () {
        this.comment = ''
      })
    },
    recordHandle(devList,dataForm){
      this.recordVisible = true
      this.$nextTick(() => {
        this.$refs.recordDeal.init(devList,dataForm);
      })
    },
}
}


</script>

<style scoped>

</style>
