<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公司名称" prop="name">
        <el-input
            v-model="queryParams.name"
            placeholder="请输入公司名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司地址" prop="address">
        <el-input
            v-model="queryParams.address"
            placeholder="请输入公司地址"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司法人" prop="legalPerson">
        <el-input
            v-model="queryParams.legalPerson"
            placeholder="请输入公司法人"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择公司状态" clearable>
          <el-option
              v-for="dict in sys_normal_disable"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="companiesList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司名称" align="center" prop="name" />
      <el-table-column label="公司地址" align="center" prop="address" />
      <el-table-column label="公司法人" align="center" prop="legalPerson" />
      <el-table-column label="公司联系电话" align="center" prop="phoneNumber" />
      <el-table-column label="每日可派单人数" align="center" prop="dispatchPersonNumber" />
      <el-table-column label="派单数" align="center" prop="count" />
      <el-table-column label="公司状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="sys_normal_disable" :value="scope.row.status"/>
        </template>
      </el-table-column>

    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script setup name="CompaniesDispatch">
import { dispatchCompanies} from "@/api/care/companies";

const { proxy } = getCurrentInstance();
const { sys_normal_disable } = proxy.useDict('sys_normal_disable');

const companiesList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: null,
    address: null,
    legalPerson: null,
    phoneNumber: null,
    email: null,
    dispatchPersonNumber: null,
    userId: null,
    status: null,
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询护理公司列表 */
function getList() {
  loading.value = true;
  dispatchCompanies(queryParams.value).then(response => {
    companiesList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

getList();
</script>
