oil.vue 6.96 KB
<template>
  <div class="system-container">
    <div class="container">
      <h1>油耗统计</h1>
      <div class="m-b-md title_tips">统计车辆油耗情况,以自然日为时间单位统计(此功能仅针对OBD设备)</div>

      <!-- 搜索区域 开始 -->
      <div class="search_box">
        <el-form :model="searchForm" :inline="true" size="small">
          <el-form-item label="关键字:">
            <el-input v-model="searchForm.keywords" class="a_input" placeholder="特约店编码|店名称|车架号|车型"></el-input>
          </el-form-item>
          <el-form-item label="年份:">
            <el-date-picker v-model="searchForm.dataRange" type="month" placeholder="选择月" value-format="yyyy-MM" @change="initColumn">
            </el-date-picker>
          </el-form-item>
          <!-- <el-form-item label="月份:">
            <el-select v-model="searchForm.month" placeholder="请选择" @change="onChange">
              <el-option label="1月" value="1"></el-option>
              <el-option label="2月" value="2"></el-option>
              <el-option label="3月" value="3"></el-option>
              <el-option label="4月" value="4"></el-option>
              <el-option label="5月" value="5"></el-option>
              <el-option label="6月" value="6"></el-option>
              <el-option label="7月" value="7"></el-option>
              <el-option label="8月" value="8"></el-option>
              <el-option label="9月" value="9"></el-option>
              <el-option label="10月" value="10"></el-option>
              <el-option label="11月" value="11"></el-option>
              <el-option label="12月" value="12"></el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="getList()">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-refresh" size="mini" @click="rest()">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 搜索区域 end -->

      <!-- 按钮区域 开始 -->
      <div class="links_group">
        <span>油耗信息</span>
        <el-button class="pull-right" type="primary" icon="el-icon-download" size="mini" :loading="dloading" @click="downloadExcel()">导出Excel</el-button>
      </div>
      <!-- 按钮区域 end -->

      <!-- 列表 开始 -->
      <glsx-table ref="glsxTable" :list="tableData" :column="tableColumnList" :pageTotal="pageTotal" @change="getList">
      </glsx-table>
      <!-- <div class="table_box">
        <el-table :data="tableData" border>
          <el-table-column label="工单号" prop=""></el-table-column>
          <el-table-column label="姓名" prop=""></el-table-column>
          <el-table-column label="设备号" prop=""></el-table-column>
          <el-table-column label="车架号" prop=""></el-table-column>
          <el-table-column label="总行驶次数" prop=""></el-table-column>
          <el-table-column label="总里程km" prop=""></el-table-column>
          <el-table-column label="操作" prop=""></el-table-column>
        </el-table>
      </div> -->
      <!-- <basic-table ref="reportTable" :tableParams="reportTableParams" :beforeSearchFn="beforeSearchFn" :searchForm="searchDataForm" :getListApi="getListApi" @dataFinished="tableDataFinished" :hasNum="false">
      </basic-table> -->
      <!-- 列表 end -->
    </div>
  </div>
</template>

<script>
import GlsxTable from "@/components/glsx-table";
import {
  OIL_STATISTICS_SEARCH,
  OIL_YEARS_LIST,
  OIL_STATISTICS_EXPORT,
} from "services/report";
import moment from "moment";
import { deepClone } from "@/utils/util";
export default {
  data() {
    return {
      searchForm: {},
      tableData: [],
      columnList: [
        {
          label: "特约店代码",
          prop: "shopCode",
          fixed: "left",
          width: "100px",
        },
        {
          label: "特约店名称",
          prop: "shopName",
          fixed: "left",
          width: "100px",
        },
        { label: "车型", prop: "modelName", fixed: "left", width: "160px" },
        { label: "设备号", prop: "sn", fixed: "left", width: "160px" },
        { label: "车架号VIN码", prop: "vin", fixed: "left", width: "160px" },
        { label: "时间", prop: "statDate", fixed: "left", width: "100px" },
      ],
      tableColumnList: [],
      pageTotal: 0,
      yearList: [],
      dloading: false,
    };
  },
  components: {
    GlsxTable,
  },
  mounted() {
    this.getYear();
    this.initColumn();
    this.getList();
  },
  methods: {
    // 获取查询参数
    getParams() {
      let oParams = deepClone(this.searchForm);
      let o = oParams.dataRange;

      if(o){
        oParams.year = o.split('-')[0]
        oParams.month = o.split('-')[1]
        delete oParams.dataRange
      }

      return oParams;
    },

    // 获取列表
    getList(options) {
      let oParams = this.getParams();
      oParams.pageSize = this.$refs.glsxTable.pageSize;
      oParams.pageNumber = options ? options.pageNumber || 1 : 1;
      OIL_STATISTICS_SEARCH(oParams).then((res) => {
        let { data } = res;
        let { list, totalElements } = data;
        this.pageTotal = totalElements;
        this.tableData = list;
      });
    },

    // 查看详情
    lookDetail(row) {
      console.log(row);
      this.$router.push({ name: "mileageDetail" });
    },

    /** 初始化 表格日期 */
    initColumn(e) {
      let y = e?e.split('-')[0] : moment().date();
      let m = e?e.split('-')[1] : moment().month() + 1;
      let day = moment(`${y}-${m}`, "YYYY-MM").daysInMonth();
      let list = deepClone(this.columnList);

      for (let i = 1, len = day; i <= len; i++) {
        let o = { label: `${i}日`, prop: `dayNum${i}` };
        list.push(o);
      }
      list.push({ label: "总计(升)", prop: "summation" });
      this.tableColumnList = list;
    },

    //监听月份和年份 切换
    // onChange() {
    //   this.initColumn();
    // },

    // 重置
    rest() {
      this.searchForm = {};
      this.getList();
      this.$refs.glsxTable.rest();
    },

    // 获取年份
    getYear() {
      OIL_YEARS_LIST().then((res) => {
        this.yearList = res.data || [];
      });
    },

    // 导出excel
    downloadExcel() {
      let _this = this;
      let oParams = this.getParams();
      _this.dloading = true;
      _this.$Common.exportExcel({
        url: `${_this.$store.state.baseURL}${OIL_STATISTICS_EXPORT}`,
        method: "GET",
        data: oParams,
        fileName: "油耗统计报表",
        success: () => {
          _this.dloading = false;
        },
        fail: () => {
          _this.dloading = false;
        },
      });
    },

  },
};
</script>

<style lang="scss" scoped>
.pre_select {
  width: 100px;
}
.title_tips {
  font-size: 14px;
}
.links_group {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.search_box{
  .a_input{
    width:260px;
  }
}
</style>>