<template>
  <div>
    <div class="divBox">
      <el-form class="search-form" :inline="true" >
        <el-form-item >
          <el-select v-model="value" placeholder="请选择日期">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item >
          <treeselect :clearable="false"  v-model="deptId"  :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
        </el-form-item>
        <el-form-item>
           <el-select v-model="userIds" multiple  placeholder="请选择员工">
              <el-option
                v-for="item in users"
                :key="item.userId"
                :label="item.nickName"
                :value="item.userId">
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="cyan" icon="el-icon-search"   @click="quiry">搜索</el-button>
        </el-form-item>
      </el-form>
            <el-card :bordered="false" dis-hover :padding="12" style="margin: 0 0  20px 0;">
              <div style="height: 20px;margin: 10px;font-weight:bold;"><span>销售统计</span></div>
              <div>
               <el-row>
                 <el-col :span="8">
                   <div class="box2">
                     <div style="font-size: 14px; margin-bottom:15px;">
                       <span>新增客户量</span>
                     </div>
                    <div class="content" v-if="count">
                      <span class="content-number spBlock mb15"><count-to :start-val="0" :end-val="count.newCustomerCount" :duration="3200" class="card-panel-num" /></span>
                      <div class="blue-line"></div>
                      <div class="acea-row row-between-wrapper" style="margin-top: 15px;font-size: 12px;">
                        <span class="content-time">总客户量</span>
                        <span >{{ count.customerCount }} 人</span>
                      </div>
                    </div>
                    </div>
                 </el-col>
                 <el-col :span="8">
                   <div class="box2">
                     <div style="font-size: 14px; margin-bottom:15px;">
                       <span>客户转化率</span>
                     </div>
                    <div class="content" v-if="count">
                      <span class="content-number spBlock mb15"><count-to :start-val="0" :end-val="count.customerRate" :duration="3200" class="card-panel-num" /> <span>%</span></span>
                      <div class="blue-line"></div>
                      <div class="acea-row row-between-wrapper" style="margin-top: 15px;font-size: 12px;">
                        <span class="content-time" >客户转化金额</span>
                        <span >{{ count.customerMoney }} ￥</span>
                      </div>
                    </div>
                    </div>
                 </el-col>
                 <el-col :span="8">
                   <div class="box2">
                     <div style="font-size: 14px; margin-bottom:15px;">
                       <span>新增复购客户数</span>
                     </div>
                    <div class="content" v-if="count">
                      <span class="content-number spBlock mb15"><count-to :start-val="0" :end-val="count.customerRe" :duration="3200" class="card-panel-num" /></span>
                      <div class="blue-line"></div>
                      <div class="acea-row row-between-wrapper" style="margin-top: 15px;font-size: 12px;">
                        <span class="content-time">客户复购总金额</span>
                        <span >{{ count.customerReMoney }} ￥</span>
                      </div>
                    </div>
                    </div>
                 </el-col>
                 <el-col :span="8">
                   <div class="box2">
                     <div style="font-size: 14px; margin-bottom:15px;">
                       <span>全款订单数</span>
                     </div>
                    <div class="content" v-if="count">
                      <span class="content-number spBlock mb15"><count-to :start-val="0" :end-val="count.orderFull" :duration="3200" class="card-panel-num" /></span>
                      <div class="blue-line"></div>
                      <div class="acea-row row-between-wrapper" style="margin-top: 15px;font-size: 12px;">
                        <span class="content-time">全款订单占比</span>
                        <span >{{ count.orderFullRate }} %</span>
                      </div>
                    </div>
                    </div>
                 </el-col>
                 <el-col :span="8">
                   <div class="box2">
                     <div style="font-size: 14px; margin-bottom:15px;">
                       <span>订金订单数</span>
                     </div>
                    <div class="content" v-if="count">
                      <span class="content-number spBlock mb15"><count-to :start-val="0" :end-val="count.orderDeposit" :duration="3200" class="card-panel-num" /></span>
                      <div class="blue-line"></div>
                      <div class="acea-row row-between-wrapper" style="margin-top: 15px;font-size: 12px;">
                        <span class="content-time">订金订单占比</span>
                        <span >{{ count.orderDepositRate }} %</span>
                      </div>
                    </div>
                    </div>
                 </el-col>
                 <el-col :span="8">
                   <div class="box2">
                     <div style="font-size: 14px; margin-bottom:15px;">
                       <span>退款订单数</span>
                     </div>
                    <div class="content" v-if="count">
                      <span class="content-number spBlock mb15"><count-to :start-val="0" :end-val="count.orderRefund" :duration="3200" class="card-panel-num" /></span>
                      <div class="blue-line"></div>
                      <div class="acea-row row-between-wrapper" style="margin-top: 15px;font-size: 12px;">
                        <span class="content-time">退款订单占比</span>
                        <span >{{ count.orderRefundRate }} %</span>
                      </div>
                    </div>
                    </div>
                 </el-col>
               </el-row>
              </div>
            </el-card>
    </div>
    <el-row>
      <el-col :span="14">
        <el-card :bordered="false" dis-hover style="margin-right: 10px;">
          <div slot="header">
            <div class="acea-row row-middle">
              <el-avatar
                icon="el-icon-s-operation"
                size="small"
                style="color: #1890ff; background: #e6f7ff; font-size: 13px"
              />
              <span class="ivu-pl-8" style="font-weight:bold;">客户遗忘提醒</span>
            </div>
          </div>
              <div>
                <el-row>
                    <el-col :span="8">
                      <div class="box1"><span class="boxt">超过7天未联系</span><span class="number1">{{ count.sevenDays }}</span> 人</div>
                    </el-col>
                    <el-col :span="8">
                      <div class="box1"><span class="boxt">超过15天未联系</span><span class="number1">{{ count.fifteenDays }}</span> 人</div>
                    </el-col>
                    <el-col :span="8">
                      <div class="box1"><span class="boxt">超过30天未联系</span><span class="number1">{{ count.oneMonth }}</span> 人</div>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                      <div class="box1"><span style="display: block;margin-bottom: 15px;"><span class="boxc">超过3个月未联系</span> <span style="background-color: rgb(255, 240, 179); font-size: 13px;padding: 2px;border-radius: 3px;">警告</span></span><span class="number1">{{ count.threeMonth }}</span> 人</div>
                    </el-col>
                    <el-col :span="8">
                      <div class="box1"><span style="display: block;margin-bottom: 15px;"><span class="boxc">超过6个月未联系</span><span style="background-color: rgb(255, 240, 179); font-size: 13px;padding: 2px;border-radius: 3px;">警告</span></span><span class="number1">{{ count.sixMonth }}</span> 人</div>
                    </el-col>
                    <el-col :span="8">
                      <div class="box1"><span style="display: block;margin-bottom: 15px;"><span class="boxc">逾期未联系</span><span style="background-color: rgb(255, 189, 173); font-size: 13px;padding: 2px;color: rgb(191, 38, 0);border-radius: 3px;">警告</span></span><span class="number1">{{ count.unContactCustomerCount }}</span> 人</div>
                    </el-col>
                </el-row>
              </div>
        </el-card>
      </el-col>
      <el-col :span="10">
        <el-card :bordered="false" dis-hover style="margin-left: 10px;">
<!--          <div slot="header">-->
<!--            <div class="acea-row row-middle">-->
<!--              <el-avatar-->
<!--                icon="el-icon-s-operation"-->
<!--                size="small"-->
<!--                style="color: #1890ff; background: #e6f7ff; font-size: 13px"-->
<!--              />-->
<!--              <span class="ivu-pl-8" style="font-weight:bold;">订单金额支付比例</span>-->
<!--            </div>-->
<!--          </div>-->
          <div slot="header">
            <div class="acea-row row-middle" style="display: flex; justify-content: space-between; align-items: center;">
              <div style="display: flex; align-items: center;">
                <el-avatar
                  icon="el-icon-s-operation"
                  size="small"
                  style="color: #1890ff; background: #e6f7ff; font-size: 13px"
                />
                <span class="ivu-pl-8" style="font-weight: bold;">订单金额支付比例</span>
              </div>
            </div>
          </div>



          <div  id="echart-customer2"  style="width: 100%; height: 260px;" />

        </el-card>
      </el-col>
    </el-row>


  </div>
</template>
<script>
import CountTo from "vue-count-to";
import { getIndexData } from "@/api/index";
import { getUserListByDeptId} from "@/api/company/companyUser";
import { treeselect } from "@/api/company/companyDept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import * as echarts from 'echarts'

import { debounce } from '@/utils'
import { getStorePaymentData } from "@/api/index";
export default {
  components: {
    CountTo,Treeselect
  },
  watch: {
  // 监听deptId
  'deptId': 'currDeptChange'
  },
  data() {
    return {
      deptOptions:[],
      deptId:undefined,
      userIds:undefined,
      users:[],
      dateRange:[],
      chart: null,
      chart2: null,

      options: [{
         value: '1',
         label: '今天'
       }, {
         value: '2',
         label: '昨天'
       }, {
         value: '3',
         label: '本周'
       }, {
         value: '4',
         label: '上周'
       }, {
         value: '5',
         label: '本月'
       }
       , {
         value: '6',
         label: '上月'
       }
       , {
         value: '7',
         label: '本季度'
       }
       , {
         value: '8',
         label: '上季度'
       }
       , {
         value: '9',
         label: '本年'
       }
       , {
         value: '10',
         label: '上年'
       }],
       value: '5',

       dates:[],
      count: {
        customerCount: 0,
        newCustomerCount: 0,
        customerRate: 0,
        customerMoney: 0,
        customerRe: 0,
        customerReMoney: 0,
        orderFull: 0,
        orderFullRate: 0,
        orderDeposit: 0,
        orderDepositRate: 0,
        orderRefund: 0,
        orderRefundRate: 0,
        sevenDays: 0,
        fifteenDays: 0,
        oneMonth: 0,
        threeMonth: 0,
        sixMonth: 0,
        unContactCustomerCount: 0,
        orderPayRate:1,
      },

    };
  },
  created() {
    this.getTreeselect();
  },
 methods:{
    currDeptChange(val){
      this.deptId=val;
      this.getUserListByDeptId();
    },


    /** 查询部门下拉树结构 */
    getTreeselect() {
    var that=this;
    treeselect().then((response) => {
      this.deptOptions = response.data;
      if(response.data!=null&&response.data.length>0){
        this.deptId=response.data[0].id;
        that.quiry()
      }
    });
    },
    getUserListByDeptId() {
      this.userIds=undefined;
      var data={deptId:this.deptId};
      getUserListByDeptId(data).then(response => {
        this.users = response.data;
      });
    },

    quiry(){
      var data;
      if(this.userIds!=undefined){
          data={type:this.value,userIds:this.userIds+"",deptId:this.deptId}
      }
      else{
          data={type:this.value,deptId:this.deptId}
      }
      getIndexData(data).then((response) => {
        this.count=response.data
          setTimeout(() => {
            this.initEchart();
          }, 500);
      });
    },

    initEchart(){
      var option = {
             series: [{
                 type: 'gauge',
                 axisLine: {
                     lineStyle: {
                         width: 10,
                         color: [
                             [0.2, '#1c4587'],
                             [0.8, '#980000'],
                             [1, '#009100']
                         ]
                     }
                 },
                 pointer: {
                     itemStyle: {
                         color: 'auto'
                     }
                 },
                 axisTick: {
                     distance: -30,
                     length: 8,
                     lineStyle: {
                         color: '#fff',
                         width: 2
                     }
                 },
                 splitLine: {
                     distance: -30,
                     length: 30,
                     lineStyle: {
                         color: '#fff',
                         width: 4
                     }
                 },
                 axisLabel: {
                     color: 'auto',
                     distance: 0,
                     fontSize: 14
                 },
                 detail: {
                     fontSize: 18,
                     valueAnimation: true,
                     formatter: '{value} %',
                     color: 'auto'
                 },
                 data: [{
                     value: this.count.orderPayRate
                 }]
             }]
         };
      this.chart=echarts.init(document.getElementById("echart-customer2"));
      this.chart.setOption(option,true);
    },
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.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, 0.05);
border-color: rgba(0, 0, 0, 0.05);

.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;
}
}
}
.baseInfo {
::v-deep .el-card__header {
padding: 15px 20px !important;
}
}

.ivu-mb {
margin-bottom: 10px;
font-size: 12px!important;
}
.up,
.el-icon-caret-top {
color: #f5222d;
font-size: 12px;
opacity: 1 !important;
}

.down,
.el-icon-caret-bottom {
color: #39c15b;
font-size: 12px;
/*opacity: 100% !important;*/
}

.content {
&-number {
font-size: 30px;
}
&-time {
font-size: 14px;
/*color: #8C8C8C;*/
}
}
.spBlock {
display: block;
}

.app-container{
border: 1px solid #e6e6e6;
padding: 12px;

.app-content{
background-color: white;
.title{
padding: 20px 30px 0px 30px;
font-size: 18px;
font-weight: bold;
color: black;

}
.search-form{
margin: 20px 30px 0px 30px;
}
.data-box{
padding: 30px;
background-color:  rgb(255, 255, 255);
height: 100%;

.echart-box{
margin: 0 auto;
text-align: center;
}
.el-select{
margin: 5px 10px;
}
.table-box{
margin-top: 15px;
.export{
float: right;
margin: 10px 0px;
}
}
}
}
}
#echart-customer{
width:100%;
height:350px
}
#echart-customer2{
width:100%;
height:350px
}
.vue-treeselect{
width: 217px;
height: 36px;
}

.vue-treeselect__control{
display: block;
}

.box {
height: 100px;
border: 1px solid #e7e7e7;
border-radius: 3px;
transition: border-radius 0.3s, background-color 0.3s;
margin: 20px 20px 20px 20px;
display: flex;
padding: 10px;
align-items: center;
justify-content: space-between;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); /* 水平偏移 0px，垂直偏移 0px，模糊半径 10px，阴影颜色为半透明黑色 */
transition: box-shadow 0.1s; /* 添加过渡效果，使阴影变化更加平滑 */
}
.box2 {
height: 120px;
border: 1px solid #e7e7e7;
border-radius: 3px;
transition: border-radius 0.3s, background-color 0.3s;
margin: 10px 15px 30px 10px;
padding: 10px 20px 20px 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); /* 水平偏移 0px，垂直偏移 0px，模糊半径 10px，阴影颜色为半透明黑色 */
transition: box-shadow 0.1s; /* 添加过渡效果，使阴影变化更加平滑 */
}
.box2:hover {
box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3); /* 鼠标悬停时阴影效果变化 */
}
.number{
margin-top: 10px;
font-size: 20px;
}

.box:hover {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); /* 鼠标悬停时阴影效果变化 */
}
.box1 {
height: 100px;
border: 1px solid #e7e7e7;
border-radius: 4px;
margin: 10px 10px 20px 10px;
background: rgb(235, 235, 240);
padding: 20px;

}
.boxt {
  font-size: 15px;
display: block;
margin-bottom: 15px;
color: #666;
}
.boxc {
font-size: 15px;
padding-top: 2px;
padding-right: 6px;
color: #666;
}
.number1 {
margin-top: 15px;
font-size: 24px;
}
.blue-line {
width: 40%;
height: 2px; /* 横线高度 */
background-color: rgb(0, 82, 204);
float: right;
}

</style>
