<template>
  <div>
    <el-container>
      <!--搜索-->
      <el-header class="searchBox">
        <el-form :inline="true" :model="searchForm" class="demo-form-inline">
          <el-form-item label="渠道key">
            <el-input v-model="searchForm.channelKey" placeholder="渠道key" />
          </el-form-item>
          <el-form-item label="客户来源">
            <el-input v-model="searchForm.fromSource" placeholder="客户来源" />
          </el-form-item>
          <el-form-item label="产品名称">
            <el-input v-model="searchForm.productName" placeholder="产品名称" />
          </el-form-item>
          <el-form-item label="时间范围">
            <el-date-picker
              v-model="searchForm.date"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="searchBtn">查询</el-button>
            <el-button @click="reset">重置</el-button>
          </el-form-item>
        </el-form>
      </el-header>

      <!--表格-->
      <el-main class="tableBox">
        <el-table :data="tableData" stripe style="width: 100%">
          <el-table-column prop="prouductName" label="产品名称" />
          <el-table-column prop="spid" label="spid" />
          <el-table-column prop="fullCode" label="渠道编码" />
          <el-table-column prop="pvNum" label="PV" />
          <el-table-column prop="uvNum" label="UV" />
          <el-table-column prop="fromSource " label="获客来源" />
          <el-table-column prop="orderNum" label="订单数" />
          <el-table-column prop="orderProfit" label="订单收益" />
          <el-table-column prop="refundOrderNum" label="退单数" />
          <el-table-column prop="primaryConversionRate" label="分类名称" />
          <el-table-column prop="seconfaryConversionRate" label="分类名称" />
          <el-table-column prop="thirdConversionRate" label="分类名称" />
          <el-table-column prop="data" label="创建时间" width="160" />
        </el-table>
        <div class="block">
          <el-pagination
            :current-page.sync="searchForm['pageNum']"
            :page-sizes="[20, 50, 100, 300]"
            :page-size="searchForm['pageSize']"
            layout="total, sizes, pager"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </el-main>
    </el-container>
  </div>

</template>

<script>
import { post, get } from '@/api/common'
export default {
  name: 'RunData',
  data() {
    return {
      searchForm: {
        channelKey: '',
        date: '',
        fromSource: '',
        productName: '',
        pageSize: 20,
        pageNum: 1
      },
      tableData: [],
      total: 5000,
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      }
    }
  },
  created() {
    var that = this
    that.search()
  },
  methods: {
    async search() { // 同步搜索
      await get('/sysData/dataReport', this.searchForm)
        .then((res) => {
          this.tableData = res.data.list
          this.total = res.data.total
        }).catch((err) => {
          console.log(err)
        })
    },
    searchBtn() { // 搜索按钮
      this.search()
    },
    reset() { // 重置
      this.searchForm = {
        cpid: '',
        categoryName: '',
        pageSize: 20,
        pageNum: 1
      }
      this.search()
    },
    handleSizeChange(e) { // 单页数量
      this.searchForm.pageSize = e
      this.search()
    },
    handleCurrentChange(e) { // 跳页
      this.searchForm.pageNum = e
      this.search()
    }
  }
}
</script>

<style scoped lang="scss">
.searchBox {
  background-color: #fff;
  border-radius: 4px;
  box-shadow: #bfbfbf 0 0 2px;
  height: unset !important;
  form {
    margin: auto;
    .el-form-item {
      margin: 5px 5px;
    }
  }
}
.el-header {padding: 20px}
.el-form-item {margin-bottom: unset}
.tableBox{
  margin-top: 10px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: #bfbfbf 0 0 2px;
}
.block {
  margin-top: 20px;
  float: right;
}
.demo-drawer__content {
  padding: 20px 5%;
  line-height: 32px;
  .el-form-item {
    margin-top: 20px;
  }
  .demo-drawer__footer {
    position: fixed;
    bottom: 30px;
    width: 45%;
    margin-top: 20px;
    display: flex;
    button {
      flex: 1;
    }
  }
}
</style>
