<template>
  <a-spin :spinning="confirmLoading">
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="6" :sm="6">
              <a-month-picker style="width:100%" placeholder="选择日期" valueFormat="YYYYMM" v-model="time" />
            </a-col>
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-col :md="6" :sm="6">
                <a-button type="primary" @click="searchQuery">查询</a-button>
                <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
              </a-col>
            </span>
          </a-row>
        </a-form>
      </div>

      <a-row :gutter="12">
        <!-- <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
          <div class="statistics">
            <div class="icon" style="color:#1890ff;"><a-icon type="gold" /></div>
            <div>
              <p style="color:#666;margin-bottom:5px;">绑定商铺数量</p>
              <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">23</p>
            </div>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
          <div class="statistics">
            <div class="icon" style="color:#7262fd;"><a-icon type="home" /></div>
            <div>
              <p style="color:#666;margin-bottom:5px;">平台总小区数量</p>
              <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">56</p>
            </div>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
          <div class="statistics">
            <div class="icon" style="color:#ffaa00;"><a-icon type="user" /></div>
            <div>
              <p style="color:#666;margin-bottom:5px;">平台总业主数量</p>
              <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">45634</p>
            </div>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
          <div class="statistics">
            <div class="icon" style="color:#52c41a;"><a-icon type="team" /></div>
            <div>
              <p style="color:#666;margin-bottom:5px;">合作伙伴分利</p>
              <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">5656</p>
            </div>
          </div>
        </a-col>

        <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
          <div class="statistics">
            <div class="icon" style="color:#1890ff;"><a-icon type="line-chart" /></div>
            <div>
              <p style="color:#666;margin-bottom:5px;">新增订单数量</p>
              <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">5656</p>
            </div>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
          <div class="statistics">
            <div class="icon" style="color:#52c41a;"><a-icon type="dollar" /></div>
            <div>
              <p style="color:#666;margin-bottom:5px;">总营收</p>
              <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">5656</p>
            </div>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
          <div class="statistics">
            <div class="icon" style="color:#52c41a;"><a-icon type="dollar" /></div>
            <div>
              <p style="color:#666;margin-bottom:5px;">本月营收</p>
              <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">5656</p>
            </div>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
          <div class="statistics">
            <div class="icon" style="color:#52c41a;"><a-icon type="dollar" /></div>
            <div>
              <p style="color:#666;margin-bottom:5px;">本月营收</p>
              <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">5656</p>
            </div>
          </div>
        </a-col> -->
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">平台总合作伙伴数</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.partners || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">平台总商铺数量</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.shop || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">平台总小区数量</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.bindCommunity || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">平台总业主数量</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.bindOwner || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">总营收</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.totalMoney || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">月营收</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.monthMoney || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">日营收</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.todayMoney || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">新增合作伙伴数</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.newPartners || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">推广商铺数量</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.newShop || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">新增小区数量</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.newBindCommunity || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">新增业主数量</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.newBindOwner || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">新增订单数量</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.newOrderAmount || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">商铺平均人流</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.personSvg || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">总平台分利</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.todaySaasMoney || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">合作伙伴分利</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.todayPartnerMoney || 0}}</p>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="3" :style="{ marginBottom: '12px' }">
          <div class="statistics">
            <p style="color:#666;margin-bottom:5px;">小区分利</p>
            <p style="margin-bottom:0;color:#333;font-size:28px;line-height:1;">{{pageData.todayCommunityMoney || 0}}</p>
          </div>
        </a-col>
      </a-row>

      <a-row :gutter="24">
        <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '12px' }">
          <div class="statistics-box">
            <h3 class="title">今日成交订单</h3>

            <div class="order" v-if="pageData.shareOrder && pageData.shareOrder.length">
              <div class="order-title">
                <span style="width: 30%;">订单编号</span>
                <span>提交时间</span><span>买家名称</span>
                <span>订单金额</span>
              </div>
              <vue-seamless-scroll :data="pageData.shareOrder" class="seamless-warp" :class-option="defineScroll">
                <div v-for="(item, index) in pageData.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 v-else style="margin-top:50px">
              <a-empty />
            </div>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '24px' }">
          <div class="statistics-box">
            <h3 class="title">月成交金额</h3>
            <line-chart-multid :dataSource="dataList1" :fields="dayFields1" style="padding: 0 10px;" />
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '24px' }">
          <div class="statistics-box">
            <h3 class="title">月成交订单数量</h3>
            <line-chart-multid :dataSource="dataList2" :fields="dayFields2" style="padding: 0 10px;" />
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '24px' }">
          <div class="statistics-box">
            <h3 class="title">总平台、合作伙伴、商铺分利金额</h3>
            <line-chart-multid :dataSource="dividendAmount" :fields="dayFields3" style="padding: 0 10px;" />
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '24px' }">
          <div class="statistics-box">
            <h3 class="title">合作伙伴新增数量</h3>
            <bar :dataSource="dataList3" style="padding:0;" />
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '24px' }">
          <div class="statistics-box">
            <h3 class="title">入驻商铺新增数量</h3>
            <bar :dataSource="shopByMonthList" style="padding:0;" />
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '24px' }">
          <div class="statistics-box">
            <h3 class="title">巡报订单数量</h3>
            <template v-if="dataList4.length">
              <line-chart-multid :dataSource="dataList4" :fields="dayFields4" style="padding: 0 10px;" />
            </template>
            <div v-else style="margin-top:50px">
              <a-empty />
            </div>
          </div>
        </a-col>
        <a-col :sm="24" :md="12" :xl="12" :style="{ marginBottom: '24px' }">
          <div class="statistics-box">
            <h3 class="title">巡报订单金额</h3>
            <template v-if="dataList5.length">
              <line-chart-multid :dataSource="dataList5" :fields="dayFields5" style="padding: 0 10px;" />
            </template>
            <div v-else style="margin-top:50px">
              <a-empty />
            </div>
          </div>
        </a-col>
      </a-row>
    </a-card>
  </a-spin>
</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: 'PermissionListAsync',
  components: {
    Bar,
    LineChartMultid,
    vueSeamlessScroll
  },
  data() {
    return {
      // 表头
      confirmLoading: false,
      time: '',
      pageData: {},
      dayFields1: ['月成交金额'],
      dataList1: [],
      dayFields2: ['月成交订单数量'],
      dataList2: [],
      dayFields3: ['总平台', '合作伙伴', '商铺分利金额'],
      dividendAmount: [],
      dataList3: [],
      shopByMonthList: [],
      dayFields4: ['巡报订单数量'],
      dataList4: [],
      dayFields5: ['巡报订单金额'],
      dataList5: [],

      defineScroll: {
        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: {
    searchQuery() {
      this.getDataStatistics()
    },
    searchReset() {
      this.time = ''
      this.getDataStatistics()
    },
    async getDataStatistics() {
      this.confirmLoading = true
      let { result } = await shareBoardApi({ platformType: 'central', date: this.time || '' })
      if (result) {
        this.pageData = {...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.partnerByMonth.map((item) => {
          return {
            x: item.MONTH,
            y: item.partnerCount
          }
        }) || []
        this.dividendAmount = result.shareSaasByMonth.map((item, index)=> {
          return {
            type: item.MONTH,
            总平台: item.shareMoney,
            合作伙伴: result.sharePartnerByMonth[index].shareMoney,
            商铺分利金额: result.shareCommunityByMonth[index].shareMoney
          }
        })
        this.shopByMonthList =  result.shopByMonth.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
          }
        }) || []
      }
      this.confirmLoading = false
    }
  },
  created() {
    this.getDataStatistics()
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';

.statistics {
  // flex: none;
  background: #fff;
  width: 100%;
  height: 90px;
  box-sizing: border-box;
  border: 1px solid #e0dfdf;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  // padding-left: 20px;
  .icon {
    width: 60px;
    height: 60px;
    border-radius: 60px;
    margin-right: 12px;
    display: flex;
    text-align: center;
    align-items: center;
    justify-content: center;
    .anticon {
      font-size: 50px;
    }
  }
  span {
    font-size: 14px;
    color: #1890ff;
  }
}
.statistics-box {
  background: #fff;
  width: 100%;
  height: 320px;
  box-sizing: border-box;
  border: 1px solid #e0dfdf;
  overflow: hidden;
  .title {
    line-height: 40px;
    background-color: #f1f1f1;
    text-align: center;
    margin-bottom: 0;
  }
  .order {
    .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;
      overflow: hidden;
      .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;
        }
      }
    }
  }
}
</style>