<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="测量批次" prop="measurementBatch">
        <el-input v-model="queryParams.measurementBatch" placeholder="请输入测量批次" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="发动机型号" prop="engineModel">
        <el-input v-model="queryParams.engineModel" placeholder="请输入发动机型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="发动机状态" prop="engineStatus">
        <el-select v-model="queryParams.engineStatus" placeholder="请选择发动机状态" clearable>
          <el-option v-for="(item, index) in engineStatusOptions" :key="index" :label="item" :value="item" />
        </el-select>
      </el-form-item>
      <el-form-item label="角度" prop="angle">
        <el-select v-model="queryParams.angle" placeholder="请选择角度" clearable>
          <el-option v-for="item in angleOptions" :key="item" :label="item" :value="item" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['meas:thermalImagerTesDdata:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['meas:thermalImagerTesDdata:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['meas:thermalImagerTesDdata:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="thermalImagerTesDdataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="测量批次" align="center" prop="measurementBatch" />
      <el-table-column label="发动机型号" align="center" prop="engineModel" />
      <el-table-column label="发动机状态" align="center" prop="engineStatus"/>
      <el-table-column label="发动机角度" align="center" prop="angle"/>
      <el-table-column label="型号" align="center" prop="engineModel" />
      <el-table-column label="镜头视场角" align="center" prop="lensFView" />
      <el-table-column label="滤镜编号" align="center" prop="filterNo" />
      <el-table-column label="帧率" align="center" prop="fps" />
      <el-table-column label="波段" align="center" prop="spectralBand" />
      <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width" >
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['meas:envData:edit']"
            @click="checkView(scope.row)">查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['meas:thermalImagerTesDdata:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['meas:thermalImagerTesDdata:remove']"
          >删除</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"
    />

    <!-- 添加或修改热像仪测试数据对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="70%" append-to-body>
      <dialogContent :TIForm="TIForm" :form="form" @submit-form="submitForm" :isCheck="isCheck" @cancel="cancel"/>
    </el-dialog>
  </div>
</template>

<script>
import { listThermalImagerTesDdata, getThermalImagerTesDdata, delThermalImagerTesDdata, updateThermalImagerTesDdata,getTIDataByEnvData } from "@/api/meas/thermalImagerTesDdata";
import { angleOption } from "@/api/meas/angle";
import { statusOption } from "@/api/meas/status";
import dialogContent from "@/views/meas/components/dialogContent";
import { getEnvData } from "@/api/meas/envData";

export default {
  name: "ThermalImagerTesDdata",
  components: { dialogContent },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      measurementBatchIds: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 热像仪测试数据表格数据
      thermalImagerTesDdataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        measurementBatch: null,
        engineModel: null,
        engineStatus: null,
        angle: null,
      },
      // 表单参数
      form: {},
      TIForm: {},
      // 发动机状态
      engineStatusOptions: [],
      // 发动机角度
      angleOptions: [],
      isCheck:false,
    };
  },
  created() {
    this.getList();
    this.getAngleOption();
    this.getStatusOption();
  },
  methods: {
    /** 查询热像仪测试数据列表 */
    getList() {
      this.loading = true;
      listThermalImagerTesDdata(this.queryParams).then(response => {
        this.thermalImagerTesDdataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getAngleOption() {
      this.loading = true;
      angleOption().then((response) => {
        this.angleOptions = response.data;
        this.loading = false;
      });
    },
    getStatusOption() {
      this.loading = true;
      statusOption().then((response) => {
        this.engineStatusOptions = response.data;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.TIForm = {
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        id: null,
        measurementBatchId: null,
        engineModel: null,
        geometryFiles: null,
        geometryImage: null,
        measurementBatch: null,
        engineStatus: null,
        angle: null,
        model: null,
        lensFView: null,
        filterNo: null,
        fps: null,
        spectralBand: null,
        integrationTime: null,
        tempCal: null,
        radiance: null,
        radIllumination: null,
        radTemp: null
      };
      this.resetForm("TIForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.measurementBatchIds = selection.map(item => item.measurementBatchId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加热像仪测试数据";
    },
    checkView(row){
      this.handleUpdate(row)
      this.isCheck=true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.isCheck = false
      const id = row.measurementBatchId || this.measurementBatchIds
      getEnvData(id).then((response) => {
        this.form = response.data;
      });
      getTIDataByEnvData(id).then(response => {
        this.TIForm = response.data;
        this.open = true;
        this.title = this.isCheck?'查看热像仪测试数据':"修改热像仪测试数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      const promises = [];
      let successMessages = [];
      let failureMessages = [];
      promises.push(
        (this.form.id ? updateEnvData(this.form) : addEnvData(this.form))
          .then(() => {
            successMessages.push(`测量环境数据`);
          })
          .catch(() => {
            failureMessages.push(`测量环境数据`);
          }),
        (this.TIForm.id ? updateThermalImagerTesDdata(this.TIForm) : addThermalImagerTesDdata(this.TIForm))
          .then(() => {
            successMessages.push(`热像仪数据`);
          })
          .catch(() => {
            failureMessages.push(`热像仪数据`);
          })
      );
      Promise.all(promises)
        .then(() => {
          let message = ''
          if (successMessages.length > 0) {
            message += `${successMessages.join('、')}操作成功； `
            this.$modal.msgSuccess(message);
          }
          if (failureMessages.length > 0) {
            message += `${failureMessages.join('、')}操作失败`
            this.$modal.msgWarning(message);
          }
          this.open = false;
          this.getList();
        })
        .catch(() => {
          this.$modal.msgError("操作过程中发生了错误");
          this.open = false;
        });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.measurementBatchId || this.measurementBatchIds;
      this.$modal.confirm('是否确认删除热像仪测试数据编号为"' + ids + '"的数据项？').then(function() {
        return delThermalImagerTesDdata(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('meas/thermalImagerTesDdata/export', {
        ...this.queryParams
      }, `thermalImagerTesDdata_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped lang="scss">
::v-deep .el-form-item .el-select {
  width: 200px;
}

::v-deep .el-form-item .el-input {
  width: 200px;
}

::v-deep .el-form-item .upload-file {
  width: 200px;
}
</style>
