
<style>
/* .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;
}
th div {
  white-space: nowrap;
}
.data-display-statistics th {
  text-align: center !important;
} */
</style>
<template>
  <div class="data-refuse-statistics">
    <a-row class="image-list-heading vm-panel">
      <div class="panel-heading" style="display:flex;justify-content: space-between;">{{ title }}</div>
      <a-row type="flex" align="middle" justify="space-between" class="panel-body">
        <div class="search-bar" style="width:100%">
          <span>账户选择：</span>
          <a-select
            v-model="appId"
            showSearch
            allowClear
            placeholder="请选择账户"
            optionFilterProp="children"
            style="width:600px"
          >
            <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}}</a-select-option>
          </a-select>
          <a-button type="primary" style="margin:10px" @click="addUser">搜索</a-button>
        </div>
      </a-row>
    </a-row>
    <a-row :gutter="10" style="margin-top:10px">
      <a-col :span="24">
        <a-card style="width:100%;">
          <div style="display:flex;margin:0 0 20px 0">
            <a-input placeholder="请输出要查找的创意名称" style="width:300px;" v-model="keyWord" />
            <a-button type="primary" style="margin-left:10px" @click="addUserKey">搜索</a-button>
          </div>

          <a-table :columns="columns" :dataSource="dataList" bordered :loading="loading">
            <div slot="videoUrl" slot-scope="videoUrl">
              <video
                class="video"
                :src="videoUrl"
                controls="controls"
                style="height:200px;width:112.5px"
              >您的浏览器不支持 video 标签。</video>
            </div>
            <div slot="coverUrl" slot-scope="coverUrl">
              <img :src="coverUrl" controls="controls" style="height:200px;width:112.5px" />
            </div>
            <template slot="creativeName" slot-scope="text, record">
              <!-- <editable-cell :text="text" @change="onCellChange(record, 'creativeName', $event)" /> -->
              <div>
                {{text}}
                <a-icon
                  type="edit"
                  style="cursor: pointer;"
                  @click="onCellChange(record, 'creativeName')"
                />
              </div>
            </template>
            <template slot="description" slot-scope="text, record">
              <!-- <editable-cell :text="text" @change="onCellChange(record, 'description', $event)" /> -->
              <div>
                {{text}}
                <a-icon
                  type="edit"
                  style="cursor: pointer;"
                  @click="onCellChange(record, 'description')"
                />
              </div>
            </template>
          </a-table>
        </a-card>
      </a-col>
    </a-row>
    <a-modal
      :title="editTitle"
      :visible="visible"
      @ok="handleOk"
      :confirmLoading="confirmLoading"
      @cancel="handleCancel"
    >
      <a-textarea v-model="editWord" autosize />
    </a-modal>
  </div>
</template>

<script>
import moment from 'moment'
import { getMaterialAccount, getRefuseCreative, updateCreative, selectByCreateName } from '@api/statistics'
import axios from 'axios'
import EditableCell from './components/EditableCell'
import { mapGetters } from 'vuex'
import { stopOtherVideo, closeAllVideoFun } from '@/utils/videoControl' // 停止除当前外的其他视频播放，及停止所有视频播放的方法
const columns = [
  {
    title: '账号Id',
    dataIndex: 'accountId',
    key: 'accountId',
    align: 'center'
  },
  {
    title: '计划Id',
    dataIndex: 'campaignId',
    key: 'campaignId',
    align: 'center'
  },
  {
    title: '广告组id',
    dataIndex: 'unitId',
    key: 'unitId',
    align: 'center'
  },
  {
    title: '创意id',
    dataIndex: 'creativeId',
    key: 'photoClick',
    align: 'center'
  },
  {
    title: '创意名称',
    dataIndex: 'creativeName',
    key: 'creativeName',
    align: 'left',
    scopedSlots: { customRender: 'creativeName' }
  },
  {
    title: '视频',
    dataIndex: 'videoUrl',
    key: 'videoUrl',
    align: 'center',
    scopedSlots: { customRender: 'videoUrl' }
  },
  {
    title: '封面',
    dataIndex: 'coverUrl',
    key: 'coverUrl',
    align: 'center',
    scopedSlots: { customRender: 'coverUrl' }
  },
  {
    title: '拒绝原因',
    dataIndex: 'reviewDetail',
    key: 'reviewDetail',
    align: 'left'
  },

  {
    title: '广告语',
    dataIndex: 'description',
    key: 'description',
    align: 'left',
    scopedSlots: { customRender: 'description' }
  }
]

export default {
  name: 'refuse-data',
  components: {
    EditableCell
  },

  data: function() {
    return {
      title: '被拒创意列表',
      appId: null,
      options: [],
      loading: false,
      columns,
      dataList: [],
      keyWord: '',
      editTitle: '',
      confirmLoading: false,
      visible: false,
      editWord: '',
      nowData: null
    }
  },
  filters: {},
  methods: {
    handleOk(e) {
      this.confirmLoading = true
      var params = {}
      params.accountId = this.nowData.accountId
      params.campaignId = this.nowData.campaignId
      params.unitId = this.nowData.unitId
      params.creativeId = this.nowData.creativeId
      params.creativeName = this.editTitle == '创意名称修改' ? this.editWord : this.nowData.creativeName
      params.description = this.editTitle == '广告语修改' ? this.editWord : this.nowData.description
      updateCreative(params).then(res => {
        if (res.code == 0) {
          this.addUser()
          this.visible = false
          this.confirmLoading = false
        } else {
          this.$message.error(res.message)
          this.visible = false
          this.confirmLoading = false
        }
      })
    },
    handleCancel(e) {
      this.visible = false
    },
    onCellChange(item, dataIndex) {
      this.editWord = item[dataIndex]
      this.editTitle = dataIndex == 'creativeName' ? '创意名称修改' : '广告语修改'
      this.nowData = item
      this.visible = true
    },
    moment,
    ...mapGetters(['nickname', 'avatar', 'userInfo']),
    addUser() {
      this.loading = true
      var params = {}
      params.accountId = this.appId + ''
      if (this.appId) {
        getRefuseCreative(params).then(res => {
          if (res.code == 0) {
            this.dataList = res.data.map((v, index) => {
              return {
                ...v,
                key: index
              }
            })
            this.list = this.dataList
            this.loading = false
          }
        })
      } else {
        this.$message.error('请选择账户')
      }
    },
    addUserKey() {
      this.dataList = this.list.filter(item => {
        return item.creativeName.toLowerCase().indexOf(this.keyWord.toLowerCase()) > -1
      })
    }
  },
  watch: {},
  distoryed() {},
  updated() {
    stopOtherVideo()
  },
  mounted: function() {
    this.$nextTick(() => {
      getMaterialAccount({ userId: this.userInfo().id }).then(res => {
        this.options = res
      })
    })
  }
}
</script>
