<template>
  <el-dialog
    v-dialogDrag
    title="查看剥离力测试"
    :visible.sync="open"
    width="1200px"
    append-to-body
    @open="dialogOpen"
    @close="dialogClose"
  >
    <el-row :gutter="10" class="mb20">
      <el-col :span="1.5">
        <el-button type="primary" size="mini" @click="handleViewWaveform"
          >查看波形图</el-button
        >
      </el-col>
    </el-row>
    <!-- 列表 -->
    <el-table
      ref="table"
      v-loading="loading"
      :data="list"
      border
      size="mini"
      max-height="700px"
    >
      <el-table-column
        label=""
        align="center"
        prop="sn"
        :formatter="formatScientific"
      >
        <template slot-scope="scope">
          <span v-if="sn !== scope.row.sn">{{ scope.row.sn }}</span>
          <span v-else>\</span>
        </template>
      </el-table-column>
      <el-table-column label="第1区间平均荷重(gf)" align="center" prop="avg1" />
      <el-table-column label="第2区间平均荷重(gf)" align="center" prop="avg2" />
      <el-table-column label="第3区间平均荷重(gf)" align="center" prop="avg3" />
      <el-table-column label="第4区间平均荷重(gf)" align="center" prop="avg4" />
      <el-table-column
        label="剥离区间最大荷重(gf)"
        align="center"
        prop="pmax"
        :formatter="formatScientific"
      />
      <el-table-column
        label="剥离区间最小荷重(gf)"
        align="center"
        prop="pmin"
        :formatter="formatScientific"
      />
      <el-table-column
        label="剥离区间平均荷重(gf)"
        align="center"
        prop="pavg"
        width="100"
        :formatter="formatScientific"
      />
    </el-table>

    <!-- 查看波形图 -->
    <IssuePrinit ref="issuePrint" />
  </el-dialog>
</template>

<script>
import { getPeelingList } from "@/api/wms/quality/iqcInspectionExecute";
// import { createMaterialItem, modifyMaterialItem } from '@/api/wms/quality/inspectionCase'
import IssuePrinit from "@/views/wms/output/productionIssue/issueDetails/IssuePrinit.vue";

export default {
  name: "AddInspectionItems",
  components: {
    IssuePrinit,
  },
  props: {
    inspectionType: {
      type: Number,
      default: 0,
    },
    caselist: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      ensureLoading: false,
      selectDisabled: false,
      // 是否是第一次加载
      isFirst: true,
      // 总条数
      total: 0,
      // WMS 品质管理-检验项管理列表
      list: [],
      currentRows: [],
      // 选中的
      selectList: [],
      // 弹出层标题
      title: "",
      caseTitle: "",
      // 物料编码，modify时传
      materialNo: "",
      // 是否显示弹出层
      open: false,
      dom: "",
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        materialLots: null,
        resultId: null,
      },
      sn: null,
      //
      modifyParams: {},
      // 表单参数
      form: {},
      isLoading: false,
      // 表单校验
      rules: {
        inspectionNo: [
          { required: true, message: "检验项编码不能为空", trigger: "blur" },
        ],
        inspectionName: [
          { required: true, message: "检验项名称不能为空", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    /** 查询列表 */
    getList() {
      // 暂时不调getPeelingList()屏蔽掉
      // this.loading = true
      // // 执行查询
      // getPeelingList(this.queryParams).then(response => {
      //   this.list = response.data
      // }).finally(() => {
      //   this.loading = false
      // })
      this.loading = false;
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        inspectionNo: undefined,
        inspectionName: undefined,
        inspectionModel: undefined,
        inspectionType: undefined,
        minValue: undefined,
        standValue: undefined,
        maxValue: undefined,
        code: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加检验项管理";
    },
    dialogOpen() {
      this.$nextTick(() => {
        this.getList();
      });
    },
    dialogClose() {
      const { queryParams } = this;
      queryParams.pageNo = 1;
      queryParams.pageSize = 10;
      this.selectList = [];
      this.getList();
    },
    getOnlyRowKey(row) {
      return row.id;
    },
    // 数据转换
    formatScientific(row, column, cellValue) {
      const scientificNotation = /\d(?:\.(\d*))?e([+-]\d+)/;
      if (scientificNotation.test(cellValue) === true) {
        return parseFloat(cellValue).toFixed(7);
      } else {
        return cellValue;
      }
    },
    // 查看波形图
    handleViewWaveform() {
      if (this.list && this.list[0]?.url) {
        const { url } = this.list[0];
        this.$refs.issuePrint.title = "查看波形图";
        this.$refs.issuePrint.src = url;
        this.$refs.issuePrint.dialogVisible = true;
      } else {
        this.$modal.msgWarning(this.list ? "暂无可展示的波形图！" : "暂无数据");
      }
    },
  },
};
</script>
