<template>
  <!-- 添加或修改特种设备申请对话框 -->
  <el-dialog  :close-on-click-modal="false" :title="$t('申请月度检查')" :visible.sync="visible" width="1200px" append-to-body>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="" label-width="80px">
      <el-form-item label="申请设备">
        <el-table
          :data="devList"
          border
          style="width: 100%">
          <el-table-column :label="$t('装置名称')" align="center" prop="plantCode" :show-overflow-tooltip="true"/>
          <el-table-column :label="$t('检查年月')" align="center" prop="checkMonth" width="100">
          </el-table-column>
          <el-table-column header-align="center" align="center" :label="$t('压力容器')">
            <el-table-column :label="$t('容器单元')" align="center" prop="rqUnit" :show-overflow-tooltip="true"/>
            <el-table-column :label="$t('容器本体')" align="center" prop="rqSelf" :formatter="rqSelfFormat" />
            <el-table-column :label="$t('安全附件')" align="center" prop="rqSafe" :formatter="rqSafeFormat" />
            <el-table-column :label="$t('安全保护装置')" align="center" prop="rqProtect" :formatter="rqProtectFormat" />
            <el-table-column :label="$t('测量调控装置，紧急切断阀')" align="center" prop="rqControl" :formatter="rqControlFormat" />
            <el-table-column :label="$t('附属仪器仪表')" align="center" prop="rqIns" :formatter="rqInsFormat" />
            <el-table-column :label="$t('有无泄漏')" align="center" prop="rqOut" :formatter="rqOutFormat" />
            <el-table-column :label="$t('其它情况描述')" align="center" prop="rqOther" :show-overflow-tooltip="true"/>
            <el-table-column :label="$t('容器备注')" align="center" prop="rqRemark" :show-overflow-tooltip="true"/>
          </el-table-column>
          <el-table-column header-align="center" align="center" :label="$t('压力管道')">
            <el-table-column :label="$t('管道区域/单元')" align="center" prop="gdUnit" :show-overflow-tooltip="true"/>
            <el-table-column :label="$t('管道宏观')" align="center" prop="gdSelf" :formatter="gdSelfFormat" />
            <el-table-column :label="$t('安全附件')" align="center" prop="gdSafe" :formatter="gdSafeFormat" />
            <el-table-column :label="$t('测量调控装置')" align="center" prop="gdControl" :formatter="gdControlFormat" />
            <el-table-column :label="$t('附属仪器仪表')" align="center" prop="gdIns" :formatter="gdInsFormat" />
            <el-table-column :label="$t('有无泄漏')" align="center" prop="gdOut" :formatter="gdOutFormat" />
            <el-table-column :label="$t('其它情况描述')" align="center" prop="gdOther" :show-overflow-tooltip="true"/>
            <el-table-column :label="$t('管道备注')" align="center" prop="gdRemark" :show-overflow-tooltip="true"/>
          </el-table-column>
          <el-table-column header-align="center" align="center" :label="$t('锅炉')">
            <el-table-column :label="$t('锅炉区域/单元')" align="center" prop="glUnit" :show-overflow-tooltip="true"/>
            <el-table-column :label="$t('承压部件')" align="center" prop="glPressure" :formatter="glPressureFormat" />
            <el-table-column :label="$t('安全附件')" align="center" prop="glSafe" :formatter="glSafeFormat" />
            <el-table-column :label="$t('仪表及联锁保护装置')" align="center" prop="glIns" :formatter="glInsFormat" />
            <el-table-column :label="$t('燃烧器')" align="center" prop="glBurn" :formatter="glBurnFormat" />
            <el-table-column :label="$t('人员')+$t('证书')" align="center" prop="glCer" :formatter="glCerFormat" />
            <el-table-column :label="$t('水质化验')" align="center" prop="glWater" :formatter="glWaterFormat" />
            <el-table-column :label="$t('其它情况描述')" align="center" prop="glOther" :show-overflow-tooltip="true"/>
            <el-table-column :label="$t('锅炉')+$t('备注')" align="center" prop="glRemark" :show-overflow-tooltip="true"/>
          </el-table-column>
        </el-table>
      </el-form-item>
      <el-form-item :label="$t('机械维修')" prop="mechanical">
        <el-select v-model="dataForm.mechanical" filterable :placeholder="$t('请选择')+$t('机械维修')">
          <el-option
            v-for="item in userOption"
            :key="item.userId"
            :label="item.nickName"
            :value="item.userId"
            :disabled="item.disabled">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('电仪维修')" prop="electric">
        <el-select v-model="dataForm.electric" filterable :placeholder="$t('请选择')+$t('电仪维修')">
          <el-option
            v-for="item in userOption"
            :key="item.userId"
            :label="item.nickName"
            :value="item.userId"
            :disabled="item.disabled">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('工艺部门')" prop="craft">
        <el-select v-model="dataForm.craft" filterable :placeholder="$t('请选择')+$t('工艺部门')">
          <el-option
            v-for="item in userOption"
            :key="item.userId"
            :label="item.nickName"
            :value="item.userId"
            :disabled="item.disabled">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">{{ $t('提交') }}</el-button>
      <el-button @click="cancel">{{ $t('取 消') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {getToken} from "@/utils/auth";
import {addMonthApprove} from "@/api/sems/approve";
import {listPostUser} from "@/api/system/user";

export default {
  name: "tapprove-add",
  data() {
    return {
      visible: false,
      devList: [],
      userOption:[],
      fileTips: '',
      showDelay: false,
      dataForm: {
        id: 0,
        monthId: '',
        approveType: 8,
        devId: '',
        mechanical: '',
        electric: '',
        craft: ''
      },
      conOptions: [],
      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' }
        ]
      },
      approveOption: [],
      // 容器本体字典
      rqSelfOptions: [],
      // 安全附件字典
      rqSafeOptions: [],
      // 安全保护装置字典
      rqProtectOptions: [],
      // 测量调控装置，紧急切断阀字典
      rqControlOptions: [],
      // 附属仪器仪表字典
      rqInsOptions: [],
      // 有无泄漏字典
      rqOutOptions: [],
      // 管道宏观字典
      gdSelfOptions: [],
      // 安全附件字典
      gdSafeOptions: [],
      // 测量调控装置字典
      gdControlOptions: [],
      // 附属仪器仪表字典
      gdInsOptions: [],
      // 有无泄漏字典
      gdOutOptions: [],
      // 承压部件字典
      glPressureOptions: [],
      // 安全附件字典
      glSafeOptions: [],
      // 仪表及联锁保护装置字典
      glInsOptions: [],
      // 燃烧器字典
      glBurnOptions: [],
      // 人员证书字典
      glCerOptions: [],
      // 水质化验字典
      glWaterOptions: [],
      plantOptions: [],
      belong: '',
      fileList: [],
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getDicts("REPORT_CON").then(response => {
      this.conOptions = response.data;
    });
    this.getDicts("ABNORMALITY").then(response => {
      this.rqSelfOptions = response.data;
    });
    this.getDicts("CONFORM").then(response => {
      this.rqSafeOptions = response.data;
    });
    this.getDicts("CONFORM").then(response => {
      this.rqProtectOptions = response.data;
    });
    this.getDicts("INTACT").then(response => {
      this.rqControlOptions = response.data;
    });
    this.getDicts("INTACT").then(response => {
      this.rqInsOptions = response.data;
    });
    this.getDicts("WITH_WITHOUT").then(response => {
      this.rqOutOptions = response.data;
    });
    this.getDicts("ABNORMALITY").then(response => {
      this.gdSelfOptions = response.data;
    });
    this.getDicts("CONFORM").then(response => {
      this.gdSafeOptions = response.data;
    });
    this.getDicts("CONFORM").then(response => {
      this.gdControlOptions = response.data;
    });
    this.getDicts("INTACT").then(response => {
      this.gdInsOptions = response.data;
    });
    this.getDicts("WITH_WITHOUT").then(response => {
      this.gdOutOptions = response.data;
    });
    this.getDicts("ABNORMALITY").then(response => {
      this.glPressureOptions = response.data;
    });
    this.getDicts("CONFORM").then(response => {
      this.glSafeOptions = response.data;
    });
    this.getDicts("CONFORM").then(response => {
      this.glInsOptions = response.data;
    });
    this.getDicts("INTACT").then(response => {
      this.glBurnOptions = response.data;
    });
    this.getDicts("CONFORM").then(response => {
      this.glCerOptions = response.data;
    });
    this.getDicts("CONFORM").then(response => {
      this.glWaterOptions = response.data;
    });
  },
  methods: {
    init (rows, type) {
      this.visible = true
      this.fileList = []
      this.devList = rows
      listPostUser(this.queryParams).then(response => {
        this.userOption = response;
      });
    //这里的monthId是指的月度检查的Id
      for (let i = 0; i < rows.length; i++) {
        if (i == 0){
          this.dataForm.monthId = rows[i].id
        }else {
          this.dataForm.monthId += ',' + rows[i].id
        }
      }
    },
    // 设备类型：字典翻译
    devTypeFormat(row, column) {
      return this.selectDictLabel(this.devTypeOptions, row.devType);
    },
    // 审批类型字典翻译
    approveTypeFormat(row, column) {
      return this.selectDictLabel(this.approveTypeOptions, row.approveType);
    },
    // 检查结论字典翻译
    conFormat(row, column) {
      return this.selectDictLabel(this.conOptions, row.con);
    },
    // 容器本体字典翻译
    rqSelfFormat(row, column) {
      return this.selectDictLabel(this.rqSelfOptions, row.rqSelf);
    },
    // 安全附件字典翻译
    rqSafeFormat(row, column) {
      return this.selectDictLabel(this.rqSafeOptions, row.rqSafe);
    },
    // 安全保护装置字典翻译
    rqProtectFormat(row, column) {
      return this.selectDictLabel(this.rqProtectOptions, row.rqProtect);
    },
    // 测量调控装置，紧急切断阀字典翻译
    rqControlFormat(row, column) {
      return this.selectDictLabel(this.rqControlOptions, row.rqControl);
    },
    // 附属仪器仪表字典翻译
    rqInsFormat(row, column) {
      return this.selectDictLabel(this.rqInsOptions, row.rqIns);
    },
    // 有无泄漏字典翻译
    rqOutFormat(row, column) {
      return this.selectDictLabel(this.rqOutOptions, row.rqOut);
    },
    // 管道宏观字典翻译
    gdSelfFormat(row, column) {
      return this.selectDictLabel(this.gdSelfOptions, row.gdSelf);
    },
    // 安全附件字典翻译
    gdSafeFormat(row, column) {
      return this.selectDictLabel(this.gdSafeOptions, row.gdSafe);
    },
    // 测量调控装置字典翻译
    gdControlFormat(row, column) {
      return this.selectDictLabel(this.gdControlOptions, row.gdControl);
    },
    // 附属仪器仪表字典翻译
    gdInsFormat(row, column) {
      return this.selectDictLabel(this.gdInsOptions, row.gdIns);
    },
    // 有无泄漏字典翻译
    gdOutFormat(row, column) {
      return this.selectDictLabel(this.gdOutOptions, row.gdOut);
    },
    // 承压部件字典翻译
    glPressureFormat(row, column) {
      return this.selectDictLabel(this.glPressureOptions, row.glPressure);
    },
    // 安全附件字典翻译
    glSafeFormat(row, column) {
      return this.selectDictLabel(this.glSafeOptions, row.glSafe);
    },
    // 仪表及联锁保护装置字典翻译
    glInsFormat(row, column) {
      return this.selectDictLabel(this.glInsOptions, row.glIns);
    },
    // 燃烧器字典翻译
    glBurnFormat(row, column) {
      return this.selectDictLabel(this.glBurnOptions, row.glBurn);
    },
    // 人员证书字典翻译
    glCerFormat(row, column) {
      return this.selectDictLabel(this.glCerOptions, row.glCer);
    },
    // 水质化验字典翻译
    glWaterFormat(row, column) {
      return this.selectDictLabel(this.glWaterOptions, row.glWater);
    },
    // 取消按钮
    cancel() {
      this.visible = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: 0,
        devType: 2,
        approveType: 7,
        devId: '',
        inspectorOne: '',
        inspectorTwo: '',
        inspectorThree: '',
        auditor: '',
        approver: '',
        checkDate: ''
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          addMonthApprove(this.dataForm).then(response => {
              this.msgSuccess(this.$t('申请成功'));
              this.visible = false;
            });
        }
      });
      this.$emit('refreshDataList')
    },
}
}


</script>

<style scoped>

</style>
