<style lang="scss">
.display-none-selset {
  display: none !important;
}
.chouzhen span {
  display: inline-block;
}

.check-video .ant-tabs-nav-container {
  text-align: center;
  font-size: 20px;
}

.step3-image {
  span {
    padding: 0;
  }

  .ant-checkbox {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
  }
}

.step3-modal {
  .ant-checkbox {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 100;
  }
}

.onlny-click-track {
  .ant-list-item-content {
    width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
.sticker-styles .ant-radio-wrapper {
  margin-right: 0;
}
</style>
<style scoped lang="scss">
.actor-photo-list {
  display: flex;
  padding-left: 0;

  li {
    width: 20%;
    margin: 10px;
    position: relative;
    height: 380px;
    border: 1px solid #f2f2f2;
    list-style: none;

    img,
    video {
      width: 100%;
    }
  }
}

.chouzhen {
  border-style: solid;
  border-width: 1px;
  border-color: #e4e4e4;
  width: calc(20% - 10px);
  padding: 10px;
  margin-right: 10px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  background: #fff;
  position: relative;
  z-index: 99;
  float: left;
}

li.chouzhen.first:before {
  font-size: 12px;
  content: '首帧';
  position: absolute;
  top: 7px;
  left: 5px;
  width: 36px;
  height: 20px;
  color: rgb(255, 255, 255);
  line-height: 20px;
  text-align: center;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 2px;
  z-index: 1000;
}

.actor-photo-list {
  display: flex;
  padding-left: 0;

  li {
    width: 25%;
    margin: 10px;
    position: relative;
    height: 250px;
    border: 1px solid #f2f2f2;
    list-style: none;
    img,
    video {
      width: 100%;
      margin-top: auto;
      margin-bottom: auto;
      top: 0;
      bottom: 0;
      position: absolute;
      max-height: 250px;
    }
  }
}
</style>
<style>
.create-creative .ant-form-item-control {
  line-height: inherit;
}
.create-creative .ant-tabs-bar {
  width: 50%;
  margin: auto;
  margin-bottom: 16px;
  border-bottom: 1px solid #e8e8e8;
  outline: none;
  -webkit-transition: padding 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: padding 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}
.create-creative .ant-tabs.ant-tabs-card .ant-tabs-card-bar .ant-tabs-tab-active {
  color: #fff;
  background: #1890ff !important;
  border-color: #1890ff !important;
  border-bottom: 1px solid #1890ff !important;
}
.create-creative .ant-tabs.ant-tabs-card .ant-tabs-card-bar .ant-tabs-tab {
  height: 40px;
  margin: 0;
  margin-right: 2px;
  padding: 0 16px;
  line-height: 38px;
  background: #fafafa;
  border: 1px solid #e8e8e8 !important;
  border-radius: 4px 4px 0 0 !important;
  -webkit-transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}
.create-creative .ant-form-item-control-wrapper {
  line-height: 3;
}
</style>
<template>
  <a-card :body-style="{ padding: '24px 32px' }" :bordered="false" class="create-creative">
    <a-form-model ref="createCreate" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
      <a-tabs type="card" @change="changeAccount">
        <a-tab-pane
          :key="pane.unitId + '@' + pane.accountId + '@' + pane.campaignId"
          :tab="'组:' + pane.unitName"
          v-for="(pane, index) of form.accountArr"
        >
          <div style="margin: auto; width: 50%">
            <a-form-model-item label="账户ID" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-input v-model="pane.accountId" disabled style="width: 300px"></a-input>
            </a-form-model-item>
          </div>
          <a-layout style="margin: auto; width: 50%">
            <a-layout-content style="padding: 10px">
              <a-row>
                <a-col :span="24" v-for="(item, photoIndex) of pane.photoArr" :key="photoIndex">
                  <a-card title :ref="item">
                    <a-icon
                      type="close"
                      style="float: right; cursor: pointer"
                      @click="deleteCreative(photoIndex, pane)"
                    />
                    <div style="clear: both"></div>
                    <div v-if="item.creativeMaterialType != '4'">
                      <a-form-model-item label="素材类型">
                        <a-radio-group buttonStyle="solid" v-model="item.creativeMaterialType">
                          <a-radio-button value="1">竖版视频</a-radio-button>
                          <a-radio-button value="2">横版视频</a-radio-button>
                          <!-- <a-radio-button value="4" v-if="JSON.parse(pane.sceneId).indexOf(7)>0">便利贴创意</a-radio-button> -->
                        </a-radio-group>
                      </a-form-model-item>
                      <a-form-model-item label="视频素材">
                        <a @click="getVideoList('video', item.creativeMaterialType, pane.accountId, photoIndex, index)"
                          >选择视频</a
                        >
                        <a @click="uploadVideo(index, photoIndex, item, pane.accountId)" style="margin-left: 10px"
                          >上传视频</a
                        >
                        <br />
                        <video
                          :src="item.videoList.url"
                          controls="controls"
                          style="width: 25%"
                          v-if="item.videoList"
                        ></video>
                      </a-form-model-item>
                      <a-form-model-item v-bind="formItemLayout" v-if="item.imageUrlList.length > 0">
                        <div class="downLoad" style="overflow: auto">
                          <ul
                            class="actor-photo-list step3-image"
                            :style="{
                              width: item.imageUrlList.length > 4 ? 25 * item.imageUrlList.length + '%' : '100%',
                            }"
                          >
                            <a-checkbox-group
                              v-model="item.imageToken"
                              style="width: 100%; display: flex; paddinlseg-left: 0"
                              @change="onChangeCheckImage"
                            >
                              <li v-for="(item, indexElse) of item.imageUrlList" :key="indexElse">
                                <a-checkbox :value="item.code" style="height: 100%; width: 100%">
                                  <img class="video" :src="item.url" />
                                </a-checkbox>
                              </li>
                            </a-checkbox-group>
                          </ul>
                        </div>
                      </a-form-model-item>
                      <a-form-model-item label="封面素材">
                        <a @click="getVideoList('image', item.creativeMaterialType, pane.accountId, photoIndex, index)"
                          >选择封面</a
                        >
                        <a
                          @click="uploadImages(index, photoIndex, item.creativeMaterialType, pane.accountId)"
                          style="margin-left: 10px"
                          >上传封面</a
                        >
                        <a @click="showImages(index, photoIndex)" v-if="item.chouzhenShow" style="margin-left: 10px"
                          >推荐封面</a
                        >
                        <br />
                        <span
                          v-for="(item, deleteIndex) of item.imageList"
                          style="position: relative"
                          :key="deleteIndex"
                        >
                          <img :src="item.url" style="width: 18%; margin: 1%" :key="item.url" />
                          <a-icon
                            type="close-circle"
                            @click="deleteData(index, photoIndex, deleteIndex)"
                            style="position: absolute; right: 0px"
                          />
                        </span>
                      </a-form-model-item>

                      <a-form-model-item
                        label="封面贴纸"
                        v-if="item.creativeMaterialType != '4' && stickerStyles.length > 0"
                      >
                        <a @click="getCoverUrl(index, photoIndex, item)">封面贴纸</a>
                        <br />
                        <span style="position: relative; display: block; width: 25%" v-if="item.overlayType">
                          <img :src="showStickerStyles(item.overlayType)" style="width: 100%" />
                          <a-icon
                            type="close-circle"
                            @click="deleteCover(index, photoIndex)"
                            style="position: absolute; right: -10px; top: -10px"
                          />
                        </span>
                      </a-form-model-item>
                      <a-form-model-item label="贴纸广告语" v-if="item.overlayType">
                        <a-textarea
                          placeholder="请输入贴纸广告语"
                          v-model.trim="item.stickerTitle"
                          :autosize="{ minRows: 2, maxRows: 2 }"
                          :max-length="14"
                        ></a-textarea>
                        <p
                          style="
                            font-size: 12px;
                            color: #b6bbc7;
                            letter-spacing: 0.3px;
                            text-align: right;
                            line-height: 20px;
                            position: absolute;
                            bottom: 0;
                            right: 6px;
                            width: 100%;
                            margin-bottom: 0;
                          "
                        >
                          {{ item.stickerTitle.length + '/14' }}
                        </p>
                      </a-form-model-item>
                    </div>
                    <div v-else-if="item.creativeMaterialType == '4' && pane.sceneId.indexOf(3) >= 0">
                      <a-form-model-item label="便利贴广告">
                        <a @click="getVideoList('image', item.creativeMaterialType, pane.accountId, photoIndex, index)"
                          >选择封面</a
                        >
                        <a
                          @click="
                            uploadImages(index, photoIndex, item.creativeMaterialType, pane.accountId, 'postAdList')
                          "
                          style="margin-left: 10px"
                          >上传封面</a
                        >
                        <br />
                        <span v-for="(item, deleteIndex) of item.imageList" style="position: relative">
                          <img :src="item.url" style="width: 18%; margin: 1%" :key="item.url" />
                          <a-icon
                            type="close-circle"
                            @click="deleteData(index, photoIndex, deleteIndex)"
                            style="position: absolute; right: 0px"
                          />
                        </span>
                      </a-form-model-item>

                      <a-form-item label="短广告语">
                        <a-textarea
                          class="rending"
                          placeholder="请输入短广告语"
                          v-model.trim="item.shortSlogan"
                          :autosize="{ minRows: 2, maxRows: 6 }"
                          :maxLength="8"
                        ></a-textarea>
                        <span v-if="item.shortSlogan.length > 8" style="color: red">短广告语长度不能超过30个字符</span>
                      </a-form-item>
                    </div>

                    <a-form-model-item
                      label="广告语"
                      :prop="'accountArr.' + index + '.photoArr.' + photoIndex + '.description'"
                      :rules="{
                        required: true,
                        message: '广告语必填，并且小于30个字符',
                        trigger: 'blur',
                      }"
                    >
                      <a @click="showTitle(index, photoIndex)">推荐广告语</a>
                      <div
                        class="step4-else"
                        style="display: inline-block; position: relative; border-radius: 4px; width: 100%"
                      >
                        <a-textarea
                          class="rending"
                          placeholder="请输入广告语"
                          v-model.trim="item.description"
                          :autosize="{ minRows: 2, maxRows: 6 }"
                          :max-length="30"
                        ></a-textarea>
                        <p
                          style="
                            font-size: 12px;
                            color: #b6bbc7;
                            letter-spacing: 0.3px;
                            text-align: right;
                            line-height: 20px;
                            position: absolute;
                            bottom: 10px;
                            right: 6px;
                            width: 100%;
                            margin-bottom: 0;
                          "
                        >
                          {{ item.description.length + '/30' }}
                        </p>
                      </div>
                      <br />
                      <a @click="cunTitle(index, photoIndex, pane.accountId)">收藏</a>
                      <a @click="showCunTitle(index, photoIndex, pane.accountId)" style="margin-left: 10px">收藏列表</a>
                      <!-- <a-tag
                        v-for="(itemTag, indexTag) of tags"
                        :key="indexTag"
                        @click="getChange(item, itemTag, index)"
                        >{{ itemTag.name }}</a-tag
                      > -->
                    </a-form-model-item>
                    <a-form-model-item
                      label="创意标题"
                      :prop="'accountArr.' + index + '.photoArr.' + photoIndex + '.creativeName'"
                      :rules="{
                        required: true,
                        message: '创意标题必填',
                        trigger: 'blur',
                      }"
                    >
                      <a-input v-model="item.creativeName"></a-input>
                    </a-form-model-item>
                  </a-card>
                </a-col>
              </a-row>
              <div :style="{ marginBottom: '16px' }">
                <a-button @click="addCreative('all', pane)"> 添加创意</a-button>
                <a-button @click="addCreative('else', pane)" v-if="pane.sceneId.indexOf(3) >= 0">
                  添加便利贴创意</a-button
                >
              </div>
            </a-layout-content>
          </a-layout>
          <div style="margin: auto; width: 50%">
            <a-form-model-item label="创意分类">
              <a-cascader
                :options="createOptions"
                v-model="pane.creativeCategory"
                :fieldNames="fieldNames"
                placeholder="请选择创意分类"
              />
            </a-form-model-item>
            <!-- v-decorator="['creativeTag', { validator: creativeTagValid }]" -->
            <a-form-model-item label="创意标签">
              <a-select
                mode="tags"
                style="width: 100%"
                placeholder="按回车生成标签"
                v-model="pane.creativeTag"
                dropdownClassName="display-none-selset"
                :token-separators="[',', ' ', '，']"
              >
              </a-select>
              <span v-if="pane.creativeTag && pane.creativeTag.length > 10" style="color: red"
                >创意标签最多填写10个，请删减</span
              >
              <br />
              <a-popconfirm @confirm="getInfo(pane, pane.accountId)">
                <div slot="title">
                  <div>
                    分类名称:
                    <a-input placeholder="请输入" v-model="tagName" style="display: inline-block; width: 300px" />
                  </div>
                </div>
                <!-- <a-button slot="okText" type="primary" :disabled="refuseReason == ''">确定</a-button> -->
                <!-- <a @click="setData(record)">复制</a> -->
                <a style="margin-right: 10px" :disabled="pane.creativeTag.length == 0">收藏</a>
                <!-- @click="collection('creativeTag')" -->
              </a-popconfirm>

              <a @click="showCunTag('creativeTag', pane.accountId, index)">收藏列表</a>
            </a-form-model-item>
            <!-- v-decorator="['actionBarText', { rules: [{ required: true, message: '行动号召按钮文案' }] }]" -->
            <a-form-model-item
              label="行动号召"
              :prop="'accountArr.' + index + '.actionBarText'"
              :rules="{
                required: true,
                message: '行动号召按钮文案',
                trigger: 'change',
              }"
            >
              <a-select
                v-model="pane.actionBarText"
                showSearch
                allowClear
                placeholder="选择行动号召按钮文案"
                optionFilterProp="children"
                :filterOption="filterOption"
              >
                <a-select-option v-for="appModel in appList" :key="appModel.id" :value="appModel.actionBarText">
                  {{ appModel.actionBarText }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
            <a-form-model-item label="下载详情" v-if="showSite">
              <a-select
                v-model="pane.siteId"
                showSearch
                allowClear
                placeholder="选择应用下载详情页"
                optionFilterProp="children"
                :filterOption="filterOption"
              >
                <a-select-option v-for="appModel in siteList" :key="appModel.siteId" :value="appModel.siteId">
                  {{ appModel.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>

            <a-form-model-item
              label="监测链接"
              :prop="'accountArr.' + index + '.clickTrackUrl'"
              :rules="{
                required: pane.bidType == 6,
                message: '请输入第三方检测链接',
                trigger: 'blur',
              }"
            >
              <a-input v-model="pane.clickTrackUrl" placeholder="请输入第三方检测链接"> </a-input>
              <!-- <a
                        v-if="item.clickTrackUrl != ''"
                        @click="
                          clickTrackUrlShow = true
                          accountId = pane.accountId
                        "
                        style="margin-right: 10px"
                        >收藏监测链接</a
                      >
                      <a @click="getClickTrackUrlList()">监测链接列表</a> -->
            </a-form-model-item>
          </div>
        </a-tab-pane>
      </a-tabs>
    </a-form-model>

    <a-form-model :wrapperCol="{ span: 24 }" style="text-align: center">
      <a-button type="primary" @click="handleSubmit('createCreate')" :loading="submitFormLoading">提交</a-button>
    </a-form-model>

    <!-- 封面选择 -->
    <checkMatemal ref="check" @showVideo="showData"></checkMatemal>
    <!-- 视频选择 -->
    <a-modal :maskClosable="false" title="选择素材" v-model="visibleMatemal" @ok="handleOkShow" :width="1000">
      <a-tabs type="card" @change="callback" v-model="active" class="check-video">
        <a-tab-pane :tab="item.label" v-for="item of tab" :key="item.value">
          <a-row :gutter="24">
            <a-col :span="12">
              <a-form-item label="日期选择" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-range-picker name="buildTime" v-model="time" />
              </a-form-item>
            </a-col>
            <!-- <a-col :span="12">
              <a-form-item label="筛选条件" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-select v-model="orderBy" style="width: 100%">
                  <a-select-option value="time"> 按时间排序 </a-select-option>
                  <a-select-option value="cost"> 按消耗排序</a-select-option>
                </a-select>
              </a-form-item>
            </a-col> -->
          </a-row>

          <ul v-if="dataSource.length > 0" style="overflow: auto; padding-left: 0">
            <a-checkbox-group v-model="checkVideo" @change="onChangeVideo" style="width: 100%">
              <li v-for="(item, index) of dataSource" :key="index" class="chouzhen" style="height: 400px">
                <!-- <video class="video" :src="item.url" controls="controls" style="width:100%">
                  您的浏览器不支持 video 标签。
                </video> -->
                <a-checkbox :value="item" style="width: 100%; position: absolute; z-index: 100; right: 0; top: 0">
                  <img :src="item.coverUrl" alt="" style="width: 100%; margin-bottom: 30px" />
                  <div style="width: 100%; text-align: center">
                    {{ item.statDate ? '时间：' + item.statDate.split(' ')[0] : '消耗：' + item.charge }}
                  </div>
                </a-checkbox>
                <a @click="matemalVideo(item, index)" style="position: absolute; z-index: 100; right: 56px; bottom: 5px"
                  >查看视频</a
                >
              </li>
            </a-checkbox-group>
          </ul>
          <div v-else style="width: 100%; height: 400px; display: flex; justify-content: center; align-items: center">
            <img
              src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1575627350102&di=02972956f2243933bffc0d85099adbfe&imgtype=jpg&src=http%3A%2F%2Fimg0.imgtn.bdimg.com%2Fit%2Fu%3D1095310825%2C1528244349%26fm%3D214%26gp%3D0.jpg"
              alt=""
              v-if="!loadingVideoList"
            />
            <img v-else src="@/views/modules/material/loading.gif" />
          </div>
        </a-tab-pane>
        <a-button slot="tabBarExtraContent" type="primary" @click="tongbu()" :loading="tongbuLoading">
          刷新素材</a-button
        >
      </a-tabs>
      <div style="text-align: right">
        <a-pagination
          size="small"
          :showTotal="ipagination.showTotal"
          style="float: right"
          v-if="dataSource.length > 0"
          showQuickJumper
          :pageSize.sync="ipagination.pageSize"
          :total="ipagination.total"
          v-model="ipagination.current"
          @change="getDataSource"
        />
      </div>
    </a-modal>
    <!-- 视频预览 -->
    <a-modal title="查看视频" v-model="visibleVideo" :width="400" :footer="null">
      <video class="video" :src="videoUrlShow" controls="controls" style="width: 100%">
        您的浏览器不支持 video 标签。
      </video>
    </a-modal>
    <!-- 视频上传 -->
    <a-modal
      :maskClosable="false"
      title="视频上传"
      @cancel="closeVideo"
      @afterClose="closeVideo"
      v-model="addVideoVisible"
    >
      <template slot="footer">
        <a-button key="back" @click="closeVideo">取消</a-button>
        <a-button key="submit" type="primary" @click="handleOkVideo" :loading="loadingVideo"> 确定 </a-button>
      </template>
      <a-form-item label="" class="add-image-material">
        <uploadFile
          v-if="addVideoVisible"
          :checkFile="file"
          :value.sync="urlList.url"
          @overUpload="overUpload"
          :fileCount="10"
          uploadType="video"
          :multiple="false"
        />

        <!-- <upload-to-ali v-model="urlList.url" :customDomain="customDomain" preview :region="region" :bucket="bucket"
          :accept="acceptVideo" :max="10" :size="1024000" :accessKeyId="accessKeyId" :accessKeySecret="accessKeySecret"
          :before-upload="file" :dir="dirVideo" @loaded="overUpload">
        </upload-to-ali> -->
        <span v-if="messageTip" style="color: red">{{ messageTip }}</span>
      </a-form-item>
    </a-modal>
    <!-- 封面上传 -->
    <a-modal
      :maskClosable="false"
      title="封面上传"
      @cancel="closeImage"
      @afterClose="closeImage"
      v-model="addImageVisible"
    >
      <template slot="footer">
        <a-button key="back" @click="closeImage">取消</a-button>
        <a-button key="submit" type="primary" @click="handleOkImage" :loading="loadingImage"> 确定 </a-button>
      </template>
      <a-form-item label="" class="add-image-material">
        <uploadFile
          v-if="addImageVisible"
          :value.sync="urlListImage.url"
          :checkFile="fileWater"
          @overUpload="overUploadImage"
          @removeUpload="deleteImage"
          :fileCount="15"
          uploadType="image"
        />
        <span
          v-if="material.filter((item) => item == false).length > 0 && urlListImage.url.length > 0"
          style="color: red"
          >上传素材的尺寸不符,请修改(<span v-for="(item, index) of material" :key="index" v-show="!item"
            >第{{ index + 1 }}张</span
          >出错)</span
        >
        <span
          v-else-if="urlListImage.url.length > 0 && material.filter((item) => item == false).length == 0"
          style="color: green"
          >上传成功</span
        >
      </a-form-item>
    </a-modal>
    <!-- 抽帧展示 -->
    <a-modal :maskClosable="false" title="抽帧展示" v-model="chouzhen" :width="1000">
      <template slot="footer">
        <a-button key="back" @click="chouzhen = false">关闭</a-button>
        <a-button key="submit" type="primary" @click="handleOkChouzhen"> 确定 </a-button>
      </template>
      <a-button type="primary" @click="onCheckAllChange"> 全选 </a-button>
      <!-- </a-checkbox> -->
      <ul v-if="chouzhenList.length > 0" style="height: 600px; overflow: auto; padding-left: 0" class="step3-modal">
        <a-checkbox-group v-model="checkList" @change="onChange" style="width: 100%">
          <li
            v-for="(item, index) of chouzhenList"
            :key="index"
            class="chouzhen"
            style="height: 320px"
            :class="{ first: index == 0 }"
          >
            <a-checkbox
              :value="item.signature"
              style="position: absolute; z-index: 100; width: 100%; height: 100%; right: 0; top: 0; float: right"
            >
              <img :src="item.url" alt="" style="width: 100%" />
            </a-checkbox>
            <a
              style="position: absolute; bottom: 0; width: 100%; text-align: center; margin-left: -10px; z-index: 100"
              @click.stop="
                showImageStr = item.url
                showImageChouzhen = true
              "
              >查看封面</a
            >
          </li>
        </a-checkbox-group>
      </ul>
    </a-modal>
    <!-- 抽帧详情展示 -->
    <a-modal title="抽帧详情" v-model="showImageChouzhen" :width="400" :footer="null">
      <img :src="showImageStr" style="width: 100%" />
    </a-modal>

    <!-- 封面贴纸 -->
    <a-modal :maskClosable="false" title="封面贴纸" v-model="stickerVisible" @ok="handleOkCover" :width="1000">
      <a-radio-group v-model="stickerStylesValue" class="sticker-styles" v-if="stickerStyles.length > 0">
        <a-radio v-for="(item, index) in stickerStyles" :key="index" :value="item.overlay_type">
          <img :src="item.overlay_preview_url" alt="" style="width: 100px; margin: 10px; opacity: 0.5" />
        </a-radio>
      </a-radio-group>
    </a-modal>

    <!-- 推荐广告语 -->
    <a-modal title="推荐标题" v-model="titleVisible" :width="1000" :footer="null">
      <a-row :gutter="10">
        <a-col :sm="10" style="margin-bottom: 20px; z-index: 10">
          <a-card class="search-box" style="min-height: 500px">
            <div style="margin-bottom: 30px">
              <span style="display: inline-block; width: 80px">行业</span>
              <a-cascader
                style="margin-top: 1rem; width: 300px"
                v-model="dataOne"
                :options="options"
                :showSearch="{ filter }"
                expandTrigger="hover"
                @change="onChangeTitle"
                placeholder="请选择行业"
              >
                <a-icon type="smile" slot="suffixIcon" class="test" />
              </a-cascader>
            </div>
            <div style="margin-bottom: 30px">
              <span style="display: inline-block; width: 80px">关键词</span>
              <a-input placeholder="请输入关键词" v-model="value" style="width: 300px" />
            </div>
            <span style="display: inline-block; width: 80px; float: left"></span>
            <a-button type="primary" @click="searchQuery" :disabled="value == ''">生成</a-button>
          </a-card>
        </a-col>
        <a-col :sm="14" style="margin-bottom: 20px; z-index: 10">
          <a-card class="search-box" style="over-flow: auto">
            <a-list size="large" bordered :dataSource="title">
              <a-list-item slot="renderItem" slot-scope="item">
                <a slot="actions" @click="okTitle(item)">选择</a>
                {{ item }}
              </a-list-item>
            </a-list>
          </a-card>
        </a-col>
      </a-row>
    </a-modal>
    <!-- 收藏广告语列表 -->
    <a-modal title="收藏标题" v-model="cunTitleVisible" :width="1000" :footer="null">
      <a-row :gutter="10">
        <a-col :sm="24" style="margin-bottom: 20px; z-index: 10">
          <a-card class="search-box" style="over-flow: auto">
            <a-list size="large" bordered :dataSource="cunTitleList">
              <a-list-item slot="renderItem" slot-scope="item">
                <div slot="actions">
                  <a @click="okTitleCun(item)">选择</a>
                  <a-divider type="vertical" />
                  <a @click="removeTitleCun(item)">删除</a>
                </div>
                {{ item.title }}
              </a-list-item>
            </a-list>
          </a-card>
        </a-col>
      </a-row>
    </a-modal>

    <!-- 收藏标签列表 -->
    <a-modal title="收藏标题" v-model="creativeTagVisible" :width="1000" @ok="okTag">
      <el-tree :data="optionsTag" show-checkbox node-key="id" :props="defaultProps" :check-strictly="true" ref="tree">
      </el-tree>
    </a-modal>
    <!-- 收藏检测链接 -->
    <a-modal title="监测链接名称" v-model="clickTrackUrlShow">
      <template slot="footer">
        <a-button
          key="submit"
          :disabled="trackUrlName == '' && !showTrackUrlNameElse"
          type="primary"
          @click="clickTrackUrlOk"
        >
          确定
        </a-button>
      </template>
      <a-input placeholder="请输入监测链接名称" v-model="trackUrlName" @blur="changeTrackUrlName" style="width: 100%" />
      <span style="color: red" v-if="!showTrackUrlNameElse">名称重复</span>
    </a-modal>

    <a-modal v-model="showCreate" title="创建失败条数">
      <template slot="footer">
        <a-button key="back" @click="showCreate = false">取消</a-button>
        <a-button key="submit" type="primary" @click="tiaozhuan"> 确定 </a-button>
      </template>
      <ul v-if="createUnitList.length > 0">
        <li v-for="(item, index) in createUnitList">
          <p v-if="item.code == -1">
            创意名称：{{ item.creativeName }}，创建失败 <br /><span style="margin-left: 10px"
              >失败原因：{{ item.message }}</span
            >
          </p>
        </li>
      </ul>
      <div v-else style="width: 100%; height: 200px; text-align: center; line-height: 200px">无创建失败条数</div>
    </a-modal>
  </a-card>
</template>

<script>
import { getAction, postAction, deleteAction } from '@/api/manage'
import { mapGetters } from 'vuex'
import moment from 'moment'
// import VuePreview from 'vue-preview'
import jq from 'jquery'
import { stopOtherVideo, closeAllVideoFun } from '@/utils/videoControl' // 停止除当前外的其他视频播放，及停止所有视频播放的方法
import checkMatemal from '../account/stepForm/stepModule/checkMatemal'
import BMF from 'browser-md5-file'
import uploadFile from '@/components/uploadFile.vue'
let nowIndex = 0
let bestIndex = 0
let showRemove = false
export default {
  name: 'create-creative',
  components: {
    checkMatemal,
    uploadFile,
  },
  data() {
    return {
      loading: false,
      labelCol: { span: 4 },
      wrapperCol: { span: 20 },
      formItemLayout: {
        labelCol: {
          xs: { span: 4 },
          sm: { span: 4 },
        },
        wrapperCol: {
          xs: { span: 20, offset: 0 },
          sm: { span: 20, offset: 4 },
        },
      },

      form: {
        accountArr: [
          {
            sceneId: [3, 6, 7],
            accountId: 23212,
            campaignId: 26570382,
            unitId: 108905427,
            bidType: 6,
            unitName: '测试啊',
            creativeCategory: [],
            creativeTag: [],
            actionBarText: '行动号召按钮文案',
            siteId: '安卓下载中间页ID',
            clickTrackUrl: '第三方点击检测链接',
            photoArr: [
              {
                creativeMaterialType: '1',
                creativeName: '',
                photoId: null,
                videoInfo: { url: '', signature: '' },
                imageList: [],
                checkArrImage: [],
                imageUrlList: [],
                chouzhenShow: false,
                imageToken: [],
                imageTokenArr: [],
                stickerTitle: '', //封面广告语标题
                overlayType: '', //贴纸样式类型
                description: '广告语',

                // creativeCategory: [],
                // creativeTag: [],
                // actionBarText: '行动号召按钮文案',
                // siteId: '安卓下载中间页ID',
                // clickTrackUrl: '第三方点击检测链接',

                // shortSlogan: '便利贴创意短广告语',
                // stickyImageTokens: ['creative_material_type为4存在'],
                // expose_tag: '广告标签',
                // new_expose_tag: ['广告标签2期'],s
                // click_track_url: '第三方点击检测链接',
                // impression_url: '第三方开始播放监测链接',
                // ad_photo_played_t3s_ur: '第三方有效播放监测链接',
                // creativeCategory: '创意分类',
                // creative_tag: '创意标签',
              },
              {
                creativeMaterialType: '4',
                imageTokens: [],
                shortSlogan: '',
                description: '',
                imageList: [],
                creativeName: '',
              },
            ],
          },
        ],
      },

      accountId: '', //本页面最重要的值，所有的值都基于accountId来进行操作

      //视频选择参数
      orderBy: 'time', //视频的筛选参数   time为时间筛选  cost为消耗排序
      visibleMatemal: false, //视频选择的模态框
      checkVideo: [], //选择的视频相关   使用的为checkbox，必须为数组形式，否则会报错
      active: 0, //页签绑定值，默认为内部视频
      time: [], //时间筛选条件的绑定值
      channelType: 0, //内外部素材的筛选值绑定，0内部，1外部
      creativeMaterialType: '1', //视频类型  1竖版  2横板
      dataSource: [], //视频数据
      loadingVideoList: true, //确定的loading
      tab: [
        //视频的的页签
        {
          value: 0,
          label: '内部',
        },
        {
          value: 1,
          label: '外部',
        },
      ],
      ipagination: {
        //选择视频时的分页
        current: 1,
        pageSize: 5,
        //   pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        //   showSizeChanger: true,
        total: 0,
        onChange: (current) => {
          // 切换分页时的回调，
          // 当在页面定义change事件时，切记要把此处的事件清除，因为这两个事件重叠了，可能到时候会导致一些莫名的bug
          this.ipagination.current = current
        },
      },
      //视频选择刷新
      tongbuLoading: false,
      //视频预览
      visibleVideo: false, //视频预览模态框
      videoUrlShow: '', //视频预览链接
      //上传视频
      addVideoVisible: false, //上传视频模态框
      urlList: {
        //上传视频信息
        url: '',
        md5: '',
        photoId: '', //快手端视频唯一码
      },
      messageTip: null, //上传失败时，展示的信息
      loadingVideo: false, //上传视频模态框

      //上传封面
      addImageVisible: false, //上传封面模态框
      loadingImage: false, //确定加载loading
      postAdTrue: false, //是否为便利贴判断
      urlListImage: {
        //MD5以及链接获取
        url: [],
        md5: [],
      },
      imageArrList: [], //上传的封面信息存储
      material: [], //判断上传素材
      //抽帧展示
      chouzhen: false, //抽帧模态框
      chouzhenList: [], //抽帧封面展示数据
      checkList: [], //选择的抽帧绑定
      checkAll: false, //抽帧封面全选
      showImageStr: '', //预览抽帧封面的链接
      showImageChouzhen: false, //预览抽帧封面模态框
      indeterminate: false, //全选按钮的展示形式 -

      //封面贴纸
      stickerStyles: [],
      stickerVisible: false,
      stickerStylesValue: '',

      //收藏相关
      titleVisible: false, //展示推荐的广告语
      options: [], //推荐广告语数据
      dataOne: [], //行业选择值  动态填写默认 [0]不限
      value: '', //填写关键词
      title: [], //推荐的广告语
      cunTitleVisible: false, //收藏广告语
      cunTitleList: [],
      tagName: '', //收藏标签名称
      creativeTagVisible: false, //收藏标签模态框展示
      optionsTag: [], //收藏的标签数据
      createOptions: [], //创意分类列表
      fieldNames: {
        //创意分类配置
        label: 'category_name',
        value: 'category_id',
        children: 'child',
      },
      defaultProps: {
        children: 'children',
        label: 'label',
        id: 'id',
      },

      //其他数据
      appList: [], //行动号召数据
      siteList: [], //下载详情数据
      showSite: false,
      clickTrackUrlShow: false,
      showTrackUrlNameElse: true,
      trackUrlList: [],
      trackUrlName: '',

      submitFormLoading: false, //提交loading
      createUnitList: [],
      createUnitSuccess: [],
      showCreate: false,
    }
  },
  methods: {
    //调用vuex状态管理方法
    ...mapGetters(['nickname', 'avatar', 'userInfo']),
    tiaozhuan() {
      this.$bus.$emit('remove', '/crossAccount/createCreative')
    },
    changeAccount(data) {
      // pane.unitId + '@' + pane.accountId + '@' + pane.campaignId
      var dataArr = data.split('@')
      this.getCreativeWordStyles(dataArr[1])
      this.getCreativeWord(dataArr[1])
      this.getTagList(dataArr[1])
      this.getActionBarText(dataArr[2])
      this.getAppIdDownSite(dataArr[1], dataArr[0])
    },
    handleSubmit(formName) {
      this.submitFormLoading = true

      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert('submit!')

          var params = this.form.accountArr.map((item) => {
            return {
              ...item,
              creativeCategory: item.creativeCategory ? item.creativeCategory[item.creativeCategory.length - 1] : null,
              photoArr: item.photoArr.map((i) => {
                if (i.creativeMaterialType == '1') {
                  return {
                    ...i,
                    imageTokenArr: i.imageList.map((c) => {
                      return c.signature
                    }),
                  }
                } else if (i.creativeMaterialType == '4') {
                  return {
                    ...i,

                    imageTokens: i.imageList.map((c) => {
                      return c.imageToken
                    }),
                  }
                }
              }),
            }
          })
          console.log(params)
          postAction('/kuaishou/crossAccount/crossAccountCreativeCreate', { accountArr: params }).then((res) => {
            console.log(res)
            if (res.success) {
              this.submitFormLoading = false
              this.showCreate = true
              this.createUnitList = res.result.filter((item) => {
                return item.code != 0
              })
              this.createUnitSuccess = res.result.filter((item) => {
                return item.code == 0
              })
            } else {
              this.submitFormLoading = false
            }
          })
        } else {
          setTimeout(() => {
            var isError = document.getElementsByClassName('has-error')
            console.log(isError)
            isError[0].querySelector('input').focus()
          }, 100)
          this.submitFormLoading = false
          console.log('error submit!!')
          return false
        }
      })
    },
    addCreative(type, item) {
      if (type == 'all') {
        item.photoArr.push({
          creativeMaterialType: '1',
          creativeName: '',
          photoId: null,
          videoInfo: { url: '', signature: '' },
          imageList: [],
          checkArrImage: [],
          imageUrlList: [],
          chouzhenShow: false,
          imageToken: [],
          imageTokenArr: [],
          stickerTitle: '', //封面广告语标题
          overlayType: '', //贴纸样式类型
          description: '',
        })
      } else {
        item.photoArr.push({
          creativeMaterialType: '4',
          imageToken: [],
          shortSlogan: '',
          description: '',
          imageList: [],
        })
      }
    },
    deleteCreative(index, item) {
      item.photoArr.splice(index, 1)
    },
    changeType() {},
    //选择素材   type区分视频图片素材
    getVideoList(type, creativeMaterialType, accountId, photoIndex, index) {
      if (type == 'video') {
        nowIndex = photoIndex
        bestIndex = index
        this.orderBy = 'time'
        this.visibleMatemal = true
        this.checkVideo = []
        this.active = 0
        this.time = []
        this.channelType = 0
        this.creativeMaterialType = creativeMaterialType
        this.accountId = accountId
      } else {
        this.creativeMaterialType = creativeMaterialType
        this.accountId = accountId
        nowIndex = photoIndex
        bestIndex = index
        this.$refs.check.showCheck(
          creativeMaterialType,
          '/kuaishou/batch/getImageList',
          null,
          type,
          photoIndex,
          accountId
        )
      }
    },
    //模态框回调
    //确认视频选择
    handleOkShow(e) {
      //
      this.visibleMatemal = false
      this.form.accountArr[bestIndex].photoArr[nowIndex].imageList = []
      getAction('/kuaishou/batch/getCreativeCopywriter', {
        code: this.checkVideo[0].signature,
        accountId: this.accountId,
      }).then((res) => {
        if (res.success) {
          this.form.accountArr[bestIndex].photoArr[nowIndex].description = res.result
            ? res.result.creativeCopywriter
              ? res.result.creativeCopywriter
              : ''
            : ''
        }
      })
      getAction('/ctop/MaterialImageInfo/list', {
        videoId: this.checkVideo[0].signature,
        status: 1,
      }).then((res) => {
        // console.log(res)
        if (res.success) {
          this.form.accountArr[bestIndex].photoArr[nowIndex].imageUrlList = res.result
          this.form.accountArr[bestIndex].photoArr[nowIndex].checkArrImage = res.result.map((item) => {
            return item.code
          })
          this.form.accountArr[bestIndex].photoArr[nowIndex].imageToken = res.result.map((item) => {
            return item.code
          })
        }
      })

      this.form.accountArr[bestIndex].photoArr[nowIndex].videoList = this.checkVideo[0]
      this.form.accountArr[bestIndex].photoArr[nowIndex].photoId = this.checkVideo[0].photoId
      this.visibleMatemal = false
      this.ipagination.current = 1
      var params = {
        videoSignature: this.checkVideo[0].signature,
        pageSize: 20,
        pageNo: 1,
      }
      getAction('/cutFrame/material/list', params).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            this.form.accountArr[bestIndex].photoArr[nowIndex].chouzhenShow = true
          } else {
            this.form.accountArr[bestIndex].photoArr[nowIndex].chouzhenShow = false
          }
        }
      })
    },

    //删除选择的封面
    deleteData(index, photoIndex, deleteIndex, type) {
      // nowIndex = photoIndex
      // bestIndex = index
      if (type) {
        this.form.accountArr[index].photoArr[photoIndex].imageList.splice(deleteIndex, 1)
        this.form.accountArr[index].photoArr[photoIndex]
      } else {
        this.form.accountArr[index].photoArr[photoIndex].imageList.splice(deleteIndex, 1)
      }
    },

    //公共方法  以accountId获取页面所需数据
    getCreativeWordStyles(accountId) {
      //获取贴纸信息
      getAction('/kuaishou/batch/getCreativeWordStyles', {
        accountId: accountId,
      }).then((res) => {
        this.stickerStyles = []
        if (res.success) {
          if (res.result) {
            var data = res.result.map((item) => {
              return item.sticker_styles
            })
            data.map((item) => {
              item.map((i) => {
                this.stickerStyles.push(i)
              })
            })
          }

          // console.log(this.stickerStyles)
        } else {
          this.stickerStyles = []
        }
      })
    },
    getCreativeWord(accountId) {
      //获取推荐广告关键词
      this.tags = []
      getAction('/kuaishou/batch/creativeWord', {
        accountId: accountId,
      }).then((res) => {
        if (res.success) {
          this.tags = res.result
        }
      })
    },
    getTagList(accountId) {
      //获取标签数据
      this.createOptions = []
      getAction('/kuaishou/batch/getCreativeCategory', {
        accountId: accountId,
      }).then((res) => {
        if (res.success) {
          this.createOptions = res.result
        }
      })
    },
    getActionBarText(campaignId) {
      //获取行动号召按钮数据
      this.appList = []
      getAction('/kuaishou/batch/getActionBarText', {
        campaignId: campaignId,
      }).then((res) => {
        if (res.success) {
          this.appList = res.result
        }
      })
    },
    getAppIdDownSite(accountId, unitId) {
      getAction('/kuaishou/batch/getAppId', {
        accountId: accountId,
        unitId: unitId,
      }).then((res) => {
        if (res.success) {
          if (res.result) {
            this.showSite = true
            this.getSiteList(res.result, accountId)
          } else {
            this.showSite = false
          }
        }
      })
    },
    getSiteList(appId, accountId) {
      getAction('/kuaishou/batch/getPageList', {
        accountId: accountId,
        appId: appId,
        viewComp: 7,
      }).then((res) => {
        if (res.success) {
          this.siteList = res.result
        }
      })
    },

    //切换内部外部素材
    callback(key) {
      this.channelType = key
      this.checkVideo = []
      this.ipagination.current = 1
      this.time = []
    },

    onChangeVideo() {
      if (this.checkVideo.length > 1) {
        this.checkVideo.shift()
      }
    },
    getDataSource(page, pageSize) {
      this.ipagination.current = page
      var params = {}
      params.accountId = this.accountId
      params.materialType = this.creativeMaterialType
      params.pageSize = this.ipagination.pageSize
      params.pageNo = page
      params.channelType = this.channelType
      params.status = 0
      params.orderBy = this.orderBy
      if (this.time.length > 0) {
        // params.startDate = moment(this.time[0]).format('YYYY-MM-DD')
        // params.endDate = moment(this.time[1]).format('YYYY-MM-DD')
        params.startDate = moment(this.time[0]).format('YYYY-MM-DD') + ' 00:00:00'
        params.endDate = moment(this.time[1]).format('YYYY-MM-DD') + ' 23:59:59'
      }
      this.showVideoList('/kuaishou/kuaiShouVideoGet/getVideoList', params)
    },
    showVideoList(url, params) {
      this.dataSource = []
      this.loadingVideoList = true
      getAction(url, params).then((res) => {
        console.log(res)
        if (res.success) {
          this.dataSource = res.result.list
          this.ipagination.total = res.result.total
          this.loadingVideoList = false
        } else {
          this.loadingVideoList = false
        }
      })
    },

    //封面选择相关
    showData(item, type) {
      //调用组件，返回值
      // this.pans[index].list[item.key].imageList = []

      if (this.creativeMaterialType == '4') {
        if (item.image.length > 15) {
          this.$message.error('当前选择封面' + item.image.length + '张,最多可选择15张')
          return
        } else {
          this.form.accountArr[bestIndex].photoArr[nowIndex].imageList.push(...item.image)
          this.chouzhen = false
          this.chouzhenList = []
          this.checkList = []
          this.checkAll = false
        }
      } else {
        if (item.image.length + this.contentAll > 15) {
          this.$message.error('当前选择封面' + item.image.length + '张,最多可选择' + (15 - this.contentAll) + '张')
          return
        } else {
          this.form.accountArr[bestIndex].photoArr[nowIndex].imageList.push(...item.image)
          this.chouzhen = false
          this.chouzhenList = []
          this.checkList = []
          this.checkAll = false
        }
      }
    },

    onChange(checkedList) {
      this.indeterminate = !!checkedList.length && checkedList.length < this.chouzhenList.length
      this.checkAll = checkedList.length === this.chouzhenList.length
    },
    showImages(index, photoIndex) {
      this.chouzhen = true
      this.chouzhenList = []
      nowIndex = photoIndex
      bestIndex = index
      var params = {
        videoSignature: this.form.accountArr[bestIndex].photoArr[nowIndex].videoList.signature,
        pageSize: 20,
        pageNo: 1,
      }
      getAction('/cutFrame/material/list', params).then((res) => {
        if (res.success) {
          this.chouzhenList.push(...res.result.records)
        }
      })
    },
    onChangeCheckImage(checkedList) {},
    handleOkChouzhen(e) {
      var arr = []
      for (let i = 0; i < this.chouzhenList.length; i++) {
        for (let j = 0; j < this.checkList.length; j++) {
          if (this.chouzhenList[i].signature == this.checkList[j]) {
            arr.push(this.chouzhenList[i])
          }
        }
      }
      if (arr.length > 15) {
        this.$message.error('当前选择封面' + arr.length + '张,最多可选择15张')
        return
      } else {
        this.form.accountArr[bestIndex].photoArr[nowIndex].imageList.push(...arr)
        this.chouzhen = false
        this.chouzhenList = []
        this.checkList = []
        this.checkAll = false
      }
    },
    onCheckAllChange(e) {
      if (this.checkAll) {
        this.checkList = []
      } else {
        this.checkList = this.chouzhenList.map((item) => {
          return item.signature
        })
      }
      this.checkAll = !this.checkAll
    },
    //封面选择相关方法结束

    // 视频预览 和 视频素材同步
    matemalVideo(item) {
      this.visibleVideo = true
      this.videoUrlShow = item.url
    },
    tongbu() {
      this.tongbuLoading = true
      getAction('/kuaishou/batch/syncVideo', {
        accountId: this.accountId,
      }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.tongbuLoading = false
          var params = {}
          params.accountId = this.accountId
          params.materialType = this.creativeMaterialType
          params.pageSize = this.ipagination.pageSize
          params.pageNo = 1
          params.status = 0
          params.channelType = this.channelType
          params.orderBy = this.orderBy
          if (this.time.length > 0) {
            // params.startDate = moment(this.time[0]).format('YYYY-MM-DD')
            // params.endDate = moment(this.time[1]).format('YYYY-MM-DD')
            params.startDate = moment(this.time[0]).format('YYYY-MM-DD') + ' 00:00:00'
            params.endDate = moment(this.time[1]).format('YYYY-MM-DD') + ' 23:59:59'
          }
          this.showVideoList('/kuaishou/kuaiShouVideoGet/getVideoList', params)
        } else {
          this.$message.error(res.message)
          this.tongbuLoading = false
        }
      })
    },
    //视频预览 和 视频素材同步方法结束

    //上传视频
    uploadVideo(photoIndex, index, item, accountId) {
      nowIndex = photoIndex
      bestIndex = index
      this.addVideoVisible = true
      this.creativeMaterialType = item.creativeMaterialType
      this.accountId = accountId
    },
    closeVideo() {
      this.addVideoVisible = false
      this.urlList = {
        url: '',
        md5: '',
        photoId: '',
      }
      nowIndex = 0
      bestIndex = 0
      this.messageTip = null
    },
    file(file) {
      var bmf = new BMF()
      var that = this
      return new Promise(function (resolve, reject) {
        bmf.md5(file, (err, md5) => {
          getAction('/kusiShouUpload/checkVideo', {
            signature: md5,
            accountId: that.accountId,
          }).then((res) => {
            if (res.code == 0) {
              if (res.result.isExistence) {
                showRemove = res.result.isExistence
                that.urlList.md5 = res.result.signature
                that.urlList.url = res.result.videoUrl
                that.urlList.photoId = res.result.photoId
                reject()
              } else {
                showRemove = res.result.isExistence
                that.urlList.md5 = md5
                resolve()
              }
            } else {
              reject()
            }
          })
        })
      })
    },
    overUpload(urlAll) {
      console.log(this.urlList)
    },
    handleOkVideo(e) {
      this.loadingVideo = true
      if (showRemove) {
        this.form.accountArr[bestIndex].photoArr[nowIndex].videoList = {
          photoId: this.urlList.photoId,
          url: this.urlList.url,
        }
        this.form.accountArr[bestIndex].photoArr[nowIndex].photoId = this.urlList.photoId
        this.loadingVideo = false
        var params = {
          videoSignature: this.urlList.md5,
          pageSize: 20,
          pageNo: 1,
        }
        getAction('/cutFrame/material/list', params).then((res) => {
          if (res.success) {
            if (res.result.records.length > 0) {
              this.form.accountArr[bestIndex].photoArr[nowIndex].chouzhenShow = true
            } else {
              this.form.accountArr[bestIndex].photoArr[nowIndex].chouzhenShow = false
            }
          }
        })
        this.closeVideo()
      } else {
        var params = {
          url: this.urlList.url,
          type: this.creativeMaterialType,
          signature: this.urlList.md5,
          accountId: this.accountId,
        }
        postAction('/kusiShouUpload/video', params).then((res) => {
          if (res.success) {
            this.form.accountArr[bestIndex].photoArr[nowIndex].videoList = {
              photoId: res.result.photoId,
              url: this.urlList.url,
            }
            this.form.accountArr[bestIndex].photoArr[nowIndex].photoId = res.result.photoId
            this.loadingVideo = false
            this.closeVideo()
          } else {
            this.messageTip = res.message
            this.loadingVideo = false
            this.urlList = {
              url: '',
              md5: '',
              photoId: '',
            }
            nowIndex = 0
            bestIndex = 0
          }
        })
      }
    },
    //上传视频方法结束

    //上传封面
    uploadImages(index, photoIndex, creativeMaterialType, accountId, type) {
      nowIndex = photoIndex
      bestIndex = index
      this.accountId = accountId
      this.addImageVisible = true
      this.loadingImage = false
      this.creativeMaterialType = creativeMaterialType
      if (type) {
        this.postAdTrue = true
      } else {
        this.postAdTrue = false
      }
    },
    closeImage() {
      this.addImageVisible = false
      this.urlListImage = {
        url: [],
        md5: [],
      }
      this.imageArrList = []
      nowIndex = 0
      bestIndex = 0
      this.loadingImage = false
    },
    handleOkImage(e) {
      this.loadingImage = true
      var params = {
        accountId: this.accountId,
        uploadImageArr: this.imageArrList,
        creativeMaterialType: this.creativeMaterialType,
      }
      postAction('/kusiShouUpload/image', params).then((res) => {
        if (res.success) {
          if (!this.postAdTrue) {
            if (res.result.length > 15) {
              this.$message.error('当前上传封面' + res.result.length + '张,最多可上传15张')
              this.loadingImage = false
              return
            } else {
              this.form.accountArr[bestIndex].photoArr[nowIndex].imageList.push(...res.result)
              this.closeImage()
              this.loadingImage = false
            }
          } else {
            if (res.result.length > 15) {
              this.$message.error('当前上传封面' + res.result.length + '张,最多可上传15张')
              this.loadingImage = false
              return
            } else {
              this.form.accountArr[bestIndex].photoArr[nowIndex].imageList.push(...res.result)
              this.closeImage()
              this.loadingImage = false
            }
          }
        } else {
          this.$message.error('封面上传失败')
          this.loadingImage = false
        }
      })
    },
    deleteImage(url) {
      var index = this.imageArrList.findIndex((v) => v.url === url)
      this.imageArrList.splice(index, 1)
    },
    overUploadImage(urlAll) {
      var that = this
      // that.material = []
      that.imageArrList = []
      var img
      if (urlAll.length > 0) {
        for (var i = 0; i < urlAll.length; i++) {
          that.imageArrList.push({
            signature: this.urlListImage.md5[i],
            url: urlAll[i].url,
          })

          img = new Image()
          img.src = urlAll[i].url
        }
      }
    },
    fileWater(file) {
      var bmf = new BMF()
      var that = this
      return new Promise(function (resolve, reject) {
        bmf.md5(file, (err, md5) => {
          that.urlListImage.md5.push(md5)
          resolve()
        })
      })
    },
    //上传封面方法结束

    //封面贴纸相关
    getCoverUrl(index, photoIndex, item) {
      nowIndex = photoIndex
      bestIndex = index
      this.stickerVisible = true
      this.stickerStylesValue = ''
    },
    showStickerStyles(value) {
      return this.stickerStyles.filter((item) => item.overlay_type == value)[0].overlay_preview_url
    },
    deleteCover(index, photoIndex) {
      this.form.accountArr[index].photoArr[photoIndex].overlayType = ''
      this.form.accountArr[index].photoArr[photoIndex].ostickerTitle = ''
    },
    handleOkCover() {
      this.form.accountArr[bestIndex].photoArr[nowIndex].overlayType = this.stickerStylesValue
      this.stickerVisible = false
    },
    //封面贴纸方法结束

    //收藏广告语相关
    showTitle(index, photoIndex) {
      //展示推荐广告语
      nowIndex = photoIndex
      bestIndex = index
      this.titleVisible = true
      this.getHangye()
    },
    getHangye() {
      //获取推荐广告语数据
      getAction('/ctop/creativeTitle/getTitleLabel', '').then((res) => {
        if (res.success) {
          this.options = res.result.map((item) => {
            return {
              label: item.label,
              value: item.value,
              children:
                item.children.length > 0
                  ? [
                      {
                        label: '不限',
                        value: 0,
                      },
                    ].concat(item.children)
                  : [
                      {
                        label: '不限',
                        value: 0,
                      },
                    ],
            }
          })
          this.options = [
            {
              label: '不限',
              value: 0,
            },
          ].concat(this.options)
          if (this.dataOne.length > 0) {
            return
          } else {
            this.dataOne = [0]
          }
        }
      })
    },
    onChangeTitle(value, selectedOptions) {
      //选择行业
      this.dataOne = value
      this.value = ''
      this.title = []
    },
    filter(inputValue, path) {
      //行业的手动搜索筛选
      return path.some((option) => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1)
    },
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    searchQuery() {
      //生成推荐的广告语
      // /ctop/creativeTitle/titleSuggestion
      getAction('/ctop/creativeTitle/titleSearch', {
        firstCategory: this.dataOne[0],
        secondCategory: this.dataOne[1],
        keywords: this.value,
      }).then((res) => {
        this.title = res.result ? res.result : []
      })
      // firstCategory，secondCategory，keywords
    },
    okTitle(item) {
      //选择推荐的广告语填值
      this.form.accountArr[bestIndex].photoArr[nowIndex].description = item
      this.titleVisible = false
      this.dataOne = []
      this.value = ''
      this.title = []
    },
    cunTitle(index, photoIndex, accountId) {
      //收藏广告语
      if (this.form.accountArr[index].photoArr[photoIndex].description == '') {
        this.$message.error('请填写广告语后再进行收藏')
      } else {
        var params = {}
        params.accountId = accountId
        params.userId = this.userInfo().id
        params.title = this.form.accountArr[index].photoArr[photoIndex].description
        postAction('/kuaishou/kuaiShouTitleCollection/add', params).then((res) => {
          if (res.success) {
            this.$message.success('收藏成功')
          } else {
            this.$message.error(res.message)
          }
        })
      }
    },
    showCunTitle(index, photoIndex, accountId) {
      //展示收藏的广告语
      nowIndex = photoIndex
      bestIndex = index
      this.accountId = accountId
      this.cunTitleVisible = true
      this.getCunTitle()
    },
    okTitleCun(item) {
      //选择收藏的广告语
      this.form.accountArr[bestIndex].photoArr[nowIndex].description = item.title
      this.cunTitleVisible = false
      this.cunTitleList = []
    },
    getCunTitle() {
      //根据accountId获取收藏的广告语
      var params = {}
      params.accountId = this.accountId
      params.userId = this.userInfo().id
      params.pageNo = 1
      params.pageSize = 500
      getAction('/kuaishou/kuaiShouTitleCollection/list', params).then((res) => {
        if (res.success) {
          this.cunTitleList = res.result.records
        }
      })
    },
    removeTitleCun(item) {
      //删除收藏的某条广告语
      deleteAction('/kuaishou/kuaiShouTitleCollection/delete', {
        id: item.id,
      }).then((res) => {
        if (res.success) {
          this.getCunTitle()
        }
      })
    },
    //收藏广告语相关方法结束

    //收藏分类标签相关
    getInfo(item, accountId) {
      if (this.tagName == '') {
        this.$message.error('请输入分类名称')
        return
      } else {
        let params = {}
        params.tagName = this.tagName
        //   params.campaignBudget = this.campaignBudget
        params.tagArray = JSON.stringify(item.creativeTag)
        params.userId = this.userInfo().id
        params.accountId = accountId
        postAction('/tag/kuaiShouCreativeTagCollection/add', params).then((res) => {
          if (res.success) {
            this.$message.success('添加成功')
            this.tagName = ''
          } else {
            this.$message.error(res.message)
          }
        })
      }
    },
    showCunTag(type, accountId, index) {
      //收藏的标签展示
      this.creativeTagVisible = true
      this.accountId = accountId
      nowIndex = 0
      bestIndex = index
      var params = {}
      params.accountId = accountId
      params.userId = this.userInfo().id
      params.pageSize = 1000
      params.pageNo = 1

      getAction('/tag/kuaiShouCreativeTagCollection/list', params).then((res) => {
        if (res.success) {
          console.log(res.result)
          this.optionsTag = res.result.records.map((item) => {
            return {
              id: item.id,
              label: item.tagName,
              children: JSON.parse(item.tagArray).map((item) => {
                return {
                  id: item,
                  label: item,
                  disabled: true,
                }
              }),
            }
          })
        }
      })
    },
    okTag() {
      var data = this.$refs.tree.getCheckedKeys()
      if (data.length > 1) {
        this.$message.error('只能选择一个选项')
        //  this.$refs.tree.setCheckedKeys([]);
      } else {
        var params = {}
        params.accountId = this.accountId
        params.userId = this.userInfo().id
        params.pageSize = 1000
        params.pageNo = 1
        params.id = data[0]

        getAction('/tag/kuaiShouCreativeTagCollection/list', params).then((res) => {
          if (res.success) {
            console.log(res.result)
            this.$nextTick(() => {
              this.form.accountArr[bestIndex].creativeTag = JSON.parse(res.result.records[0].tagArray).map((item) => {
                return item
              })
            })

            this.creativeTagVisible = false
          } else {
            this.$message.error('选择出错，请稍后选择或自行手填')
          }
        })
      }
    },
    //收藏分类标签相关结束

    //收藏检测链接方法
    removeClickTrackUrl(item) {
      //删除检测链接
      deleteAction('/kuaishou/kuaiShouTrackUrlCollection/delete', {
        id: item.id,
      }).then((res) => {
        if (res.success) {
          this.getClickTrackUrlList(this.accountId)
        }
      })
    },
    getClickTrackUrlList(accountId) {
      this.clickTrackUrlList = true

      var params = {}
      params.accountId = accountId
      params.userId = this.userInfo().id
      params.pageNo = 1
      params.pageSize = 500
      getAction('/kuaishou/kuaiShouTrackUrlCollection/list', params).then((res) => {
        if (res.success) {
          this.trackUrlList = res.result.records
        } else {
          this.$message.error(res.message)
        }
      })
    },
    changeTrackUrlName() {
      var params = {}
      params.accountId = this.accountId
      params.userId = this.userInfo().id
      params.trackName = this.trackUrlName
      getAction('/kuaishou/kuaiShouTrackUrlCollection/checkTrackName', params).then((res) => {
        this.showTrackUrlNameElse = res.result
      })
    },
    clickTrackUrlOk() {
      var params = {}
      params.accountId = localStorage.getItem('accountId')
      params.userId = this.userInfo().id
      params.trackName = this.trackUrlName
      params.trackUrl = this.getData('clickTrackUrl')
      postAction('/kuaishou/kuaiShouTrackUrlCollection/add', params).then((res) => {
        if (res.success) {
          this.clickTrackUrlShow = false
          this.trackUrlName = ''
          this.$message.success('添加成功')
        } else {
          this.$message.error(res.message)
        }
      })
    },
  },
  computed: {},
  watch: {
    time(n, o) {
      if (n.length > 0) {
        var params = {}
        params.accountId = this.accountId
        params.materialType = this.creativeMaterialType
        params.pageSize = this.ipagination.pageSize
        params.pageNo = 1
        params.status = 0
        params.channelType = this.channelType
        params.startDate = moment(n[0]).format('YYYY-MM-DD') + ' 00:00:00'
        params.endDate = moment(n[1]).format('YYYY-MM-DD') + ' 23:59:59'
        params.orderBy = this.orderBy
        this.showVideoList('/kuaishou/kuaiShouVideoGet/getVideoList', params)
      } else {
        var params = {}
        params.accountId = this.accountId
        params.materialType = this.creativeMaterialType
        params.pageSize = this.ipagination.pageSize
        params.pageNo = 1
        params.status = 0
        params.channelType = this.channelType
        params.orderBy = this.orderBy
        this.ipagination.current = 1
        this.showVideoList('/kuaishou/kuaiShouVideoGet/getVideoList', params)
      }
    },
    orderBy(n, o) {
      var params = {}
      params.accountId = this.accountId
      params.materialType = this.creativeMaterialType
      params.pageSize = this.ipagination.pageSize
      params.pageNo = 1
      params.status = 0
      params.channelType = this.channelType
      if (this.time.length > 0) {
        params.startDate = moment(this.time[0]).format('YYYY-MM-DD') + ' 00:00:00'
        params.endDate = moment(this.time[1]).format('YYYY-MM-DD') + ' 23:59:59'
      } else {
      }
      params.orderBy = n
      this.showVideoList('/kuaishou/kuaiShouVideoGet/getVideoList', params)
    },
  },
  mounted: function () {
    this.$nextTick(() => {
      Splitting()

      if (localStorage.getItem('crossAccountUnit')) {
        var data = JSON.parse(localStorage.getItem('crossAccountUnit'))
        this.form.accountArr = data.map((item) => {
          return {
            sceneId: item.sceneId,
            accountId: item.accountId,
            campaignId: item.campaignId,
            unitId: item.unitId,
            bidType: item.bidType,
            unitName: item.unitName,
            creativeCategory: [],
            creativeTag: [],
            actionBarText: '',
            siteId: '',
            clickTrackUrl: '',
            photoArr: [
              {
                creativeMaterialType: '1',
                creativeName: '',
                photoId: null,
                videoInfo: { url: '', signature: '' },
                imageList: [],
                checkArrImage: [],
                imageUrlList: [],
                chouzhenShow: false,
                imageToken: [],
                imageTokenArr: [],
                stickerTitle: '', //封面广告语标题
                overlayType: '', //贴纸样式类型
                description: '',

                // creativeCategory: [],
                // creativeTag: [],
                // actionBarText: '行动号召按钮文案',
                // siteId: '安卓下载中间页ID',
                // clickTrackUrl: '第三方点击检测链接',

                // shortSlogan: '便利贴创意短广告语',
                // stickyImageTokens: ['creative_material_type为4存在'],
                // expose_tag: '广告标签',
                // new_expose_tag: ['广告标签2期'],s
                // click_track_url: '第三方点击检测链接',
                // impression_url: '第三方开始播放监测链接',
                // ad_photo_played_t3s_ur: '第三方有效播放监测链接',
                // creativeCategory: '创意分类',
                // creative_tag: '创意标签',
              },
              // {
              //   creativeMaterialType: '4',
              //   imageTokens: [],
              //   shortSlogan: '',
              //   description: '',
              //   imageList: [],
              //   creativeName: '',
              // },
            ],
          }
        })
      }
      // accountArr: [

      // ],
      this.getCreativeWordStyles(this.form.accountArr[0].accountId)
      this.getCreativeWord(this.form.accountArr[0].accountId)
      this.getTagList(this.form.accountArr[0].accountId)
      this.getActionBarText(this.form.accountArr[0].campaignId)
      this.getAppIdDownSite(this.form.accountArr[0].accountId, this.form.accountArr[0].unitId)
    })
  },
}
</script>
<style lang="scss" scope>
$colors: #f9ca24, #3498db, #ff7979, #1abc9c, #e74c3c, #f8c291;

/* Recommended styles for Splitting */
.splitting .word,
.splitting .char {
  display: inline-block;
}

/* Psuedo-element chars */
.splitting .char {
  position: relative;
}

/**
 * Populate the psuedo elements with the character to allow for expanded effects
 * Set to `display: none` by default; just add `display: block` when you want
 * to use the psuedo elements
 */
.splitting .char::before,
.splitting .char::after {
  content: attr(data-char);
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  transition: inherit;
  user-select: none;
}

/* Expanded CSS Variables */

.splitting {
  /* The center word index */
  --word-center: calc((var(--word-total) - 1) / 2);

  /* The center character index */
  --char-center: calc((var(--char-total) - 1) / 2);

  /* The center character index */
  --line-center: calc((var(--line-total) - 1) / 2);
}

.splitting .word {
  /* Pecent (0-1) of the word's position */
  --word-percent: calc(var(--word-index) / var(--word-total));

  /* Pecent (0-1) of the line's position */
  --line-percent: calc(var(--line-index) / var(--line-total));
}

.splitting .char {
  /* Percent (0-1) of the char's position */
  --char-percent: calc(var(--char-index) / var(--char-total));

  /* Offset from center, positive & negative */
  --char-offset: calc(var(--char-index) - var(--char-center));

  /* Absolute distance from center, only positive */
  --distance: calc((var(--char-offset) * var(--char-offset)) / var(--char-center));

  /* Distance from center where -1 is the far left, 0 is center, 1 is far right */
  --distance-sine: calc(var(--char-offset) / var(--char-center));

  /* Distance from center where 1 is far left/far right, 0 is center */
  --distance-percent: calc((var(--distance) / var(--char-center)));
}

* {
  box-sizing: border-box;
}
* {
  margin: 0;
  padding: 0;
}

// html, body {
//   height: 100%;
// }

.headline {
  align-items: center;
  // background-color: var(--color);
  display: flex;
  font-family: 'Lexend Deca', sans-serif;
  font-weight: 400;
  // font-size: calc(1rem + 15vmin);
  height: 72px;
  justify-content: center;
  // overflow: hidden;
  perspective: 1000px;
  scroll-snap-align: start;
  width: 100%;
}

.word,
.char {
  animation-delay: var(--del);
  animation-direction: var(--dir, normal);
  animation-duration: var(--dur);
  animation-iteration-count: infinite;
  animation-name: var(--name);
  animation-timing-function: var(--tf);
  display: inline-block;
  position: relative;
  transform-origin: 50% 100%;
  z-index: 1;
}

// =========================
// Headline animations
// =========================

.headline--yell .char {
  --name: yell;
  --dur: 2s;
  --tf: ease;
  -webkit-transform-origin: 50% 100%;
  transform-origin: 50% 100%;
}
@-webkit-keyframes yell {
  3% {
    -webkit-transform: scale(calc(1 * var(--distance-percent) + 1.5)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
    transform: scale(calc(1 * var(--distance-percent) + 1.5)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
  }
  6% {
    -webkit-transform: scale(calc(1 * var(--distance-percent) + 1.2)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
    transform: scale(calc(1 * var(--distance-percent) + 1.2)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
  }
  12% {
    -webkit-transform: scale(calc(1 * var(--distance-percent) + 1.5)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
    transform: scale(calc(1 * var(--distance-percent) + 1.5)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
  }
  18% {
    -webkit-transform: scaleY(1) translateY(-2%);
    transform: scaleY(1) translateY(-2%);
  }
  25% {
    -webkit-transform: scaleY(0.98);
    transform: scaleY(0.98);
  }
  50% {
    -webkit-transform: scaleY(1);
    transform: scaleY(1);
  }
  75% {
    -webkit-transform: scale(0.98);
    transform: scale(0.98);
  }
}
@keyframes yell {
  3% {
    -webkit-transform: scale(calc(1 * var(--distance-percent) + 1.5)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
    transform: scale(calc(1 * var(--distance-percent) + 1.5)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
  }
  6% {
    -webkit-transform: scale(calc(1 * var(--distance-percent) + 1.2)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
    transform: scale(calc(1 * var(--distance-percent) + 1.2)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
  }
  12% {
    -webkit-transform: scale(calc(1 * var(--distance-percent) + 1.5)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
    transform: scale(calc(1 * var(--distance-percent) + 1.5)) rotate(calc(15deg * var(--distance-sine)))
      translateY(-10%);
  }
  18% {
    -webkit-transform: scaleY(1) translateY(-2%);
    transform: scaleY(1) translateY(-2%);
  }
  25% {
    -webkit-transform: scaleY(0.98);
    transform: scaleY(0.98);
  }
  50% {
    -webkit-transform: scaleY(1);
    transform: scaleY(1);
  }
  75% {
    -webkit-transform: scale(0.98);
    transform: scale(0.98);
  }
}
</style>