<style>
.advertising-group .ant-card-body .count {
  display: inline-block;
  /* height: 32px;
    line-height: 32px; */
}

.checked .ant-checkbox-wrapper {
  width: 140px;
}

/* .advertising-group .ant-table td {
    white-space: nowrap;
  } */

.ant-tabs {
  overflow: visible;
}

.else-table {
  display: table;
  margin-top: 10px;
}
</style>
<template>
  <div class="advertising-group">
    <a-row style="margin-top: 15px">
      <a-card title="">
        <!-- :tabList="title" :activeTabKey="titleKey" @tabChange="key => onTabChange(key, 'titleKey')" -->
        <a-tabs v-model="titleKey" type="editable-card" hideAdd @edit="remove">
          <a-tab-pane v-for="pane in title" :tab="pane.tab" :key="pane.key">
            <a-button @click="dianji" style="margin-bottom: 15px">新增广告组</a-button>
            <a-button type="primary" style="margin: 0 10px" @click="searchRe">刷新</a-button>
            <a-table
              size="middle"
              :columns="columns"
              :dataSource="dataList"
              bordered
              :customRow="rowClick"
              :pagination="ipagination"
              @change="sort"
              :scroll="{ x: 1500 }"
              style="margin-top: 30px"
              :loading="loadingList"
            >
              <!-- getCheckboxProps: getCheckboxProps -->
              <template slot="dayBudget" slot-scope="text, record">
                <div style="display: flex; justify-content: center">
                  <span class="count">{{ text ? (text / 1000).toFixed(2) : '不限制预算' }}</span>
                </div>
              </template>
              <span slot="bidType" slot-scope="text, record" :title="text">
                {{ text | bidType }}
              </span>
              <span slot="unitName" slot-scope="text, record" :title="text">
                {{ text }}
              </span>

              <span slot="ocpxActionType" slot-scope="text, record" :title="text">
                {{ text | ocpxActionType }}
              </span>
              <span slot="bid" slot-scope="text, record" :title="text">
                {{ text ? text / 1000 : record.cpaBid / 1000 }}
              </span>
              <span slot="createCreativeCount" slot-scope="text, record" :title="text">
                <div style="display: flex; justify-content: center">
                  <a :title="text" @click="toDetail(record)"> {{ text }}</a>
                </div>
              </span>
              <span slot="unitId" slot-scope="text, record" :title="text">
                {{ text ? text : '未创建成功' }}
              </span>
              <span slot="taskStatus" slot-scope="text">{{ text | taskStatus }}</span>
              <span slot="creativeStatus" slot-scope="text">{{ text | creativeStatus }}</span>

              <span slot="putStatus" slot-scope="text">{{ text | putStatus }}</span>
              <span slot="reviewDetail" slot-scope="text">
                <div style="display: flex; justify-content: center" v-if="text">
                  <a :title="text" style="color: rgba(0, 0, 0, 0.65);"> {{ text }}</a>
                </div>
                <span v-else>无</span>
              </span>
              <span slot="creativeReviewDetail" slot-scope="text">
                <div style="display: flex; justify-content: center">
                  <a :title="text" style="color: rgba(0, 0, 0, 0.65);"> {{ text }}</a>
                </div>
              </span>

              <span slot="sceneId" slot-scope="text"
                ><span v-for="item of text" :key="item">{{ item | sceneId }}</span></span
              >
              <span slot="showMode" slot-scope="text">{{ text | showModel }}</span>
            </a-table>
          </a-tab-pane>
        </a-tabs>
      </a-card>
    </a-row>
    <!-- <editGroup ref="editGroup" @getList="getDataList" />
    <editGroupNew ref="editGroupNew" @getListNew="getDataList" /> -->
  </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 countTo from 'vue-count-to'
import { deleteAction, getAction, postAction } from '@/api/manage'
// import lifting from './components/lifting'
import { mapGetters } from 'vuex'

import editGroup from '../account/editGroup'
import editGroupNew from '../account/editGroupNew'
import editAllGroup from '../account/editAllGroup'

var columns = [
  {
    title: '广告组名称',
    align: 'center',
    dataIndex: 'unitName',
    scopedSlots: {
      customRender: 'unitName',
    },
    fixed: 'left',
    width: 150,
  },

  {
    title: '广告组id',
    align: 'center',
    dataIndex: 'unitId',
    scopedSlots: {
      customRender: 'unitId',
    },
    fixed: 'left',
    width: 150,
  },
  {
    title: '账户id',
    align: 'center',
    dataIndex: 'accountId',
    scopedSlots: {
      customRender: 'accountId',
    },
    fixed: 'left',
    width: 150,
  },
  {
    title: '预算',
    align: 'center',
    dataIndex: 'dayBudget',
    scopedSlots: {
      customRender: 'dayBudget',
    },
    fixed: 'left',
    width: 150,
  },
  {
    title: '出价方式',
    align: 'center',
    dataIndex: 'bidType',
    scopedSlots: {
      customRender: 'bidType',
    },
  },
  {
    title: '转化目标',
    align: 'center',
    dataIndex: 'ocpxActionType',
    scopedSlots: {
      customRender: 'ocpxActionType',
    },
  },
  {
    title: '出价',
    align: 'center',
    dataIndex: 'bid',
    scopedSlots: {
      customRender: 'bid',
    },
  },

  {
    title: '广告位',
    align: 'center',
    dataIndex: 'sceneId',
    scopedSlots: {
      customRender: 'sceneId',
    },
  },

  {
    title: '创意展现方式',
    align: 'center',
    dataIndex: 'showMode',
    scopedSlots: {
      customRender: 'showMode',
    },
  },
  {
    title: '绑定创意数',
    align: 'center',
    dataIndex: 'createCreativeCount',
    scopedSlots: {
      customRender: 'createCreativeCount',
    },
  },
  {
    title: '组创建状态',
    align: 'center',
    dataIndex: 'taskStatus',
    scopedSlots: {
      customRender: 'taskStatus',
    },
  },

  {
    title: '组创建拒绝理由',
    align: 'center',
    dataIndex: 'reviewDetail',
    scopedSlots: {
      customRender: 'reviewDetail',
    },
    // width: 300,
  },
  {
    title: '创意创建状态',
    align: 'center',
    dataIndex: 'creativeStatus',
    scopedSlots: {
      customRender: 'creativeStatus',
    },
  },
  {
    title: '创意创建返回信息',
    align: 'center',
    dataIndex: 'creativeReviewDetail',
    scopedSlots: {
      customRender: 'creativeReviewDetail',
    },
    // width: 300,
  },
]

let realTimeColumn = [
  {
    title: '广告组名称',
    align: 'center',
    dataIndex: 'unitName',
    fixed: 'left',
    width: 300,
    scopedSlots: {
      customRender: 'unitName',
    },
  },
  {
    title: '时间',
    align: 'center',
    dataIndex: 'stat_date',
    fixed: 'left',
    width: 200,
    scopedSlots: {
      customRender: 'stat_date',
    },
  },
  {
    title: '消耗',
    align: 'center',
    dataIndex: 'charge',
    scopedSlots: { customRender: 'charge' },
  },
  {
    title: '封面曝光数',
    align: 'center',
    dataIndex: 'show',
    scopedSlots: { customRender: 'show' },
  },
  {
    title: '封面点击数',
    align: 'center',
    dataIndex: 'photo_click',
    scopedSlots: { customRender: 'photo_click' },
  },
  {
    title: '素材曝光数',
    align: 'center',
    dataIndex: 'aclick',
    scopedSlots: { customRender: 'aclick' },
  },
  {
    title: '行为数',
    align: 'center',
    dataIndex: 'bclick',
    scopedSlots: { customRender: 'bclick' },
  },
  {
    title: '行为率',
    align: 'center',
    dataIndex: 'action_ratio',
    scopedSlots: { customRender: 'action_ratio' },
  },
  {
    title: '封面点击率',
    align: 'center',
    dataIndex: 'photo_click_ratio',
    scopedSlots: { customRender: 'photo_click_ratio' },
  },
  {
    title: '激活数',
    align: 'center',
    dataIndex: 'activation',
    scopedSlots: { customRender: 'activation' },
  },
  {
    title: '激活成本',
    align: 'center',
    dataIndex: 'activationCost',
    scopedSlots: { customRender: 'activationCost' },
  },
  {
    title: '注册数',
    align: 'center',
    dataIndex: 'event_register',
    scopedSlots: { customRender: 'event_register' },
  },
  {
    title: '注册成本',
    align: 'center',
    dataIndex: 'event_register_cost',
    scopedSlots: { customRender: 'event_register_cost' },
  },
  {
    title: '表单提交数',
    align: 'center',
    dataIndex: 'form_count',
    scopedSlots: { customRender: 'form_count' },
  },
  {
    title: '表单提交单价',
    align: 'center',
    dataIndex: 'form_cost',
    scopedSlots: { customRender: 'form_cost' },
  },
  {
    title: '付费数',
    align: 'center',
    dataIndex: 'event_order_paid',
    scopedSlots: { customRender: 'event_order_paid' },
  },
  {
    title: '付费成本',
    align: 'center',
    dataIndex: 'event_order_paid_cost',
    scopedSlots: { customRender: 'event_order_paid_cost' },
  },
]

export default {
  name: 'account-statistics',
  components: {
    ACol,
    ARow,
    countTo,
    editGroup,
    editAllGroup,
    editGroupNew,
  },

  data: function () {
    return {
      // 实时数据
      realTimeVisiable: false,
      realTimeColumn,
      realTimeData: [],
      scrollX: 2500,
      realTimeLoading: false,
      dateValue: [moment(), moment()],
      realTimeRecords: {},

      // 实时数据

      clickTrackUrl: '',
      loadingMoney: false,
      loadingState: false,
      loadingAllMoney: false,
      unitName: '',
      unitNameInit: '',
      unitId: '',
      editOk: '1',
      loadingList: false,
      visible: false,
      visibleData: null,
      visibleEditAll: false,
      visibleBatch: false,
      campaignType: '2',
      campaignId: localStorage.getItem('campaignList'),
      createCount: 1,
      unitNameList: [],
      form: this.$form.createForm(this),
      campaignList: [],
      visibleCopy: false,
      copyLoading: true,
      loading: false,
      columns,
      columnsElse: columns,
      dataList: [],
      populationData: {},
      allForm: {
        group: [],
        groupTypeData: null,
      },
      rowClick: (record, index) => ({
        // 事件
        on: {
          dblclick: () => {},
        },
      }),
      ipagination: {
        current: 1,
        pageSize: 10,
        //   pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        pageSizeOptions: ['10', '30', '50'],
        total: 0,
        onChange: (current, pageSize) => {
          // 切换分页时的回调，
          // 当在页面定义change事件时，切记要把此处的事件清除，因为这两个事件重叠了，可能到时候会导致一些莫名的bug
          this.ipagination.current = current
          this.ipagination.pageSize = pageSize
          this.getDataList(this.titleKey)
        },
      },
      url: {
        list: '/kuaishou/kuaiShouGroupCreateLog/list',
        delete: '/kuaishou/kuaiShouGroupCreateLog/delete',
        deleteBatch: '/kuaishou/kuaiShouGroupCreateLog/deleteBatch',
        exportXlsUrl: 'kuaishou/kuaiShouGroupCreateLog/exportXls',
        importExcelUrl: 'kuaishou/kuaiShouGroupCreateLog/importExcel',
      },
      name: null,
      title: [],
      titleKey: null,
      dataValue: [],
      indeterminate: true,
      checkAll: false,
      allMoney: 1.2,
      allMoneyBid: null,
      deepConversionBid: null,
      allMoneyBidProportion: 1.2,
      allType: '1',
      allPrice: '1',
      maxBid: null,
      copyData: null,
      showDeepBid: false,
      nameEdit: false,
      unitNameEdit: '',
      unitIdEdit: '',
      loadingUnit: false,
    }
  },
  filters: {
    status(sta) {
      var data = {
        '-1': '不限',
        1: '计划已暂停',
        3: '计划超预算',
        6: '余额不足',
        11: '审核中',
        12: '审核未通过',
        14: '已结束',
        15: '已暂停',
        17: '组超预算',
        19: '未达投放时间',
        20: '有效',
      }
      return data[sta]
    },
    taskStatus(sta) {
      var data = {
        0: '待提交',
        1: '提交中',
        2: '创建成功',
        3: '创建失败',
      }
      return data[sta]
    },
    creativeStatus(sta) {
      var data = {
        0: '待创建',
        1: '创建中',
        2: '创建成功',
        3: '创建失败',
      }
      return data[sta]
    },
    putStatus(sta) {
      var data = {
        1: '投放中',
        2: '暂停',
      }
      return data[sta]
    },
    createChannel(sta) {
      var data = {
        0: '投放后台创建',
        1: '汇创助手创建',
      }
      return data[sta]
    },
    bidType(sta) {
      var data = {
        1: 'CPM',
        2: 'CPC',
        6: 'OCPC',
        10: 'OCPM',
      }
      return data[sta]
    },
    ocpxActionType(sta) {
      var data = {
        0: '封面点击',
        2: '行为数',
        10: '曝光',
        11: '点击',
        31: '下载完成',
        53: '提交线索',
        394: '订单提交',
        348: '使用有效线索',
        383: '授信出价',
        180: '激活',
        384: '完件出价',
        190: '付费出价',
        191: '首日ROI',
        396: '注册优化目标',
      }
      return data[sta]
    },
    speed(sta) {
      var data = {
        0: '未知',
        1: '正常',
        2: '点击转化链接',
      }
      return data[sta]
    },
    sceneId(sta) {
      var data = {
        0: '未知',
        1: '优选广告位',
        3: '视频播放页广告-便利贴广告',
        5: '联盟广告',
        6: '上下滑大屏广告',
        7: '信息流广告',
      }
      return data[sta]
    },
    showModel(sta) {
      var data = {
        0: '未知',
        1: '轮播',
        2: '优选',
      }
      return data[sta]
    },
    urlType(sta) {
      var data = {
        1: '淘宝商品短链',
        2: '淘宝商品itemID',
      }
      return data[sta]
    },
    deepConversionType(sta) {
      var data = {
        0: '未使用',
        3: '付费',
        7: '次日留存',
        10: '完件',
        11: '授信',
        13: '添加购物车',
        14: '提交订单',
        15: '购买联盟广告无门槛要求',
      }
      return data[sta]
    },
    toPercentage(val) {
      if (val) {
        if (typeof val != 'string') {
          return (val * 100).toFixed(2) + '%'
        } else {
          return val
        }
      } else if (typeof val == 'string') {
        return val
      } else {
        return 0
      }
    },
    //保留两位小数并且变成货币格式
    decimalsHandle(val) {
      if (val && typeof val != 'string') {
        if (val >= 0) {
          val = parseFloat(val).toFixed(2)
          let numberStr = val.toString()
          let str = numberStr.split('.')

          let str0 = str[0].split('').reverse()
          for (let i = 0; i < str0.length; i++) {
            if ((i + 1) % 4 === 0) {
              str0.splice(i, 0, ',')
            }
          }
          str0.reverse()
          let handleResult = ''
          for (let j = 0; j < str0.length; j++) {
            handleResult += str0[j]
          }

          return handleResult + '.' + str[1]
        } else {
          val = parseFloat(val).toFixed(2)
          let numberStr = val.toString()
          let str = numberStr.split('.')

          let str0 = str[0].substr(1).split('').reverse()
          for (let i = 0; i < str0.length; i++) {
            if ((i + 1) % 4 === 0) {
              str0.splice(i, 0, ',')
            }
          }
          str0.reverse()
          let handleResult = ''
          for (let j = 0; j < str0.length; j++) {
            handleResult += str0[j]
          }

          return '-' + handleResult + '.' + str[1]
        }
      } else if (typeof val == 'string') {
        return val
      } else {
        return 0
      }
    },
    //变成货币格式
    formatCurrency(val) {
      if ((val || val == 0) && typeof val != 'string') {
        let numberStr = val.toString()
        let str = numberStr.split('').reverse()
        for (let i = 0; i < str.length; i++) {
          if ((i + 1) % 4 === 0) {
            str.splice(i, 0, ',')
          }
        }
        str.reverse()
        let handleResult = ''
        for (let j = 0; j < str.length; j++) {
          handleResult += str[j]
        }
        return handleResult
      } else if (typeof val == 'string') {
        return val
      } else {
        return '-'
      }
    },
  },
  methods: {
    disabledDate(current) {
      // console.log(current)
      return (current && current > moment()) || (current && current < moment().subtract(7, 'days'))
    },
    // 查看实时数据
    realTimedata(records) {
      console.log(records)
      this.realTimeRecords = records
      this.realTimeVisiable = true
      this.realTimeHttp()
    },
    dateValueChange(date, dateString) {
      this.realTimeHttp()
    },
    // 获取实时数据请求
    realTimeHttp() {
      this.realTimeLoading = true
      postAction('/kuaishou/realTime/getUnitDate', {
        accountId: this.realTimeRecords.accountId,
        unitId: this.realTimeRecords.unitId,
        startDate: this.dateValue[0].format('YYYY-MM-DD'),
        endDate: this.dateValue[1].format('YYYY-MM-DD'),
      }).then((res) => {
        console.log(res)
        this.realTimeData = []
        this.realTimeLoading = false
        if (res.success) {
          if (res.result) {
            res.result.forEach((item) => {
              item.unitName = this.realTimeRecords.unitName
            })

            this.realTimeData = res.result
          }
        }
      })
    },

    sort(pagination, filters, sorter, { currentDataSource }) {
      this.ipagination.current = pagination.current

      this.ipagination.pageSize = pagination.pageSize
      this.getDataList(this.titleKey)
    },

    unitEdit(e) {
      this.loadingUnit = true
      var params = {}
      params.accountId = localStorage.getItem('campaignAccountId')
      params.unitId = this.unitIdEdit
      params.unitName = this.unitNameEdit
      postAction('/kuaishou/batch/updateUnit', params).then((res) => {
        if (res.result.code == 0) {
          this.loadingUnit = false
          this.nameEdit = false
          this.$message.success('修改成功')
          this.getDataList(localStorage.getItem('campaignList'))
        } else {
          this.loadingUnit = false
          this.$message.error(res.result.message)
        }
      })
    },
    editShowName(item) {
      this.nameEdit = true
      this.unitNameEdit = item.unitName
      this.unitIdEdit = item.unitId
    },
    createUnitName() {
      this.unitNameList = []
      for (let i = 0; i < this.getData('createCount'); i++) {
        this.unitNameList.push({
          unitName: '',
        })
      }
    },
    getData(className) {
      return this.form.getFieldValue(className)
    },
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },

    remove(targetKey) {
      let activeKey = this.titleKey
      let lastIndex
      this.title.forEach((pane, i) => {
        if (pane.key === targetKey) {
          lastIndex = i - 1
        }
      })
      const panes = this.title.filter((pane) => pane.key !== targetKey)
      if (panes.length && activeKey === targetKey) {
        if (lastIndex >= 0) {
          activeKey = panes[lastIndex].key
        } else {
          activeKey = panes[0].key
        }
      }
      this.title = panes
      this.titleKey = activeKey
      if (this.title.length == 0) {
        this.$bus.$emit('remove', '/batchCreation/unitList')
        localStorage.removeItem('campaignListGroup')
      } else {
        localStorage.setItem('campaignListGroup', JSON.stringify(this.title))
        localStorage.setItem('campaignList', this.titleKey)
        this.getDataList(activeKey)
      }
    },
    editDetail(item) {
      this.$refs.editGroup.handleOk(item, 'edit')
    },
    copyDetail(item) {
      this.clickTrackUrl = ''
      this.campaignId = localStorage.getItem('campaignList')
      this.form.resetFields()
      this.getCampaignList()
      this.$nextTick(() => {
        this.unitNameInit = item.unitName
      })
      this.copyLoading = true
      this.visibleCopy = true
      var params = {}
      params.accountId = item.accountId
      params.unitId = item.unitId
      // copyUnit
      getAction('/kuaishou/batch/getUnitDetail', params).then((res) => {
        if (res.success) {
          this.copyData = {
            ...res.result.baseInfo,
            ...res.result.appInfo,
            ...res.result.target,
          }

          this.copyLoading = false
        }
      })
      getAction('/kuaishou/batch/getIsActivate', {
        accountId: localStorage.getItem('campaignAccountId'),
      }).then((res) => {
        if (res.success) {
          this.allForm.groupTypeData = res.result
        }
      })
    },
    toDetail(record) {
      // 点击改行时要做的事情
      localStorage.setItem('originalityKeyElse', record.unitId)
      localStorage.setItem('campaignList', record.campaignId)

      if (localStorage.getItem('originalityElse')) {
        var dataElse = JSON.parse(localStorage.getItem('originalityElse'))
        // for (let i = 0; i < dataElse.length; i++) {
        //   if (dataElse[i].unitId == record.unitId) {
        //     this.$router.replace({
        //       path: '/account/originality'
        //     })
        //     return
        //   }
        // }
        dataElse = [record]
        localStorage.setItem('originalityElse', JSON.stringify(dataElse))
      } else {
        var data = [record]
        localStorage.setItem('originalityElse', JSON.stringify(data))
      }
      this.$router.replace({
        path: '/batchCreation/creativeList',
      })
    },
    ...mapGetters(['nickname', 'avatar', 'userInfo']),
    onChangeSwitch(item) {
      console.log(item)
      var params = {}
      params.accountId = localStorage.getItem('campaignAccountId')
      params.putStatus = item.showSwich ? 1 : 2
      params.userId = this.userInfo().id
      params.unitIds = [item.unitId]
      postAction('/kuaishou/batch/batchUpdateUnitStatus', params).then((res) => {
        console.log(res)
      })
    },
    editShowBid(item) {
      if (!item.editBid) {
        if (item.elseMoneyBid < 1 || item.elseMoneyBid > this.maxBid) {
          this.$message.error('不得低于1元，不得高于项目最高出价' + this.maxBid + '元')
          return
        } else {
          item.bid = item.elseMoneyBid * 1000
          var params = {}
          params.accountId = localStorage.getItem('campaignAccountId')
          params.bid = item.elseMoneyBid * 1000
          params.userId = this.userInfo().id
          params.unitIds = [item.unitId]
          postAction('/kuaishou/batch/batchUpdateUnitBid', params).then((res) => {
            console.log(res)
            if (res.result.failCount > 0) {
              this.$message.error(
                '广告组：' + res.result.failInfo[0].unitName + '          ' + '错误：' + res.result.failInfo[0].message
              )
              this.visibleData = res.result
              this.visible = true
            }
          })
        }
      } else {
        item.elseMoneyBid = item.bid == 0 ? item.cpaBid / 1000 : item.bid / 1000
      }
    },
    editShow(item) {
      if (!item.edit) {
        if (item.elseMoney < 500 || item.elseMoney > 100000000) {
          this.$message.error('请输入大于500并且小于100000000的预算')
          return
        } else {
          item.dayBudget = item.elseMoney * 1000
          var params = {}
          params.accountId = localStorage.getItem('campaignAccountId')
          params.dayBudget = item.elseMoney * 1000
          params.userId = this.userInfo().id
          params.unitIds = [item.unitId]
          postAction('/kuaishou/batch/batchUpdateUnitBudget', params).then((res) => {
            console.log(res)
            if (res.result.failCount > 0) {
              this.visibleData = res.result
              this.visible = true
              this.$message.error(
                '广告计划：' +
                  res.result.failInfo[0].unitName +
                  '          ' +
                  '错误：' +
                  res.result.failInfo[0].message
              )
            }
          })
        }
      } else {
        item.elseMoney = item.dayBudget / 1000
      }
    },

    titleArr() {
      var data = JSON.parse(localStorage.getItem('campaignListGroup'))
      var one = data.filter((item) => {
        return item.campaignId == localStorage.getItem('campaignList')
      })
      if (one[0].campaignType == 3) {
        this.columns = this.columnsElse.concat(this.three)
      } else {
        this.columns = this.columnsElse
      }
    },
    searchLabel() {
      this.ipagination.current = 1
      this.getDataList(localStorage.getItem('campaignList'))
    },
    searchRe() {
      this.unitId = ''
      this.unitName = ''
      this.getDataList(localStorage.getItem('campaignList'))
    },

    getDataList(id) {
      this.loadingList = true
      this.dataList = []
      var params = {}
      // params.userId = this.userInfo().id
      params.accountId = localStorage.getItem('campaignAccountId')
      params.campaignId = id
      params.pageNo = this.ipagination.current
      params.pageSize = this.ipagination.pageSize
      // params.unitId = this.unitId
      // params.unitName = this.unitName
      getAction('/batch/kuaiShouGroupTemplate/list', params).then((res) => {
        if (res.success) {
          this.loadingList = false
          this.dataList = res.result.records.map((v, index) => {
            return {
              ...v,
              key: index,
              edit: false,
              editBid: false,
              elseMoney: null,
              elseMoneyBid: null,
              showSwich: v.putStatus == 1 ? true : false,
            }
          })
          this.ipagination.total = res.result.total
        } else {
          this.loadingList = false
          this.$message.error(res.message)
        }
      })
    },
    dianji() {
      if (localStorage.getItem('step')) {
        this.$message.error('正在进行广告计划创建,请关闭创建页面后,重新进行创建')
        return
      } else {
        localStorage.setItem('campaignId', this.titleKey)
        this.$router.replace({
          path: '/creat/creatUnit',
        })
      }
    },

    handleSubmitCopy(e) {
      if (this.getData('createCount') == 1) {
        this.form.validateFields((err, values) => {
          if (!err) {
            this.visibleCopy = false
            this.$refs.editGroup.handleOk(
              this.copyData,
              'copy',
              this.getData('campaignId'),
              values.unitName,
              this.getData('isUpdateTrackUrl'),
              this.clickTrackUrl
            )
          }
        })

        // postAction('/kuaishou/batch/copyUnit', params).then(res => {})
      } else if (this.getData('createCount') > 1) {
        if (this.editOk == '1') {
          this.loading = true
          if (this.getData('createType') == '1') {
            var params = {
              // ...this.copyData,
              // groupArr: groupArr,
              type: 'copy',
              unitId: this.copyData.unitId,
              copyToCampaignId: this.getData('campaignId'),
              createCount: this.getData('createCount'),
              createType: this.getData('createType'),
              accountId: this.copyData.accountId,
            }
            if (this.getData('isUpdateTrackUrl')) {
              params.otherJson = {
                isUpdateTrackUrl: true,
                clickTrackUrl: this.clickTrackUrl,
                isUpdate: false,
              }
            } else {
              params.otherJson = {
                isUpdateTrackUrl: false,
                isUpdate: false,
              }
            }
            postAction('/kuaishou/batch/copyUnit', params).then((res) => {
              if (res.success) {
                //   visibleData
                if (res.result.failCount > 0) {
                  this.visible = true
                  this.visibleData = res.result
                } else {
                  this.$message.success('批量复制成功')
                  this.allMoneyBidProportion = 1.2
                  this.selectedRowKeysValue = []
                  this.selectedRowKeys = []
                }
                setTimeout(() => {
                  this.visibleCopy = false
                  this.loading = false
                  this.getDataList(localStorage.getItem('campaignList'))
                }, 3000)
                // this.getDataList(localStorage.getItem('campaignList'))
              }
            })
          } else if (this.getData('createType') == '2') {
            var params = {
              // ...this.copyData,
              // groupArr: groupArr,
              type: 'copy',
              unitId: this.copyData.unitId,
              copyToCampaignId: this.getData('campaignId'),
              createCount: this.getData('createCount'),
              createType: this.getData('createType'),
              accountId: this.copyData.accountId,
              unitNames: this.unitNameList.map((item) => {
                return item.unitName
              }),
            }
            if (this.getData('isUpdateTrackUrl')) {
              params.otherJson = {
                isUpdateTrackUrl: true,
                clickTrackUrl: this.clickTrackUrl,
                isUpdate: false,
              }
            } else {
              params.otherJson = {
                isUpdateTrackUrl: false,
                isUpdate: false,
              }
            }
            postAction('/kuaishou/batch/copyUnit', params).then((res) => {
              if (res.success) {
                if (res.result.failCount > 0) {
                  this.visible = true
                  this.visibleData = res.result
                } else {
                  this.$message.success('批量复制成功')
                  this.allMoneyBidProportion = 1.2
                  this.selectedRowKeysValue = []
                  this.selectedRowKeys = []
                }
                setTimeout(() => {
                  this.visibleCopy = false
                  this.loading = false
                  this.getDataList(localStorage.getItem('campaignList'))
                }, 3000)

                // this.getDataList(localStorage.getItem('campaignList'))
              }
            })
          }
        } else {
          this.visibleCopy = false
          if (this.getData('createType') == '1') {
            this.$refs.editGroupNew.handleOk(
              this.copyData,
              'typeOne',
              this.getData('campaignId'),
              [],
              this.getData('createCount'),
              this.getData('isUpdateTrackUrl'),
              this.clickTrackUrl
            )
          } else if (this.getData('createType') == '2') {
            this.unitNameList.map((item) => {
              return {
                unitName: item.unitName,
              }
            })
            this.$refs.editGroupNew.handleOk(
              this.copyData,
              'typeTwo',
              this.getData('campaignId'),
              this.unitNameList,
              this.getData('createCount'),
              this.getData('isUpdateTrackUrl'),
              this.clickTrackUrl
            )
          }
        }
      }
    },

    getCampaignList() {
      var params = {}
      params.accountId = localStorage.getItem('campaignAccountId')
      params.pageNo = 1
      params.pageSize = 100

      //   params.campaignId = this.campaignId ? this.campaignId : localStorage.getItem('campaignId')
      getAction('/kuaishou/batch/getCampaignList', params).then((res) => {
        if (res.success) {
          this.campaignList = res.result.records.map((item) => {
            return {
              label: item.campaignName,
              value: item.campaignId,
            }
          })
          this.campaignType = res.result.records.filter((item) => {
            return item.campaignId == localStorage.getItem('campaignList')
          })[0].campaignType
        }
      })
    },
  },
  watch: {},
  computed: {},
  activated() {
    var data = JSON.parse(localStorage.getItem('campaignListGroup'))
    this.titleKey = localStorage.getItem('campaignList')
    this.title = data.map((item) => {
      return {
        key: item.campaignId ? item.campaignId + '' : item.key + '',
        tab: item.campaignName ? '广告计划：' + item.campaignName : '广告计划：' + item.tab,
      }
    })
    this.getDataList(localStorage.getItem('campaignList'))

    this.dataValue = this.columns.map((item) => {
      return item.dataIndex
    })
  },
}
</script>