<template>
  <div class="app-container">
    <div v-if="isShow">
      <!-- 筛选条件 -->
      <div>
        <el-form ref="searchForm" :model="searchForm" label-width="70px" size="mini" label-position="left">
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="名称" prop="name">
                <el-input v-model="searchForm.name" placeholder="请输入名称"></el-input>
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="12" :lg="18" class="tr">
              <el-form-item label="">
                <el-button size="mini" @click="clearFn">清空</el-button>
                <el-button size="mini" type="primary" @click="searchFn">搜索</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <!-- 表格 -->
      <div class="mymain-container">
        <div class="table">
          <el-table v-loading="listLoading" :data="dataList" element-loading-text="Loading" border fit highlight-current-row stripe>
            <el-table-column align="left" label="编码" prop="number" min-width="60" label-class-name="bianma" class-name="fontstyle">
              <template slot-scope="scope">
                <CopyButton :copyText="scope.row.number" />
                <span>{{scope.row.number}}</span>
              </template>
            </el-table-column>
            <el-table-column align="left" label="使用组织" prop="useOrgName" min-width="160"></el-table-column>
            <el-table-column align="left" label="名称" prop="name" min-width="200">
              <template slot-scope="scope">
                <CopyButton :copyText="scope.row.name" />
                <span>{{scope.row.name}}</span>
              </template>
            </el-table-column>
            <el-table-column align="left" label="简称" prop="shortName" min-width="160"> </el-table-column>
            <el-table-column align="left" label="供应商分组" prop="groupName" min-width="160"></el-table-column>
            <el-table-column align="center" label="操作" prop="caozuo" min-width="160" show-overflow-tooltip fixed="right">
              <template slot-scope="scope">
                <el-button type="text" class="textColor" @click="editFn(scope.row.id)">详情</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <div class="fr">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 50]" :page-size="10" layout="total, sizes, prev, pager, next, jumper" :total="listTotal">
          </el-pagination>
        </div>
      </div>
    </div>
    <SupplierListDetail :infoList="infoList" v-else />
  </div>
</template>

<script>
import { getList, getInfoApi } from "@/api/basic_data/supplier";
import SupplierListDetail from "./components/supplier_list-detail.vue";

export default {
  data() {
    return {
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数

      listLoading: false, // 加载
      screenForm: {}, // 筛选表单数据
      dataList: [], // 表格数据

      isShow: true,
      searchForm: {
        // 筛选表单数据
        name: "",
      },
      dataList: [],
      infoList: {},
    };
  },

  components: {
    SupplierListDetail,
  },

  async created() {
    await this.getList();
  },
  methods: {
    //搜索功能
    async searchFn() {
      await this.getList();
    },
    //重置
    clearFn() {
      this.$refs.searchForm.resetFields();
    },

    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
    },
    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
    },
    async editFn(id) {
      this.isShow = false;
      const res = await getInfoApi({ id });
      this.infoList = res.data;
    },
    async getList() {
      let params = {
        name: this.searchForm.name,
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      };
      let res = await getList(params);
      this.dataList = res.data.records;
      this.listTotal = res.data.total;
    },
  },
};
</script>

<style lang="scss" scoped>
.base {
  padding: 20px;
}
.fr {
  margin-top: 20px;
}
</style>
