activeList.vue 11.2 KB
<template>
  <v-layout>
    <template slot="breadcrumb">
      <el-breadcrumb-item>统计报表</el-breadcrumb-item>
      <el-breadcrumb-item>设备激活</el-breadcrumb-item>
    </template>
    <template slot="main">
      <div class="ibox ibox-search">
        <!-- 表单查询 -->
        <el-form :inline="true" ref="form" :model="form">
          <el-form-item>
            <!-- 时间范围选择组件 -->
            <v-date-range :date="form.dateRange" :options="['all','today', 'last7', 'thisMonth', 'lastMonth', 'last30']" activeType="today" @onDateRangeChange="dateRangeChange">
            </v-date-range>
            <!-- 时间范围选择组件 -->
          </el-form-item>

          <el-form-item label="是否在线:">
            <el-select v-model="form.isOnLine" placeholder="请选择分组" size="small" class="el-slect">
              <el-option v-for="item in form.onlineOpts" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <br />
          <!-- 车辆分组分类组件 -->
          <v-vechicle-select ref="vechicle" label="分组/分类" @onVechicleChange="vechicleChange"></v-vechicle-select>
          <!-- 车辆分组分类组件 /-->

          <el-form-item>
            <el-input placeholder="请输入对应条件值" v-model="form.queryTerm" size="small" class="input-with-select" clearable>
              <el-select v-model="form.queryType" slot="prepend" style="width:100px;" placeholder="请选择" size="small">
                <el-option label="设备号" value="1"></el-option>
                <el-option label="车架号" value="2"></el-option>
                <el-option label="姓名" value="3"></el-option>
                <el-option label="工单号" value="4"></el-option>
              </el-select>
            </el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit" size="small">查询</el-button>
          </el-form-item>
        </el-form>
        <!-- 表单查询 /-->
      </div>
      <div class="ibox">
        <div class="ibox-title">
          <h3 class="pull-left">设备激活</h3>
          <el-button type="primary" v-show="!auditAccount" plain size="small" class="pull-right ibox-ctrl" @click="exportExcel">导出excel&nbsp;<i class="fa fa-download"></i></el-button>
        </div>
        <div class="ibox-content">
          <el-table :data="tableData" border size="small" v-loading="loading" @selection-change="selectChange" style="width: 100%">
            <el-table-column type="selection" width="40" align="center"></el-table-column>
            <!-- <el-table-column fixed type="index" label="序号" :index="getIndex" align="center" width="70"></el-table-column> -->
            <el-table-column prop="sqbh" label="工单号" min-width="160" align="center"></el-table-column>
            <el-table-column prop="name" label="姓名" min-width="160" align="center"></el-table-column>
            <el-table-column prop="standno" label="车架号" min-width="180" align="center"></el-table-column>
            <el-table-column prop="brand" label="品牌车型" min-width="160" align="center"></el-table-column>
            <el-table-column prop="sn" label="设备号" min-width="100" align="center"></el-table-column>
            <el-table-column prop="unitType" label="设备型号" min-width="100" align="center"></el-table-column>
            <el-table-column prop="isOnLine" label="是否在线" min-width="100" align="center"></el-table-column>
            <el-table-column prop="className" label="所属分类" min-width="160" align="center"></el-table-column>
            <el-table-column prop="activeDate" label="激活时间" min-width="160" align="center"></el-table-column>
            <el-table-column prop="operator" label="激活操作人" min-width="160" align="center"></el-table-column>
            <el-table-column label="激活经纬度" min-width="160" align="center">
              <template slot-scope="scope">
                <span v-show="scope.row.lng||scope.row.lat">{{scope.row.lng}},{{scope.row.lat}} </span>
              </template>
            </el-table-column>
            <el-table-column label="激活位置" min-width="160" align="center">
              <template slot-scope="scope">
                <span v-show="scope.row.lng && !scope.row.addressIsInit">加载中... </span>
                <span v-show="scope.row.lng &&scope.row.addressIsInit&&scope.row.address">{{scope.row.address}} </span>
                <span v-show="scope.row.lng &&scope.row.addressIsInit&&!scope.row.address">解析失败,<el-button type="text" @click="retryGetAddress(scope.row)">重试</el-button> </span>
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="120" align="center">
              <template slot-scope="{row}">
                <el-link type="primary" :underline="false" v-show="row.lng||row.lat" @click="lookActiveLocation(row)">查看激活位置</el-link>
              </template>
            </el-table-column>
          </el-table>
          <div class="table-page-wrap">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
          </div>
        </div>
      </div>
    </template>
  </v-layout>
</template>
<script>
import vDateRange from "@/components/DateRange.vue";
const vVechicleSelect = () =>
  import(
    /* webpackChunkName: "vVechicleSelect" */ "@/components/VechicleSelect.vue"
  );
import { exportExcel } from "@/utils";
import { services } from "@/api";
import { mapGetters, mapActions } from "vuex";
import moment from "moment";
const REPORT_SERVICE = services.report;
export default {
  data() {
    return {
      loading: true,
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      form: {
        dateRange: [],
        onlineOpts: [
          {
            value: "",
            label: "全部",
          },
          {
            value: "1",
            label: "在线",
          },
          {
            value: "2",
            label: "离线",
          },
        ],
        isOnLine: "",
        sTime: moment().format("YYYY-MM-DD HH:mm:ss"),
        eTime: moment().format("YYYY-MM-DD HH:mm:ss"),
        classIdList: "",
        groupId: "",
        queryType: "1",
        queryTerm: "",
      },
      selectedIds: [],
    };
  },
  created() {
    this.getData();
  },
  computed: {
    ...mapGetters(["auditAccount"]),
  },
  mounted() {
    this.getRoleInfo().then(() => {});
  },
  methods: {
    retryGetAddress(row) {
      row.addressIsInit = false;
      this.tableData = this.tableData.concat([]);
      REPORT_SERVICE.batchParseAddress(
        JSON.stringify([
          {
            lng: row.lng,
            lat: row.lat,
          },
        ])
      ).then((res) => {
        const item = res.data[0];
        row.addressIsInit = true;
        if (item.valid === 0) {
          row.address = item.address;
        }

        this.tableData = this.tableData.concat([]);
      });
    },
    getIndex(index) {
      return (this.currentPage - 1) * this.pageSize + index + 1;
    },
    getData(curr = this.currentPage, size = this.pageSize) {
      this.loading = true;
      let params = this.getParams();
      params.currentPage = curr;
      params.pageSize = size;

      REPORT_SERVICE.deviceActive(params)
        .then((response) => {
          if (Array.isArray(response.data)) {
            this.tableData = response.data;
            this.total = response.recordsTotal;

            const lnglatArr = response.data.map((item) => {
              return {
                lng: item.lng,
                lat: item.lat,
              };
            });
            REPORT_SERVICE.batchParseAddress(JSON.stringify(lnglatArr)).then(
              (res) => {
                const data = res.data;

                data.forEach((item, idx) => {
                  const tableItem = this.tableData[idx];
                  tableItem.addressIsInit = true;
                  if (item.valid === 0) {
                    tableItem.address = item.address;
                  }
                });
                this.tableData = this.tableData.concat([]);
              }
            );
          } else {
            this.tableData = [];
            this.total = 0;
          }

          this.loading = false;
        })
        .catch((error) => console.log(error));
    },
    getParams() {
      const form = this.form;
      const params = {};
      if (form.sTime) {
        params.sTime = moment(form.sTime)
          .startOf("day")
          .format("YYYY-MM-DD HH:mm:ss");
      }
      if (form.eTime) {
        params.eTime = moment(form.eTime)
          .endOf("day")
          .format("YYYY-MM-DD HH:mm:ss");
      }
      if (form.isOnLine) {
        params.isOnLine = form.isOnLine;
      }
      if (form.groupId) {
        params.groupId = form.groupId;
      }
      if (form.classIdList) {
        params.classIdList = form.classIdList;
      }
      const queryTerm = form.queryTerm.trim();
      if (queryTerm) {
        switch (form.queryType) {
          case "1":
            params.sn = queryTerm;
            break;
          case "2":
            params.standNo = queryTerm;
            break;
          case "3":
            params.name = queryTerm;
            break;
          case "4":
            params.workOrderNo = queryTerm;
            break;
        }
      }

      return params;
    },
    dateRangeChange(dateArr) {
      if (dateArr && dateArr.length) {
        this.form.sTime = dateArr[0].format("YYYY-MM-DD HH:mm:ss");
        this.form.eTime = dateArr[1].format("YYYY-MM-DD HH:mm:ss");
      } else {
        this.form.sTime = "";
        this.form.eTime = "";
      }
    },
    selectChange(selection) {
      this.selectedIds = [];
      selection.map((obj) => {
        this.selectedIds.push(obj.id);
      });
    },
    vechicleChange(groupId, classId) {
      this.form.groupId = groupId;
      this.form.classIdList = classId;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData(this.currentPage, this.pageSize);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData(val);
    },
    onSubmit() {
      this.currentPage = 1;
      this.pageSize = 10;
      this.getData();
    },
    exportExcel() {
      const url = "deviceActive/exportDeviceActive";

      if (this.selectedIds.length) {
        exportExcel(url, { idList: this.selectedIds.join(",") });
      } else {
        exportExcel(url, this.getParams());
      }
    },

    // 查看设备激活位置
    lookActiveLocation(row) {
      this.$router.push({
        name: "activeLocation",
        query: {
          lng: row.lng,
          lat: row.lat,
          time: row.activeDate,
          address: row.address,
          standNo: row.standno,
          name:row.name,
          sn:row.sn,
          source:row.source
        },
      });
    },

    ...mapActions(["getLoginUser", "getRoleInfo"]),
  },
  components: {
    vDateRange,
    vVechicleSelect,
  },
};
</script>
<style lang="scss">
</style>