<template>
  <div class="app-container">
    <!-- 搜索插件 -->
    <SearchForm v-show="showSearch" ref="SearchForm" @search="_getTableList" :areaOptions="areaOptions" />

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['statistic:areaStudent:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" :columns="columns" @queryTable="_getTableList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column type="index" width="55" align="center" />
      <el-table-column label="区域" align="center" min-width="120" prop="areaName" />
      <el-table-column label="月份" align="center" min-width="120" prop="month" />
      <el-table-column label="线索数" align="center" min-width="120" prop="clueNum" />
      <el-table-column label="成交数" align="center" min-width="120" prop="signNum" />
      <el-table-column label="成交率" align="center" min-width="120" sortable prop="dealRate" />
      <el-table-column label="平均利润" align="center" min-width="120" sortable prop="avgProfit" />
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="searchForm.pageNum" :limit.sync="searchForm.pageSize" @pagination="_getTableList" />

  </div>
</template>
  
  <script>
import { listReport } from "@/api/statistic/areaStudent";
import SearchForm from "./components/SearchForm.vue";
import { getAllPlaces } from '@/api/sch/place'

const date = new Date();
const month = date.getFullYear() + "-" + (date.getMonth() + 1);
export default {
  name: "AreaStudent",
  components: {
    SearchForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 列表数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      searchForm: {
        month: month,
        pageNum: 1,
        pageSize: 10
      },
      columns: [],
      dialogVisible: false,
      areaOptions: []
    };
  },
  created() {
    this._getTableList();
    this.getDicts('dm_area').then((response) => {
      this.areaOptions = response.data;
    });
  },
  methods: {
    /** 查询报名点成交登记列表 */
    _getTableList() {
      this.loading = true;
      const tempForm = this.$refs.SearchForm?.searchForm || {};
      const params = { ...this.searchForm, ...tempForm };
      listReport(params).then(response => {
        this.dataList = response.data;
        // this.total = response.total;
        this.loading = false;
      });
    },
    async getAllPlaces() {
      const resp = await getAllPlaces();
      if (resp.code == 200) {
        this.placeOptions = resp.data;
      }

    },
    /** 导出按钮操作 */
    handleExport() {
      const tempForm = this.$refs.SearchForm?.searchForm || {};
      const params = { ...this.searchForm, ...tempForm };
      this.download('/statistic/area/student/export', params, `区域学员报表_${new Date().getTime()}.xlsx`)
    }
  }
};
  </script>
  