<template>
  <div class="app-container">
    <el-row>
      <el-col :span="12" class="card-box">
        <el-card>
          <div slot="header"><span>已完成订单量</span></div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <div ref="commandstatst" style="height: 420px" />
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" class="card-box">
        <el-card>
          <div slot="header"><span>已驳回订单量</span></div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <div ref="commandstatsts" style="height: 420px" />
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" class="card-box">
        <el-card>
          <div slot="header"><span>已退款订单量</span></div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <div ref="commandstatstst" style="height: 420px" />
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" class="card-box">
        <el-card>
          <div slot="header"><span>累计成交额</span></div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <div ref="commandstats" style="height: 420px" />
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" class="card-box">
        <el-card>
          <div slot="header">
            <span>已完成/未完成订单对比</span>
          </div>
          <div class="el-table el-table--enable-row-hover el-table--medium">
            <div ref="usedmemory" style="height: 420px" />
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" class="card-box">
        <el-button type="primary" size="medium " @click="clickStatement">导出报表</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
// import { getCache } from "@/api/monitor/cache";
import * as echarts from "echarts";
import { reportFormsGET} from '@/api/orderform/index'


export default {
  name: "Cache",
  data() {
    return {
      // 统计命令信息
      commandstats: null,
      // 使用内存
      usedmemory: null,
      // cache信息
      cache: {}
    }
  },
  created() {
    this.getList();
    this.openLoading();
  },
  methods: {
    //导出报表
    clickStatement(){
      this.download('/xinrenli/order/exportReportForms', { }, `role_${new Date().getTime()}.xlsx`)
    },
    /** 查缓存询信息 */
    getList() {
      reportFormsGET().then((response) => {
        this.cache = response.data;
        this.$modal.closeLoading();

        this.commandstats = echarts.init(this.$refs.commandstats, "macarons");
        this.commandstats.setOption({
          tooltip: {
            trigger: 'item'
          },
          legend: {
            top: '5%',
            left: 'center'
          },
          series: [
            {
              name: 'Access From',
              type: 'pie',
              radius: ['40%', '70%'],
              avoidLabelOverlap: false,
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: false,
                  fontSize: 40,
                  fontWeight: 'bold'
                }
              },
              labelLine: {
                show: false
              },
              data: [
                { value: this.cache.money, name: '累计成交额' }
              ]
            }
          ]
        });
        this.commandstatst = echarts.init(this.$refs.commandstatst, "macarons");
        this.commandstatst.setOption({
          tooltip: {
            trigger: 'item'
          },
          legend: {
            top: '5%',
            left: 'center'
          },
          series: [
            {
              name: 'Access From',
              type: 'pie',
              radius: ['40%', '70%'],
              avoidLabelOverlap: false,
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: false,
                  fontSize: 40,
                  fontWeight: 'bold'
                }
              },
              labelLine: {
                show: false
              },
              data: [
                { value: this.cache.accomplish, name: '已完成订单量' }
              ]
            }
          ]
        });
        this.commandstatsts = echarts.init(this.$refs.commandstatsts, "macarons");
        this.commandstatsts.setOption({
          tooltip: {
            trigger: 'item'
          },
          legend: {
            top: '5%',
            left: 'center'
          },
          series: [
            {
              name: 'Access From',
              type: 'pie',
              radius: ['40%', '70%'],
              avoidLabelOverlap: false,
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: false,
                  fontSize: 40,
                  fontWeight: 'bold'
                }
              },
              labelLine: {
                show: false
              },
              data: [
                { value: this.cache.reject, name: '已驳回订单量' }
              ]
            }
          ]
        });
        this.commandstatstst = echarts.init(this.$refs.commandstatstst, "macarons");
        this.commandstatstst.setOption({
          tooltip: {
            trigger: 'item'
          },
          legend: {
            top: '5%',
            left: 'center'
          },
          series: [
            {
              name: 'Access From',
              type: 'pie',
              radius: ['40%', '70%'],
              avoidLabelOverlap: false,
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: false,
                  fontSize: 40,
                  fontWeight: 'bold'
                }
              },
              labelLine: {
                show: false
              },
              data: [
                { value: this.cache.refund, name: '已退款订单量' }
              ]
            }
          ]
        });
        this.usedmemory = echarts.init(this.$refs.usedmemory, "macarons");
        this.usedmemory.setOption({
          // title: {
          //   text: 'Referer of a Website',
          //   subtext: 'Fake Data',
          //   left: 'center'
          // },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              // name: 'Access From',
              type: 'pie',
              radius: '50%',
              data: [
                { value: this.cache.accomplish, name: '已完成订单' },
                { value: this.cache.noAccomplish, name: '未完成订单' },
              ],
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        });
      });
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载缓存监控数据，请稍候！");
    }
  }
};
</script>
