<template>
  <div class="app-container" style="background-color: rgb(240, 242, 245);">

    <!-- 5大类 -->
    <el-row type="flex" justify="space-between" :gutter="30" class="panel-group">
      <el-col :span="5" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              销售总数
            </div>
            <count-to :start-val="0" :end-val="data.member" :duration="500" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :span="5" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              业绩总额
            </div>
            <count-to :start-val="0" :end-val="Number(data.price)" :duration="1500" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :span="5" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              订单总数
            </div>
            <count-to :start-val="0" :end-val="data.order" :duration="1500" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :span="5" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="goods" class-name="card-panel-goods" style="width:48px;height:48px;" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              商品总数
            </div>
            <count-to :start-val="0" :end-val="data.goods" :duration="1500" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :span="5" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="community" class-name="card-panel-goods" style="width:48px;height:48px;" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              社区文章
            </div>
            <count-to :start-val="0" :end-val="data.article" :duration="1500" class="card-panel-num" />
          </div>
        </div>
      </el-col>
    </el-row>
    <!-- 代理组成 -->
    <el-row class="model" :gutter="20">
      <el-col :span="8" class="modelCol">
        <member-rose id="memberForm1" :series-data="member" title="销售组成" show-title="销售数量:" />
      </el-col>
      <el-col :span="8" class="modelCol">
        <member-rose id="priceForm1" :series-data="price" title="销售业绩" show-title="业绩金额:" />
      </el-col>
      <el-col :span="8" class="modelCol">
        <member-rose id="orderForm1" :series-data="order" title="订单组成" show-title="订单数量:" />
      </el-col>
    </el-row>
    <!-- 往期环比 -->
    <!-- 订单金额每小时统计（折线图） -->
    <el-row class="style_num_container">
      <el-col :span="24">
        <order-account width="100%" />
      </el-col>
    </el-row>
    <!-- 订单数量每小时统计（柱状图） -->
    <el-row class="style_num_container">
      <el-col :span="24">
        <goods-every-style width="100%" />
      </el-col>
    </el-row>
    <el-row class="style_num_container">
      <el-col :span="24">
        <style-num width="100%" />
      </el-col>
    </el-row>
    <el-row class="style_num_container">
      <el-col :span="24">
        <style-account width="100%" />
      </el-col>
    </el-row>

    <!-- 新增代理 -->
    <el-row class="model" :gutter="20">
      <el-col :span="24" class="modelCol">
        <next-add ref="add" />
      </el-col>
    </el-row>
    <!-- 商品 -->
    <el-row class="model">
      <el-col :span="24" class="modelCol">
        <rank-bar id="goodsForm1" :series-data="goods" title="商品销售量前10:" show-title="销量" />
      </el-col>
    </el-row>
  </div>
</template>
<script>
// api
import {
  getTotal,
  getMemberPeople,
  getMemberPrice,
  getMemberOrder,
  getGoodsTen
} from '@/api/home'
import CountTo from 'vue-count-to'
// 组件
import MemberRose from './components/MemberRose'
import RankBar from './components/RankBar'
import NextAdd from './components/NextAdd'
import StyleNum from './components/styleNum'
import styleAccount from './components/styleAccount'
import orderAccount from './components/orderAccount'
import goodsEveryStyle from './components/goodsEveryStyle'

export default {
  components: {
    CountTo,
    MemberRose,
    RankBar,
    NextAdd,
    StyleNum,
    styleAccount,
    orderAccount,
    goodsEveryStyle
  },
  data() {
    return {
      data: {
        member: 0,
        price: 0,
        order: 0,
        goods: 0,
        article: 0
      },
      member: [],
      price: [],
      order: [],
      goods: []
    }
  },
  created() {
    this.$nextTick(() => {
      this.getTotal()
      this.getMemberPeople()
      this.getMemberPrice()
      this.getMemberOrder()
      this.getGoodsTen()
      this.$refs.add.handleInit()
    })
  },
  methods: {
    // 获取数字统计
    async getTotal() {
      const res = await getTotal()
      try {
        const { message, code } = res
        if (code === 200) {
          const { data } = res
          this.data.member = data.userCount
          this.data.price = data.account
          this.data.order = data.orderCount
          this.data.goods = data.goodsCount
          this.data.article = data.articleCount
        } else {
          this.$message.error(message)
        }
      } catch (e) {
        console.log(`获取首页统计数据失败:${e}`)
      }
    },
    // 获取代理组成
    async getMemberPeople() {
      const res = await getMemberPeople()
      try {
        const { message, code } = res
        if (code === 200) {
          const { data } = res
          for (const item in data) {
            switch (item) {
              case 'crownCount':
                this.member.push({ name: `代理公司(${data[item]}人)`, value: data[item] })
                break
              case 'superCount':
                this.member.push({ name: `销售主管(${data[item]}人)`, value: data[item] })
                break
              default:
                this.member.push({ name: `销售经理(${data[item]}人)`, value: data[item] })
            }
          }
        } else {
          this.$message.error(message)
        }
      } catch (e) {
        console.log(`获取销售组成失败:${e}`)
      }
    },
    // 获取业绩组成
    async getMemberPrice() {
      const res = await getMemberPrice()
      try {
        const { message, code } = res
        if (code === 200) {
          const { data } = res
          for (const item in data) {
            switch (item) {
              case 'crownAccount':
                this.price.push({ name: `代理公司:\n(${data[item]}元)`, value: data[item] })
                break
              case 'superAccount':
                this.price.push({ name: `销售主管:\n(${data[item]}元)`, value: data[item] })
                break
              default:
                this.price.push({ name: `销售经理:\n(${data[item]}元)`, value: data[item] })
            }
          }
        } else {
          this.$message.error(message)
        }
      } catch (e) {
        console.log(`获取代理业绩组成失败:${e}`)
      }
    },
    // 获取订单组成
    async getMemberOrder() {
      const res = await getMemberOrder()
      try {
        const { message, code } = res
        if (code === 200) {
          const { data } = res
          for (const item in data) {
            switch (item) {
              case 'crownCount':
                this.order.push({ name: `代理公司(${data[item]}单)`, value: data[item] })
                break
              case 'superCount':
                this.order.push({ name: `销售主管(${data[item]}单)`, value: data[item] })
                break
              default:
                this.order.push({ name: `销售经理(${data[item]}单)`, value: data[item] })
            }
          }
        } else {
          this.$message.error(message)
        }
      } catch (e) {
        console.log(`获取代理订单组成失败:${e}`)
      }
    },
    // 获取商品销量前10
    async getGoodsTen() {
      const res = await getGoodsTen()
      try {
        const { message, code } = res
        if (code === 200) {
          const { data } = res
          this.goods = data
        } else {
          this.$message.error(message)
        }
      } catch (e) {
        console.log(`获取商品销量前10失败:${e}`)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
  .style_num_container {
    padding: 20px 10px;
    background: #fff;
    margin-bottom: 20px;
  }
  .panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    // &:hover {
    //   .card-panel-icon-wrapper {
    //     color: #fff;
    //   }

    //   .icon-people {
    //     background: #40c9c6;
    //   }

    //   .icon-message {
    //     background: #36a3f7;
    //   }

    //   .icon-money {
    //     background: #f4516c;
    //   }

    //   .icon-shopping {
    //     background: #34bfa3
    //   }
    // }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}

.model{
  margin-bottom: 40px;
  .modelCol{
    padding: 20px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #fff !important;

    .rankModel{
      height: 500px;
      width: 100%;
      margin-left: 20px;
      .title{
        margin: 0;
        text-align: left;
        width: 100%;
      }
      .rankList{
        list-style: none;
        height: 450px;
        display: flex;
        justify-content: space-between;
        flex-direction: column;
        margin: 0;
        padding: 0;
        width: 100%;
      }
    }
  }
}
</style>
