<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="90px" >
      <el-form-item label="供应商名称">
        <el-input v-model="queryParams.name" placeholder="请输入商品名称" clearable @clear="queryParams.pageNum = 1;getList()"  @keyup.enter.native="queryParams.pageNum = 1;getList()"></el-input>
      </el-form-item>
      <el-form-item >
        <el-input v-show="false" />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getList()"
        >搜索</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="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:supplier:add']"
        >添加供应商</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList()"
      ></right-toolbar>
    </el-row>
    <!-- 列表 -->
    <el-table ref="table" v-loading="loading" :data="list">
      <el-table-column label="供应商编号" prop="id" />
      <el-table-column label="供应商名称" prop="name" />
      <el-table-column label="联系人" prop="contact" />
      <el-table-column label="手机号码" prop="phone" />
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <div>
            <el-button
              v-hasPermi="['business:supplier:query']"
              type="text"
              @click="seeEdit(row)"
            >查看</el-button
            >
            <el-button
              v-hasPermi="['business:supplier:edit']"
              type="text"
              @click="edit(row)"
            >编辑</el-button
            >
            <el-button
              v-hasPermi="['business:supplier:remove']"
              type="text"
              class="del"
              @click="del(row)"
            >删除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="pageParams.pageNum"
      :limit.sync="pageParams.pageSize"
      @pagination="getList"
    />

    <add-supplier
      v-if="createShow"
      :dialog-show="createShow"
      :id="id"
      @close="close"
    />
    <see-supplier
      v-if="seeShow"
      :dialog-show="seeShow"
      :id="id"
      @seeClose="seeClose"
    />
  </div>
</template>
<script>
import { getSupplierList, removeSupplierList } from "@/api/business/supplier";
import AddSupplier from "./components/addSupplier";
import SeeSupplier from "./components/seeSupplier"
export default {
  name: "ListBanner",
  components: {
    AddSupplier,
    SeeSupplier,
  },
  data() {
    return {
      loading: false,
      showSearch: true,
      queryParams: {
        name:"",
      },
      pageParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      list: [],
      createShow: false,
      seeShow: false,
      id: '',
    };
  },
  created() {
    this.getList();
  },
  methods: {

    getList() {
      this.loading = true;
      let data = {
        name:this.queryParams.name
      }
      getSupplierList( "pageNum=" + this.pageParams.pageNum + "&pageSize=" + this.pageParams.pageSize+'&', data )
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.total = res.total;
            this.list = res.rows;
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },

    edit(item) {
      this.id = item.id;
      this.createShow = true;
    },

    seeEdit(item) {
      this.id = item.id;
      this.seeShow = true;
    },


    del(item) {
      this.$confirm(`确认删除供应商 “${item.name}” 吗？`, "删除供应商", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        removeSupplierList(item.id).then((res) => {
          if (res.code === 0) {
            this.$message.success("操作已完成！");
            this.getList();
          }
        });
      });
    },

    // 重置
    resetQuery() {
      this.queryParams = {};
      this.pageParams.pageNum = 1
      this.getList();
    },

    handleAdd() {
      this.createShow = true;
    },

    // 关闭弹框
    close() {
      this.createShow = false;
      this.id = "";
      this.getList();
    },

    seeClose() {
      this.seeShow = false;
    }
  },
};
</script>
<style>
</style>
