HistoricalVisitors.vue 4.52 KB
<template>
  <div class="historicalVisitors">
    <div class="searchBox">
      <a-input placeholder="访客人员" v-model="searchSource.visitorName" style="width: 120px"/>
      <a-input placeholder="访客人员" v-model="searchSource.visitorName" style="width: 120px"/>
      <a-date-picker
        :disabledDate="disabledStartDate"
        format="YYYY-MM-DD"
        v-model="startValue"
        placeholder="开始日期"
        @change="onChangeStartValue"
        @openChange="handleStartOpenChange"
      />

      <a-date-picker
        :disabledDate="disabledEndDate"
        format="YYYY-MM-DD"
        placeholder="结束日期"
        @change="onChangeEndValue"
        v-model="endValue"
        :open="endOpen"
        @openChange="handleEndOpenChange"
      />
      <a-button type="primary" @click="getStatisticalProductPage">查询</a-button>
    </div>
    <div class="title">账单汇总</div>
    <a-table :columns="columns" :dataSource="dataSource" rowKey="productId" :pagination="pagination" @change="handleTableChange">
      <span slot="productIcon" slot-scope="productIcon">
        <img style="width: 100px" :src="productIcon" alt="" />
      </span>
      <span slot="productName"></span>
      <!-- <span slot="productPrice" slot-scope="productPrice">
        {{ productPrice.toFixed(2) }}
      </span> -->
      <span slot="productStatisticalQuantity"></span>
    </a-table>
  </div>
</template>

<script>
import { $http } from './../../../api/axios.js'
import moment from 'moment'
export default {
  name: 'historicalVisitors',
  data () {
    return {
      startTime: '',
      endTime: '',
      startValue: null,
      endValue: null,
      endOpen: false,
      pagination: {
        current: 1,
        defaultCurrent: 10,
        defaultPageSize: 10,
        hideOnSinglePage: true,
        total: 0
      },
      columns: [{
        title: '产品图',
        dataIndex: 'productIcon',
        scopedSlots: { customRender: 'productIcon' }
      }, {
        title: '菜名',
        dataIndex: 'productName'
      }, {
        title: '售出(份数)',
        dataIndex: 'productStatisticalQuantity'
      }],
      dataSource: []
    }
  },
  created () {
    let date = new Date()
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let day = (new Date(year, month, 0).getDate().toString()).length > 1 ? new Date(year, month, 0).getDate() : '0' + new Date(year, month, 0).getDate()
    this.startTime = `${year}-${month.toString().length > 1 ? month : '0' + month}-01`
    this.endTime = `${year}-${month.toString().length > 1 ? month : '0' + month}-${day}`
    this.startValue = this.moment(`${year}-${month.toString().length > 1 ? month : '0' + month}-01`, 'YYYY-MM-DD')
    this.endValue = this.moment(`${year}-${month.toString().length > 1 ? month : '0' + month}-${day}`, 'YYYY-MM-DD')
    this.getStatisticalProductPage()
  },
  methods: {
    moment,
    disabledStartDate (startValue) {
      const endValue = this.endValue
      if (!startValue || !endValue) {
        return false
      }
      return startValue.valueOf() > endValue.valueOf() || startValue.valueOf() >= moment().endOf('day').valueOf()
    },
    disabledEndDate (endValue) {
      const startValue = this.startValue
      if (!endValue || !startValue) {
        return false
      }
      return startValue.valueOf() > endValue.valueOf() || endValue.valueOf() > moment().endOf('day').valueOf()
    },
    handleStartOpenChange (open) {
      if (!open) {
        this.endOpen = true
      }
    },
    handleEndOpenChange (open) {
      this.endOpen = open
    },
    onChangeStartValue (date, dateString) {
      this.startTime = dateString
    },
    onChangeEndValue (date, dateString) {
      this.endTime = dateString
    },
    getStatisticalProductPage () {
      let SubsidyListData = {
        startTime: this.startTime,
        endTime: this.endTime,
        pageNumber: 10,
        currentPage: this.pagination.current
      }
      $http.post(`/admin/visit/list`, SubsidyListData).then((res) => {
        if (res.data.resultCode === 0) {
          this.dataSource = res.data.data.list
          this.pagination.total = res.data.data.total
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    // 分页
    handleTableChange (pagination, filters, sorter) {
      this.pagination.current = pagination.current
      this.getStatisticalProductPage()
    }
  }
}
</script>

<style lang="less" scoped>
.title{
  font-weight: bold;
  margin-top: 20px;
  margin-bottom: 20px;
}
.searchBox button{
  margin-left: 10px;
}
</style>