<template>
  <el-scrollbar style="height:100%">
    <div>
      <div style="width:99%;">
        <span style="color:#ff9955;font-size:25px;">|</span>
        <span style="font-size:20px;">数据概览</span>
        <el-row :gutter="10" class="panel-group">
          <el-col :xs="12" :sm="12" :lg="6">
            <div class="flex xiaoliang">
              <div style="font-size: 28px;">电子会员余额</div>
              <div style="line-height: 62px;font-size: 32px;">{{hzAmt }}元</div>
            </div>
          </el-col>
          <el-col :xs="12" :sm="12" :lg="6">
            <div class="flex xiaoe">
              <div style="font-size: 28px;">电子会员总数</div>
              <div style="line-height: 62px;font-size: 32px;">{{ cardNum }}个</div>
            </div>
          </el-col>
        </el-row>
      </div>
      <div style="width:99%; height: 181px;">
        <span style="color:#ff9955;font-size:25px;">|</span>
        <span style="font-size:20px;">详情：</span>
        <el-table v-loading="loading"  :data="dayReportList">
          <el-table-column label="日期" align="center" prop="createTime">
              <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="充值金额" align="center" prop="czamt" />
          <el-table-column label="消费金额" align="center" prop="xfamt"/>
          <el-table-column label="新增电子会员" align="center" prop="cardnum" />
        </el-table>
        <div  style="float:right;">
          <el-pagination
            style="padding-top: 15px;"
            @size-change="findSizeChange"
            @current-change="findPage"
            :current-page.sync="pageNow"
            background
            :pager-count="6"
            :page-sizes="[5,10,20,50,100]"
            :page-size="size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div> 
      <el-dialog :title="title" width="800px"  :visible.sync="open" append-to-body>
        <el-table v-loading="loading" :data="dayReportDetailsList">
          <el-table-column label="订单单号" align="center" prop="orderNo" />
          <el-table-column label="微信用户唯一标识" align="center" prop="unionId" v-if="false" />
          <el-table-column label="会员号ID" align="center" prop="customerNo" />
          <el-table-column label="会员名" align="center" prop="customerName" />
          <el-table-column label="油品" align="center" prop="cardOilsType" :formatter="cardOilsTypeFotmat"/>
          <el-table-column label="订单类型" align="center" prop="usageType" :formatter="usageTypeFotmat"/>
          <el-table-column label="消费金额" align="center" prop="amt" />
          <el-table-column label="余额" align="center" prop="balance" />
          <el-table-column label="消费方式" align="center" prop="payType" :formatter="payTypeFotmat"/>
          <el-table-column label="油站ID" align="center" prop="stationId" v-if="false"/>
          <el-table-column label="油站名称" align="center" prop="stationName" />
          <el-table-column label="油站名称" align="center" prop="create_time" v-if="false"/>
        </el-table>
        <div  class="pagination-container">
          <el-pagination
            style="padding-top: 15px"
            @size-change="sizeChange"
            @current-change="currentChange"
            :current-page.sync="pageNow2"
            background
            :pager-count="6"
            :page-sizes="[5,10,20,50,100]"
            :page-size="setting"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total1">
          </el-pagination>
        </div>
      </el-dialog>
    </div>
  </el-scrollbar>
</template>

<script>

import {listSum,selectCard} from "@/api/customer/card";
import { xfAmtQuery } from "@/api/customer/consumption";
import { czAmtQuery,selectCardDetail } from "@/api/customer/recharge";
export default {
  name: "source",
  data() {
    return {
      charts: null,
      size:10,
      pageNow:1,
      pageNow2:1,
      setting:10,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      hzAmt: 0,
      cardNum:0,
      // 优惠劵管理表格数据
      couponList: [],
      dayReportDetailsList: [],
      dateRangeCreatedDate: [],
      //x轴数据
      xdata: [],
      //92#汽油数据
      czdata: [],
      //95#汽油数据
      xfdata: [],
      // 弹出层标题
      title: "",
      rows:[],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageSetting:10,
        pageNum:1,
        createdDate: null,
        stationId:null,
        stationName: null,
        beginTime: null,
        endTime: null,
        payDate: null,
        status:"1"
      },
      // 查询参数
      queryInfo: {
        pageSetting:10,
        pageNo:1,
        createDate: null
      },
      query:{
        stationId:null
      },
      //日报数据
      dayReportList: [],
      // 表单参数
      form: {
        czAmt: 0,
        xfAmt: 0
      },
      // 表单校验
      rules: {}
    };
  },
 
  created() {
    this.dayDataSource();
    this.getHZlist();
    //获取折线图的数据
    this.reset();
    this.queryParams.beginTime = this.getMonthDate();
    this.queryParams.endTime = this.getEndFormatDate(new Date());
    this.queryParams.stationId=this.$store.selectDeptId;
  },
  methods: {
    usageTypeFotmat(row, column){
      if(row.usageType === '+'){
        return '充值'
      }else if(row.usageType === '-'){
        return '消费'
      }
    },
    payTypeFotmat(row, column){
      if(row.payType === '1'){
        return '小程序'
      }else if(row.payType === '2'){
        return 'POS'
      }
    },
    cardOilsTypeFotmat(row, column){
      if(row.cardOilsType === '1'){
        return '汽油'
      }else if(row.cardOilsType === '2'){
        return '柴油'
      }
    },
    /** 查询电子会员数据 */
    getList() {
      if(this.queryParams.stationId==null || this.queryParams.stationId==""){
        this.queryParams.stationId =this.$store.state.user.deptId;
      }
      xfAmtQuery(this.queryParams).then(response => {
        if (response.hasOwnProperty('data')) {
          this.form.xfAmt = response.data.amt;
        }
      });
      czAmtQuery(this.queryParams).then(response => {
        if (response.hasOwnProperty('data')) {
          this.form.czAmt = response.data.amt;
        }
      });
      this.dayReportDetail();
    },
    getHZlist(){
      //汇总电子会员数据
      this.query.stationId=this.$store.selectDeptId;
      if(this.query.stationId==null || this.query.stationId==""){
        this.query.stationId =this.$store.state.user.deptId;
      }
      listSum(this.query).then(response => {
        if (response.hasOwnProperty('data')) {
          this.cardNum= response.data.num;
          this.hzAmt = response.data.amt;
        }
      });
    },
    findPage(val){
      this.pageNow = val;
      this.dayReportDetail();
    },
    findSizeChange(size) {
      //将val赋值给size
      this.size = size;
      //重新去后台查询数据
      this.dayReportDetail();
    },
    dayReportDetail(){
      this.loading = false;
      this.queryParams.pageNo =this.pageNow;
      this.queryParams.pageSetting =this.size;
      selectCard(this.queryParams).then(response => {
       this.dayReportList= response.rows;
        this.total = response.total;
      });
    },
    //本日的数据
    dayDataSource() {
      this.reset();
      this.queryParams.beginTime = this.getNowFormatDate(new Date());
      this.queryParams.endTime = this.getEndFormatDate(new Date());
      this.queryParams.stationId=this.$store.selectDeptId;
      if(this.queryParams.stationId==null || this.queryParams.stationId==""){
        this.queryParams.stationId =this.$store.state.user.deptId;
      }
      this.getList();
    },
    //今天
    getNowFormatDate(date) {
      let seperator1 = "-";
      let month = date.getMonth() + 1;
      let strDate = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      let currentdate1 =
        date.getFullYear() + seperator1 + month + seperator1 + strDate;
      return currentdate1;
    },
    //明天
    getEndFormatDate(myDate) {
      let date = myDate.getDate();
      date = date + 1;
      myDate.setDate(date);
      let seperator2 = "-";
      let month = myDate.getMonth() + 1;
      let strDate = myDate.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      let currentdate2 =
        myDate.getFullYear() + seperator2 + month + seperator2 + strDate;
      return currentdate2;
    },
    //昨天
    getFormatDate(myDate) {
      let date = myDate.getDate();
      date = date - 1;
      myDate.setDate(date);
      let seperator3 = "-";
      let month = myDate.getMonth() + 1;
      let strDate = myDate.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      let currentdate3 =
        myDate.getFullYear() + seperator3 + month + seperator3 + strDate;
      return currentdate3;
    },
    getDates() {
      var new_Date = new Date();
      var timesStamp = new_Date.getTime();
      var currenDay = new_Date.getDay();
      var dates = new Date(
        timesStamp + 24 * 60 * 60 * 1000 * (0 - ((currenDay + 6) % 7))
      )
        .toLocaleDateString()
        .replace(/[年月]/g, "-")
        .replace(/[日上下午]/g, "");
      let s = dates.replace(/-/g, "/");
      var dt = new Date(s);
      var m = dt.getMonth() + 1;
      var d = dt.getDate();
      m = m < 10 ? "0" + m : m;
      d = d < 10 ? "0" + d : d;
      dates = dt.getFullYear() + "-" + m + "-" + d;
      return dates;
    },
    //本月第一天
    getMonthDate() {
      let date = new Date();
      let seperator1 = "-";
      let month = date.getMonth() + 1;
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      let currentdate =
        date.getFullYear() + seperator1 + month + seperator1 + "01";
      return currentdate;
    },
    // 表单重置
    reset() {
      this.queryParams = {
        pageSetting:10,
        pageNo:1,
        createDate: null,
        stationId: null,
        stationName: null,
        beginTime:null,
        endTime:null
      };
      this.form = {
        czAmt: 0,
        xfAmt: 0
      };
      this.queryInfo={
        pageSetting:10,
        pageNo:1,
        createDate: null
      };
    },

    /** 查看详情按钮操作 */
    handleLook(row) {
      this.rows=row;
      this.getLookOrder(row);
    },
    sizeChange(psize){
      //将val赋值给size
      this.setting = psize;
      this.getLookOrder(this.rows);
    },
    currentChange(val) {
      this.pageNow2 = val;
      //重新去后台查询数据
      this.getLookOrder(this.rows);
    },
    getLookOrder(row) {
      const createDate = row.createTime;
      this.queryInfo.createDate =createDate.substring(0,10);
      this.queryInfo.pageNo =this.pageNow2;
      this.queryInfo.pageSetting =this.setting;
      return selectCardDetail(this.queryInfo).then(response => {
        this.dayReportDetailsList = response.rows;
        this.total1 = response.total;
        this.open = true;
        this.title = "电子会员明细";
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.flex {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 170px;
  flex-direction: column;
}
.flex-qy {
  display: flex;
  align-items: center;
  justify-content: center;
}
.flex-qy-sx {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.panel-group {
  padding-left: 10px;
}

.flex-sr {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex-direction: column;
}
.sr-font {
  font-size: 20px;
  color: #f4a645;
}
</style>
