<template>
  <el-dialog
    title="质检选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal="true"
    width="80%"
    center
  >
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="检测项编码" prop="indexCode">
        <el-input
          v-model="queryParams.indexCode"
          placeholder="请输入检测项编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检测项名称" prop="indexName">
        <el-input
          v-model="queryParams.indexName"
          placeholder="请输入检测项名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检测项类型" prop="indexType">
        <el-select
          v-model="queryParams.indexType"
          placeholder="请选择检测项类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.mes_index_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </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-table
      v-loading="loading"
      :data="qualityList"
      @current-change="handleCurrent"
      @row-dblclick="handleRowDbClick"
    >
      <el-table-column width="50" align="center">
        <template v-slot="scope">
          <el-radio
            v-model="selectedQualityId"
            :label="scope.row.indexId"
            @change="handleRowChange(scope.row)"
            >{{ "" }}</el-radio
          >
        </template>
      </el-table-column>
      <el-table-column label="检测项编码" align="center" prop="indexCode" />
      <el-table-column label="检测项名称" align="center" prop="indexName" />
      <el-table-column label="检测项类型" align="center" prop="indexType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.mes_index_type"
            :value="scope.row.indexType"
          />
        </template>
      </el-table-column>
      <el-table-column label="检测工具" align="center" prop="qcTool" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">确 定</el-button>
      <el-button @click="showFlag = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listQcindex } from "@/api/mes/qc/qcindex";

export default {
  name: "QualityTestSelect",
  dicts: ["mes_index_type"],
  components: {},
  data() {
    return {
      showFlag: false,
      // 选中数组
      selectedQualityId: undefined,
      selectedRows: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 品牌表格数据
      qualityList: [],
      // // 品牌名称
      // brandName: undefined,
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brandCode: null,
        brandName: null,
        indexId: null,
      },
      // 列信息
      columns: [
        { key: 0, label: `品牌编码`, visible: true },
        { key: 1, label: `品牌名称`, visible: true },
        { key: 2, label: `集团`, visible: true },
        // { key: 3, label: `地址`, visible: true },
        { key: 3, label: `销售对接人`, visible: true },
        { key: 4, label: `开发对接人`, visible: true },
        // { key: 6, label: `品牌背景`, visible: true },
        { key: 5, label: `经营范围`, visible: true },
        { key: 6, label: `潜力项目`, visible: true },
        // { key: 6, label: `廉洁规定`, visible: true },
      ],
    };
  },
  // watch: {
  //   // 根据名称筛选分类树
  //   itemTypeName(val) {
  //     this.$refs.tree.filter(val);
  //   },
  // },
  created() {
    console.log("日志:已进入brandSingle页面的列表查询方法"); // 在created钩子函数中输出日志
    this.getList();
  },
  methods: {
    // /** 查询物料编码列表 */
    // getList() {
    //   this.loading = true;
    //   listMdItem(this.queryParams).then((response) => {
    //     this.itemList = response.rows;
    //     this.total = response.total;
    //     this.loading = false;
    //   });
    // },
    /** 查询品牌列表 */
    getList() {
      this.loading = true;
      listQcindex(this.queryParams).then((response) => {
        this.qualityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCurrent(row) {
      if (row) {
        this.selectedRows = row;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if (row) {
        this.selectedRows = row;
      }
    },
    //双击选中
    handleRowDbClick(row) {
      if (row) {
        this.selectedRows = row;
        this.$emit("onSelected", this.selectedRows);
        this.showFlag = false;
      }
    },
    //确定选中
    confirmSelect() {
      if (this.selectedQualityId == null || this.selectedQualityId == 0) {
        this.$notify({
          title: "提示",
          type: "warning",
          message: "请至少选择一条数据!",
        });
        return;
      }
      this.$emit("onSelected", this.selectedRows);
      this.showFlag = false;
    },
  },
};
</script>
