<template>
  <section class="recharge">
    <div class="dm-wrap">
      日期：<el-date-picker :clearable="false" :pickerOptions="pickerOptions" v-model="dateTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="loadAll(false)"></el-date-picker>
      <span class="fz12 gray">* 此处仅支持筛选近半年的统计数据</span>
    </div>
    <div class="dm-form__wrap">
      <h3 class="dm-title__label">趋势分析图</h3>
      <div class="text-center fz16" v-if="$route.params.type === 'record'">{{ formatDateTimeByType(dateTime[0], 'yyyy-MM-dd') }}至{{ formatDateTimeByType(dateTime[1], 'yyyy-MM-dd') }} 成功存储：{{ sumCount || 0 }} 分钟 总计消费：{{ (sumFee / 100).toFixed(2) }} 元</div>
      <div class="text-center fz16" v-if="$route.params.type === 'video'">{{ formatDateTimeByType(dateTime[0], 'yyyy-MM-dd') }}至{{ formatDateTimeByType(dateTime[1], 'yyyy-MM-dd') }} 共消耗流量{{ sumCount }}MB 累计支出{{ sumFee }}元</div>
      <div class="text-center fz16" v-else>
        {{ formatDateTimeByType(dateTime[0], 'yyyy-MM-dd') }}至{{ formatDateTimeByType(dateTime[1], 'yyyy-MM-dd') }} 成功发送：{{ sumCount || 0 }} 条
        <!-- <template v-if="['sms', 'marketing'].includes($route.params.type)">，其中国内短信{{ localCount || 0 }}条，国外短信{{ sumInternational || 0 }}条</template> -->
        &nbsp;总计消费：{{ (sumFee / 1000).toFixed(2) }} 元
      </div>
      <div>
        <div id="mountNode" ref="mountNode" v-show="list.length"></div>
        <div class="chart--nodata" v-show="!list.length"></div>
      </div>
    </div>
    <div class="dm-form__wrap" v-loading="loading">
      <div class="pb22" style="overflow:hidden;line-height:40px;" v-if="$route.params.type === 'video'">
        <!-- 视频资费 -->
        <el-date-picker :clearable="false" v-model="dateTimeVideo" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="changeVideoTime"></el-date-picker>
        <span class="fz12 gray">* 此处时间跨度不超过7天</span>
        <el-button type="primary" class="fr" icon="iconfont icon-icon_yunxiazai fz14 mr5" @click="downloadTrafficCostListExcel">导出记录</el-button>
      </div>
      <div v-else class="pb22" style="overflow:hidden;line-height:40px;">
        <!-- 非视频资费 -->
        <!-- <el-select v-if="$route.params.type === 'call'" class="dm-select" v-model="taskType" placeholder="选择发送状态" @change="loadAll(true)">
          <el-option v-for="item in taskTypeOptions" :key="item.taskType" :label="item.ecmName" :value="item.taskType"></el-option>
        </el-select> -->
        <el-input v-model="listParams.searchParam" class="w250" :placeholder="placeholder" clearable @change="loadAll(true)"><i slot="prefix" class="el-input__icon el-icon-search"></i></el-input>
      </div>
      <!-- 短信营销 -->
      <el-table tooltipEffect="light" :data="tableList" style="width:100%" v-if="$route.params.type === 'marketing'">
        <el-table-column align="left" width="170" prop="sendTime" label="发送时间">
          <template slot-scope="scope">
            <p class="cell-time">
              {{ formatDateTimeByType(scope.row.sendTime, 'yyyy-MM-dd-HH-mm-ss', true).y }}<br />
              <span>{{ formatDateTimeByType(scope.row.sendTime, 'yyyy-MM-dd-HH-mm-ss', true).h }}</span>
            </p>
          </template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="telephone" label="接收号码"></el-table-column>
        <el-table-column align="left" width="100" prop="countNum" label="计费条数">
          <template slot-scope="scope">{{ scope.row.countNum }}条 </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="left" width="320" prop="storeName" label="主门店">
          <template slot-scope="scope">
            <p>{{ scope.row.storeName }}</p>
            <p class="gray">{{ scope.row.storeGroupName }}</p>
          </template>
        </el-table-column>
        <el-table-column label="触发计划名称" :show-overflow-tooltip="true" align="left" width="300" prop="sourceName"></el-table-column>
        <el-table-column label="计划创建人" align="left" width="100" prop="sourceCreatorName"></el-table-column>
        <!-- <el-table-column label="模板ID" align="left" width="100" prop="chartsDate"></el-table-column> -->
        <el-table-column label="短信内容" align="left" min-width="200" prop="remark">
          <template slot-scope="scope">
            <el-popover class="item" trigger="hover" width="200" v-if="scope.row.remark && scope.row.remark.length > 10" :content="scope.row.remark" placement="top-start">
              <span class="ellipsis" slot="reference">{{ scope.row.remark }}</span>
            </el-popover>
            <span v-else>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 短信验证码 -->
      <el-table tooltipEffect="light" :data="tableList" style="width:100%" v-if="$route.params.type === 'sms'">
        <el-table-column align="left" width="170" prop="createTime" label="发送时间">
          <template slot-scope="scope">
            <p class="cell-time">
              {{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).y }}<br />
              <span>{{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).h }}</span>
            </p>
          </template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="receivePhone" label="接收号码"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="left" width="320" prop="storeName" label="主门店">
          <template slot-scope="scope">
            <p>{{ scope.row.storeName }}</p>
            <p class="fz13 gray">{{ scope.row.storeGroupName }}</p>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="短信内容" align="left" min-width="200" prop="paramInfo">
          <template slot-scope="scope">您的验证码是：{{ scope.row.paramInfo }} </template>
        </el-table-column>
        <el-table-column label="状态" align="left" width="100" prop="status">
          <template slot-scope="scope">
            {{ scope.row.status === 1 ? '成功' : '失败' }}
          </template>
        </el-table-column>
      </el-table>
      <!-- 语音验证码 -->
      <el-table tooltipEffect="light" :data="tableList" style="width:100%" v-if="$route.params.type === 'voice'">
        <el-table-column align="left" prop="createTime" label="发送时间" width="170px">
          <template slot-scope="scope">
            <p class="cell-time">
              {{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).y }}<br />
              <span>{{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).h }}</span>
            </p>
          </template>
        </el-table-column>
        <el-table-column align="left" prop="receivePhone" label="接收号码"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="left" width="320" prop="storeName" label="主门店">
          <template slot-scope="scope">
            <p>{{ scope.row.storeName }}</p>
            <p class="fz13 gray">{{ scope.row.storeGroupName }}</p>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="left" prop="status">
          <template slot-scope="scope">
            {{ scope.row.status === 1 ? '成功' : '失败' }}
          </template>
        </el-table-column>
      </el-table>
      <!-- 双向呼叫 -->
      <el-table tooltipEffect="light" :data="tableList" style="width:100%" v-if="$route.params.type === 'call'">
        <el-table-column align="left" width="200" prop="createTime" label="呼叫时间">
          <template slot-scope="scope">
            <p class="cell-time">
              {{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).y }}<br />
              <span>{{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).h }}</span>
            </p>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="left" min-width="320" prop="storeName" label="主门店">
          <template slot-scope="scope">
            <p>{{ scope.row.storeName }}</p>
            <p class="fz13 gray">{{ scope.row.storeGroupName }}</p>
          </template>
        </el-table-column>
        <el-table-column label="触发计划名称" align="left" :show-overflow-tooltip="true" min-width="320" prop="sourceName"></el-table-column>
        <el-table-column label="计划创建人" align="left" width="150" prop="sourceCreatorName"></el-table-column>
        <el-table-column align="left" width="150" prop="clerkName" label="主叫">
          <template slot-scope="scope">
            <p>{{ scope.row.clerkName || '--' }}</p>
            <p class="gray">{{ scope.row.sendPhone }}</p>
          </template>
        </el-table-column>
        <el-table-column align="left" width="160" prop="memberId" label="被叫(会员)">
          <template slot-scope="scope">
            <img :src="scope.row.memberPic || defaultAvatar" width="32" height="32" alt="" />
            <div class="inline-block">
              <p>{{ scope.row.memberName || '--' }}</p>
              <p class="fz13 gray">{{ scope.row.receivePhone || '--' }}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="status" label="通话状态">
          <template slot-scope="scope">
            {{ scope.row.callStatus === 1 ? '未接通' : scope.row.callStatus === 2 ? '接通' : '成功' }}
          </template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="callTime" label="时间（秒）">
          <template slot-scope="scope">{{ scope.row.callTime }}秒</template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="callFee" label="消费金额（元）">
          <template slot-scope="scope">{{ Number(scope.row.callFee / 1000).toFixed(2) }}元</template>
        </el-table-column>
      </el-table>

      <el-table tooltipEffect="light" :data="tableList" style="width:100%" v-if="$route.params.type === 'record'">
        <el-table-column align="left" width="160" prop="createTime" label="呼叫时间">
          <template slot-scope="scope">
            <p class="cell-time">
              {{ formatDateTimeByType(scope.row.callBeginTime, 'yyyy-MM-dd-HH-mm-ss', true).y }}<br />
              <span>{{ formatDateTimeByType(scope.row.callBeginTime, 'yyyy-MM-dd-HH-mm-ss', true).h }}</span>
            </p>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="left" prop="storeName" width="350" label="主门店">
          <template slot-scope="scope">
            <p>{{ scope.row.storeName }}</p>
            <p class="fz13 gray">{{ scope.row.storeGroupName }}</p>
          </template>
        </el-table-column>
        <el-table-column label="触发计划名称" align="left" width="350" prop="sourceName" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="计划创建人" align="left" width="100" prop="sourceCreatorName"></el-table-column>
        <el-table-column align="left" width="150" prop="clerkName" label="主叫">
          <template slot-scope="scope">
            <p>{{ scope.row.clerkName || '--' }}</p>
            <p class="gray">{{ scope.row.clerkPhoneNumber }}</p>
          </template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="memberId" label="被叫(会员)">
          <template slot-scope="scope">
            <img :src="scope.row.memberImgUrl || defaultAvatar" width="32" height="32" alt="" />
            <div class="inline-block">
              <p>{{ scope.row.memberName || '--' }}</p>
              <p class="fz13 gray">{{ scope.row.memberPhoneNumber || '--' }}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="status" label="类型">
          <template slot-scope="scope">
            {{ scope.row.telTaskTitle }}
          </template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="status" label="录音保存时长">
          <template slot-scope="scope">
            {{ scope.row.storageTypeRemark }}
          </template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="callTime" label="时间（分钟）">
          <template slot-scope="scope"> {{ scope.row.callTime }}分钟 </template>
        </el-table-column>
        <el-table-column align="left" width="150" prop="callFee" label="消费金额（元）">
          <template slot-scope="scope"> {{ Number(scope.row.storageFee / 100).toFixed(2) }}元 </template>
        </el-table-column>
      </el-table>
      <!-- 视频资费 -->
      <el-table tooltipEffect="light" :data="tableList" style="width:100%" v-if="$route.params.type === 'video'">
        <el-table-column align="left" prop="createTime" label="时间">
          <template slot-scope="scope">
            <p class="cell-time">
              {{ formatDateTimeByType(scope.row.time, 'yyyy-MM-dd-HH-mm-ss') }}
            </p>
          </template>
        </el-table-column>
        <el-table-column align="left" prop="traffic" label="流量消耗统计">
          <template slot-scope="scope"> {{ scope.row.traffic }}GB </template>
        </el-table-column>
        <el-table-column align="left" prop="trafficCost" label="流量费用支出">
          <template slot-scope="scope"> ¥ {{ scope.row.trafficCost }} </template>
        </el-table-column>
      </el-table>
      <dm-pagination v-show="tableList.length" background class="dm-pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listParams.currentPage" :page-sizes="[20, 40, 60, 80]" :page-size="listParams.pageSize" layout="total, sizes, prev, pager, next" :total="total"></dm-pagination>
    </div>
    <vue-gic-export-excel :dialogVisible.sync="dialogVisible" :dataArr="tableList" :type="2" :excelUrl="excelUrl" :params="params" :projectName="projectName"></vue-gic-export-excel>
  </section>
</template>
<script>
import { messageMarketingChart, messageMarketingPage, smsData, voiceData, callData, recordData, videoPage, videoChartData, downloadTrafficCostListExcel } from '@/service/api/rechargeApi.js';
import { formatDateTimeByType } from '@/utils/index.js';
import G2 from '@antv/g2';
export default {
  name: 'recharge-consume',
  data() {
    return {
      list: [],
      // eslint-disable-next-line
      defaultAvatar: require('../../assets/img/head_default.png'),
      formatDateTimeByType,
      dateTime: [Date.now() - 30 * 24 * 60 * 60 * 1000, Date.now()],
      dateTimeVideo: [Date.now() - 7 * 24 * 60 * 60 * 1000, Date.now()],
      dateTimeVideoCopy: [Date.now() - 7 * 24 * 60 * 60 * 1000, Date.now()],
      loading: false,
      tableList: [],
      listParams: {
        currentPage: 1,
        pageSize: 20,
        beginTime: '',
        endTime: '',
        searchParam: ''
      },
      total: 0,
      taskType: '',
      taskTypeOptions: [],
      sumFee: 0,
      sumCount: 0,
      sumInternational: 0,
      localCount: 0,
      placeholder: '',
      pickerOptions: {
        disabledDate(val) {
          return Date.now() >= val.getTime() + 6 * 30 * 24 * 60 * 60 * 1000;
        }
      },
      videoListParams: {
        currentPage: 1,
        pageSize: 20,
        requestProject: 'marketing',
        startTime: '',
        endTime: ''
      },
      projectName: 'marketing', // 当前项目名
      dialogVisible: false,
      excelUrl: '', // 下载数据的地址
      params: {} // 传递的参数
    };
  },
  created() {
    this.loadAll();
    this.$store.commit('mutations_breadcrumb', [{ name: '企业管理', path: '' }, { name: '计费中心', path: '/recharge' }, { name: '消费详情', path: '' }]); // eslint-disable-line
  },
  methods: {
    handleSizeChange(val) {
      this.listParams.pageSize = val;
      this.loadAll();
    },
    handleCurrentChange(val) {
      this.listParams.currentPage = val;
      this.loadAll();
    },
    loadAll(onlyList = false) {
      if (this.dateTime) {
        this.listParams.beginTime = formatDateTimeByType(this.dateTime[0], 'yyyy-MM-dd');
        this.listParams.endTime = formatDateTimeByType(this.dateTime[1], 'yyyy-MM-dd');
      } else {
        this.listParams.beginTime = '';
        this.listParams.endTime = '';
      }
      if (this.$route.params.type === 'marketing') {
        this.placeholder = '输入手机号码/模板ID/内容';
        if (!onlyList) {
          this.marketingCharts();
        }
        this.marketingList();
      }
      if (this.$route.params.type === 'sms') {
        this.placeholder = '输入手机号码';
        if (!onlyList) {
          this.smsData('charts');
        }
        this.smsData('list');
      }
      if (this.$route.params.type === 'voice') {
        this.placeholder = '输入手机号码';
        if (!onlyList) {
          this.voiceData('charts');
        }
        this.voiceData('list');
      }
      if (this.$route.params.type === 'call') {
        this.placeholder = '输入手机号码';
        if (!onlyList) {
          this.callData('charts');
        }
        this.callData('list');
      }
      if (this.$route.params.type === 'record') {
        this.placeholder = '输入手机号码';
        if (!onlyList) {
          this.recordData('charts');
        }
        this.recordData('list');
      }
      if (this.$route.params.type === 'video') {
        if (!onlyList) {
          this.videoPage('charts');
        }
        this.videoPage('list');
      }
    },
    async marketingList() {
      this.loading = true;
      try {
        let resList = await messageMarketingPage(this.listParams);
        if (resList.errorCode === 0 && resList.result.result) {
          this.tableList = resList.result.result || [];
          this.total = resList.result.totalCount;
        } else {
          this.tableList = [];
        }
      } catch (err) {}
      this.loading = false;
    },
    async marketingCharts() {
      try {
        let res = await messageMarketingChart(this.listParams);
        this.sumCount = res.result.sumCount;
        this.sumFee = res.result.sumFee;
        this.sumInternational = res.result.sumInternational;
        this.localCount = this.sumCount - this.sumInternational;
        let chartList = res.result.chartList || [];
        let list = [];
        chartList.map(v => {
          list.push({ day: v.chartsDate, name: '消费', temperature: v.fee ? (parseInt(v.fee) / 1000).toFixed(2) : 0 });
        });
        list.sort((a, b) => {
          return a.temperature - b.temperature;
        });
        this.list = list;
        this.$nextTick(_ => {
          this.initCharts(list, 'mountNode');
        });
      } catch (err) {}
    },
    async smsData(type = 'list') {
      this.loading = true;
      try {
        let res = await smsData(Object.assign({ ajaxType: type }, this.listParams));
        if (type === 'list') {
          if (res.errorCode === 0 && res.result.page.result) {
            this.tableList = res.result.page.result || [];
            this.total = res.result.page.totalCount;
          } else {
            this.tableList = [];
          }
        } else if (type === 'charts') {
          this.sumCount = res.result.sumCount;
          this.sumFee = res.result.sumFee;
          this.sumInternational = res.result.sumInternational;
          this.localCount = this.sumCount - this.sumInternational;
          let chartList = res.result.chartList || [];
          let list = [];
          chartList.map(v => {
            list.push({ day: v.chartsDate, name: '消费', temperature: v.fee ? (parseInt(v.fee) / 1000).toFixed(2) : 0 });
          });
          list.sort((a, b) => {
            return a.temperature - b.temperature;
          });
          this.list = list;
          this.$nextTick(_ => {
            this.initCharts(list, 'mountNode');
          });
        }
      } catch (err) {}
      this.loading = false;
    },
    async voiceData(type = 'list') {
      this.loading = true;
      try {
        let res = await voiceData(Object.assign({ ajaxType: type }, this.listParams));
        if (type === 'list') {
          if (res.errorCode === 0 && res.result.page.result) {
            this.tableList = res.result.page.result || [];
            this.total = res.result.page.totalCount;
          } else {
            this.tableList = [];
          }
        } else if (type === 'charts') {
          this.sumCount = res.result.sumCount;
          this.sumFee = res.result.sumFee;
          let chartList = res.result.chartList || [];
          let list = [];
          chartList.map(v => {
            list.push({ day: v.chartsDate, name: '消费', temperature: v.fee ? (parseInt(v.fee) / 1000).toFixed(2) : 0 });
          });
          list.sort((a, b) => {
            return a.temperature - b.temperature;
          });
          this.list = list;
          this.$nextTick(_ => {
            this.initCharts(list, 'mountNode');
          });
        }
      } catch (err) {}
      this.loading = false;
    },
    async callData(type = 'list') {
      this.loading = true;
      try {
        let res = await callData(Object.assign({ ajaxType: type, taskType: type === 'list' ? this.taskType : '' }, this.listParams));
        if (type === 'list') {
          if (res.errorCode === 0 && res.result.page.result) {
            this.tableList = res.result.page.result || [];
            this.total = res.result.page.totalCount;
            this.taskTypeOptions = [{ taskType: '', ecmName: '全部' }, { taskType: 1, ecmName: '不良评价回访' }]; // eslint-disable-line
          } else {
            this.tableList = [];
          }
        } else if (type === 'charts') {
          this.sumCount = res.result.sumCount;
          this.sumFee = res.result.sumFee;
          let chartList = res.result.chartList || [];
          let list = [];
          chartList.map(v => {
            list.push({ day: v.chartsDate, name: '消费', temperature: v.fee ? (parseInt(v.fee) / 1000).toFixed(2) : 0 });
          });
          list.sort((a, b) => {
            return a.temperature - b.temperature;
          });
          this.list = list;
          this.$nextTick(_ => {
            this.initCharts(list, 'mountNode');
          });
        }
      } catch (err) {}
      this.loading = false;
    },
    // 视频资费相关接口
    async videoPage(type = 'list') {
      this.loading = true;
      try {
        this.videoListParams.startTime = formatDateTimeByType(this.dateTimeVideo[0], 'yyyy-MM-dd');
        this.videoListParams.endTime = formatDateTimeByType(this.dateTimeVideo[1], 'yyyy-MM-dd');
        if (type === 'list') {
          let res = await videoPage(this.videoListParams);
          if (res.errorCode === 0 && res.result.result) {
            this.tableList = res.result.result || [];
            this.total = res.result.totalCount;
          } else {
            this.tableList = [];
          }
        } else if (type === 'charts') {
          const params = { ...this.listParams, startTime: this.listParams.beginTime };
          let res = await videoChartData(params);
          this.sumCount = res.result.sumCount;
          this.sumFee = res.result.sumFee;
          let chartList = res.result.chartList || [];
          let list = [];
          chartList.map(v => {
            list.push({ day: v.chartsDate, name: '支出费用', temperature: v.trafficCost || 0 });
          });
          list.sort((a, b) => {
            return a.temperature - b.temperature;
          });
          this.list = list;
          this.$nextTick(_ => {
            this.initCharts(list, 'mountNode');
          });
        }
      } catch (err) {}
      this.loading = false;
    },
    // 修改视频时间 范围不能超过7天
    changeVideoTime(date) {
      // 单张卡券可以设置领取n久
      if (new Date(this.dateTimeVideo[1]).getTime() - new Date(this.dateTimeVideo[0]).getTime() > 7 * 24 * 60 * 60 * 1000) {
        this.$tips({ message: '领取时间段范围不能超过7天', type: 'warning' });
        this.dateTimeVideo = [...this.dateTimeVideoCopy];
        return;
      }
      this.dateTimeVideoCopy = [...this.dateTimeVideo];
      this.videoPage('list');
    },
    // 导出
    downloadTrafficCostListExcel() {
      this.dialogVisible = true;
      this.excelUrl = downloadTrafficCostListExcel;
      this.params = {
        startTime: formatDateTimeByType(this.dateTimeVideo[0], 'yyyy-MM-dd'),
        endTime: formatDateTimeByType(this.dateTimeVideo[1], 'yyyy-MM-dd'),
        requestProject: 'marketing'
      };
    },
    async recordData(type = 'list') {
      this.loading = true;
      try {
        let res = await recordData(Object.assign({ ajaxType: type, taskType: type === 'list' ? this.taskType : '' }, this.listParams));
        if (type === 'list') {
          if (res.errorCode === 0 && res.result.page.result) {
            this.tableList = res.result.page.result || [];
            this.total = res.result.page.totalCount;
            this.taskTypeOptions = [{ taskType: '', ecmName: '全部' }, { taskType: 1, ecmName: '不良评价回访' }]; // eslint-disable-line
          } else {
            this.tableList = [];
          }
        } else if (type === 'charts') {
          this.sumCount = res.result.sumCallTime;
          this.sumFee = res.result.sumFee;
          let chartList = res.result.chartList || [];
          let list = [];
          chartList.map(v => {
            list.push({ day: v.chartsDate, name: '录音存储消费', temperature: v.fee ? (parseInt(v.fee) / 100).toFixed(2) : 0 });
          });
          list.sort((a, b) => {
            return a.temperature - b.temperature;
          });
          this.list = list;
          this.$nextTick(_ => {
            this.initCharts(list, 'mountNode');
          });
        }
      } catch (err) {}
      this.loading = false;
    },
    //生成折线图
    initCharts(data, nodeName) {
      //先清空原先图表
      const mountNode = this.$refs[nodeName];
      const mountNodeChilds = Array.from(mountNode.childNodes);
      mountNodeChilds.map(v => {
        mountNode.removeChild(v);
      });
      var chart = new G2.Chart({
        container: nodeName,
        forceFit: true,
        height: 400,
        padding: [20, 60, 80, 60]
      });
      chart.source(data, {
        day: {
          range: [0, 1]
        },
        temperature: {
          range: [0, 1]
        }
      });
      chart.tooltip({
        crosshairs: {
          type: 'line'
        }
      });
      chart.axis('temperature', {
        label: {
          formatter: function formatter(val) {
            // console.log(val);
            return (isNaN(val) ? '0.00' : val) + '元';
          }
        }
      });
      chart
        .line()
        .position('day*temperature')
        .color('name');
      chart
        .point()
        .position('day*temperature')
        .color('name')
        .size(4)
        .shape('circle')
        .style({
          stroke: '#fff',
          lineWidth: 1
        });
      chart.render();
    }
  }
};
</script>

<style lang="scss" scoped>
.recharge-today {
  &-item {
    padding: 20px;
    margin: 10px 20px;
    .fl {
      line-height: 24px;
    }
    .fr {
      line-height: 34px;
    }
  }
}
</style>
