<template>
  <div class="app-container">
    <div v-if="isShow">
      <!-- 筛选条件 -->
      <div>
        <Collapse :screen-form="searchForm">
          <template #right_btn>
            <el-button size="mini" @click="clearFn">清空</el-button>
            <el-button size="mini" type="primary" @click="searchFn">搜索</el-button>
          </template>
          <template #search>
            <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="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-row>
            </el-form>
          </template>
        </Collapse>
      </div>
      <!-- 按钮 -->
      <div class="btn-group clearfix">
        <div class="fl">
          <el-button type="primary" size="mini">删除</el-button>
        </div>
        <div class="fr">
          <el-button type="primary" size="mini">导出</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="left"
              label="企业名称"
              prop="customerName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="left"
              label="联系人"
              prop="linkName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="left"
              label="联系电话"
              prop="linkPhone"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="left"
              label="邮箱"
              prop="email"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="left"
              label="联系地址"
              prop="linkAddress"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="left"
              label="申请时间"
              prop="reqDate"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="left"
              label="跟进人"
              prop="lastFollowerName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="left"
              label="跟进时间"
              prop="lastFollowerTime"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="left"
              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="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="listTotal"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <DealerApplyDetail v-else  @close="handleClose"/>
  </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: ''
      },
      isCollapse: true
    }
  },
  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
    },
    handleClose(){
      this.isShow = true
    }
  }
}
</script>
<style lang="scss" scoped></style>
