index.vue 6.45 KB
<template>
  <div class="system-container">
    <div class="container">
      <h1>有效试驾(日报)</h1>
      <div class="m-b-md">用于展示日运营数据并支持下载Excel文件</div>
      <search-form class="searchTop border-shadow" :formModel="searchDataForm" :formList="reportFormList">
        <span class="inline-b" slot="form-slot">
          <el-button type="primary" :size="btn_size" icon="el-icon-search" :id="reportTableParams.btnId" @click="getTableList()">搜索</el-button>
          <el-button type="primary" :size="btn_size" icon="el-icon-refresh" @click="refresh">重置</el-button>

        </span>
      </search-form>
      <h3>
        有效试驾信息
        <el-button class="pull-right" type="primary" :size="btn_size" @click="btnClick('export')">导出Excel</el-button>
      </h3>
      <!-- <basic-table ref="reportTable" @click="goDetail" :tableParams="reportTableParams" :beforeSearchFn="beforeSearchFn" :searchForm="searchDataForm" :getListApi="getListApi" :hasNum="false">
      </basic-table> -->
      <el-table class="el_table" :data="tableDta" v-loading="loading" :header-cell-style="{background:'#f5f7fa'}">
        <el-table-column v-for="(item,index) in reportTableParams.tableColumns" :key="`td_${index}`" :label="item.label" :prop="item.prop" width="120px" fixed="left" show-overflow-tooltip></el-table-column>
        <el-table-column v-for="(item,index) in dayList" :key="`tds_${index}`" :label="item.label" :prop="item.prop">
          <template slot-scope="{row}">
            <a href="javascript:void(0)" @click="goDetail(item.prop,row)">{{row[item.prop]}}</a>
          </template>
        </el-table-column>
        <el-table-column label="总计" prop="summation"></el-table-column>
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="total,prev, pager, next, jumper" hide-on-single-page :total="totalElements" :page-size="pageSize" :current-page.sync="pageNumber" @current-change="getTableList" />
      </div>
    </div>
  </div>
</template>

<script>
import { REPORT_API } from "@/config/config";
import store from "@/store";
import { getList, getYears } from "services/report";
import { deepClone, showToast } from "@/utils/util";
export default {
  data() {
    const _this = this;
    return {
      searchDataForm: {},
      searchForm: {},
      tableDta: [],
      pageNumber: 1,
      pageSize: 10,
      totalElements: 0,
      reportFormList: [
        {
          type: "input",
          inputType: "text",
          prop: "keywords",
          placeholder: "特约店编码|店名称",
        },
        {
          type: "singleDate",
          dateType: "month",
          prop: "date",
          placeholder: "请选择年月",
          pickerOptions: {
            disabledDate(time) {
              return time.getTime() < new Date(_this.date).getTime();
            },
          },
        },
      ],
      dayList: [],
      reportTableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        tableOption: false,
        tableColumns: [
          {
            label: "特约店编码",
            prop: "shopCode",
            fixed: true,
          },
          {
            label: "特约店名称",
            prop: "shopName",
            fixed: true,
          },
          {
            label: "车型",
            prop: "vehicleTypeName",
            fixed: true,
          },
          {
            label: "车架号VIN码",
            prop: "vin",
            width: 120,
            fixed: true,
          },
          {
            label: "时间",
            prop: "statDate",
            fixed: true,
          },
        ],
      },
      getListApi: getList,
      date: "",
      loading: false,
    };
  },
  mounted() {
    getYears({}).then((res) => {
      console.log(res.data[0]);
      this.date = `${res.data[0]}-01-01`;
    });

    for (let i = 1; i <= 31; i++) {
      this.dayList.push({
        label: `${i}日`,
        prop: `dayNum${i}`,
      });
      // if (i == 31) {
      //   this.dayList.push({
      //     label: "总计",
      //     prop: "summation",
      //   });
      // }
    }

    this.getTableList();
  },
  methods: {
    // 获取参数
    getParams() {
      let oParams = deepClone(this.searchDataForm);

      if (oParams.date) {
        oParams.year = oParams.date.split("-")[0];
        oParams.month = oParams.date.split("-")[1];
        delete oParams.date;
      }

      return oParams;
    },

    // 获取列表数据
    getTableList(current) {
      let oParams = this.getParams();
      oParams.pageNumber = current || this.pageNumber;
      oParams.pageSize = this.pageSize;
      this.loading = true;
      getList(oParams)
        .then((res) => {
          this.loading = false;
          let { data } = res;
          let { list, totalElements } = data || {};
          this.tableDta = list;
          this.totalElements = totalElements;
        })
        .catch((error) => {
          this.loading = false;
        });
    },

    refresh() {
      this.searchForm = {};
      this.searchDataForm = {};
      this.$refs.reportTable.refreshTable();
    },
    beforeSearchFn() {
      return new Promise((resolve, reject) => {
        console.log(this.searchForm.date);
        if (this.searchForm.date) {
          this.searchDataForm.year = this.searchForm.date.split("-")[0];
          this.searchDataForm.month = this.searchForm.date.split("-")[1];
        } else {
          this.searchDataForm.year = "";
          this.searchDataForm.month = "";
        }
        this.searchDataForm.keywords = this.searchForm.keywords;
        resolve();
      });
    },
    btnClick(type, scope) {
      let oParams = deepClone(this.searchDataForm);
      if (oParams.date && oParams.date.length > 0) {
        oParams.year = oParams.date.split("-")[0];
        oParams.month = oParams.date.split("-")[1];
        delete oParams.date;
      }
      this.$Common.exportExcel({
        url: `${store.state.baseURL}${REPORT_API.REPORT_EXPORT}`,
        method: "GET",
        data: oParams,
        fileName: "有效试驾统计报表",
      });
    },

    // 查看详情
    goDetail(id, row) {
      let n = id.replace("dayNum", "");
      console.log(n);
      console.log(row);
      this.$router.push({
        name: "driverDetail",
        query: { day: `${row.statDate}-${n}`, vin: row.vin },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.pagination_list {
  text-align: right;
  padding: 10px 0;
}
</style>