status.vue 8.12 KB
<template>
  <div>
    <div class="scrm-sub-client-container">
      <div class="pageContent">
        <GLCombiForm class="search-wrap" :rowNumber="1" :formObj="searchForm" :formData="searchFormList" @handleOk="searchTable" @handleRest="resetTable">
          <div class="date-select-wrap" slot="dateSelectSlot" slot-scope="scope">
            <div :class="['date-item', { 'seleted-item': searchForm.curDate == item.value }]" v-for="(item, index) in scope.scope.dateList" @click="selectDate(item.value)" :key="index">{{ item.name }}</div>
          </div>
          <div slot="inputSlot">
            <el-input placeholder="请输入完整车位编号" v-model.trim="searchForm.parkingNumber" :clearable="true" type="text"></el-input>
          </div>
        </GLCombiForm>
        <div class="statusList">
          <div>
            <span>历史详情</span>
          </div>
          <div>
            <el-button size="small" @click="handleExport">导出</el-button>
          </div>
        </div>
        <GLTable ref="statusTableRef" :beforeSearchFn="beforeSearchFn" :getListApi="getListApi" :noDataImg="url" :searchForm="realSearchForm" :pageConf="pageConf" :tableParams="tableParams">
          <div slot="statusSlot" slot-scope="scope">
            <span v-if="parkingStatusEnum[scope.scope.parkingStatus]" class="status-class" :style="{ 'background-color': parkingStatusEnum[scope.scope.parkingStatus].color }"></span>
            <span>{{ parkingStatusEnum[scope.scope.parkingStatus] ? parkingStatusEnum[scope.scope.parkingStatus].name : '--' }}</span>
          </div>
        </GLTable>
      </div>
    </div>
  </div>
</template>

<script>
const PARKING_STATUS_ENUM = { 0: { color: '#999999', name: '未知' }, 1: { color: '#2CCA74', name: '空闲' }, 2: { color: '#EB4E4E', name: '占用' } }
import url from '@/assets/empty.png'
import dayjs from 'dayjs'
import util from '@/utils/util'
export default {
  name: 'statusList',
  components: {},
  data() {
    return {
      url: url,
      searchForm: {
        curDate: '',
        parkingNumber: '',
        searchDate: []
      },
      realSearchForm: {},
      parkingStatusEnum: PARKING_STATUS_ENUM,
      searchFormList: [
        {
          name: 'curDate',
          addHtml: 'dateSelectSlot',
          dateList: [
            {
              name: '全部',
              value: ''
            },
            {
              name: '昨日',
              value: 1
            },
            {
              name: '本周',
              value: 2
            },
            {
              name: '上周',
              value: 3
            },
            {
              name: '本月',
              value: 4
            },
            {
              name: '上月',
              value: 5
            }
          ]
        },
        {
          name: 'searchDate',
          type: 'datePicker',
          labelWidth: 95,
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        },
        {
          name: 'parkingNumber',
          addHtml: 'inputSlot'
        }
      ],
      getListApi: this.$apis.parkingSpace.getHistoryListApi,
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' },
      tableParams: {
        listName: 'data',
        tableColumns: [
          {
            label: '小区名称',
            prop: 'merchantName',
            width: 200,
            line: 1
          },
          {
            label: '停车场区域',
            prop: 'parkingArea',
            width: 180
          },
          {
            label: '所在楼层',
            prop: 'parkingFloor',
            width: 180
          },
          {
            label: '楼栋',
            prop: 'parkingBuilding',
            width: 100
          },
          {
            label: '车位编号',
            prop: 'parkingNumber',
            width: 150
          },
          {
            label: '车位状态',
            prop: 'parkingStatus',
            addHtml: 'statusSlot',
            width: 100
          },
          {
            label: '雷达编号',
            prop: 'radarNumber',
            width: 200
          },
          {
            label: '开始-结束时间',
            formatter: cell => {
              return dayjs(cell.startTime).format('YYYY/MM/DD HH:mm:ss') + '-' + dayjs(cell.endTime).format('YYYY/MM/DD HH:mm:ss')
            },
            width: 320
          },
          {
            label: '状态时长',
            prop: 'duration',
            formatter: cell => {
              return util.formatSeconds(cell.duration)
            }
          }
        ]
      }
    }
  },
  //   watch: {
  //     'searchForm.searchDate': {
  //       handler(newValue, oldValue) {
  //         this.searchForm.curDate = ''
  //       },
  //       deep: true
  //     }
  //   },
  created() {},
  mounted() {},
  methods: {
    setTableFinishFun() {
      this.$refs.statusTableRef.data.length ? (this.$refs.statusTableRef.tableHeightValues = '') : this.$refs.statusTableRef.setTableHeightFun()
    },
    setTableHeightEvent() {
      this.$refs.statusTableRef.setTableHeightFun()
    },
    // 搜索表格
    searchTable() {
      this.$refs.statusTableRef.refreshTable()
    },
    //重置表格
    resetTable() {
      this.searchForm = {
        curDate: '',
        parkingNumber: '',
        searchDate: []
      }
      this.realSearchForm = {}
      this.searchTable()
    },
    selectDate(val) {
      this.searchForm.searchDate = []
      this.searchForm.curDate = val
    },

    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm.searchDate.length) {
        params.startTime = new Date(this.searchForm.searchDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.endTime = new Date(this.searchForm.searchDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      } else if (this.searchForm.curDate) {
        const list = util.getDateRange(this.searchForm.curDate)
        params.startTime = dayjs(list[0]).format('YYYY-MM-DD') + ' 00:00:00'
        params.endTime = dayjs(list[1]).format('YYYY-MM-DD') + ' 23:59:59'
      }
      delete params.searchDate
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.realSearchForm = this.getParams()
        resolve()
      })
    },
    handleExport() {
      const params = this.getParams()
      params.pageNum = 1
      params.pageSize = 5000
      this.$apis.parkingSpace.exportHistoryListApi(params).then(res => {
        util.exportFn(res)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.scrm-sub-client-container {
  /deep/ .el-table .cell {
    text-overflow: clip;
  }
  /deep/ .el-table .cell,
  .el-table th div {
    text-overflow: clip;
  }
  .pageContent {
    padding: 20px 20px 30px;

    // min-width: 1300px;
    background-color: #fff;
    /deep/ .el-icon-user-solid {
      color: #75acff;
      // margin-right: 3px;
      font-size: 14px;
    }
    .statusList {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 8px;
      div {
        text-align: center;
        span:nth-child(1) {
          font-weight: 600;
          font-size: 16px;
        }
        span:nth-child(2) {
          font-size: 14px;
          margin-left: 8px;
          color: #5850ff;
          border-bottom: 1px solid #5850ff;
          cursor: pointer;
        }
      }
    }
    .status-class {
      display: inline-block;
      margin-right: 8px;
      width: 6px;
      height: 6px;
      background: #eb4e4e;
      border-radius: 4px;
      vertical-align: middle;
    }
  }
  .blue-text {
    color: #5850ff;
  }
}

.search-wrap {
  /deep/ .search-item {
    .name {
      display: none;
    }
  }
  .date-select-wrap {
    display: flex;
    margin-top: 1px;
    .date-item {
      cursor: pointer;
      flex: 1;
      height: 32px;
      line-height: 32px;
      background: #ffffff;
      border: 1px solid #e5e5e5;
      color: #000000a6;
      box-sizing: border-box;
      border-radius: 2px 0 0 2px;
      text-align: center;
    }
    .seleted-item {
      background: #5850ff;
      border: 1px solid #5850ff;
      color: #fff;
    }
  }
}
</style>