<template>
  <div class="detail-container">
    <el-page-header @back="goBack" content="动态素材详情"></el-page-header>
    <!-- <el-divider></el-divider> -->

    <div class="top-container">
      <el-row :gutter="20">
        <el-col :xs="24" :sm="12" :lg="12">
          <div class="left-content">
            <div class="item">素材名称: <span class="text">{{detail.title}}</span></div>
            <el-row :gutter="20">
              <el-col :xs="24" :sm="12" :lg="12">
                <div class="item">创建时间: <span class="text">{{detail.createTime | dateToMinFilter}}</span></div>
              </el-col>
              <el-col :xs="24" :sm="12" :lg="12">
                <div class="item">创建人: <span class="text">{{detail.createName}}</span></div>
              </el-col>
            </el-row>
            <div class="item" style="margin-bottom: 0;">推送内容: 
              <div class="card1" v-if="detail.type == 4">
                <div class="left">
                  <div class="title ellipsis">{{detail.title}}</div>
                  <div class="desc ellipsis-2">{{detail.abstractText}}</div>
                </div>
                <div class="right"><img :src="detail.fileUrl"></div>
              </div>
              <div class="card2" v-if="detail.type == 6">
                <img src="@/assets/common/pdf.png">
                <div class="name ellipsis">{{detail.title}}</div>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :xs="24" :sm="12" :lg="12">
          <div class="right-content">
            <div class="title">素材统计</div>
            <div class="data">
              <div class="content">
                <div class="item">
                  <div class="num">{{detail.totalCount || 0}}</div>
                  <div class="text">总点击次数</div>
                </div>
                <div class="item">
                  <div class="num">{{detail.totalUserCount || 0}}</div>
                  <div class="text">总点击人数</div>
                </div>
                <div class="item">
                  <div class="num">{{detail.todayCount || 0}}</div>
                  <div class="text">今日点击次数</div>
                </div>
                <div class="item">
                  <div class="num">{{detail.todayUserCount || 0}}</div>
                  <div class="text">今日点击人数</div>
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>

    <div class="screen-container">
      <el-form ref="screenForm" :model="screenForm" label-width="70px" size="small" label-position="left">
        <el-row :gutter="20">
          <el-col :xs="18" :sm="8" :lg="8">
            <el-form-item label="客户信息" prop="keyword">
              <el-input v-model="screenForm.keyword" placeholder="请输入客户信息"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="18" :sm="8" :lg="8">
            <el-form-item label="点击时间" prop="clickDate">
              <el-date-picker
                v-model="screenForm.clickDate"
                type="daterange"
                size="small"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="6" :sm="6" :lg="6">
            <el-form-item label="">
              <el-button size="small" @click="resetScreenForm">清空</el-button>
              <el-button size="small" type="primary" @click="submitScreenForm">搜索</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <div class="table">
      <el-table :data="dataList" border fit highlight-current-row stripe>
        <el-table-column align="center" label="客户" prop="username" min-width="160" show-overflow-tooltip></el-table-column>
        <el-table-column align="center" label="所属员工" prop="adminUsername" min-width="160" show-overflow-tooltip></el-table-column>
        <el-table-column align="center" label="最近点击时间" prop="newTime" min-width="160" show-overflow-tooltip></el-table-column>
        <el-table-column align="center" label="总点击次数" prop="totalCount" min-width="160" show-overflow-tooltip></el-table-column>
      </el-table>
    </div>

  </div>
</template>

<script>
import { getDynamicDetail } from "@/api/marketing";

export default {
  props: ['listItem'],
  data() {
    return {
      screenForm: {
        keyword: '',
        clickDate: '',
      },
      detail: {},
      dataList: [],
    }
  },
  created() {
    this.getDetail();
  },
  methods: {
    // 返回主页
    goBack() {
      this.$emit('backListFormDetail');
    },

    // 获取详情
    getDetail() {
      getDynamicDetail({
        materialsId: this.listItem.marketingMaterialsId,
        name: this.screenForm.keyword,
        beginTime: this.screenForm.clickDate ? this.screenForm.clickDate[0] + ' 00:00:00' : '',
        endTime: this.screenForm.clickDate ? this.screenForm.clickDate[1] + ' 23:59:59' : '',
      }).then(res => {
        this.detail = res.data;
        this.dataList = res.data.visitList || [];
      })
    },

    // 提交筛选表单
    submitScreenForm() {
      this.currentPage = 1;
      this.getDetail();
    },

    // 重置筛选表单
    resetScreenForm() {
      this.$refs.screenForm.resetFields();
      this.currentPage = 1;
      this.getDetail();
    },

  }
}

</script>

<style scoped lang="scss">
  .detail-container {
    width:100%;
    height: 100%;
  }
  .top-container {
    margin-bottom: 30px;
    margin-top: 20px;
    .left-content {
      height: 186px;
      overflow-y: auto;
      padding: 16px;
      border: 1px solid #e4e7ed;
      .item {
        margin-bottom: 20px;
        color: rgba(0,0,0,.45);
        font-size: 14px;
        display: flex;
        .text {
          padding-left: 10px;
          color: rgba(0,0,0,.95);
        }
        .card1 {
          display: flex;
          align-items: center;
          margin-left: 5px;
          width: 240px;
          padding: 10px;
          border: 1px solid #e4e7ed;
          cursor: pointer;
          margin-left: 10px;
          .left {
            flex: 1;
            padding-right: 10px;
            .title {
              color: #222;
              font-weight: 600;
            }
            .desc {
              color: #999;
              font-size: 12px;
              margin-top: 10px;
            }
          }
          .right {
            flex-shrink: 0;
            img {
              height: 40px;
              display: block;
            }
          }
        }
        .card2 {
          display: flex;
          align-items: center;
          margin-left: 5px;
          width: 240px;
          border: 1px solid #e4e7ed;
          cursor: pointer;
          margin-left: 10px;
          height: 65px;
          padding: 0 10px;
          img {
            width: 40px;
            height: 40px;
            display: block;
          }
          .name {
            flex: 1;
            color: #222;
            font-weight: 600;
            margin-left: 10px;
          }
        }
      }
    }
    .right-content {
      border: 1px solid #e4e7ed;
      .title {
        padding: 0 16px;
        height: 50px;
        line-height: 50px;
        border-bottom: 1px solid #e4e7ed;
        font-size: 14px;
        color: #606266;
      }
      .data {
        padding: 16px;
        .content {
          color: #606266;
          border-radius: 2px;
          background-color: #ebf5ff;
          border: 1px solid #e6f0ff;
          display: flex;
          .item {
            flex: 1;
            padding: 16px 0;
            text-align: center;
            .num {
              color: #222;
              font-size: 30px;
              font-weight: 600;
              margin-bottom: 15px;
            }
            .text {
              font-size: 14px;
              color: rgba(0,0,0,.45);
            }
          }
        }
      }
    }
  }
</style>