<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
        <el-form-item label="渠道公司名称" prop="name">
          <el-input
              v-model="queryParams.name"
              clearable
              style="width: 300px"
              @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="派遣公司" prop="dispatch">
          <el-select
              v-model="queryParams.dispatch"
              placeholder="请选择"
              filterable
              style="width: 300px"
          >
            <el-option
                v-for="item in dispatchList"
                :key="item.value"
                :label="item.label"
                :value="item.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-table v-loading="loading" :data="list">
        <el-table-column label="渠道公司名称" align="left" prop="name" />
        <el-table-column label="所属派遣公司" align="left" prop="dispatch"  />
        <el-table-column label="联系人" align="center" prop="contracts" />
        <el-table-column label="联系电话" align="center" prop="contract_number" />
        <el-table-column label="联系地址" align="center" prop="address" />
        <el-table-column label="入库时间" align="left" prop="create_time" />
        <el-table-column label="更新时间" align="left" prop="update_time" />
      </el-table>
  
      <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.page"
          v-model:limit="queryParams.limit"
          @pagination="getList"
      />

    </div>
  </template>
  
<script setup>


import {channelL, dispatchSelect} from "@/api/channel";
  
  const { proxy } = getCurrentInstance();
  
  const list = ref([]);
  const loading = ref(true);
  const showSearch = ref(true);
  const total = ref(0);
  const dispatchList = ref([])

  const data = reactive({
    form: {
    },
    queryParams: {
      page: 1,
      limit: 10,
    },
  });
  
  const { queryParams, form } = toRefs(data);


//查询所有派遣公司
dispatchSelect().then(res => {
  dispatchList.value  = [{
    value:'',
    label: '请选择'
  },...res.data.map(item => {
    return {
      value:item,
      label: item,
      id:item
    }
  })]
})

  /** 查询列表 */
  function getList() {
    loading.value = true;
    channelL(queryParams.value).then(response => {
      list.value = response.data;
      total.value = response.count;
      loading.value = false;
    });
  }
  
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.page = 1;
    queryParams.value.limit = 10;
    getList();
  }
  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
  }


  getList();

  </script>
  