<template>
  <div class="app-container">
    <div style="text-align: right; margin-bottom: 10px">
      <el-date-picker
        v-model="dateRange"
        type="datetimerange"
        range-separator="-"
        value-format="yyyy-MM-dd HH:mm:ss"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        @change="tjdatePicker"
      >
      </el-date-picker>
    </div>
    <div class="header" style="width: 100%">
      <el-row class="row" :gutter="12">
        <el-col :span="3">
          <div class="item">
            <div class="count">
              {{ orderStatistics ? orderStatistics.peopleNum : 0 }} 个
            </div>
            <div class="title">
              <span>活动订单总金额(元)</span>
            </div>
          </div>
        </el-col>
        <el-col :span="3">
          <div class="item">
            <div class="count">
              {{ orderStatistics ? orderStatistics.totalOrderNum : 0 }}
            </div>
            <div class="title">
              <span>活动订单总笔数(元)</span>
            </div>
          </div>
        </el-col>
        <el-col :span="3">
          <div class="item">
            <div class="count">
              {{ orderStatistics ? orderStatistics.totalOrderNum : 0 }}个
            </div>
            <div class="title">
              <span>总返红包数量</span>
            </div>
          </div>
        </el-col>
        <el-col :span="3">
          <div class="item">
            <div class="count">
              {{ orderStatistics ? orderStatistics.reduce : 0 }}个
            </div>
            <div class="title">
              <span>总返红包金额(元)</span>
            </div>
          </div>
        </el-col>
        <el-col :span="3">
          <div class="item">
            <div class="count">
              {{ orderStatistics ? orderStatistics.peopleNum : 0 }}个
            </div>
            <div class="title">
              <span>获得活动满返红包人数</span>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-form
      style="margin-top: 20px"
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="120px"
    >
      <el-form-item label="" prop="key">
        <el-input
          v-model="queryParams.key"
          placeholder="请输入活动ID/活动名称/用户Id/用户昵称/用户手机号/订单编号搜索"
          clearable
          style="width: 300px"
        />
      </el-form-item>
      <el-form-item label="下单时间" prop="dateRange">
        <el-date-picker
          v-model="queryParams.dateRange"
          type="datetimerange"
          range-separator="-"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="datePicker"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="返红包时间" prop="dateRange">
        <el-date-picker
          v-model="queryParams.dateRange1"
          type="datetimerange"
          range-separator="-"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="fhbdatePicker"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          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
      ref="multipleTable"
      v-loading="loading"
      :data="spuList"
      :border="true"
      row-key="id"
    >
      <el-table-column type="selection" align="center" />
      <el-table-column label="领取人ID" align="center" prop="userId" />
      <el-table-column label="领取人昵称" align="center" prop="nick" />
      <el-table-column label="领取人手机号" align="center" prop="phone" />
      <el-table-column label="代金券ID" align="center" prop="voucherId" />
      <el-table-column label="代金券名称" align="center" prop="voucherName" />

      <el-table-column label="类型" align="center" width="120">
        <template slot-scope="scope">
          {{
            scope.row.type == 0
              ? "通用券"
              : scope.row.type == 1
              ? "独立券"
              : scope.row.type == 2
              ? "连锁券"
              : scope.row.type == 3
              ? "联合券"
              : ""
          }}
        </template>
      </el-table-column>

      <el-table-column label="推广方式" align="center">
        <template slot-scope="scope">
          {{
            scope.row.showType == 0
              ? "全网自动推出"
              : scope.row.showType == 1
              ? "定向渠道推广"
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="面额(元)" align="center" prop="sendAmount" />
      <el-table-column label="领取时间" align="center">
        <template slot-scope="scope">
          {{
            scope.row.reviewTime
              ? $moment(scope.row.reviewTime).format("YYYY-MM-DD HH:mm:ss")
              : ""
          }}
        </template>
      </el-table-column>
    </el-table>

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

<script>
import moment from "moment";
import { statisticsActivity, queryPageRecord } from "@/api/marketing/voucher";
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      total: 0,
      // 参数表格数据
      spuList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      dateRange: [],
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        key: "",
        showType: "",
        startTime: "",
        endTime: "",
        type: "",
        dateRange: [],
      },
      orderStatistics: {},
      queryStatistics: {
        startTime: "",
        endTime: "",
      },
    };
  },
  mounted() {
    this.getList();
    this.getstatisticsOrder();
  },
  methods: {
    tjdatePicker(val) {
      if (val) {
        this.queryStatistics.startTime = moment(val[0]).valueOf();
        this.queryStatistics.endTime = moment(val[1]).valueOf();
      } else {
        this.queryStatistics.startTime = "";
        this.queryStatistics.endTime = "";
      }
      this.getstatisticsOrder();
    },
    fhbdatePicker(val) {
      this.queryParams.returnStartTime = moment(val[0]).valueOf();
      this.queryParams.returnEndTime = moment(val[1]).valueOf();
    },
    datePicker(val) {
      this.queryParams.orderStartTime = moment(val[0]).valueOf();
      this.queryParams.orderEndTime = moment(val[1]).valueOf();
    },
    getstatisticsOrder() {
      statisticsActivity(this.queryStatistics).then((res) => {
        if (res.code == 200) {
          this.orderStatistics = res.data;
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },

    /** 查询参数列表 */
    getList() {
      this.loading = true;
      queryPageRecord(this.queryParams).then((response) => {
        if (response.code == 200) {
          this.spuList = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        }
      });
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.dateRange = [];
      this.queryParams.dateRange1 = [];
      this.queryParams.orderStartTime = "";
      this.queryParams.orderEndTime = "";
      this.queryParams.returnStartTime = "";
      this.queryParams.returnEndTime = "";
      this.resetForm("queryForm");
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
  },
};
</script>
<style scoped lang="scss">
.header {
  .item {
    height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 40px;
  }
  .row {
    background: #f4f4f4;
    padding: 10px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    .title {
      text-align: center;
    }
    .count {
      text-align: center;
      font-size: 20px;
      font-weight: bold;
      color: rgb(64, 158, 255);
    }
    .zz {
      font-size: 14px;
      color: red;
      padding: 0px 10px;
    }
  }
}
.radio {
  margin: 20px 0px;
}
</style>
<style>
.el-radio-button__inner {
  width: 150px;
}
</style>
