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

            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="电子邮箱" prop="email">
                <el-input
                  v-model="searchForm.email"
                  placeholder="请输入电子邮箱"
                ></el-input>
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="24" :lg="24" class="tr">
              <el-form-item label="">
                <el-button size="small" @click="clearFn">清空</el-button>
                <el-button size="small" type="primary" @click="searchFn"
                  >搜索</el-button
                >
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!-- 按钮 -->
      <div class="btn-group clearfix">
        <div class="fl">
          <el-button type="primary" size="small">删除</el-button>
        </div>
        <div class="fr">
          <el-button type="primary" size="small">导出</el-button>
        </div>
      </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
              type="selection"
              align="center"
              min-width="100"
            ></el-table-column>
            <el-table-column
              align="center"
              label="企业名称"
              prop="customerName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="联系人"
              prop="linkName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="联系电话"
              prop="linkPhone"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="邮箱"
              prop="email"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="联系地址"
              prop="linkAddress"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="申请时间"
              prop="reqDate"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="跟进人"
              prop="lastFollowerName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="跟进时间"
              prop="lastFollowerTime"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="跟进状态"
              prop="status"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="操作"
              min-width="160"
              show-overflow-tooltip
              fixed="right"
            >
              <el-button type="text" class="textColor" @click="editFn"
                >跟进</el-button
              >
              <el-button type="text" class="textColor">删除</el-button>
            </el-table-column>
          </el-table>
        </div>
        <!-- 分页 -->
        <div class="fr">
          <el-pagination
            :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>

    <DealerApplyDetail v-else />
  </div>
</template>

<script>
import { getDealerApplyList } from "@/api/basic_data/dealer";
import DealerApplyDetail from "./components/dealer-apply-detail.vue";
export default {
  data() {
    return {
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数
      isShow: true,
      showDialog: false,
      listLoading: false, // 列表加载loading
      dataList: [],
      searchForm: {
        customerName: "",
        email: "",
        linkName: "",
        linkPhone: "",
      },
    };
  },
  components: {
    DealerApplyDetail,
  },
  async created() {
    await this.getList({ pageNum: 1, pageSize: 10 });
  },
  methods: {
    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.getList({ pageNum: 1, pageSize: this.pageSize });
    },
    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList({ pageNum: val, pageSize: 10 });
    },
    //搜索功能
    async searchFn() {
      console.log(this.searchForm);
      await this.getList({ ...this.searchForm, pageNum: 1, pageSize: 10 });
    },
    //重置
    clearFn() {
      this.$refs.searchForm.resetFields();
    },
    //获取列表数据
    async getList(data) {
      const res = await getDealerApplyList(data);
      console.log(res);
      this.dataList = res.data.records;
      this.listTotal = res.data.total;
    },
    editFn() {
      this.isShow = false;
    },
  },
};
</script>
<style lang="scss" scoped></style>
