<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" @change="onTabChange">
          <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 @click="showEdit = true" style="margin:0 0 15px 15px;">列表项筛选</a-button>
            <a-form layout="inline">
              <a-row class="image-list-heading vm-panel" style="padding: 8px 20px;">
                <a-col :md="7" :sm="8" style="display:flex">
                  <a-form-item label="广告组id">
                    <a-input placeholder="请输入广告组id" v-model="unitId"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :md="7" :sm="8" style="display:flex">
                  <a-form-item label="广告组名称">
                    <a-input placeholder="请输入广告组名称" v-model="unitName"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :md="4" :sm="8" style="display:flex">
                  <a-button type="primary" style="margin:0 10px" @click="searchLabel">查询</a-button>
                  <a-button type="primary" style="margin:0 10px" @click="searchRe">重置</a-button>
                </a-col>

              </a-row>
            </a-form>
            <div v-show="selectedRowKeys.length > 0">
              批量修改预算：
              <a-input-number :min="-1" :step="0.1" v-model="allMoney" style="width:150px" @fouse.stop />
              <a-button @click="editMoney" style="margin:0 15px 15px 15px" type="primary" :loading="loadingMoney">修改
              </a-button>

              批量修改出价：
              <a-select style="width: 120px" v-model="allPrice" @change="changePrice">
                <a-select-option value="1">比例</a-select-option>
                <a-select-option value="2">出价</a-select-option>
              </a-select>
              <a-input-number :min="-1" :step="0.1" v-model="allMoneyBidProportion" style="width:150px" @fouse.stop
                v-if="allPrice == '1'" />
              <div v-else style="display:inline-block">
                <a-input-number :min="0" :step="0.01" v-model="allMoneyBid" placeholder="请输入修改的出价" style="width:200px"
                  @fouse.stop />
                <a-input-number v-if="showDeepBid" class="else-table" :min="0" :step="0.01" v-model="deepConversionBid"
                  placeholder="请输入修改的深度转化出价" style="width:200px" @fouse.stop />
                <span class="else-table" v-if="allMoneyBid&&deepConversionBid">当前目标深度转化率为:
                  {{allMoneyBid&&deepConversionBid?((allMoneyBid/deepConversionBid)*100).toFixed(2)+'%':''}}</span>
              </div>

              <a-button @click="editMoneyBid" style="margin:0 15px 15px 15px" type="primary" :loading="loadingAllMoney">
                修改</a-button>

              批量操作：
              <a-select style="width: 120px" v-model="allType">
                <a-select-option value="1">启动</a-select-option>
                <a-select-option value="2">暂停</a-select-option>
                <a-select-option value="3">删除</a-select-option>
                <a-select-option value="4">修改</a-select-option>
                <a-select-option value="5">复制</a-select-option>
              </a-select>
              <a-button @click="editStatus" style="margin:0 0 15px 15px" type="primary" :loading="loadingState">确认
              </a-button>
            </div>
            <a-modal title="列表项筛选" v-model="showEdit" @ok="handleOk">
              <a-checkbox :indeterminate="indeterminate" @change="onCheckAllChange" :checked="checkAll">全选</a-checkbox>
              <a-checkbox-group :options="showList" v-model="dataValue" class="checked" />
            </a-modal>

            <a-table size="middle" :columns="columns" :dataSource="dataList" bordered :customRow="rowClick"
              :pagination="ipagination" :scroll="{ x: 2500 }" :rowSelection="{
                selectedRowKeys: selectedRowKeys,
                onChange: onSelectChange
              }" @change="sort" style="margin-top:30px" :loading="loadingList">
              <!-- getCheckboxProps: getCheckboxProps -->
              <span slot="unitName" slot-scope="text, record" :title="text">
                <div style="display:flex;justify-content: center;">
                  <a :title="text" @click="toDetail(record)">
                    {{ text }}</a>
                  <a-icon type="edit" @click.stop="editShowName(record)" style="margin-left:10px" class="count" />
                </div>
              </span>
              <span slot="action" slot-scope="text, record">
                <a-switch v-model="record.showSwich" @change="onChangeSwitch(record)" />
              </span>
              <span slot="deepConversionType" slot-scope="text">{{text|deepConversionType}}</span>
              <span slot="actionTwo" slot-scope="text, record">
                <a @click="editDetail(record)">编辑</a>
                <a-divider type="vertical" />
                <a @click="copyDetail(record)" :disabled="record.unitType+'' == '7'||record.unitType+'' == '5'">复制</a>
                <a-divider type="vertical" />
                <a @click="realTimedata(record)">查看实时数据</a>
                
              </span>
              <span slot="status" slot-scope="text">{{ text | status }}</span>
              <span slot="putStatus" slot-scope="text">{{ text | putStatus }}</span>
              <span slot="createChannel" slot-scope="text">{{ text | createChannel }}</span>
              <span slot="reviewDetail" slot-scope="text">
                <span :title="text"
                  style="margin:0;display:block;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">
                  {{ text }}</span>
              </span>
              <span slot="bidType" slot-scope="text, record">
                <!-- {{ text | bidType }} -->
                {{ record.ocpxActionType | ocpxActionType }}</span>
              <!-- <span slot="ocpxActionType" slot-scope="text">{{ text | ocpxActionType }}</span> -->

              <span slot="speed" slot-scope="text">{{ text | speed }}</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>
              <span slot="unitType" slot-scope="text">{{ text == 4 ? '自定义' : '程序化创意2.0' }}</span>
              <span slot="urlType" slot-scope="text">{{ text | urlType }}</span>

              <template slot="dayBudget" slot-scope="text, record">
                <div style="display:flex;justify-content: center;">
                  <span v-show="!record.edit" class="count">{{ text ? (text / 1000).toFixed(2) : '不限制预算' }}</span>
                  <a-input-number :min="0" :step="0.01" v-show="record.edit" v-model="record.elseMoney"
                    style="width:150px" @fouse.stop />
                  <a-icon :type="record.edit ? 'check' : 'edit'"
                    @click.stop=";(record.edit = !record.edit), editShow(record)" style="margin-left:10px"
                    class="count" />
                </div>
              </template>
              <template slot="bid" slot-scope="text, record">
                <!-- <span slot="bid" slot-scope="text, record">{{ text == 0 ? record.cpaBid / 1000 : text / 1000 }}</span> -->
                <div style="display:flex;justify-content: center;">
                  <span v-show="!record.editBid" class="count">{{
                    text == 0 ? record.cpaBid / 1000 : text / 1000
                  }}</span>
                  <a-input-number :min="0" :step="0.01" v-show="record.editBid" v-model="record.elseMoneyBid"
                    style="width:150px" @fouse.stop />
                  <a-icon :type="record.editBid ? 'check' : 'edit'"
                    @click.stop=";(record.editBid = !record.editBid), editShowBid(record)" style="margin-left:10px"
                    class="count" />
                </div>
              </template>
            </a-table>
          </a-tab-pane>
        </a-tabs>
      </a-card>
    </a-row>
    <editGroup ref="editGroup" @getList="getDataList" />
    <editGroupNew ref="editGroupNew" @getListNew="getDataList" />
    <a-modal title="批量修改" v-model="visibleEditAll" :width="900">
      <editAllGroup :populationData.sync="populationData" ref="population" />
      <template slot="footer">
        <a-button key="submit" type="primary" @click="handleSubmit">
          确定
        </a-button>
      </template>
    </a-modal>
    <a-modal v-model="visible" title="错误信息" onOk="handleOk" :footer="null">
      <div v-if="visibleData">
        修改条数：{{ visibleData.totalCount }} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;失败条数：{{ visibleData.failCount }}
        <div style="margin-top:20px">
          <p v-for="(item, index) of visibleData.failInfo" :key="index">
            <span>名称：{{ item.campaignName?item.campaignName:item.unitName }}</span><br />
            <span>错误信息：{{ item.message }}</span>
          </p>
        </div>
      </div>
    </a-modal>
    <a-modal title="批量复制" v-model="visibleBatch" :width="900">
      <div style="width:100%;display:flex;margin:20px 0">
        <span style="width:100px;line-height:32px">广告计划名称:</span>
        <a-select style="width:100%" v-model="campaignId" optionFilterProp="children" showSearch
          :filterOption="filterOption">
          <a-select-option v-for="item in campaignList" :key="item.value" :value="item.value+''">{{
            item.label
          }}</a-select-option>
        </a-select>
      </div>
      <template slot="footer">
        <a-button key="submit" type="primary" @click="handleSubmitBatch" :loading='loading'>
          确定
        </a-button>
      </template>
    </a-modal>
    <a-modal title="拷贝" v-model="visibleCopy" :width="900">
      <a-spin :spinning="copyLoading">
      <span style="color:red;display:block;width:100%;text-align:center;margin:10px">快手后台抽帧，程序化创意暂不支持被复制</span>
      <span style="color:red;display:block;width:100%;text-align:center;margin:10px">第三方人群包不能复制</span>
      <a-form :form="form">
        <a-form-item label="广告计划名称" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
          <a-select style="width:100%" optionFilterProp="children" showSearch :filterOption="filterOption" v-decorator="[
          'campaignId',
           {
            initialValue:campaignId
          }
        ]">
            <!-- initialValue -->
            <a-select-option v-for="item in campaignList" :key="item.value" :value="item.value+''">{{
            item.label
          }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="修改监测链接" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
          <a-radio-group buttonStyle="solid" v-decorator="['isUpdateTrackUrl',{initialValue: false}]">
            <a-radio-button :value="false">否</a-radio-button>
            <a-radio-button :value="true">是</a-radio-button>
          </a-radio-group>
        </a-form-item>
        <a-form-item label="监测链接" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }" v-if="getData('isUpdateTrackUrl')">
          <a-input v-model="clickTrackUrl" />
        </a-form-item>
        <a-form-item label="迭代次数" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
          <a-input-number v-decorator="[
          'createCount',
          {
            initialValue: 1
          }
        ]" :max="10" :min="1" style="width:100%">
          </a-input-number>
        </a-form-item>
        <a-form-item label="广告组名称" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }" v-if="getData('createCount')==1">
          <a-input v-decorator="[
          'unitName',
           { rules: [{ required: true, message: '请输入广告组名称' }],initialValue: unitNameInit} ]" />
        </a-form-item>
        <a-form-item label="广告组名称生成类型" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }" v-if="getData('createCount')>1">
          <a-radio-group buttonStyle="solid" v-decorator="[
          'createType',
           {
            initialValue:'1' } ]" @change="createUnitName">
            <a-radio-button value="1">系统生成</a-radio-button>
            <a-radio-button value="2">自定义</a-radio-button>
          </a-radio-group>
        </a-form-item>
        <a-form-item label="广告组名称输入" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
          v-if="getData('createCount')>1&&getData('createType')=='2'">
          <a-input v-for="(item,key) in unitNameList" :key="key" v-model="item.unitName" />
        </a-form-item>
        <a-form-item label="是否修改" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
          :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }" v-if="getData('createCount')>1">
          <a-radio-group buttonStyle="solid" v-model="editOk">
            <a-radio-button value="1">否</a-radio-button>
            <a-radio-button value="2">是</a-radio-button>
          </a-radio-group>
        </a-form-item>
      </a-form>
    </a-spin>

      <template slot="footer">
        <a-button key="submit" type="primary" @click="handleSubmitCopy"
          :disabled="getData('isUpdateTrackUrl')?clickTrackUrl==''?true:false:false" :loading='loading'>
          确定
        </a-button>
      </template>
    </a-modal>
    <a-modal v-model="nameEdit" title="广告组名称修改" :width="900" :maskClosable="false">
      <a-form-item label="广告组名称" :labelCol="{ lg: { span: 4 }, sm: { span: 7 } }"
        :wrapperCol="{ lg: { span: 17 }, sm: { span: 17 } }">
        <a-input placeholder="请输入" v-model="unitNameEdit" style="display: inline-block;" />
      </a-form-item>
      <template slot="footer">
        <a-button key="submit" type="primary" @click="unitEdit" :loading="loadingUnit">
          确定
        </a-button>
      </template>
    </a-modal>


      <!-- 实时数据 -->
    <a-modal v-model="realTimeVisiable" title="广告组实时数据"  width="80%" :maskClosable="false">
        <div class="optBody">
          <a-range-picker
            :disabled-date="disabledDate"
            format="YYYY-MM-DD"
            style="width: 250px;"
           @change="dateValueChange"
            v-model="dateValue"
          />
        </div>
        <div class="tableBox" style="margin-top:20px;min-height:400px">
          <a-table
                size="middle"
                :columns="realTimeColumn"
                :dataSource="realTimeData"
                bordered
                :pagination="false"
                :scroll="{ x: scrollX }"
                :loading="realTimeLoading"
                ref="accountTable"  
                style="word-break: break-all;min-height:350px"
              >

                <span slot="ctr" slot-scope="text">{{ text | toPercentage }}</span>
                <span slot="action_ratio" slot-scope="text">{{ text | toPercentage }}</span>
                <span slot="photo_click_ratio" slot-scope="text">{{ text | toPercentage }}</span>

                <span slot="charge" slot-scope="text">{{ text | decimalsHandle }}</span>
                <span slot="activationCost" slot-scope="text,records">{{ (records.activation/records.charge) | decimalsHandle }}</span>
                <span slot="event_register_cost" slot-scope="text">{{ text | decimalsHandle }}</span>
                <span slot="form_cost" slot-scope="text">{{ text | decimalsHandle }}</span>
                <span slot="event_order_paid_cost" slot-scope="text">{{ text | decimalsHandle }}</span>
               

                <span slot="show" slot-scope="text">{{ text | formatCurrency }}</span>
                <span slot="photo_click" slot-scope="text">{{ text | formatCurrency }}</span>
                <span slot="aclick" slot-scope="text">{{ text | formatCurrency }}</span>
                <span slot="bclick" slot-scope="text">{{ text | formatCurrency }}</span>
                <span slot="activation" slot-scope="text">{{ text | formatCurrency }}</span>
                <span slot="event_register" slot-scope="text">{{ text | formatCurrency }}</span>
                <span slot="form_count" slot-scope="text">{{ text | formatCurrency }}</span>
                <span slot="event_order_paid" slot-scope="text">{{ text | formatCurrency }}</span>

            </a-table>
        </div>
    </a-modal>
  </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 './editGroup'
  import editGroupNew from './editGroupNew'
  import editAllGroup from './editAllGroup'

  var columns = [{
      title: '开关',
      align: 'center',
      dataIndex: 'action',
      fixed: 'left',
      width: 100,
      scopedSlots: {
        customRender: 'action'
      }
    },

    {
      title: '广告组名称',
      align: 'center',
      dataIndex: 'unitName',
      scopedSlots: {
        customRender: 'unitName'
      },
      fixed: 'left',
      width: 250
    },
    {
      title: '操作',
      align: 'center',
      dataIndex: 'actionTwo',
      fixed: 'left',
      width: 220,
      scopedSlots: {
        customRender: 'actionTwo'
      }
    },
    {
      title: '预算',
      align: 'center',
      dataIndex: 'dayBudget',

      scopedSlots: {
        customRender: 'dayBudget'
      },
      width: 150,

    },
    {
      title: '出价',
      align: 'center',
      dataIndex: 'bid',
      scopedSlots: {
        customRender: 'bid'
      },
      width: 150,
    },
    {
      title: '深度转化类型',
      align: 'center',
      dataIndex: 'deepConversionType',
      scopedSlots: {
        customRender: 'deepConversionType'
      },
      filters: [{
          text: '未使用',
          value: '0'
        },
        {
          text: '付费',
          value: '3'
        }, {
          text: '次日留存',
          value: '7'
        }, {
          text: '完件',
          value: '10'
        }, {
          text: '授信',
          value: '11'
        }, {
          text: '添加购物车',
          value: '13'
        }, {
          text: '提交订单',
          value: '14'
        }, {
          text: '购买联盟广告无门槛要求',
          value: '15'
        },
      ],
      onFilter: (value, record) =>
        record.deepConversionType
        .toString()
        .toLowerCase()
        .includes(value.toLowerCase()),
    },
    {
      title: '广告组状态',
      align: 'center',
      dataIndex: 'status',
      scopedSlots: {
        customRender: 'status'
      }
    },
    {
      title: '投放状态',
      align: 'center',
      dataIndex: 'putStatus',
      scopedSlots: {
        customRender: 'putStatus'
      },
      filters: [{
          text: '投放中',
          value: '1'
        },
        {
          text: '暂停',
          value: '2'
        }
      ],
      onFilter: (value, record) =>
        record.putStatus
        .toString()
        .toLowerCase()
        .includes(value.toLowerCase()),
    },
    {
      title: '创建渠道',
      align: 'center',
      dataIndex: 'createChannel',
      filters: [{
          text: '投放后台创建',
          value: '0'
        },
        {
          text: '汇创助手创建',
          value: '1'
        }
      ],
      onFilter: (value, record) =>
        record.createChannel
        .toString()
        .toLowerCase()
        .includes(value.toLowerCase()),
      scopedSlots: {
        customRender: 'createChannel'
      }
    },
    {
      title: '审核拒绝理由',
      align: 'center',
      dataIndex: 'reviewDetail',
      scopedSlots: {
        customRender: 'reviewDetail'
      },
      width: 300
    },
    {
      title: '出价类型',
      align: 'center',
      dataIndex: 'bidType',
      filters: [{
          text: '封面点击',
          value: '0'
        },
        {
          text: '行为数',
          value: '2'
        },
        //   { text: '曝光', value: '10' },
        {
          text: '点击',
          value: '11'
        },
        //   { text: '下载完成', value: '31' },
        {
          text: '提交线索',
          value: '53'
        },
        {
          text: '激活',
          value: '180'
        }
      ],
      onFilter: (value, record) =>
        record.ocpxActionType
        .toString()
        .toLowerCase()
        .includes(value.toLowerCase()),
      scopedSlots: {
        customRender: 'bidType'
      }
    },
    //   {
    //     title: 'OCPC出价',
    //     align: 'center',
    //     dataIndex: 'cpaBid',
    //     colSpan: 1
    //   },
    {
      title: '投放方式',
      align: 'center',
      dataIndex: 'speed',

      scopedSlots: {
        customRender: 'speed'
      }
    },
    {
      title: '投放开始时间',
      align: 'center',
      dataIndex: 'beginTime',
      colSpan: 1
    },
    //   {
    //     title: '投放结束时间',
    //     align: 'center',
    //     dataIndex: 'endTime',
    //     colSpan: 1
    //   },
    {
      title: '广告位',
      align: 'center',
      dataIndex: 'sceneId',

      scopedSlots: {
        customRender: 'sceneId'
      }
    },
    {
      title: '创意展现方式',
      align: 'center',
      dataIndex: 'showMode',

      scopedSlots: {
        customRender: 'showMode'
      }
    },
    {
      title: '创意制作方式',
      align: 'center',
      dataIndex: 'unitType',

      scopedSlots: {
        customRender: 'unitType'
      }
    },
    // {
    //   title: '落地页链接',
    //   align: 'center',
    //   dataIndex: 'url',

    //   scopedSlots: {
    //     customRender: 'url'
    //   }
    // }
  ]

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('advertisingGroupKey'),
        createCount: 1,
        unitNameList: [],
        form: this.$form.createForm(this),
        campaignList: [],
        showEdit: false,
        visibleCopy: false,
        copyLoading:true,
        loading: false,
        columns,
        columnsElse: columns,
        dataList: [],
        selectedRowKeys: [],
        selectedRowKeysValue: [],
        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,
        showList: 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]
      },
      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',
          20: 'eCPC'
        }
        return data[sta]
      },
      ocpxActionType(sta) {
        var data = {
          0: '封面点击',
          2: '行为数',
          10: '曝光',
          11: '点击',
          31: '下载完成',
          53: '提交线索',
          180: '激活'
        }
        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)
      },
      // getCheckboxProps(record) {
      //   return {
      //     props: {
      //       defaultChecked: this.selectedRowKeys.includes(record.unitId)
      //     }
      //   }
      // },
      unitEdit(e) {
        this.loadingUnit = true
        var params = {}
        params.accountId = localStorage.getItem("accountId")
        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('advertisingGroupKey'))
          } 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', '/account/advertisingGroup')
        } else {
          localStorage.setItem('advertisingGroup', JSON.stringify(this.title))
          localStorage.setItem('advertisingGroupKey', this.titleKey)
          this.getDataList(activeKey)
        }
      },
      editDetail(item) {
        this.$refs.editGroup.handleOk(item, 'edit')
      },
      copyDetail(item) {

        this.clickTrackUrl = ''
        this.campaignId = localStorage.getItem('advertisingGroupKey')
        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
            }
          if(this.campaignType=='2'||this.campaignType==2){
            getAction('/kuaishou/batch/getIsActivate', {
              accountId: localStorage.getItem('accountId'),
              appId:this.copyData.appId,
              campaignType:2
            }).then(res => {
              if (res.success) {
                this.allForm.groupTypeData = res.result
              }
            })
          }else{
            getAction('/kuaishou/batch/getIsActivate', {
              accountId: localStorage.getItem('accountId'),
              campaignType:this.campaignType
            }).then(res => {
              if (res.success) {
                this.allForm.groupTypeData = res.result
              }
            })
          }
            this.copyLoading = false
          }

        })
        
       
      },
      toDetail(record) {
        // 点击改行时要做的事情
        localStorage.setItem('originalityKey', record.unitId)
        localStorage.setItem('campaignId', record.campaignId)
        if (localStorage.getItem('originality')) {
          var dataElse = JSON.parse(localStorage.getItem('originality'))
          // 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('originality', JSON.stringify(dataElse))
        } else {
          var data = [record]
          localStorage.setItem('originality', JSON.stringify(data))
        }
        this.$router.replace({
          path: '/account/originality'
        })
      },
      ...mapGetters(['nickname', 'avatar', 'userInfo']),
      onChangeSwitch(item) {
        console.log(item)
        var params = {}
        params.accountId = localStorage.getItem('accountId')
        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('accountId')
            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
        }
        console.log(item)
      },
      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('accountId')
            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
        }
      },
      editStatus() {
        this.loadingState = true
        if (this.allType == '4') {
          this.loadingState = false
          this.visibleEditAll = true
        } else if (this.allType == '5') {
          this.getCampaignList()
          this.campaignId = localStorage.getItem('advertisingGroupKey')
          this.visibleBatch = true
          this.loadingState = false
        } else {

          var params = {}
          params.accountId = localStorage.getItem('accountId')
          params.putStatus = this.allType
          params.userId = this.userInfo().id
          params.unitIds = this.selectedRowKeysValue
          postAction('/kuaishou/batch/batchUpdateUnitStatus', params).then(res => {
            if (res.result.failCount > 0) {
              this.visible = true
              this.visibleData = res.result
              this.loadingState = false
            } else {
              this.getDataList(localStorage.getItem('advertisingGroupKey'))
              this.$message.success('批量修改成功')
              this.allType = '1'
              this.selectedRowKeysValue = []
              this.selectedRowKeys = []
              this.loadingState = false
            }

          })
        }
      },
      editMoney() {
        this.loadingMoney = true
        var params = {}
        params.accountId = localStorage.getItem('accountId')
        params.proportion = this.allMoney
        params.userId = this.userInfo().id
        params.unitIds = this.selectedRowKeysValue
        postAction('/kuaishou/batch/batchUpdateUnitBudgetByProportion', params).then(res => {
          console.log(res)
          if (res.success) {
            this.loadingMoney = false
            if (res.result.failCount > 0) {
              this.visible = true
              this.visibleData = res.result
              this.getDataList(localStorage.getItem('advertisingGroupKey'))
            } else {
              this.allMoney = 1.2
              this.$message.success('批量修改成功')
              this.getDataList(localStorage.getItem('advertisingGroupKey'))
              this.selectedRowKeysValue = []
              this.selectedRowKeys = []
            }
          } else {
            this.loadingMoney = false
            this.$message.error(res.message)
          }
        })
      },

      changePrice() {
        if (this.allPrice == '2') {
          if (this.selectedRowKeys.length > 0) {
            var arr = []
            for (let i = 0; i < this.dataList.length; i++) {
              for (let j = 0; j < this.selectedRowKeysValue.length; j++) {
                if (this.dataList[i].unitId == this.selectedRowKeysValue[j]) {
                  if (this.dataList[i].deepConversionType > 0) {
                    arr.push(true)
                  } else {
                    arr = []
                  }
                }
              }

            }
            if (arr.length > 0) {
              this.showDeepBid = true
            } else {
              this.showDeepBid = false
            }
          }
        }
      },
      editMoneyBid() {
        this.loadingAllMoney = true
        if (this.allPrice == '2') {


          if (this.allMoneyBid < 1 || this.allMoneyBid > this.maxBid) {
            this.$message.error('不得低于1元，不得高于项目最高出价' + this.maxBid + '元')
            this.loadingAllMoney = false
            return
          }
          var params = {}
          params.accountId = localStorage.getItem('accountId')
          params.bid = this.allMoneyBid * 1000
          params.deepConversionBid = this.deepConversionBid ? this.deepConversionBid * 1000 : null
          params.userId = this.userInfo().id
          params.unitIds = this.selectedRowKeysValue
          postAction('/kuaishou/batch/batchUpdateUnitBid', params).then(res => {
            if (res.success) {
              if (res.result.failCount > 0) {
                this.visible = true
                this.visibleData = res.result
                this.getDataList(localStorage.getItem('advertisingGroupKey'))
                this.loadingAllMoney = false
              } else {
                this.allMoneyBid = null
                this.$message.success('批量修改成功')
                this.getDataList(localStorage.getItem('advertisingGroupKey'))
                this.selectedRowKeysValue = []
                this.selectedRowKeys = []
                this.loadingAllMoney = false
              }
            } else {
              this.$message.error(res.message)
              this.loadingAllMoney = false
            }
          })
        } else if (this.allPrice == '1') {
          var params = {}
          params.accountId = localStorage.getItem('accountId')
          params.proportion = this.allMoneyBidProportion
          params.userId = this.userInfo().id
          params.unitIds = this.selectedRowKeysValue
          postAction('/kuaishou/batch/batchUpdateUnitBidByProportion', params).then(res => {
            if (res.success) {
              if (res.result.failCount > 0) {
                this.visible = true
                this.visibleData = res.result
                this.getDataList(localStorage.getItem('advertisingGroupKey'))
                this.loadingAllMoney = false
              } else {
                this.allMoneyBidProportion = 1.2
                this.$message.success('批量修改成功')
                this.getDataList(localStorage.getItem('advertisingGroupKey'))
                this.selectedRowKeysValue = []
                this.selectedRowKeys = []
                this.loadingAllMoney = false
              }
            } else {
              this.$message.error(res.message)
              this.loadingAllMoney = false
            }
          })
        }
      },
      handleOk(e) {
        console.log(e)
        this.showEdit = false
        this.onChange(this.dataValue)
      },
      onCheckAllChange(e) {
        Object.assign(this, {
          dataValue: e.target.checked ?
            this.showList.map(item => {
              return item.value
            }) : [],
          indeterminate: false,
          checkAll: e.target.checked
        })
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRowKeysValue = selectionRows.map(item => {
          return item.unitId
        })
        //    this.selectedRowKeysValue.length > 0 ? this.selectedRowKeysValue :
      },
      onChange(checkedValues) {
        var data = []
        for (let j = 0; j < this.columnsElse.length; j++) {
          if (checkedValues.indexOf(this.columnsElse[j].dataIndex) != -1) {
            data.push(this.columnsElse[j])
          } else {
            //   this.columns[j].colSpan = 0
          }
        }
        this.columns = data
      },
      titleArr() {
        var data = JSON.parse(localStorage.getItem('advertisingGroup'))
        var one = data.filter(item => {
          return item.campaignId == localStorage.getItem('advertisingGroupKey')
        })
        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('advertisingGroupKey'))
      },
      searchRe() {
        this.unitId = ''
        this.unitName = ''
        this.getDataList(localStorage.getItem('advertisingGroupKey'))
      },
      onTabChange(key) {
        this.ipagination.current = 1
        this.titleKey = key
        this.selectedRowKeys = []
        localStorage.setItem('advertisingGroupKey', key)
        this.getDataList(key)
      },
      getDataList(id) {
        this.loadingList = true
        this.dataList = []
        var params = {}
        params.campaignId = id
        params.accountId = localStorage.getItem('accountId')
        params.pageNo = this.ipagination.current
        params.pageSize = this.ipagination.pageSize
        params.unitId = this.unitId
        params.unitName = this.unitName
        getAction('/kuaishou/batch/getUnitList', 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('step', 1)
          localStorage.setItem('campaignId', this.titleKey)
          this.$router.replace({
            path: '/account/stepForm'
          })
        }
      },
      handleSubmitBatch(e) {
        this.loading = true
        var params = {}
        params.campaignId = localStorage.getItem('advertisingGroupKey')
        params.unitIds = this.selectedRowKeysValue
        params.accountId = localStorage.getItem('accountId')
        params.copyToCampaignId = this.campaignId
        postAction('/kuaishou/batch/batchCopyUnit', params).then(res => {
          console.log(res)
          if (res.success) {
            if (res.result.failInfo.length > 0) {
              //   for (let i = 0; i < res.result.failInfo.length; i++) {
              this.$message.error("复制广告组出错")
              //   }

            } else {
              this.loading = false
              this.visibleBatch = false
              this.selectedRowKeys = []
              this.getDataList(localStorage.getItem('advertisingGroupKey'))
            }
          } else {
            this.$message.error(res.message)
          }

        })
      },
      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('advertisingGroupKey'))
                  }, 3000)
                  // this.getDataList(localStorage.getItem('advertisingGroupKey'))
                }
              })
            } 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('advertisingGroupKey'))
                  }, 3000)

                  // this.getDataList(localStorage.getItem('advertisingGroupKey'))
                }
              })
            }
          } 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)

            }
          }
        }


      },
      handleSubmit(e) {
        //   this.$refs.population.handleSubmit()
        this.$refs.population.handleSubmit()

        var params = {
          ...this.populationData
        }
        params.userId = this.userInfo().id
        params.unitIds = this.selectedRowKeysValue
        params.accountId = localStorage.getItem('accountId')
        postAction('/kuaishou/batch/batchUpdateUnit', params).then(res => {
          if (res.success) {
            if (res.result.failCount > 0) {
              this.visibleEditAll = false
              this.visible = true
              this.visibleData = res.result
              this.getDataList(localStorage.getItem('advertisingGroupKey'))
            } else {
              this.visibleEditAll = false
              this.getDataList(localStorage.getItem('advertisingGroupKey'))
              this.$message.success('批量修改成功')
              this.allMoneyBidProportion = 1.2
              this.selectedRowKeysValue = []
              this.selectedRowKeys = []
            }
          } else {
            this.$message.error(res.message)
          }
        })
      },
      getCampaignList() {
        var params = {}
        params.accountId = localStorage.getItem('accountId')
        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('advertisingGroupKey')
            })[0].campaignType

          }
        })
      },
    },
    watch: {
      dataValue(n, o) {
        this.indeterminate = !!this.dataValue.length && this.dataValue.length < this.showList.length
        this.checkAll = this.dataValue.length === this.showList.length
      },
    },
    computed: {},
    activated() {
      var data = JSON.parse(localStorage.getItem('advertisingGroup'))
      this.titleKey = localStorage.getItem('advertisingGroupKey')
      this.title = data.map(item => {
        return {
          key: item.campaignId ? item.campaignId + '' : item.key + '',
          tab: item.campaignName ? '广告计划：' + item.campaignName : '广告计划：' + item.tab
        }
      })
      this.getDataList(localStorage.getItem('advertisingGroupKey'))

      this.showList = this.columns.map(item => {
        return {
          label: item.title,
          value: item.dataIndex,

        }
      })
      this.dataValue = this.columns.map(item => {
        return item.dataIndex
      })
      getAction('/kuaishou/batch/getProjectMaxBid', {
        accountId: localStorage.getItem('accountId')
      }).then(res => {
        if (res.success) {
          this.maxBid = res.result / 1000
        }
      })
    }
  }
</script>