<style lang="scss" scoped>
.search-bar {
  display: flex;
  align-items: center;
}
.search-box p {
  display: inline-block;
  border: 1px solid #f2f2f2;
  border-radius: 5px;
  margin-right: 10px;
  padding: 5px 10px;
  cursor: pointer;
}
</style>
<style>
/* .data-display-statistics .ant-card-body {
  padding: 0 15px;
} */
.data-display-statistics .ant-col-6 {
  margin: 10px 0;
}
.data-display-statistics .ant-col-6 .ant-card-body {
  display: flex;
  justify-content: center;
}
.data-display-statistics .ant-col-6 p,
.data-display-statistics .ant-col-6 span {
  text-align: center;
  line-height: 40px;
  font-size: 30px;
  font-weight: 600;
  color: red;
  margin: 0;
}
.search-box .ant-card-body {
  padding: 5px 15px;
}
.data-display-statistics .ant-col-6 .ant-card-body .styleElse {
  line-height: 60px;
  height: 40px;
  font-size: 16px;
  font-weight: 400;
  margin-left: 10px;
}
.ant-modal-wrap .yincang .ant-modal-content .ant-modal-footer {
  display: none !important;
}
.yincang .ant-col-6 p {
  text-align: left;
  color: red;
  font-size: 16px;
  font-weight: 500;
}
.ant-table-thead div {
  font-weight: 700;
}
.tool-tip {
  position: absolute;
  top: 65px;
  right: 10px;
}
</style>
<template>
  <div class="data-display-statistics">
    <a-row class="image-list-heading vm-panel">
      <div class="panel-heading">{{ title }}</div>
      <a-row type="flex" align="middle" justify="space-between" class="panel-body">
        <div class="search-bar" style="width:100%">
          <a-select
            v-model="appId"
            showSearch
            allowClear
            mode="multiple"
            placeholder="请选择账户"
            optionFilterProp="children"
            style="width: 55%"
            @focus="handleFocus"
            @blur="handleBlur"
            @change="handleChange"
            :filterOption="true"
            @search="search"
            :maxTagCount="1"
          >
            <a-select-option
              v-for="appModel in options"
              :key="appModel.id+new Date().getTime()"
              :value="appModel.accountId"
            >
              {{appModel.advertiserName}}&#12288;&#12288;{{appModel.accountId}}&#12288;&nbsp;&#12288;{{appModel.authName}}&#12288;&#12288;{{appModel.operationName}}
              <!-- <div v-if="show">
                <div
                  style="width:220px;text-align:right;display:inline-block"
                >{{appModel.advertiserName}}</div>
                <div
                  style="width:100px;text-align:center;display:inline-block;margin-right:30px"
                >{{appModel.accountId}}</div>
                <div style="width:150px;text-align:left;display:inline-block">{{appModel.authName}}</div>
                <div
                  style="width:100px;text-align:center;display:inline-block"
                >{{appModel.operationName}}</div>
              </div>-->
            </a-select-option>
          </a-select>
          <a-input-number
            :min="1"
            :max="10"
            :step="0.1"
            v-model="discount"
            placeholder="请输入折扣"
            style="width:100px"
          />
          <a-button type="primary" style="margin:10px" @click="addUser">搜索</a-button>
        </div>
      </a-row>
      <a-row>
        <a-col :span="24">
          <a-card :bordered="false" class="search-box">
            <p :style="active==1?'color:cornflowerblue;background:#f2f2f2':''" @click="getAdd(1)">今天</p>
            <p :style="active==2?'color:cornflowerblue;background:#f2f2f2':''" @click="getAdd(2)">昨天</p>
            <p
              :style="active==3?'color:cornflowerblue;background:#f2f2f2':''"
              @click="getAdd(3)"
            >近一周</p>
            <p
              :style="active==4?'color:cornflowerblue;background:#f2f2f2':''"
              @click="getAdd(4)"
            >近十五天</p>
            <p
              :style="active==5?'color:cornflowerblue;background:#f2f2f2':''"
              @click="getAdd(5)"
            >近一月</p>
            <p
              :style="active==6?'color:cornflowerblue;background:#f2f2f2':''"
              @click="getAdd(6)"
            >近三月</p>
            <p
              :style="active==7?'color:cornflowerblue;background:#f2f2f2':''"
              @click="getAdd(7)"
            >近半年</p>
            <p :style="active==8?'color:cornflowerblue;background:#f2f2f2':''" @click="getAdd(8)">所有</p>
            <a-range-picker
              style="width:400px"
              :disabledDate="disabledDate"
              :showTime="{
                hideDisabledOptions: true,
            }"
              format="YYYY-MM-DD"
              v-model="startValue"
              @ok="getAdd(9)"
            />
          </a-card>
        </a-col>
        <!-- <a-col :span="24">
          <a-card :bordered="false" class="search-box">
            <p @click="visible = true">对比</p>
          </a-card>
        </a-col>-->
      </a-row>
    </a-row>
    <a-row :gutter="16" v-if="kuaishou">
      <a-col :span="6" style="width:20%">
        <lifting
          :kuaishou.sync="kuaishou"
          :active.sync="active"
          title="总消耗"
          typeName="cost"
          typeThan="costProportion"
        ></lifting>
      </a-col>
      <a-col :span="6" style="width:20%">
        <lifting
          :kuaishou.sync="kuaishou"
          :active.sync="active"
          title="折后消耗"
          typeName="discountCost"
          typeThan="discountCostProportion"
        ></lifting>
      </a-col>
      <a-col :span="6" style="width:20%">
        <lifting
          :kuaishou.sync="kuaishou"
          :active.sync="active"
          title="封面点击数"
          typeName="photoClick"
          typeThan="photoClickProportion"
        ></lifting>
      </a-col>
      <a-col :span="6" style="width:20%">
        <lifting
          :kuaishou.sync="kuaishou"
          :active.sync="active"
          title="封面曝光数"
          typeName="photoShow"
          typeThan="showProportion"
        ></lifting>
      </a-col>
      <a-col :span="6" style="width:20%">
        <lifting
          :kuaishou.sync="kuaishou"
          :active.sync="active"
          title="素材曝光数"
          typeName="aclick"
          typeThan="aClickProportion"
        ></lifting>
      </a-col>
    </a-row>
    <a-row :gutter="10">
      <a-col :span="24">
        <a-card
          style="width:100%"
          :tabList="tabListNoTitle"
          :activeTabKey="noTitleKey"
          @tabChange="key => onTabChange(key, 'noTitleKey')"
        >
          <div id="chart" style="width:100%;height:500px"></div>
        </a-card>
      </a-col>
    </a-row>
    <a-row :gutter="10" style="margin-top:10px">
      <a-col :span="24">
        <a-card style="width:100%;">
          <div style="display:flex;margin-bottom:15px" v-show="active==1||active==2">
            <a-select
              style="width: 120px"
              v-model="statHour"
              @change="getElseData"
              allowClear
            >
              <a-select-option v-for="item of 24" :key="item-1" :value="item-1">{{item-1}}</a-select-option>
            </a-select>
            <a-button type="primary" @click="exportExcel" style="margin-left:15px">导出</a-button>
          </div>
          <a-table :columns="columns" :dataSource="data" bordered id="outTable" :pagination="false"></a-table>
        </a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import ARow from 'ant-design-vue/es/grid/Row'
import ACol from 'ant-design-vue/es/grid/Col'
import countTo from 'vue-count-to'
import moment from 'moment'
import { getAdvertiserList, getReportList, getStatistics } from '@api/statistics'
import axios from 'axios'
import lifting from './components/lifting'

// 引入基本模板
let echarts = require('echarts/lib/echarts')
// 引入柱状图组件
require('echarts/lib/chart/bar')
require('echarts/lib/chart/pie')
require('echarts/lib/chart/line')
// 引入提示框和title组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/graphic')
require('echarts/lib/component/toolbox')
require('echarts/lib/component/legend')
var length = 0
var active = 1
const columns = [
  {
    title: '时间',
    dataIndex: 'date',
    align: 'center',
    customRender: function(text, record, index) {
      const obj = {
        children: text,
        attrs: {}
      }
      for (let i = 0; i < length; i++) {
        if (index == 0 && i == 0) {
          obj.attrs.rowSpan = length
        } else {
          if (index == i) {
            obj.attrs.rowSpan = 0
          }
        }
      }
      return obj
    }
  },
  {
    title: '账户Id',
    dataIndex: 'accountId',
    align: 'center',
    customRender: function(text, record, index) {
      const obj = {
        children: text,
        attrs: {}
      }
      if (active == 1) {
        for (let i = 0; i < length; i++) {
          if (index >= length - 3) {
            obj.attrs.colSpan = 2
          }
        }
      }
      return obj
    }
  },
  {
    title: '账户名称',
    dataIndex: 'accountName',
    scopedSlots: { customRender: 'cost' },
    align: 'center',
    customRender: function(text, record, index) {
      const obj = {
        children: text,
        attrs: {}
      }
      if (active == 1) {
        for (let i = 0; i < length; i++) {
          if (index >= length - 3) {
            obj.attrs.colSpan = 0
          }
        }
      }

      return obj
    }
  },
  {
    title: '消耗',
    dataIndex: 'cost',
    scopedSlots: { customRender: 'cost' },
    align: 'center'
  },
  {
    title: '折后消耗',
    dataIndex: 'costY',
    align: 'center'
  },
  {
    title: '封面展示',
    dataIndex: 'photoShow',
    align: 'center'
  },
  {
    title: '封面点击',
    dataIndex: 'photoClick',
    align: 'center'
  },
  {
    title: '素材曝光数',
    dataIndex: 'aclick',
    align: 'center'
  },
  {
    title: '封面点击率',
    dataIndex: 'photoClickRatio',
    align: 'center'
  },
  {
    title: 'cvr',
    dataIndex: 'cvr',
    align: 'center'
  },
  {
    title: 'cpm',
    dataIndex: 'cpm',
    align: 'center'
  },
  {
    title: '行为数',
    dataIndex: 'bClick',
    align: 'center'
  },
  {
    title: '转化数',
    dataIndex: 'formCount',
    align: 'center'
  },
  {
    title: '转化单价',
    dataIndex: 'formPrice',
    align: 'center'
  },
  {
    title: '单价区间',
    dataIndex: 'price',
    align: 'center',
    customRender: function(text, record, index) {
      const obj = {
        children: text,
        attrs: {}
      }
      for (let i = 0; i < length; i++) {
        if (index == 0 && i == 0) {
          obj.attrs.rowSpan = length
        } else {
          if (index == i) {
            obj.attrs.rowSpan = 0
          }
        }
      }
      return obj
    }
  }
]

export default {
  name: 'data-display-statistics',
  components: {
    ACol,
    ARow,
    countTo,
    lifting
  },

  data: function() {
    return {
      title: '账户数据展示',
      show: true,
      data: [],
      columns,
      options: [],
      list: [],
      appId: [],
      statHour: null,
      keyValue: null,
      keyValueData: [],
      active: 1,
      startValue: [],
      allValue: [],
      discount: 1,
      duration: 1000,
      kuaishou: {
        aclick: 0,
        aClickProportion: 0,
        cost: 0,
        costProportion: 0,
        photoClick: 0,
        photoClickroportion: 0,
        photoShow: 0,
        showProportion: 0,
        discountCost: 0,
        discountCostProportion: 0
      },
      dataDetail: [],
      tabListNoTitle: [
        {
          key: 'cost',
          tab: '总消耗'
        },
        {
          key: 'discountCost',
          tab: '折后总消耗'
        },
        {
          key: 'photoClick',
          tab: '封面点击数'
        },
        {
          key: 'photoShow',
          tab: '封面曝光数'
        },
        {
          key: 'aclick',
          tab: '素材曝光数'
        }
      ],
      noTitleKey: 'cost'
    }
  },
  filters: {
    formatDate: function(value) {
      let date = new Date(value)
      let y = date.getFullYear()
      let MM = date.getMonth() + 1
      MM = MM < 10 ? '0' + MM : MM
      let d = date.getDate()
      d = d < 10 ? '0' + d : d
      let h = date.getHours()
      h = h < 10 ? '0' + h : h
      let m = date.getMinutes()
      m = m < 10 ? '0' + m : m
      let s = date.getSeconds()
      s = s < 10 ? '0' + s : s
      return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
    }
  },
  methods: {
    moment,
    disabledDate(current) {
      return current && current > moment().endOf('day')
    },
    handleChange(value) {
      console.log(value)
      //   this.appId = value
    },
    getElseData(value) {
      this.getStatistics()
    },
    handleBlur() {
      console.log('blur')
    },
    handleFocus() {
      console.log('focus')
      if (this.appId.length > 0) {
        this.options = []
        for (let i = 0; i < this.list.length; i++) {
          for (let j = 0; j < this.appId.length; j++) {
            if (this.list[i].accountId == this.appId[j]) {
              this.options.push(this.list[i])
            }
          }
        }
      } else {
        this.options = this.list
      }
    },
    search(value) {
      //   console.log(value)
      this.options = []
      if (value != '') {
        this.options = this.list.filter(item => {
          var data = item.accountId + ' ' + item.authName + ' ' + item.advertiserName + ' ' + item.operationName
          return data.toLowerCase().indexOf(value.toLowerCase()) > -1
        })
        this.options = [...this.options]
        console.log(this.options)
      } else {
        if (this.appId.length > 0) {
          this.options = []
          for (let i = 0; i < this.list.length; i++) {
            for (let j = 0; j < this.appId.length; j++) {
              if (this.list[i].accountId == this.appId[j]) {
                this.options.push(this.list[i])
              }
            }
          }
        } else {
          this.options = this.list
        }
      }
    },
    addUser() {
      var that = this
      if (this.appId.length > 0) {
        var params = {}
        params.accountIds = JSON.stringify(that.appId)
        params.type = that.active
        params.discount = that.discount
        if (that.active == 9) {
          params.startDate = this.allValue[0]
          params.endDate = this.allValue[1]
        }

        getReportList(params).then(res => {
          if (res == '') {
            that.kuaishou.aclick = 0
            that.kuaishou.cost = 0
            that.kuaishou.photoClick = 0
            that.kuaishou.photoShow = 0
            that.kuaishou.discountCost = 0
          } else {
            that.kuaishou = res.summary
            that.dataDetail = res.trend
            that.drawPie(that.noTitleKey, res.trend)
          }
        })
        that.getStatistics()
      } else {
        this.$message.error('请选择账户')
      }
    },
    getStatistics() {
      var params = {}
      params.accountIds = JSON.stringify(this.appId)
      params.type = this.active
      params.statHour = this.statHour
      params.discount = this.discount
      if (this.active == 9) {
        params.startDate = this.allValue[0]
        params.endDate = this.allValue[1]
      }
      this.data = []
      getStatistics(params).then(res => {
        console.log(res)
        this.data = res.accountDetail.map((item, index) => {
          return {
            key: index,
            ...item,
            photoClickRatio: item.photoClickRatio ? (item.photoClickRatio * 100).toFixed(2) + '%' : 0 + '%',
            cpm: item.cpm ? '￥' + item.cpm.toFixed(2) : '￥' + 0,
            cost: '￥' + item.cost.toFixed(2),
            cvr: item.cvr ? (item.cvr * 100).toFixed(2) + '%' : 0 + '%',
            costY: '￥' + (item.cost / this.discount).toFixed(2),
            formPrice: item.formPrice
              ? '￥' + (item.formPrice / this.discount).toFixed(2)
              : item.activationPrice
              ? '￥' + (item.activationPrice / this.discount).toFixed(2)
              : '￥' + 0,
            date: this.statHour ? this.getDate() + '  ' + this.statHour : this.getDate(),
            formCount: item.formCount > 0 ? item.formCount : item.activationCount
          }
        })
        var index = this.data.length
        if (this.active == 1) {
          var allNow = {
            key: index + 1,
            ...res.now,
            photoClickRatio: res.now.photoClickRatio ? (res.now.photoClickRatio * 100).toFixed(2) + '%' : 0 + '%',
            cpm: res.now.cpm ? '￥' + res.now.cpm.toFixed(2) : '￥' + 0,
            cost: '￥' + res.now.cost.toFixed(2),
            cvr: res.now.cvr ? (res.now.cvr * 100).toFixed(2) + '%' : 0 + '%',
            costY: '￥' + (res.now.cost / this.discount).toFixed(2),
            accountId: '总计',
            formPrice: res.now.formPrice
              ? '￥' + (res.now.formPrice / this.discount).toFixed(2)
              : res.now.activationPrice
              ? '￥' + (res.now.activationPrice / this.discount).toFixed(2)
              : '￥' + 0,
            formCount: res.now.formCount > 0 ? res.now.formCount : res.now.activationCount
          }
          var allYesterday = {
            key: index + 2,
            ...res.yesterday,
            photoClickRatio: res.yesterday.photoClickRatio
              ? (res.yesterday.photoClickRatio * 100).toFixed(2) + '%'
              : 0 + '%',
            cpm: res.yesterday.cpm ? '￥' + res.yesterday.cpm.toFixed(2) : '￥' + 0,
            cost: '￥' + res.yesterday.cost.toFixed(2),
            cvr: res.yesterday.cvr ? (res.yesterday.cvr * 100).toFixed(2) + '%' : 0 + '%',
            costY: '￥' + (res.yesterday.cost / this.discount).toFixed(2),
            accountId: '昨日总计',
            formPrice: res.yesterday.formPrice
              ? '￥' + (res.yesterday.formPrice / this.discount).toFixed(2)
              : res.yesterday.activationPrice
              ? '￥' + (res.yesterday.activationPrice / this.discount).toFixed(2)
              : '￥' + 0,
            formCount: res.yesterday.formCount > 0 ? res.yesterday.formCount : res.yesterday.activationCount
          }
          var chainRatio = {
            key: index + 3,
            cost: (res.chainRatio.costProportion * 100).toFixed(2) + '%',
            photoShow: (res.chainRatio.showProportion * 100).toFixed(2) + '%',
            photoClick: (res.chainRatio.photoClickProportion * 100).toFixed(2) + '%',
            aclick: (res.chainRatio.aClickProportion * 100).toFixed(2) + '%',
            photoClickRatio: res.chainRatio.photoClickRatioProportion
              ? (res.chainRatio.photoClickRatioProportion * 100).toFixed(2) + '%'
              : 0 + '%',
            cvr: (res.chainRatio.cvrProportion * 100).toFixed(2) + '%',
            cpm: (res.chainRatio.cpmProportion * 100).toFixed(2) + '%',
            bClick: (res.chainRatio.bClickProportion * 100).toFixed(2) + '%',
            formCount: res.chainRatio.formCountProportion
              ? (res.chainRatio.formCountProportion * 100).toFixed(2) + '%'
              : res.chainRatio.activationCountProportion
              ? (res.chainRatio.activationCountProportion * 100).toFixed(2) + '%'
              : 0 + '%',
            formPrice: res.chainRatio.formPriceProportion
              ? (res.chainRatio.formPriceProportion * 100).toFixed(2) + '%'
              : res.chainRatio.activationPriceProportion
              ? (res.chainRatio.activationPriceProportion * 100).toFixed(2) + '%'
              : 0 + '%',
            costY: (res.chainRatio.costProportion * 100).toFixed(2) + '%',
            accountId: '环比'
          }
          this.data.push(allNow)
          this.data.push(allYesterday)
          this.data.push(chainRatio)
        }

        length = this.data.length
      })
    },
    getAdd(checked) {
      if (checked == 9) {
        if (this.startValue.length > 0 && this.startValue[0]) {
          this.allValue[1] = moment(this.startValue[0]._d).format('YYYY-MM-DD')
          this.allValue[0] = moment(this.startValue[1]._d).format('YYYY-MM-DD')
        }
      } else {
        this.startValue = []
        this.allValue = []
      }
      this.active = checked
      active = checked
      this.addUser(checked)
    },
    onTabChange(key, type) {
      console.log(key, type)
      this[type] = key
      if (type == 'noTitleKey') {
        this.drawPie(key, this.dataDetail)
      }
    },
    drawPie(type, data) {
      console.log(type)
      var dataLegend = []
      var dataLength = []
      var dataElse = []
      var dataDate = []
      var that = this
      if (this.active == 1 || this.active == 2) {
        dataDate = data.map(item => {
          return item.statHour
        })
      } else {
        dataDate = data.map(item => {
          return item.statDate
        })
      }
      dataLength = data.map(item => {
        return item[type]
      })
      if (type == 'cost') {
        dataLegend = ['总消耗']
        dataElse = data.map(item => {
          if (item.now) {
            return { proportion: (item.now.costProportion * 100).toFixed(2) + '%', statHour: item.statHour }
          } else {
            return { proportion: 0, statHour: item.statHour }
          }
        })
      } else if (type == 'photoClick') {
        dataLegend = ['封面点击数']
        dataElse = data.map(item => {
          if (item.now) {
            return { proportion: (item.now.photoClickProportion * 100).toFixed(2) + '%', statHour: item.statHour }
          } else {
            return { proportion: 0, statHour: item.statHour }
          }
        })
      } else if (type == 'photoShow') {
        dataLegend = ['封面曝光数']
        dataElse = data.map(item => {
          if (item.now) {
            return { proportion: (item.now.showProportion * 100).toFixed(2) + '%', statHour: item.statHour }
          } else {
            return { proportion: 0, statHour: item.statHour }
          }
        })
      } else if (type == 'aclick') {
        dataLegend = ['素材曝光数']
        dataElse = data.map(item => {
          if (item.now) {
            return { proportion: (item.now.aClickProportion * 100).toFixed(2) + '%', statHour: item.statHour }
          } else {
            return { proportion: 0, statHour: item.statHour }
          }
        })
      } else if (type == 'discountCost') {
        dataLegend = ['折后总消耗']
        dataElse = data.map(item => {
          if (item.now) {
            return { proportion: (item.now.discountCostProportion * 100).toFixed(2) + '%', statHour: item.statHour }
          } else {
            return { proportion: 0, statHour: item.statHour }
          }
        })
        dataLength = data.map(item => {
          return (item.cost / this.discount).toFixed(2)
        })
      }

      console.log(dataLength, 134123)
      var series
      if (this.active == 1) {
        dataLegend = ['今天', '昨天']
        series = [
          {
            name: dataLegend[0],
            type: 'line',
            color: '#9933ff',
            smooth: true,
            symbol: 'circle',
            symbolSize: 1,
            lineStyle: {
              normal: {
                width: 2,
                color: '#9933ff'
              }
            },
            itemStyle: {
              borderColor: '#ffffff',
              borderWidth: 3
            },
            data: data.map(item => {
              if (item.now) {
                return item.now[type]
              } else {
                return 0
              }
            })
          },
          {
            name: dataLegend[1],
            type: 'line',
            color: '#0bcd74',
            smooth: true,
            symbol: 'circle',
            symbolSize: 1,
            lineStyle: {
              normal: {
                width: 2,
                color: '#0bcd74'
              }
            },
            itemStyle: {
              borderColor: '#ffffff',
              borderWidth: 3
            },
            data: dataLength
          }
        ]
      } else {
        series = [
          {
            name: dataLegend[0],
            type: 'line',
            color: '#0bcd74',
            smooth: true,
            symbol: 'circle',
            symbolSize: 1,
            lineStyle: {
              normal: {
                width: 2,
                color: '#0bcd74'
              }
            },
            itemStyle: {
              borderColor: '#ffffff',
              borderWidth: 3
            },
            data: dataLength
          }
        ]
      }

      var option = {
        backgroundColor: '#fff',
        toolbox: {
          show: true,
          feature: {
            dataView: { readOnly: false }
          }
        },
        tooltip: {
          trigger: 'axis',
          formatter: function(params) {
            var index = dataElse.findIndex(v => v.statHour == params[0].name)
            var da = null
            if (index >= 0) {
              da = dataElse[index].proportion
            }
            if (that.active == 1) {
              if (params.length > 1) {
                return `${params[0].marker}今天${params[0].name}时:${params[0].data}  <br/>
              ${params[1].marker}昨天${params[1].name}时:${params[1].data} <br/>
            环比:${da} <br/> `
              } else {
                return `${params[0].marker}时间:${params[0].name} <br/>
            数值:${params[0].data} `
              }
            } else {
              return `${params[0].marker}时间:${params[0].name} <br/>
            数值:${params[0].data} `
            }
          }
        },
        legend: {
          data: dataLegend
        },
        grid: {
          left: '2%',
          right: '2%',
          bottom: '2%',
          containLabel: true
        },

        xAxis: {
          type: 'category',
          data: dataDate,
          boundaryGap: false,
          // 坐标轴线
          axisLine: {
            show: false,
            lineStyle: {
              color: '#999'
            }
          },
          // 分割线
          splitLine: {
            show: true,
            lineStyle: {
              type: 'dashed',
              color: '#e5e5e5'
            }
          }
        },
        yAxis: {
          type: 'value',
          axisLine: {
            show: false,
            lineStyle: {
              color: '#999'
            }
          },
          splitLine: {
            lineStyle: {
              type: 'dashed',
              color: '#e5e5e5'
            }
          }
        },
        series: series
      }
      var chart = echarts.init(document.getElementById('chart'))
      chart.clear()
      chart.setOption(option, true)
      window.onresize = function() {
        chart.resize()
      }
    },
    getDate() {
      let date = new Date()
      let y = date.getFullYear()
      let MM = date.getMonth() + 1
      MM = MM < 10 ? '0' + MM : MM
      let d = date.getDate()
      d = d < 10 ? '0' + d : d
      let h = date.getHours() - 1
      h = h < 10 ? '0' + h : h
      if (this.active == 1) {
        if (this.statHour) {
          return y + '-' + MM + '-' + d
        } else {
          return y + '-' + MM + '-' + d + '  ' + h
        }
      } else {
        return y + '-' + MM + '-' + (d - 1)
      }
    },
    exportExcel() {
      var title = ''
      if (this.active == 1) {
        if (this.statHour) {
          title = this.getDate() + '  ' + this.statHour + '时数据报表'
        } else {
          title = this.getDate() + '时数据报表'
        }
      } else {
        title = this.getDate() + '数据报表'
      }
      //   var opt = {
      //     rowIndex: 4
      //   } //开头空4行
      var sheet = XLSX2.utils.table_to_sheet(document.getElementById('outTable'))
      sheet['A2'].s = {
        font: {
          name: '宋体',
          sz: 18,
          color: { rgb: 'ff0000' },
          bold: true
          //   italic: false,
          //   underline: false
        },
        alignment: {
          horizontal: 'center',
          vertical: 'center'
        }
        // fill: {
        //   fgColor: {rgb: "008000"},
        // },
      }
      //   sheet['A1'] = {
      //     t: 's',
      //     v: '表格导出'
      //   } //给A1单元格赋值
      console.log(sheet)
      //["!merges"]这个属性是专门用来进行单元格合并的
      //   sheet['!merges'].push({
      //     //如果不为空push 为空 = 赋值
      //     //合并单元格 index都从0开始
      //     s: {
      //       //s开始
      //       c: 0, //开始列
      //       r: 0 //开始行
      //     },
      //     e: {
      //       //e结束
      //       c: 12, //结束列
      //       r: 3 //结束行
      //     }
      //   })

      sheet['!cols'] = [
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        },
        {
          wpx: 100
        }
      ] //单元格列宽

      openDownloadDialog(sheet2blob(sheet), title + '.xlsx')
    }
  },
  watch: {},
  distoryed() {},
  mounted: function() {
    this.$nextTick(() => {
      getAdvertiserList().then(res => {
        console.log(res)
        if (res.code == 0) {
          this.list = res.result
          this.options = res.result
        }
      })
    })
  }
}
</script>
