<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="耗材名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入耗材名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="规格型号" prop="series">
        <el-input v-model="queryParams.series" placeholder="请输入规格型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="耗材品牌" prop="brand">
        <el-input v-model="queryParams.brand" placeholder="请输入耗材品牌" clearable @keyup.enter.native="handleQuery" />
      </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="materialList" highlight-current-row @row-dblclick="chooseClick">
      <el-table-column label="耗材编号" align="center" prop="materialId" />
      <el-table-column label="耗材名称" align="center" prop="name" />
      <!-- <el-table-column label="耗材类别" align="center" prop="type" /> -->
      <el-table-column label="规格型号" align="center" prop="series" />
      <el-table-column label="耗材品牌" align="center" prop="brand" />
      <el-table-column label="存放地点" align="center" prop="place" />
      <el-table-column label="剩余数量" align="center" prop="remain" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    
    <div class="text-center mt20">
      <el-button type="primary">确认选择</el-button>
      <el-button>清空选择</el-button>
    </div>
  </div>
</template>

<script>
import { listMaterial, getMaterial, delMaterial, addMaterial, updateMaterial } from "@/api/oa/material/material";
export default {
  name: "Material",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // cmc耗材信息表格数据
      materialList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        type: null,
        series: null,
        brand: null,
        place: null,
        remain: null,
        unit: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询cmc耗材信息列表 */
    getList() {
      this.loading = true;
      listMaterial(this.queryParams).then(response => {
        this.materialList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        materialId: null,
        name: null,
        type: null,
        series: null,
        brand: null,
        place: null,
        remain: null,
        unit: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    chooseClick(val){
      this.$emit('confirmChoose',val)
    }
  }
};
</script>

<style lang="scss" scoped></style>