<template>
  <div class="page-header-index-wide">
    <div class="query-box">
      <a-month-picker placeholder="选择日期" @change="onChange" />
      <a-button type="primary" @click="searchQuery" style="margin-left: 20px;">查询</a-button>
    </div>
    <div class="data-box">
      <div class="statistics">
        <p style="color:#666;margin-bottom:5px;">绑定商铺数量</p>
        <p style="margin-bottom:0;color:#333;font-size:24px;line-height:1;">{{data.bindShops || 0}}</p>
      </div>
      <div class="statistics">
        <p style="color:#666;margin-bottom:5px;">平台总小区数量</p>
        <p style="margin-bottom:0;color:#333;font-size:24px;line-height:1;">{{data.bindCommunity || 0}}</p>
      </div>

      <div class="statistics">
        <p style="color:#666;margin-bottom:5px;">平台总业主数量</p>
        <p style="margin-bottom:0;color:#333;font-size:24px;line-height:1;">{{data.bindOwner || 0}}</p>
      </div>

      <div class="statistics">
        <p style="color:#666;margin-bottom:5px;">合作伙伴分利</p>
        <p style="margin-bottom:0;color:#333;font-size:24px;line-height:1;">¥{{data.partnerShare || 0}}</p>
      </div>

      <div class="statistics">
        <p style="color:#666;margin-bottom:5px;">新增订单数量</p>
        <p style="margin-bottom:0;color:#333;font-size:24px;line-height:1;">{{data.newOrderAmount || 0}}</p>
      </div>
      <div class="statistics">
        <p style="color:#666;margin-bottom:5px;">总营收</p>
        <p style="margin-bottom:0;color:#333;font-size:24px;line-height:1;">¥{{data.totalMoney || 0}}</p>
      </div>
      <div class="statistics">
        <p style="color:#666;margin-bottom:5px;">本月营收</p>
        <p style="margin-bottom:0;color:#333;font-size:24px;line-height:1;">¥{{data.monthMoney || 0}}</p>
      </div>
      <div class="statistics" style="margin-right: 0;">
        <p style="color:#666;margin-bottom:5px;">今日营收</p>
        <p style="margin-bottom:0;color:#333;font-size:24px;line-height:1;">¥{{data.todayMoney || 0}}</p>
      </div>
    </div>
    <a-row :gutter="24">
      <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '20px' }">
        <div class="t-box">
          <h3 class="box-title">最新成交订单</h3>
          <div class="order">
            <div class="order-title"><span
                style="width: 30%;">订单编号</span><span>提交时间</span><span>买家名称</span><span>订单金额</span></div>
            <vue-seamless-scroll :data="data.shareOrder" class="seamless-warp" :class-option="defineScroll">
              <div v-for="(item, index) in data.shareOrder" :key="index" class="item">
                <span
                  style="width: 30%;">{{ item.order_num }}</span><span>{{ item.create_time }}</span><span>{{ item.buyer_name }}</span><span>¥{{ item.total_money }}</span>
              </div>
            </vue-seamless-scroll>
          </div>
        </div>
      </a-col>
      <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '20px' }">
        <div class="t-box">
          <h3 class="box-title">月成交金额</h3>
          <line-chart-multid :dataSource="dataList1" :fields="dayFields1" style="padding: 0;" />
        </div>
      </a-col>
    </a-row>
    <a-row :gutter="24">
      <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '20px' }">
        <div class="t-box">
          <h3 class="box-title">月成交订单数量</h3>
          <div>
            <line-chart-multid :dataSource="dataList2" :fields="dayFields2" style="padding: 0;" />
          </div>
        </div>
      </a-col>
      <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '20px' }">
        <div class="t-box">
          <h3 class="box-title">入驻商铺新增数量</h3>
          <bar :dataSource="dataList3" style="padding:0;" />
        </div>
      </a-col>
    </a-row>
    <a-row :gutter="24">
      <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '20px' }">
        <div class="t-box">
          <h3 class="box-title">巡报订单数量</h3>
          <div>
            <line-chart-multid :dataSource="dataList4" :fields="dayFields4" style="padding: 0;" />
          </div>
        </div>
      </a-col>
      <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '20px' }">
        <div class="t-box">
          <h3 class="box-title">巡报订单金额</h3>
          <line-chart-multid :dataSource="dataList5" :fields="dayFields5" style="padding: 0;" />
        </div>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import Bar from '@/components/chart/Bar'
import LineChartMultid from '@/components/chart/LineChartMultid'
import vueSeamlessScroll from 'vue-seamless-scroll'
import { shareBoardApi } from '@/api/api'
export default {
  name: 'statistical',
  components: {
    Bar,
    LineChartMultid,
    vueSeamlessScroll,
  },
  data() {
    return {
      loading: true,
      time: '',
      data: {},
      dayFields1: ['月成交金额'],
      dataList1: [],
      dayFields2: ['月成交订单数量'],
      dataList2: [],
      dataList3: [],
      dayFields4: ['巡报订单数量'],
      dataList4: [],
      dayFields5: ['巡报订单金额'],
      dataList5: [],
    }
  },
  created() {
    setTimeout(() => {
      this.loading = !this.loading
    }, 1000)
    this.getDataStatistics()
  },
  computed: {
    defineScroll() {
      return {
        data: {},
        step: 0.5, // 数值越大速度滚动越快
        limitMoveNum: 5, // 开始无缝滚动的数据量 this.dataList.length
        hoverStop: true, // 是否开启鼠标悬停stop
        direction: 1, // 0向下 1向上 2向左 3向右
        openWatch: true, // 开启数据实时监控刷新dom
        singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
        singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
        waitTime: 1000, // 单步运动停止的时间(默认值1000ms)
      }
    },
  },
  methods: {
    async getDataStatistics() {
      let { result } = await shareBoardApi({ platformType: 'partner', date: this.time })
      if (result) {
        this.data = result
        this.dataList1 =
          result.shareByMonth.map((item) => {
            return {
              type: item.MONTH,
              月成交金额: item.shareMoney,
            }
          }) || []
        this.dataList2 =
          result.orderCountByMonth.map((item) => {
            return {
              type: item.MONTH,
              月成交订单数量: item.orderCount,
            }
          }) || []
        this.dataList3 =
          result.shopCountByMonth.map((item) => {
            return {
              x: item.MONTH,
              y: item.shopCount,
            }
          }) || []
        this.dataList4 =
          result.shareList.map((item) => {
            return {
              type: item.st_date_day,
              巡报订单数量: item.order_num,
            }
          }) || []
        this.dataList5 =
          result.shareList.map((item) => {
            return {
              type: item.st_date_day,
              巡报订单金额: item.share_money,
            }
          }) || []
      }
    },
    onChange(date, dateString) {
      if (dateString) {
        this.time = dateString.replace('-', '')
      }else{
        this.time = ''
        this.getDataStatistics()
      }
    },
    searchQuery() {
      this.getDataStatistics()
    },
  },
}
</script>

<style lang="less" scoped>
.page-header-index-wide {
  padding: 16px;

  .query-box {
    background: #fff;
    padding: 20px;
    margin-bottom: 20px;
    display: flex;
    justify-content: flex-end;
  }
  .data-box {
    display: flex;
    margin-bottom: 20px;
    justify-content: space-between;
  }
  .statistics {
    background: #fff;
    width: 11.5%;
    box-sizing: border-box;
    border: 1px solid #e0dfdf;
    padding: 25px 10px;
    max-height: 100px;
    text-align: center;
  }
}
.t-box {
  background: #fff;
  padding: 15px;
  border: 1px solid #e0dfdf;
  height: 340px;
}
.box-title {
  font-weight: bold;
  margin-bottom: 15px;
  display: inline-block;
  padding-left: 10px;
  border-left: 3px solid #1890ff;
  height: 20px;
  line-height: 20px;
}
.order {
  margin: 0 10px;
  .order-title {
    background: #fafafa;
    height: 40px;
    line-height: 40px;
    display: flex;
    border-left: 1px solid #e8e8e8;
    span {
      width: 25%;
      border-right: 1px solid #e8e8e8;
      border-top: 1px solid #e8e8e8;
      text-align: center;
      font-weight: bold;
    }
  }
  .seamless-warp {
    border: 1px solid #e8e8e8;
    border-right: none;
    .item {
      height: 40px;
      line-height: 40px;
      display: flex;
      span {
        width: 25%;
        border-right: 1px solid #e8e8e8;
        //border-top: 1px solid #e8e8e8;
        border-bottom: 1px solid #e8e8e8;
        text-align: center;
        overflow: hidden;
      }
    }
  }
}
.seamless-warp {
  height: 220px;
  overflow: hidden;
}
</style>