mileage.vue 9.65 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.dddd"></el-input> -->
            <el-popover v-model="filterVisible" placement="bottom-start" width="400" trigger="click">
              <div>
                <glsx-organization @change="onChange"></glsx-organization>
              </div>
              <el-input v-model="searchForm.orgName" :placeholder="searchForm.specialShopName || '所属组织'" slot="reference" readonly>
              </el-input>
            </el-popover>
          </el-form-item>
          <el-form-item label="">
            <el-input placeholder="工单号|车架号|姓名|设备" class="a_input" v-model="searchText">
              <el-select class="pre_select" v-model="preText" slot="prepend" placeholder="请选择">
                <el-option label="工单号" value="orderNo"></el-option>
                <el-option label="车架号" value="vin"></el-option>
                <el-option label="姓名" value="ownerName"></el-option>
                <el-option label="设备" value="sn"></el-option>
              </el-select>
            </el-input>
          </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>
        <div>
          <el-popover placement="bottom-end" v-model="showPopover" trigger="click">
            <div class="el_popover">
              <div class="cell">
                <div class="name">选择日期:</div>
                <div class="txt">
                  <el-date-picker v-model="mileageDate" size="small" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" :picker-options="pickerOptions">
                  </el-date-picker>
                </div>
              </div>
              <div class="show_tips" v-if="isTimeOut">提示:导出日期范围超过60天</div>
              <div class="btn_group">
                <el-button type="primary" size="mini" :loading="cloading" @click="singleDownloadExcel" :disabled="isTimeOut">导出</el-button>
                <el-button type="default" size="mini" @click="showPopover = false">取消</el-button>
              </div>
            </div>
            <el-button slot="reference" type="default" icon="el-icon-download" size="mini">日里程导出</el-button>
          </el-popover>
          <el-button class="pull-right" type="primary" icon="el-icon-download" size="mini" :loading="dloading" @click="downloadExcel">导出Excel</el-button>
        </div>
      </div>
      <!-- 按钮区域 end -->

      <!-- 列表 开始 -->
      <glsx-table ref="glsxTable" v-loading="loading" :list="tableData" :column="columnList" :pageTotal="pageTotal" @change="getList">
        <div slot="operate" slot-scope="{scope}">
          <el-link type="primary" :underline="false" @click="lookDetail(scope)">详情</el-link>
        </div>
      </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 {
  GETMILEAGESTATISTICS,
  MILEAGESTATISTICSEXPORT,
  MILEAGEEXPORTDAILYDETAILS,
} from "services/report";
import GlsxOrganization from "@/components/glsx-organization";
import { deepClone, showToast } from "@/utils/util";
import store from "@/store";
import moment, { max } from "moment";
export default {
  components: {
    GlsxTable,
    GlsxOrganization,
  },
  data() {
    return {
      searchForm: {},
      preText: "orderNo",
      tableData: [],
      columnList: [
        { label: "工单号", prop: "orderNo", align: "center" },
        { label: "姓名", prop: "ownerName" },
        { label: "设备号", prop: "sn" },
        { label: "车架号", prop: "vin" },
        { label: "总行驶次数", prop: "totalTripsNum" },
        { label: "总里程km", prop: "totalMileage" },
      ],
      pageTotal: 0,
      filterVisible: false,
      searchText: "",
      dloading: false,
      showPopover: false,
      mileageDate: [],
      cloading: false,
      loading: false,
      isTimeOut: false,
      sTime: "",
      eTime: "",
      pickerOptions: {
        onPick: ({ maxDate, minDate }) => {
          this.sTime = minDate || "";
          this.eTime = maxDate || "";
          if (maxDate && minDate) {
            let m = moment(maxDate).diff(moment(minDate), "days");
            if (m > 60) {
              this.isTimeOut = true;
            } else {
              this.isTimeOut = false;
            }
            this.eTime = '';
            this.sTime = ''
          }
        },
      },
    };
  },

  mounted() {
    this.getList();
  },
  methods: {
    // 获取查询参数
    getParams() {
      let oParams = deepClone(this.searchForm);
      if (this.searchText) {
        oParams[this.preText] = this.searchText;
      }
      delete oParams.orgName;
      return oParams;
    },

    // 获取列表
    getList(options) {
      let oParams = this.getParams();
      oParams.pageSize = this.$refs.glsxTable.pageSizeNum;
      oParams.pageNumber = options ? options.pageNumber || 1 : 1;
      this.loading = true;
      GETMILEAGESTATISTICS(oParams)
        .then((res) => {
          this.loading = false;
          let { data } = res;
          let { list, totalElements } = data;
          this.pageTotal = totalElements || 0;
          this.tableData = list || [];
        })
        .catch((error) => {
          this.loading = false;
        });
    },

    // 查看详情
    lookDetail(row) {
      console.log(row);
      let query = { vin: row.vin };
      let path = "/trialRun#/reportManage/mileageDetail?vin=" + row.vin;
      history.pushState(query, path, path);
      //this.$router.push({ name: "mileageDetail", query: { vin: row.vin } });
    },

    // 监听树
    onChange(e) {
      this.filterVisible = false;
      console.log(e);
      if (e) {
        this.orgInfo = e.origin;
        this.searchForm.orgId = e.origin.orgId;
        this.searchForm.orgType = e.origin.type;
        this.searchForm.orgName = e.origin.orgName;
      }
    },

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

    // 日里程导出
    singleDownloadExcel() {
      let _this = this;
      let o = this.mileageDate;

      if (!o || o.length <= 0) {
        showToast({
          message: "请选择日期",
        });
        return false;
      }

      let oParams = this.getParams();

      oParams.mileageStartTime = o[0];
      oParams.mileageEndTime = o[1];

      _this.cloading = true;
      _this.$Common.exportExcel({
        url: `${store.state.baseURL}${MILEAGEEXPORTDAILYDETAILS}`,
        method: "GET",
        data: oParams,
        fileName: `日里程统计报表(${moment(oParams.mileageStartTime).format(
          "yyyy.MM.DD"
        )}-${moment(oParams.mileageEndTime).format("yyyy.MM.DD")}).xlsx`,
        success: () => {
          _this.cloading = false;
        },
        fail: () => {
          _this.cloading = false;
        },
      });
    },

    // 重置
    rest() {
      this.searchForm = {};
      this.searchText = "";
      this.preText = "orderNo";
      this.mileageDate = []
      this.$refs.glsxTable.rest();
      this.getList();
    },
  },
};
</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;
  .pull-right {
    margin-left: 10px;
  }
}
.el_popover {
  .cell {
    // display: flex;
    // align-items: center;
    .name {
      width: 80px;
      line-height: 2;
    }
  }
  .show_tips {
    //padding-left: 80px;
    color: #f00;
    font-size: 12px;
    line-height: 2;
  }
  .btn_group {
    text-align: right;
    margin: 10px 0 0 0;
  }
}
.search_box{
  .a_input{
    width:320px;
  }
}
</style>>