<template>
  <el-dialog
    title="刀模版具选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal="true"
    width="900"
    append-to-body
    center
  >
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="刀模版具编码" prop="toolCode">
        <el-input
          v-model="queryParams.toolCode"
          placeholder="请输入刀模版具编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="刀模版具名称" prop="toolName">
        <el-input
          v-model="queryParams.toolName"
          placeholder="请输入刀模版具名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="刀模版具类型" prop="toolTypeId">-->
<!--        <el-select v-model="form.toolTypeId" placeholder="请选择类型">-->
<!--          <el-option-->
<!--            v-for="dict in toolTypeOptions"-->
<!--            :key="dict.toolTypeId"-->
<!--            :label="dict.toolTypeName"-->
<!--            :value="dict.toolTypeId"-->
<!--          ></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="品牌" label-width="60px" prop="brand">
        <el-input
          v-model="queryParams.brand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="型号" label-width="60px" prop="spec">
        <el-input
          v-model="queryParams.spec"
          placeholder="请输入型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" label-width="60px" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.mes_tool_status"
            :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="toolList"
      @current-change="handleCurrent"
      @row-dblclick="handleRowDbClick"
    >
      <el-table-column width="50" align="center">
        <template v-slot="scope">
          <el-radio
            v-model="selectedToolId"
            :label="scope.row.toolId"
            @change="handleRowChange(scope.row)"
            >{{ "" }}</el-radio
          >
        </template>
      </el-table-column>
            <el-table-column label="物料编号" align="center" prop="toolCode" >
      </el-table-column>
      <el-table-column label="名称" align="center" prop="toolName" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleView(scope.row)"
            v-hasPermi="['mes:tm:tool:query']"
          >{{scope.row.toolName}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="品牌" align="center" prop="brand" :show-overflow-tooltip="true"/>
      <el-table-column label="型号" align="center" prop="spec" :show-overflow-tooltip="true"/>
      <el-table-column label="类型" align="center" prop="toolTypeName" />
      <el-table-column label="库存数量" align="center" prop="quantity" />
      <el-table-column label="可用数量" align="center" prop="quantityAvail" />
    </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 { listTool } from "@/api/mes/tm/tool";

export default {
  name: "TmToolSelect",
  dicts: ['mes_tool_status'],
  components: {},
  data() {
    return {
      showFlag: false,
      // 选中数组
      selectedToolId: undefined,
      selectedRows: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 品牌表格数据
      toolList: [],
      // // 品牌名称
      // brandName: undefined,
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brandCode: null,
        brandName: null,
        toolId: null,
      },
    };
  },
  // 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;
      listTool(this.queryParams).then((response) => {
        this.toolList = 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.selectedToolId == null || this.selectedToolId == 0) {
        this.$notify({
          title: "提示",
          type: "warning",
          message: "请至少选择一条数据!",
        });
        return;
      }
      this.$emit("onSelected", this.selectedRows);
      this.showFlag = false;
    },
  },
};
</script>
