<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="活动标题" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入活动标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker
          v-model="queryParams.date"
          type="datetimerange"s
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="活动标题" align="center" prop="title" />
      <el-table-column label="首页浏览量" align="center" prop="homeViews" />
      <el-table-column label="视频区点击量" align="center" prop="videoClick" />
      <el-table-column label="问诊区点击量" align="center" prop="doctorClick"/>
      <el-table-column label="产品区点击量" align="center" prop="goodsClick" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { list } from '@/api/his/promotionalActiveLog'

export default {
  name: 'promotionalActiveStats',
  data() {
    return {
      showSearch: true,
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        date: null,
      },
      total: 0,
      list: null,
    }
  },
  created() {
    this.handleQuery()
  },
  methods: {
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        name: null,
      }
      this.handleQuery()
    },
    getList() {
      this.loading = true
      const params = {
        ...this.queryParams,
        startTime: this.queryParams.date && this.queryParams.date[0],
        endTime: this.queryParams.date && this.queryParams.date[1],
      }
      list(params).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
  }
}
</script>

<style scoped>

</style>
