<template>
  <div class="member-summary fullcontainer">
    <div class="gic-summary-main">
      <!-- 会员 -->
      <div class="member-item">
        <div class="title">
          会员
        </div>
        <div class="total">
          <!-- 会员数 -->
          <router-link to="/wechatmembers" class="member-data m-data" tag="div">
            <!-- 会员总数 -->
            <div class="member-list">
              <p class="member-txt">会员总数</p>
              <p class="memebr-value">{{memberData.total}}</p>
            </div>
          </router-link>

          <router-link to="/wechatmembers" class="yes-data m-data" tag="div">
            <div class="member-list">
              <p class="member-txt">昨日新增</p>
              <p class="memebr-value">{{memberData.yesterdayNewMember}}</p>
            </div>
            <div class="member-list">
              <p class="member-txt">今日新增</p>
              <p class="memebr-value">{{memberData.todayNewMember}}</p>
            </div>
            <div class="member-list">
              <p class="member-txt">昨日会员率</p>
              <p class="memebr-value">{{parseInt(memberData.lastMonthNewMember, 10).toFixed(2)}}%</p>
            </div>
            <div class="member-list">
              <p class="member-txt">今日会员率</p>
              <p class="memebr-value">{{parseInt(memberData.lastMonthNewMember, 10).toFixed(2)}}%</p>
            </div>
          </router-link>

          <router-link to="/wechatmembers" class="lastmonth-data m-data" tag="div">
            <div class="member-list">
              <p class="member-txt">上月新增</p>
              <p class="memebr-value">{{memberData.lastMonthNewMember}}</p>
            </div>
            <div class="member-list">
              <p class="member-txt">本月新增</p>
              <p class="memebr-value">{{memberData.currentMonthNewMember}}</p>
            </div>
            <div class="member-list">
              <p class="member-txt">上月会员率</p>
              <p class="memebr-value">{{(memberData.currentMonth).toFixed(2)}}%</p>
            </div>
            <div class="member-list">
              <p class="member-txt">本月会员率</p>
              <p class="memebr-value">{{(memberData.currentMonth).toFixed(2)}}%</p>
            </div>
          </router-link>
          
        </div>

        <div class="member-chart" ref="memberBox">
          <all-member-chart :charData="memberchartData" :total="totalRate" :id="member" :width="memberWidth" v-if="memberchartData.length"></all-member-chart>
        </div>
      </div>

      <!-- 达成 -->
      <div class="achievement">
        <!-- 日达成 -->
        <router-link to="/salesAnalysis" tag="div" class="day a-item">
          <div class="title">
            日达成
          </div>  
          <div class="day-data" ref="dayBox">
            <!-- 如果没有数据 -->
            <div>
              <day-chart :charData="dayChartData" :id="day" :width="dayWidth" v-if="dayChartData.length"></day-chart>
              <div v-else>
                暂无数据
              </div>
            </div>
          </div>
          <div class="jt-data">
            <div class="item">
              <p>日销售额</p>
              <p>{{daySaleData.totalSale}}</p>
            </div>
            <div class="item">
              <p>日指标</p>
              <p>{{daySaleData.performanceValue}}</p>
            </div>
            <div class="item">
              <p>日达成率</p>
              <p>{{dayRate}}</p>
            </div>
          </div>
        </router-link>
        <!-- 月达成 -->
        <router-link to="/salesAnalysis" tag="div" class="month a-item">
          <div class="title">
            月达成
          </div>  
          <div class="day-data" ref="monthBox">
            <month-chart :charData="monthData" :id="month" :width="monthWidth" v-if="monthData.length"></month-chart>
          </div>
          <div class="jt-data">
            <div class="item">
              <p>月销售额</p>
              <p>{{monthSaleData.totalSale}}</p>
            </div>
            <div class="item">
              <p>月指标</p>
              <p>{{monthSaleData.performanceValue}}</p>
            </div>
            <div class="item">
              <p>月达成率</p>
              <p>{{monthRate}}</p>
            </div>
          </div>
        </router-link>
      </div>

      <!-- 今日销售单效 -->
      <div class="today-sales">
        <router-link tag="div" to="/salesAnalysis">
          <div class="title">
            今日销售单效
          </div>
          <div class="inner-data">
            <div class="item">
              <p class="return-txt">成交人数</p>
              <p class="return-txt">{{todaydata.memberCount}}</p>
              <div class="person" id="todayPerson" ref="guideBox">
                <guide-chart :width="guideWidth" :id="personbox" :charData="personData" v-if="personData.length"></guide-chart>
              </div>
            </div>
            <div class="item">
              <p class="return-txt">连带率</p>
              <p class="return-txt">{{todaydata.joint}}</p>
              <div class="person" id="todayPerson">
                <guide-chart :width="guideWidth" :id="'jointbox'" :charData="jointData" v-if="jointData.length"></guide-chart>
              </div> 
            </div>
            <div class="item">
              <p class="return-txt">平均商品单价</p>
              <p class="return-txt">{{todaydata.avgGoodsSale}}</p>
              <div class="person" id="todayPerson">
                <guide-chart :width="guideWidth" :id="'avggoodsbox'" :charData="avgData" v-if="avgData.length"></guide-chart>
              </div>
            </div>
            <div class="item">
              <p class="return-txt">当日退货率</p>
              <p class="return-txt">{{todayR}}</p>
              <div class="person">
                <guide-chart :width="guideWidth" :id="'todayreturnbox'" :charData="todayReturnData" v-if="todayReturnData.length"></guide-chart>
              </div>
            </div>
          </div>
          <div class="inner-data">
            <div class="item">
              <p class="return-txt">老客率</p>
              <p class="return-txt">{{todaydata.oldPercent}}</p>
              <div class="person" id="todayPerson">
                <guide-chart :width="guideWidth" :id="'oldPercentbox'" :charData="oldPercentData" v-if="oldPercentData.length"></guide-chart>
              </div>
            </div>
            <div class="item">
              <p class="return-txt">客单价</p>
              <p class="return-txt">{{todaydata.avgCost}}</p>
              <div class="person" id="todayPerson">
                <guide-chart :width="guideWidth" :id="'avgCostbox'" :charData="avgCostData" v-if="avgCostData.length"></guide-chart>
              </div>
            </div>
            <div class="item">
              <p class="return-txt">折扣率</p>
              <p class="return-txt">{{todaydata.avgDiscount}}</p>
              <div class="person" id="todayPerson">
                <guide-chart :width="guideWidth" :id="'avgDiscountbox'" :charData="avgDiscountData" v-if="avgDiscountData.length"></guide-chart>
              </div>
            </div>
            <div class="item">
              <p class="return-txt">隔日退货率</p>
              <p class="return-txt">{{yesterdayR}}</p>
              <div class="person">
                <guide-chart :width="guideWidth" :id="'yesterdayRbox'" :charData="yesterdayRData" v-if="yesterdayRData.length"></guide-chart>
              </div>
            </div> 
          </div> 

        </router-link>
      </div>

      <div class="other-data">
        <!-- 营销数据 -->
        <div class="market-data item">
          <div class="title">
            营销
          </div>
          <div class="yx-item">
            <div class="title">
              积分商城
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">上架优惠券数</p>
                <p class="value">{{yxData.malldata.couponCount}}</p>
              </div>
              <div class="d-item">
                <p class="txt">上架礼品数</p>
                <p class="value">{{yxData.malldata.giftCount}}</p>
              </div>
              <div class="d-item">
                <p class="txt">代发货订单数</p>
                <p class="value">{{yxData.malldata.notSendCount}}</p>
              </div>
            </div>
          </div>
          <div class="yx-item">
            <div class="title">
              门店活动
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">进行中的活动</p>
                <p class="value">{{yxData.activitydata.startingActivitys}}</p>
              </div>
              <div class="d-item">
                <p class="txt">待开始的活动</p>
                <p class="value">{{yxData.activitydata.unStartActivitys}}</p>
              </div>
              <div class="d-item">
                <p class="txt">昨日活动的浏览量</p>
                <p class="value">{{yxData.activitydata.readMembers}}</p>
              </div>
            </div>
          </div>
          <div class="yx-item">
            <div class="title">
              微信图文数据
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">已发送的图文</p>
                <p class="value">{{yxData.wechatData.startingActivitys}}</p>
              </div>
              <div class="d-item">
                <p class="txt">待发送的图文</p>
                <p class="value">{{yxData.wechatData.unStartActivitys}}</p>
              </div>
              <div class="d-item">
                <p class="txt">昨日图文的浏览量</p>
                <p class="value">{{yxData.wechatData.readMembers}}</p>
              </div>
            </div>
          </div>
          <div class="yx-item table-card-item">
            <div class="title">
              卡券数据
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">昨日核销量</p>
                <p class="value">{{yxData.cardused.usedCards}}</p>
              </div>
              <div class="d-item">
                <p class="txt">昨日核销售额</p>
                <p class="value">{{yxData.cardused.getedAmount}}</p>
              </div>
              <div class="d-item">
                <p class="txt">昨日纠错量</p>
                <p class="value">{{yxData.cardused.finishProblem}}</p>
              </div>
            </div>

            <!-- 卡券表格 -->
            <div class="table-card">
              <div class="yes-get">
                <div class="txt">
                  昨日领取量
                  <div class="value" style="text-align: center">{{yxData.cardGetData.totalReceiveCount}}</div>
                </div>
              </div>
              <div class="group-item">
                <!-- 这里的代码可以用一个配置集合来渲染 或者 封装成一个组件 render函数展示 -->
                <ul v-if="yxData.cardGetData.data.length > 0">
                  <li class="data-list">服务号对话框群发 <span class="table-value">{{yxData.cardGetData.data[0].receiveCount}}</span> </li>
                  <li class="data-list">消息图文嵌入 <span class="table-value">{{yxData.cardGetData.data[1].receiveCount}}</span> </li>
                  <li class="data-list">ECM智能引擎 <span class="table-value">{{yxData.cardGetData.data[2].receiveCount}}</span> </li>
                  <li class="data-list">门店展架 <span class="table-value">{{yxData.cardGetData.data[3].receiveCount}}</span> </li>
                  <li class="data-list">自定义展架 <span class="table-value">{{yxData.cardGetData.data[4].receiveCount}}</span> </li>
                  <li class="data-list">积分兑换 <span class="table-value">{{yxData.cardGetData.data[5].receiveCount}}</span> </li>
                  <li class="data-list">线上游戏 <span class="table-value">{{yxData.cardGetData.data[6].receiveCount}}</span> </li>
                  <li class="data-list">成就奖励 <span class="table-value">{{yxData.cardGetData.data[7].receiveCount}}</span> </li>
                  <li class="data-list">第三方 <span class="table-value">{{yxData.cardGetData.data[8].receiveCount}}</span> </li>
                </ul>
              </div>
            </div>
          </div>
        </div>

        <!-- 企业数据 -->
        <div class="entrp-data item">
          <div class="title">
            企业
          </div>
          <!-- 门店概括 -->
          <div class="yx-item">
            <div class="title">
              门店概括
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">管辖门店</p>
                <p class="value">{{qydata.clerkCountdata.storeCount}}</p>
              </div>
              <div class="d-item">
                <p class="txt">未同步门店</p>
                <p class="value">{{qydata.clerkCountdata.clerkCount}}</p>
              </div>
              <div class="d-item">
                <p class="txt">未更新门店</p>
                <p class="value">{{qydata.clerkCountdata.inviteClerkCount}}</p>
              </div>
            </div>
          </div>
          
          <!-- 成员管理 -->
          <div class="yx-item">
            <div class="title">
              成员管理
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">门店成员数</p>
                <p class="value">{{qydata.storeClerkdata.storeClerk}}</p>
              </div>
              <div class="d-item">
                <p class="txt">为完善成员</p>
                <p class="value">{{qydata.storeClerkdata.imperfectClerk}}</p>
              </div>
              <div class="d-item">
                <p class="txt">未激活成员</p>
                <p class="value">{{qydata.storeClerkdata.inactiveClerk}}</p>
              </div>
            </div>
          </div>

          <!-- 门店评价 -->
          <div class="yx-item">
            <div class="title">
              门店评价
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">昨日综合评分</p>
                <p class="value">{{qydata.evaluatedata.evaluateScore}}</p>
              </div>
              <div class="d-item">
                <p class="txt">昨日评价总数</p>
                <p class="value">{{qydata.evaluatedata.evaluateCount}}</p>
              </div>
              <div class="d-item">
                <p class="txt">昨日不良评价数</p>
                <p class="value">{{qydata.evaluatedata.badEvaluateCount}}</p>
              </div>
            </div>
          </div>

          <!-- 会员自动化管理 -->
          <div class="yx-item">
            <div class="title">
              会员自动化管理
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">昨日会员认证率</p>
                <p class="value">{{qydata.vividSearchdata.totalAuthPercent}}</p>
              </div>
              <div class="d-item">
                <p class="txt">昨日标签完善率</p>
                <p class="value">{{qydata.vividSearchdata.totalTagPercent}}</p>
              </div>
              <div class="d-item">
                <p class="txt">昨日备注率</p>
                <p class="value">{{qydata.vividSearchdata.totalRemarkPercent}}</p>
              </div>
            </div>
          </div>

          <!-- 任务管理 -->
          <div class="yx-item">
            <div class="title">
              任务管理
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">昨日任务完成量</p>
                <p class="value">{{qydata.telTaskdata.finishTask}}</p>
              </div>
              <div class="d-item">
                <p class="txt">昨日任务取消量</p>
                <p class="value">{{qydata.telTaskdata.cancelTask}}</p>
              </div>
              <div class="d-item">
                <p class="txt">当前任务逾期量</p>
                <p class="value">{{qydata.telTaskdata.unFinishTask}}</p>
              </div>
            </div>
          </div>

          <!-- 指标管理 -->
          <div class="yx-item">
            <div class="title">
              指标管理
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">待完善门店</p>
                <p class="value">{{qydata.perftdata.finishStore}}</p>
              </div>
              <div class="d-item">
                <p class="txt">已完善门店</p>
                <p class="value">{{qydata.perftdata.unFinishStore}}</p>
              </div>
            </div>
          </div>

          <!-- 投诉与建议 -->
          <div class="yx-item">
            <div class="title">
              投诉与建议
            </div>
            <div class="details">
              <div class="d-item">
                <p class="txt">待处理</p>
                <p class="value">{{qydata.problemdata.unFinishProblem}}</p>
              </div>
              <div class="d-item">
                <p class="txt">本月已解决</p>
                <p class="value">{{qydata.problemdata.finishProblem}}</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>  
</template>

<script>
import { 
    memberCount, 
    memberPercent,
    daySale,
    monthSale,
    todaySales,
    todayreFunds,
    mallData,
    activityData,
    wechatData,
    carduseData,
    cardGet,
    clerkCount,
    storeClerk,
    evaluate,
    vividSearch,
    telTask,
    perf,
    memberAllChart,
    problem,
    dataOrMonth
  } from "@/request/api";
import G2Line from "../chart/G2Line";
import { setTimeout } from 'timers';
import AllMemberChart from '../chart/AllMemberChart';
import DayChart from '../chart/DayChart';
import MonthChart from '../chart/MonthChart';
import GuideChart from '../chart/GuideChart';

export default {
  name: "memberSummary",
  components: {
    "g2-line": G2Line,
    AllMemberChart,
    DayChart,
    MonthChart,
    GuideChart
  },
  computed: {
    todayR() {
      return !!(this.tdRefundsCount / this.ysdCount) ? (this.tdRefundsCount / this.ysdCount).toFixed(2) + '%' : '--';
    },
    yesterdayR() {
      return !!(this.ysdRefundsCount / this.tdCount) ? (this.ysdRefundsCount / this.tdCount).toFixed(2) + '%' : '--';
    },
    dayRate() {
      return !!this.daySaleData.rate ? Number(this.daySaleData.rate.replace(/%/g, '')).toFixed(2) + '%' : '--';
    },
    monthRate() {
      return !!this.monthSaleData.rate ? Number(this.monthSaleData.rate.replace(/%/g, '')).toFixed(2) + '%' : '--';
    }
  },
  data() {
    return {
      // 会员数据
      totalRate: 0,
      memberData: {
        total: 0,
        todayNewMember: 0,
        yesterdayNewMember: 0,
        currentMonthNewMember: 0,
        lastMonthNewMember: 0,
        currentMonth: 0,
        today: 0,
        lastMonth: 0,
        yesterday: 0
      },
      // 日达成数据
      dayChart: [],
      c1: "c1",
      serverData: [
        {
          year: "1991",
          value: 3
        },
        {
          year: "1992",
          value: 4
        },
        {
          year: "1993",
          value: 3.5
        },
        {
          year: "1994",
          value: 5
        },
        {
          year: "1995",
          value: 4.9
        },
        {
          year: "1996",
          value: 6
        },
        {
          year: "1997",
          value: 7
        },
        {
          year: "1998",
          value: 9
        },
        {
          year: "1999",
          value: 13
        }
      ],
      // 今日销售单效
      todaySale: {
        tdRefundsCount: 0, // 当日退货数
        ysdCount: 0, // 当日卖出总数
        tdCount: 0, // 隔日卖出总数
        ysdRefundsCount: 0 // 隔日退货数
      },
      // 营销数据
      yxData: {
        // 积分商城
        malldata: {
          couponCount: 0, // 上架优惠券数
          giftCount: 0, // 上架礼品数
          notSendCount: 0 // 待发货订单数
        },
        // 门店活动
        activitydata: {
          startingActivitys: 0,  // 进行中的活动
          unStartActivitys: 0, // 待开始的活动
          readMembers: 0 // 昨日活动的浏览量
        },
        // 微信图文数据
        wechatData: {
          startingActivitys: 0, // 已发送的图文
          unStartActivitys: 0, // 待发送的图文
          readMembers: 0 // 昨日图文的浏览量
        },
        // 卡券数据
        cardused: {
          usedCards: 0, // 昨日核销量
          getedAmount: 0, // 昨日核销销售额
          finishProblem: 0 // 昨日纠错量
        },
        // 卡券领取
        cardGetData: {
          data: [],
          totalReceiveCount: 0
        }
      },
      qydata: {
        // 门店概况
        clerkCountdata: {
          storeCount: 0,
          clerkCount: 0,
          inviteClerkCount: 0
        },
        // 成员管理
        storeClerkdata: {
          storeClerk: 0,
          imperfectClerk: 0,
          inactiveClerk: 0
        },
        // 门店评价
        evaluatedata: {
          evaluateScore: 0,
          evaluateCount: 0,
          badEvaluateCount: 0
        },
        // 会员生动化管理
        vividSearchdata: {
          totalAuthPercent: 0,
          totalTagPercent: 0,
          totalRemarkPercent: 0
        },
        // 任务管理
        telTaskdata: {
          finishTask: 0,
          cancelTask: 0,
          unFinishTask: 0
        },
        // 指标管理
        perftdata: {
          finishStore: 0,
          unFinishStore: 0
        },
        // 投诉与建议
        problemdata: {
          unFinishProblem: 0,
          finishProblem: 0
        }
      },
      // 客单价
      todaydata: {
        memberCount: '',
        joint: '',
        avgGoodsSale: '',
        oldPercent: '',
        avgCost: '',
        avgDiscount: ''
      },
      memberchartData: [
        {
            "name":"新增会员",
            "keyword":"2018-06-01",
            "新增会员":867
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-02",
            "新增会员":980
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-03",
            "新增会员":869
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-04",
            "新增会员":456
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-05",
            "新增会员":479
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-06",
            "新增会员":505
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-07",
            "新增会员":532
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-08",
            "新增会员":558
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-09",
            "新增会员":1139
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-10",
            "新增会员":953
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-11",
            "新增会员":504
        },
        {
            "name":"新增会员",
            "keyword":"2018-06-12",
            "新增会员":20
        }
      ],
      ratechartData: [
        {
            "value":867
        },
        {
            "value":980
        },
        {
            "value":869
        },
        {
            "value":456
        },
        {
            "value":479
        },
        {
            "value":505
        },
        {
            "value":532
        },
        {
            "value":558
        },
        {
            "value":1139
        },
        {
            "value":953
        },
        {
            "value":504
        },
        {
            "value":20
        }
      ],
      member: 'memberbox',
      memberWidth: null,
      dayChartData: [
        {
            "keyword":"2018-06-01",
            "新增会员": 15
        },
        {
            "keyword":"2018-06-02",
            "新增会员":10
        },
        {
            "keyword":"2018-06-03",
            "新增会员": 25
        },
        {
            "keyword":"2018-06-04",
            "新增会员":30
        },
        {
            "keyword":"2018-06-05",
            "新增会员": 45
        },
        {
            "keyword":"2018-06-06",
            "新增会员":60
        }
      ],
      day: 'daybox',
      dayWidth: null,
      month: 'monthbox',
      monthWidth: null,
      monthData: [
        {
            "name":"统计数据",
            "keyword":"2018-06-01",
            "销售额":3279089.05
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-02",
            "销售额":3741105.82
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-03",
            "销售额":3619941.7
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-04",
            "销售额":1538185.21
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-05",
            "销售额":1892197.8
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-06",
            "销售额":1951366.91
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-07",
            "销售额":1811587.58
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-08",
            "销售额":2252547.37
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-09",
            "销售额":3939065.03
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-10",
            "销售额":4048179.65
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-11",
            "销售额":1673873.77
        },
        {
            "name":"统计数据",
            "keyword":"2018-06-12",
            "销售额":655845.05
        }
      ],
      daySaleData: {totalSale: '--', rate: '--', performanceValue: '--'},
      monthSaleData: {totalSale: '--', rate: '--', performanceValue: '--'},
      personData: [],
      jointData: [],
      avgData: [],
      todayReturnData: [],
      oldPercentData: [],
      avgCostData: [],
      avgDiscountData: [],
      yesterdayRData: [
        {keyword: "2013-05-31", value: 2.093},
        {keyword: "2013-06-03", value: 2.665},
        {keyword: "2013-06-04", value: 2.728},
        {keyword: "2013-06-05", value: 2.772},
        {keyword: "2013-06-06", value: 3.023},
        {keyword: "2013-06-07", value: 3.043}
      ],
      guideWidth: null
    };
  },
  created() {
    this.getData();
    this.getChart();
    this.todayS();
    this.yxdata();
    this.qyData();
    this.AllChart();
    this.getDataOrMonth();
    this.guideData();
  },
  mounted() {
    this.memberWidth = this.$refs.memberBox.clientWidth - 30;
    this.dayWidth = this.$refs.dayBox.clientWidth;
    this.monthWidth = this.$refs.monthBox.clientWidth;
    this.guideWidth = this.$refs.guideBox.clientWidth;
  },
  methods: {
    async getData() {
      // 会员相关统计
      let member = await memberCount();
      if (member.errorCode === 0) {
        this.memberData.total = member.result.totalMember; // 会员总数
        this.memberData.todayNewMember = member.result.todayNewMember; // 今日新增会员数
        this.memberData.yesterdayNewMember = member.result.yesterdayNewMember; // 昨日会员数新增
        this.memberData.currentMonthNewMember = member.result.currentMonthNewMember; // 本月新增
        this.memberData.lastMonthNewMember = member.result.lastMonthNewMember; // 上月新增
      }

      // 会员率
      let memberPrecent = await memberPercent();
      if (memberPrecent.errorCode === 0) {
        this.memberData.currentMonth = memberPrecent.result.currentMonth; // 本月会员率
        this.memberData.yesterday = memberPrecent.result.yesterday; // 昨日会员率
        this.memberData.today = memberPrecent.result.today; // 今日会员率
        this.memberData.lastMonth = memberPrecent.result.lastMonth; // 上月会员率
      }
    },
    // 日 月达成图表
    async getChart() {
      // 日达成数据 todaySales
      let datSaleData = await daySale();
      if (datSaleData.errorCode === 0) {
        
        // if (!datSaleData.result.length) {
        //   this.dayChartData = [];
        // } else {
        //   this.dayChartData = datSaleData.result;
        // }
      }
      // 今日单效数据
      let todayData = await todaySales();
      if (todayData.errorCode === 0) {
        this.todaydata = {
          memberCount: todayData.result.memberCount,
          joint: todayData.result.joint,
          avgGoodsSale: todayData.result.avgGoodsSale,
          oldPercent: todayData.result.oldPercent,
          avgCost: todayData.result.avgCost,
          avgDiscount: todayData.result.avgDiscount
        };
      }

      // 月达成数据
      // let dataSaleMonth = await monthSale({ kpiName: 'statistics-total-sale-all' });
      let personCount = await monthSale({ kpiName: 'statistics-mc-all' });
    },
    // 今日销售单效
    async todayS() {
      let sVal = await todaySales();
      let fundsVal = await todayreFunds();
      if (fundsVal.errorCode === 0) {
        this.todaySale.tdRefundsCount = fundsVal.result.tdRefundsCount;
        this.todaySale.ysdCount = fundsVal.result.ysdCount;
        this.todaySale.tdCount = fundsVal.result.tdCount;
        this.todaySale.ysdRefundsCount = fundsVal.result.ysdRefundsCount;
      }
    },
    // 营销数据
    async yxdata() {
      let malldata = await mallData();
      if (malldata.errorCode === 0) {
        this.yxData.malldata.couponCount = !!malldata.result.couponCount ? malldata.result.couponCount : 0;
        this.yxData.malldata.giftCount = !!malldata.result.giftCount ? malldata.result.giftCount : 0;
        this.yxData.malldata.notSendCount = !!malldata.result.notSendCount ? malldata.result.notSendCount : 0;
      }
      
      let activitydata = await activityData();
      if (activitydata.errorCode === 0) {
        this.yxData.activitydata.startingActivitys = activitydata.result.startingActivitys;
        this.yxData.activitydata.unStartActivitys = activitydata.result.unStartActivitys;
        this.yxData.activitydata.readMembers = activitydata.result.readMembers;
      }

      let wechatdata = await wechatData();
      if (wechatdata.errorCode === 0) {
        this.yxData.wechatData.startingActivitys = !!wechatdata.result.startingActivitys ? wechatdata.result.startingActivitys : 0;
        this.yxData.wechatData.unStartActivitys = !!wechatdata.result.unStartActivitys ? wechatdata.result.unStartActivitys : 0;
        this.yxData.wechatData.readMembers = !!wechatdata.result.readMembers ? wechatdata.result.readMembers : 0;
      }

      let cardusedata = await carduseData();
      if (cardusedata.errorCode === 0) {
        this.yxData.cardused.usedCards = !!cardusedata.result.usedCards ? cardusedata.result.usedCards : 0;
        this.yxData.cardused.getedAmount = !!cardusedata.result.getedAmount ? cardusedata.result.getedAmount : 0;
        this.yxData.cardused.finishProblem = !!cardusedata.result.finishProblem ? cardusedata.result.finishProblem : 0;
      }

      let cardGetdata = await cardGet();
      if (cardGetdata.errorCode === 0) {
        this.yxData.cardGetData.data = cardGetdata.result.data;
        this.yxData.cardGetData.totalReceiveCount = cardGetdata.result.totalReceiveCount;
      }
    },
    // 企业
    async qyData() {
      // 门店概况
      let clerkCountData = await clerkCount();
      if (clerkCountData.errorCode ===  0) {
          this.qydata.clerkCountdata = {
            storeCount: clerkCountData.result.storeCount,
            clerkCount: clerkCountData.result.clerkCount,
            inviteClerkCount: clerkCountData.result.inviteClerkCount
          };
      }
      // 成员管理
      let storeClerkData = await storeClerk();
      if (storeClerkData.errorCode === 0) {
          this.qydata.storeClerkdata = {
            storeClerk: storeClerkData.result.storeClerk,
            imperfectClerk: storeClerkData.result.imperfectClerk,
            inactiveClerk: storeClerkData.result.inactiveClerk
          };
      }
      
      // 评价
      let evaluateData = await evaluate();
      if (evaluateData.errorCode === 0) {
        this.qydata.evaluatedata = {
          evaluateScore: evaluateData.result.evaluateScore,
          evaluateCount: evaluateData.result.evaluateCount,
          badEvaluateCount: evaluateData.result.badEvaluateCount
        };
      }
      // 会员自动化管理
      let vividSearchData = await vividSearch();
      if (vividSearchData.errorCode === 0) {
        this.qydata.vividSearchdata = {
          totalAuthPercent: vividSearchData.result.totalAuthPercent,
          totalTagPercent: vividSearchData.result.totalTagPercent,
          totalRemarkPercent: vividSearchData.result.totalRemarkPercent
        };  
      }
      // 任务管理
      let telTaskData = await telTask();
      if (telTaskData.errorCode === 0) {
        this.qydata.telTaskData = {
          finishTask: telTaskData.result.finishTask,
          cancelTask: telTaskData.result.cancelTask,
          unFinishTask: telTaskData.result.unFinishTask
        };  
      }
      // 指标管理
      let perftData = await perf();
      if (perftData.errorCode === 0) {
        this.qydata.perftdata = {
          finishStore: perftData.result.finishStore,
          unFinishStore: perftData.result.unFinishStore
        };
      }
      // 投诉与建议
      let problemData = await problem();
      if (problemData.errorCode === 0) {
        this.qydata.problemdata = {
          unFinishProblem: problemData.result.unFinishProblem,
          finishProblem: problemData.result.finishProblem
        };  
      }
    },
    // 新增会员 会员率图表
    async AllChart() {
      // 新增会员图表
      let newMember = await memberAllChart({ kpiName: 'statistics-store-analysis-main-index' });
      if (newMember.errorCode === 0) {
        // this.memberchartData = newMember.result
      }
      // 会员率图表
      let memberChart = await memberAllChart({ kpiName: 'statistics-store-member-percent-main' });
      if (memberChart.errorCode === 0) {
        // this.ratechartData = memberChart.result;
        // this.memberchartData.forEach(ele => {
        //   this.ratechartData.push({...ele, rate: this.ratechartData['value'] });
        // });
        this.totalRate = this.ratechartData.reduce((ta, ele) => {
          return ta + ele['value'];
        }, 0);
        this.memberchartData = this.memberchartData.map((ele, index) => ({
          ...ele,
          会员率: this.ratechartData[index]['value']
        }));
      }
    },
    // 日 月 销售额 指标数据
    async getDataOrMonth() {
      let day = await dataOrMonth({ type: 1 }); // 日
      if (day.errorCode === 0) {
        this.daySaleData = day.result;
      }
      let month = await dataOrMonth({ type: 2 }); // 月
      if (month.errorCode === 0) {
        this.monthSaleData = month.result;
      }
    },
    async guideData() {
      // 成交人数
      let person = await memberAllChart({ kpiName: 'statistics-mc-all' });
      if (person.errorCode === 0) {
        this.personData = person.result;
      }
      // 连带率
      let joint = await memberAllChart({ kpiName: 'statistics-joint-all' });
      if (joint.errorCode === 0) {
        this.jointData = joint.result;
      }
      // 平均商品单价
      let avg = await memberAllChart({ kpiName: 'statistics-avg-goods-all' });
      if (avg.errorCode === 0) {
        this.avgData = avg.result;
      }
      // 当日退货
      let todayReturn = await memberAllChart({ kpiName: 'statistics-refunds' });
      if (todayReturn.errorCode === 0) {
        this.todayReturnData = todayReturn.result;
      }
      // 老客率
      let oldPercent = await memberAllChart({ kpiName: 'statistics-old-all' });
      if (oldPercent.errorCode === 0) {
        this.oldPercentData = oldPercent.result;
      }
      // 客单价
      let avgCost = await memberAllChart({ kpiName: 'statistics-avg-cost-all' });
      if (avgCost.errorCode === 0) {
        this.avgCostData = avgCost.result;
      }
      // 折扣率
      let avgDiscount = await memberAllChart({ kpiName: 'statistics-avg-discount-all' });
      if (avgDiscount.errorCode === 0) {
        this.avgDiscountData = avgDiscount.result;
      }
      // 隔日退货率
      let yesterdayR = await memberAllChart({ kpiName: 'statistics-refunds-nt' });
      // if (yesterdayR.errorCode === 0) {
      //   this.yesterdayRData = yesterdayR.result;
      // }
    }
  },
};
</script>

<style lang="stylus" scoped>
.member-summary 
  background-color #f5f7fc

.gic-summary-main 
  margin-left 20px
  margin-right 20px
  .member-item 
    box-shadow 0 2px 3px rgba(0, 0, 0, 0.06)
    .title 
      height 50px
      line-height 50px
      padding 0 16px
      font-size 14px
      border-bottom 1px solid #eaedf1
      background -webkit-linear-gradient(top, #ffffff 0%, #f9f9f9 100%)
      color #303133
      .icon
        float right
        font-size 24px
    .total
      display flex
      background-color #fff
      padding 25px 15px 30px
      .m-data
        display flex
        flex 1
        height 190px
        margin 0 10px
        color #fff
      .member-data
        background-color: #1496EC
        text-align center
        flex-flow column
        justify-content center
        .memebr-value 
          margin 0
          font-size 30px
      .yes-data 
        flex-wrap wrap
        display flex
        background-color #13C2C2
        .member-list
          width 50%
          padding 15px 20px 15px 20px
          box-sizing border-box
          .member-txt
            font-size 16px
            margin 0
            text-align left
          .memebr-value
            font-size 30px
            margin 0
      .lastmonth-data 
        flex-wrap wrap
        display flex
        background-color #2FC25B
        .member-list 
          width 50%
          padding 15px 20px 15px 20px
          box-sizing border-box
          .member-txt
            font-size 16px
            margin 0
            text-align left
          .memebr-value 
            font-size 30px
            margin 0
    .member-chart 
      min-height 260px
      background-color #fff
  .achievement
    display flex
    .day
      margin-right 10px
    .a-item
      flex 1
      margin-top 10px
      cursor pointer
      .title
        height 50px
        line-height 50px
        padding 0 16px
        font-size 14px
        border-bottom 1px solid #eaedf1
        background -webkit-linear-gradient(top, #ffffff 0%, #f9f9f9 100%)
        color #303133
        .icon
          float right
          font-size 24px
      .jt-data
        display flex
        justify-content center
        align-items center
        background-color #fff
        .item
          flex 1
          text-align center
      .day-data
        min-height 300px
        display flex
        background-color #fff
  .today-sales
    margin-top 10px
    .title 
      height 50px
      line-height 50px
      padding 0 16px
      font-size 14px
      border-bottom 1px solid #eaedf1
      background -webkit-linear-gradient(top, #ffffff 0%, #f9f9f9 100%)
      color #303133
    .inner-data
      display flex
      min-height 137px
      background-color #fff
      .return-text
        margin 0
      .item
        margin 10px 15px
        flex 1
        font-size 14px
.other-data
  display flex
  padding-bottom 30px
  .market-data
    margin-right 10px
  .item
    flex 1
    margin-top 10px
    background-color #fff
    border-radius 2px
    .title
      padding-left 24px
      height 56px
      line-height 56px
      border-bottom 1px solid #DCDFE6
    .yx-item
      margin: 10px 20px 0 24px
      height: 130px
      border-bottom: 1px solid #DCDFE6
      &:last-child 
        border-bottom none
      .title 
        padding-left: 0
        height 30px
        line-height 30px
        font-size 14px
        border-bottom: none
      .details
        display flex
        .d-item 
          flex 1
      .txt
        color #606266
        font-size 14px
      .value 
        font-size: 18px
    .table-card-item
      height auto
      padding-bottom 10px
    .table-card 
      display: flex
      border: 1px solid #DCDFE6
      .yes-get 
        flex: 0 0 202px
        display: flex
        justify-content: center
        align-items: center
        border-right: 1px solid #DCDFE6
      .group-item 
        flex: 1
        .data-list 
          display: flex
          justify-content: space-between
          border-bottom: 1px solid #DCDFE6
          padding: 0 20px
          height: 48px
          line-height: 48px
          font-size: 14px
          &:last-child 
            border-bottom: none
</style>
