<template>
    <a-row :gutter="24">
      <a-col :span="24">
        <a-card size="small" class="card-margin" title="个人信息">
          <p class="person-info-p">姓名：{{info.name}}</p>
          <p class="person-info-p">电话：{{info.phone}}</p>
          <p class="person-info-p">角色：{{info.roleNames}}</p>
          <p class="person-info-p">机构：{{info.deptName}}</p>
        </a-card>
      </a-col>
      <a-col :span="24">
        <a-card size="small" class="card-margin" title="业务概况">
          <a-row :gutter="24">
            <a-col :span="8">
              <a-card size="small" class="blue">
                <span class="order-title">已推广订单数</span>
                <span class="order-content">当日订单数：{{allOrders.today}}</span>
                <span class="order-content">本周订单数：{{allOrders.toweek}}</span>
                <span class="order-content">本月订单数：{{allOrders.tomonth}}</span>
              </a-card>
            </a-col>
            <a-col :span="8">
              <a-card size="small" class="violet">
                <span class="order-title">订单完成数</span>
                <span class="order-content">当日订单数：{{completeOrders.today}}</span>
                <span class="order-content">本周订单数：{{completeOrders.toweek}}</span>
                <span class="order-content">本月订单数：{{completeOrders.tomonth}}</span>
              </a-card>
            </a-col>
            <a-col :span="8">
              <a-card size="small" class="green">
                <span>订单数排名情况</span>
              </a-card>
            </a-col>
          </a-row>
        </a-card>
      </a-col>
      <a-col :span="24">
        <a-card size="small" class="card-margin" title="访问统计量">
          <div slot="extra">
            <!-- //:defaultValue="[startTime, endTime]"  defaultValue-->
            <a-range-picker :defaultValue="[params.startTime, params.endTime]" @change="onChange" :disabled-date="disabledDate" format="YYYY-MM-DD"/>
            <a-select v-model="type" class="type-style">
              <a-select-option value="hour">小时</a-select-option>
              <a-select-option value="day">天</a-select-option>
              <a-select-option value="month">月</a-select-option>
            </a-select>
          </div>
          <a-row :gutter="24">
            <a-col :span="12" class="echarts-box">
              <pv ref="pv" :pvState="params"></pv>
            </a-col>
            <a-col :span="12" class="echarts-box">
              <uv ref="uv" :uvState="params"></uv>
            </a-col>
          </a-row>
        </a-card>
      </a-col>
    </a-row>
</template>
<script>
import moment from 'moment';
import STable from '@/components/table';
import treecheck from '@/components/sysmanage/treeCheck';
import {getMenus} from '@/api/system';
import {getInfo, getOrderStatistic } from "@/api/school-center/analysisAPI"
import pv from "./pv";
import uv from "./uv";


export default {
  name: 'Analysis',
  components: {treecheck, STable, pv, uv},

  data() {
    return {
      
      dateString: [],
      defaultValue: [],
      type: 'hour',
      params:{
      startTime:moment().startOf('day').subtract(6, 'days'),//开始时间
      endTime:moment().endOf('day'),//结束时间
      },
      startTime01:"",//标准时间转为yyyy-MM-dd
      endTime01:"",//标准时间转为yyyy-MM-dd
      info: {
        deptName: '',
        phone: '',
        name: '',
        roleNames: ''
      },
      allOrders: {
        today: '',
        toweek: '',
        tomonth: ''
      },
      completeOrders: {
        today: '',
        toweek: '',
        tomonth: ''
      }
    }
  },
  watch : {
    type: function(value) {
      this.type=value;
      this.$refs.pv.getEchartsData(this.startTime01, this.endTime01, value);
      this.$refs.uv.getEchartsData(this.startTime01, this.endTime01, value);
    },
  },
  mounted() {
    getInfo().then(res => {
      this.info = res.data;
    })
    getOrderStatistic().then(res => {
      this.allOrders = res.data.allOrders;
      this.completeOrders = res.data.completeOrders;
    });
     this.$refs.pv.getEchartsData(this.startTime01, this.endTime01, this.type);
     this.$refs.uv.getEchartsData(this.startTime01, this.endTime01, this.type);
  },
  beforeUpdate(){
  },
  methods: {
    formDate(){

    },
    // 转化率
    getTransfer() {

    },
    disabledDate(current) {
      return current && current > moment().endOf('day');
    },
    onChange(date, dateString) {
      this.params.startTime = dateString[0];
      this.params.endTime = dateString[1];
      this.$refs.pv.getEchartsData(dateString[0], dateString[1],this.type);
      this.$refs.uv.getEchartsData(dateString[0], dateString[1],this.type);
    }
  },
  //初始化
  created() {
      let s = new Date(this.params.startTime._d);
      this.startTime01=s.getFullYear() + '-' + (s.getMonth() + 1) + '-' + s.getDate() 
      let e = new Date(this.params.endTime._d);
      this.endTime01=e.getFullYear() + '-' + (e.getMonth() + 1) + '-' + e.getDate()
  },
}
</script>
<style scoped lang="less">
  @itemH: 11vw;
  @mg: 1vw;
  .page-content {
    width: 80vw;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    height: 100%;
    overflow: auto;
    position: relative;
  }
  /deep/.ant-card-extra {
    float: left !important;
    margin-left: 0px !important;
  }
  /deep/.ant-card-small > .ant-card-head > .ant-card-head-wrapper > .ant-card-head-title{
    width: 100px !important;
    flex: 0.1;
  }
  .type-style{
    margin-left:10px;
    width:80px;
  }
  .page-left {
    flex: 1;
  }

  .blue{
    background-color: #6CBDF6;
  }

  .violet{
    background-color: #D58DE4;
  }

  .violet p{

  }

  .green{
    background-color: #55DA8D;
  }

  .person-info-p{
    width: 45%;
    display:inline-block;
    margin: 5px 0px 2px 2%;
  }

  .card-margin{
    margin-bottom: 10px;
  }

  .page-right {
    width: 35%;
    margin-left: @mg;
  }

  .right-box1 {
    height: @itemH;
    margin-bottom: @mg;
    background-color: #5C96FF;
    padding-left: 0.3vw;
    box-sizing: border-box;

    p {
      font-size: 1.5vw;
      color: white;

      &.text-row {
        font-size: 1vw;
        margin-bottom: 0.2vw;
      }
    }

    .nomessage {
      color: white;
      text-align: center;
      line-height: @itemH;
    }
  }

  .right-box2 {
    height: @itemH+@itemH/2;
    margin-bottom: @mg;
    background-color: white;
    display: flex;

    .flex-filling {
      width: 100%;
    }
  }

  .right-box3 {
    height: @itemH/2;
    background-color: #FEC52C;
    color: white;
    padding-left: 0.2vw;
    font-size: 1vw;
    display: flex;
    align-items: center;
  }

  .page-left {
    &:before, &:after {
      content: "";
      overflow: hidden;
      height: 0;
      visibility: hidden;
      clear: both;
    }
  }

  .left-item {
    height: @itemH;
    float: left;
    background-image: url("~@/assets/img/meun-icon.png");
    background-repeat: no-repeat;
    background-position: 95% 95%;
    background-size: 4vw 4vw;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 1vw;
    cursor: pointer;

    &.left-top {
      width: 49%;
      margin-bottom: @mg;
    }

    &.left-center {
      width: 32%;
      margin-bottom: @mg;
    }

    &.left-bottom {
      width: 49%;
    }

    &.left1 {
      background-color: #1F7EF7;
      margin-right: @mg/2;
    }

    &.left2 {
      background-color: #1FB2F7;
      margin-left: @mg/2;
    }

    &.left3 {
      background-color: #1FB2F7;
      margin-right: @mg/2;
    }

    &.left4 {
      background-color: #5CA4FF;
      margin-left: @mg/2;
      margin-right: @mg/2;
    }

    &.left5 {
      background-color: #1FB2F7;
      margin-left: @mg/2;
    }

    &.left6 {
      background-color: #5CA4FF;
      margin-right: @mg/2;
    }

    &.left7 {
      background-color: #45DAFF;
      margin-left: @mg/2;
    }
  }

  .tips-black {
    color: yellow;
    font-weight: bolder;
    font-size: 1.5vw;
  }

  .tips-red {
    color: red;
    font-weight: bolder;
    font-size: 1.5vw;
  }

</style>
<style scoped>
  /* For demo */
  .ant-carousel >>> .slick-slide {
    text-align: center;
    height: 5.5vw;
    line-height: 90px;
    background: #FEC52C;
    overflow: hidden;
  }

  .ant-carousel >>> .custom-slick-arrow {
    padding-left: 0.2vw;
    display: flex;
    align-items: center;
    font-size: 1vw;
    color: white;
    background-color: #FEC52C;
    opacity: 0.3;
  }
  .ant-carousel >>> .custom-slick-arrow:before {
    display: none;
  }
  .ant-carousel >>> .custom-slick-arrow:hover {
    opacity: 0.5;
  }

  .ant-carousel >>> .slick-slide h3 {
    color: #fff;
  }

  .ant-card-small > .ant-card-body {
    padding: 8px;
  }

  .order-title {
    marign:0px;
    display: block;

  }
  .order-content {
    margin: 5px 0px 5px 0px;
    display: block;
  }
  .echarts-box{
    height: 210px;
  }
</style>