<template>
  <div>
    <el-form :inline="true" :model="query" class="query-form" size="mini">
      <el-row>
        <el-form-item class="query-form-item">
          <el-input
            v-model="query.companyName"
            placeholder="药店名称"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button-group>
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="mini"
              @click="onReset"
            ></el-button>
            <el-button type="primary" icon="search" @click="getList" size="mini"
              >查询</el-button
            >
          </el-button-group>
        </el-form-item>
      </el-row>
    </el-form>

    <el-table v-loading="loading" :data="list" style="width: 100%">
      <el-table-column label="序号" type="index" fixed></el-table-column>
      <el-table-column label="药店名称" prop="companyName" width="320px">
      </el-table-column>
      <el-table-column label="所属地区" prop="area"></el-table-column>
      <el-table-column label="详细地址" prop="detailAddr"></el-table-column>
      <el-table-column label="联系人" prop="contacts"></el-table-column>
      <el-table-column label="联系电话" prop="tel"></el-table-column>
      <el-table-column label="手机" prop="mobile"></el-table-column>
    </el-table>

    <el-pagination
      :page-size="query.limit"
      @current-change="handleCurrentChange"
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import draggable from "vuedraggable";
import { getSubCompany } from "../../api/warehouse/company";

export default {
  data() {
    return {
      query: {
        companyName: "",

        page: 1,
        limit: 20,
      },
      list: [],

      total: 0,
      loading: false,
    };
  },
  components: {
    draggable,
  },
  methods: {
    onReset() {
      this.$router.push({
        path: "",
      });
      this.query = {
        companyName: "",

        page: 1,
        limit: 20,
      };
      this.getList();
    },
    onSubmit() {
      this.$router.push({
        path: "",
        query: this.query,
      });
      this.getList();
    },
    handleSizeChange(val) {
      this.query.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.getList();
    },

    getList() {
      this.loading = true;
      getSubCompany(this.query)
        .then((response) => {
          this.loading = false;
          this.list = response.data.list || [];
          this.total = response.data.total || 0;
        })
        .catch(() => {
          this.loading = false;
          this.list = [];
          this.total = 0;
        });
    },
  },
  filters: {},
  mounted() {},
  created() {
    this.getList();
  },
};
</script>

<style type="text/scss" lang="scss">
</style>
