<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;
}
.ant-table-thead tr th {
  background: none;
}
/* th div {
  white-space: nowrap;
} */
</style>
<template>
  <div class="data-material-statistics">
    <a-row class="image-list-heading vm-panel">
      <div class="panel-heading" style="display:flex;justify-content: space-between;">
        {{ title }}
        <a-button @click="dianji">进入账户报表</a-button>
      </div>
      <a-row>
        <a-col :span="24">
          <a-card :bordered="false" class="search-box">
            <time-check @getAdd="getAdd" :startValue.sync="startValue" :timeList="timeList" :activeNow="2"></time-check>
          </a-card>
        </a-col>
      </a-row>
    </a-row>
    <a-row :gutter="10" style="margin-top:10px">
      <a-col :span="24">
        <a-card style="width:100%;">
          <a-table
            :columns="columns"
            :dataSource="data"
            bordered
            id="outTable"
            :pagination="ipagination"
            size="middle"
            :customRow="rowClick"
            :loading="loading"
            :scroll="{ x: 2600 }"
          >
            <div slot="url" slot-scope="url">
              <video @click.stop class="video" :src="url" controls="controls" style="height:200px;width:112.5px">
                您的浏览器不支持 video 标签。
              </video>
            </div>
            <span slot="photoClickRatio" slot-scope="photoClickRatio">{{ photoClickRatio | getBo }}</span>
            <span slot="actionRatio" slot-scope="actionRatio">{{ actionRatio | getBo }}</span>
            <span slot="impression1kCost" slot-scope="impression1kCost">{{ impression1kCost | toFixtwo }}</span>
            <span slot="photoClickCost" slot-scope="photoClickCost">{{ photoClickCost | toFixtwo }}</span>
            <span slot="actionCost" slot-scope="actionCost">{{ actionCost | toFixtwo }}</span>
            <span slot="conversionPrice" slot-scope="conversionPrice">{{ conversionPrice | toFixtwo }}</span>
            <span slot="play3sRate" slot-scope="play3sRate">{{ play3sRate | getBo }}</span>
            <span slot="operation" slot-scope="text,record">
                <a href="javascript:;" @click.stop="showRelevantPeople(record)">查看相关人员</a>
            </span>
          </a-table>
        </a-card>
      </a-col>
    </a-row>
    
     
      <a-modal v-model="relevantPeopleVisible" title="相关人员" :footer="null" :centered='true'>
        <p>编导：{{relevantPeopleData.planName || '暂无数据'}}</p>
        <p>剪辑：{{relevantPeopleData.clipName || '暂无数据'}}</p>
        <p>拍摄：{{relevantPeopleData.shotName || '暂无数据'}}</p>
      </a-modal>
    <ratio-modal ref="ratio" />
  </div>
</template>

<script>
import ARow from 'ant-design-vue/es/grid/Row'
import ACol from 'ant-design-vue/es/grid/Col'
import moment from 'moment'
import { getKuaiShouMaterialMarket, getKuaiShouChainRatio } from '@api/statistics'
import axios from 'axios'
import { mapGetters } from 'vuex'
import { stopOtherVideo, closeAllVideoFun } from '@/utils/videoControl' // 停止除当前外的其他视频播放，及停止所有视频播放的方法
import { getAction } from '../../../api/manage'
import timeCheck from './components/timeCheck'
import ratioModal from './components/ratioModal'

import { JeecgListMixin } from '@/mixins/ipagination'

var length = 0
var active = 1
const columns = [
  {
    title: '视频',
    dataIndex: 'url',
    key: 'url',
    align: 'center',
    scopedSlots: { customRender: 'url' }
  },
  {
    title: '视频md5',
    dataIndex: 'signature',
    key: 'signature',
    align: 'center',
    scopedSlots: { customRender: 'signature' },
    width: 250
  },
  {
    title: '花费',
    dataIndex: 'cost',
    key: 'cost',
    align: 'center',
    sorter: (a, b) => a.cost - b.cost
  },
  {
    title: '封面曝光数',
    dataIndex: 'photoShow',
    key: 'photoShow',
    align: 'center',
    sorter: (a, b) => a.photoShow - b.photoShow
  },
  {
    title: '封面点击数',
    dataIndex: 'photoClick',
    key: 'photoClick',
    align: 'center',
    sorter: (a, b) => a.photoClick - b.photoClick
  },
  {
    title: '素材曝光数',
    dataIndex: 'aclick',
    key: 'aclick',
    align: 'center',
    sorter: (a, b) => a.aclick - b.aclick
  },
  {
    title: '行为数',
    dataIndex: 'bclick',
    key: 'bclick',
    align: 'center',
    sorter: (a, b) => a.bclick - b.bclick
  },
  {
    title: '封面点击率',
    dataIndex: 'photoClickRatio',
    key: 'photoClickRatio',
    align: 'center',
    scopedSlots: { customRender: 'photoClickRatio' },
    sorter: (a, b) => a.photoClickRatio - b.photoClickRatio
  },
  {
    title: '行为率',
    dataIndex: 'actionRatio',
    key: 'actionRatio',
    align: 'center',
    scopedSlots: { customRender: 'actionRatio' },
    sorter: (a, b) => a.actionRatio - b.actionRatio
  },

  {
    title: '均千次封面曝光花费(元)',
    dataIndex: 'impression1kCost',
    key: 'impression1kCost',
    scopedSlots: { customRender: 'impression1kCost' },
    align: 'center',
    sorter: (a, b) => a.impression1kCost - b.impression1kCost
  },
  {
    title: '平均封面点击单价(元)',
    dataIndex: 'photoClickCost',
    key: 'photoClickCost',
    scopedSlots: { customRender: 'photoClickCost' },
    align: 'center',
    sorter: (a, b) => a.photoClickCost - b.photoClickCost
  },
  {
    title: '平均行为单价(元)',
    dataIndex: 'actionCost',
    key: 'actionCost',
    scopedSlots: { customRender: 'actionCost' },
    align: 'center',
    sorter: (a, b) => a.actionCost - b.actionCost
  },
  {
    title: '转化数',
    dataIndex: 'conversions',
    key: 'conversions',
    align: 'center',
    sorter: (a, b) => a.conversions - b.conversions
  },
  {
    title: '转化单价(元)',
    dataIndex: 'conversionPrice',
    key: 'conversionPrice',
    scopedSlots: { customRender: 'conversionPrice' },
    align: 'center',
    sorter: (a, b) => a.conversionPrice - b.conversionPrice
  },
  {
    title: '3s播放率',
    dataIndex: 'play3sRate',
    key: 'play3sRate',
    scopedSlots: { customRender: 'play3sRate' },
    align: 'center',
    sorter: (a, b) => a.play3sRate - b.play3sRate
  },
  {
    title:'相关人员',
    dataIndex:'operation',
    key:'operation',
    scopedSlots: { customRender: 'operation' },
    align: 'center',
    
  }
]
const columnsDetail = [
  {
    title: '日期',
    dataIndex: 'statDate',
    key: 'statDate',
    align: 'center'
  },
  {
    title: '花费',
    dataIndex: 'cost',
    key: 'cost',
    align: 'center'
  },
  {
    title: '封面曝光数',
    dataIndex: 'photoShow',
    key: 'photoShow',
    align: 'center'
  },
  {
    title: '封面点击数',
    dataIndex: 'photoClick',
    key: 'photoClick',
    align: 'center'
  },
  {
    title: '素材曝光数',
    dataIndex: 'aclick',
    key: 'aclick',
    align: 'center'
  },
  {
    title: '行为数',
    dataIndex: 'bclick',
    key: 'bclick',
    align: 'center'
  },
  {
    title: '封面点击率',
    dataIndex: 'photoClickRatio',
    key: 'photoClickRatio',
    align: 'center',
    scopedSlots: { customRender: 'photoClickRatio' }
  },
  {
    title: '行为率',
    dataIndex: 'actionRatio',
    key: 'actionRatio',
    align: 'center',
    scopedSlots: { customRender: 'actionRatio' }
  },

  {
    title: '均千次封面曝光花费(元)',
    dataIndex: 'impression1kCost',
    key: 'impression1kCost',
    scopedSlots: { customRender: 'impression1kCost' },
    align: 'center'
  },
  {
    title: '平均封面点击单价(元)',
    dataIndex: 'photoClickCost',
    key: 'photoClickCost',
    scopedSlots: { customRender: 'photoClickCost' },
    align: 'center'
  },
  {
    title: '平均行为单价(元)',
    dataIndex: 'actionCost',
    key: 'actionCost',
    scopedSlots: { customRender: 'actionCost' },
    align: 'center'
  },
  {
    title: '转化数',
    dataIndex: 'conversions',
    key: 'conversions',
    align: 'center'
  },
  {
    title: '转化单价(元)',
    dataIndex: 'conversionPrice',
    key: 'conversionPrice',
    scopedSlots: { customRender: 'conversionPrice' },
    align: 'center'
  },
  {
    title: '3s播放率',
    dataIndex: 'play3sRate',
    key: 'play3sRate',
    scopedSlots: { customRender: 'play3sRate' },
    align: 'center',
    
  },
]
export default {
  name: 'data-display-statistics',
 
  components: {
    ACol,
    ARow,
    timeCheck,
    ratioModal
  },
  mixins: [JeecgListMixin],
  data: function() {
    return {
       relevantPeopleVisible:false,
      relevantPeopleData:{},
      title: '素材大盘报表',
      columns,
      columnsDetail,
      timeList: [
        // { label: '今天', value: 1, show: true },
        { label: '昨天', value: 2, show: true },
        { label: '近一周', value: 3, show: true },
        { label: '近十五天', value: 4, show: true },
        { label: '近一月', value: 5, show: true },
        { label: '近三月', value: 6, show: true }
      ],
      data: [],
      active: 2,
      pagin: 1,
      allValue: [],
      startValue: [],
      visible: false,
      showVideo: false,
      detail: null,
      dataDetail: [],
      dataYestodayDetail: [],
      dataChainRatio: [],
      loading: false,
      rowClick: record => ({
        // 事件
        on: {
          click: () => {
            // 点击改行时要做的事情
            // this.detail = record
            // this.visible = true
            // this.getMineList(record.signature)
            this.$refs.ratio.getMineList(record, this.active)
          }
        }
      })
    }
  },
  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
    },
    toFixtwo: function(value) {
      if (value) {
        return value.toFixed(2)
      } else {
        return 0.0
      }
    },
    getBo: function(value) {
      if (value) {
        return (value * 100).toFixed(2) + '%'
      } else {
        return '0.00%'
      }
    }
  },
  methods: {
    // 查看相关人员
    showRelevantPeople(record){
      this.relevantPeopleVisible=true;
      console.log(record)
      getAction('/ctop/materialAscription/getDetail',{
        code:record.signature
      }).then(res=>{
        console.log(res);
        this.relevantPeopleData=[];
        if(res.result&&res.success){
          this.relevantPeopleData=res.result
        }
        
      })
    },
    handleOk() {
      this.visible = false
    },
    ...mapGetters(['nickname', 'avatar', 'userInfo']),
    moment,
    disabledDate(current) {
      return current && current > moment().endOf('day')
    },
    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.ipagination.current = 1
      this.getList()
    },
    getList() {
      this.data = []
      this.loading = true
      var params = {}
      params.userId = this.userInfo().id
      params.type = this.active
      if (this.active == 9) {
        params.startDate = this.allValue[0]
        params.endDate = this.allValue[1]
      }
      getKuaiShouMaterialMarket(params).then(res => {
        if (res.success) {
          this.data = res.result.map((item, index) => {
            return {
              key: index,
              ...item
            }
          })
          this.loading = false
          this.ipagination.total = res.result.length
        } else {
          this.$message.error(res.message)
          this.loading = false
        }
      })
    },
    dianji() {
      this.$router.replace({ path: '/Statistics/accountMaterStatistics' })
    }
  },
  watch: {},
  distoryed() {},
  updated() {
    stopOtherVideo()
  },
  mounted: function() {
    this.$nextTick(() => {
        this.getList()
    })
  }
}
</script>
