<template>
  <div class="page">
    <div class="header-content">
      <div class="header-top">
        <img :src="detail.url && detail.url[0].url" alt="" />
      </div>

      <div class="header-middle">
        <div class="img-title">{{ detail.title }}</div>

        <div class="header-middle-bottom">
          <div class="left">
            <div class="left-btn" :class="'status' + detail.status">{{ $dict.getLabel('villageActivityStatus', detail.status) }}</div>
          </div>
          <div class="right">
            <img :src="detail.avatar" alt="" v-if="detail.avatar" />
            <img :src="user.avatar" alt="" v-else />
            <span>{{ detail.contactPerson }}</span>
          </div>
        </div>

        <div class="cards">
          <div class="cards-left">活动时间</div>
          <div class="cards-right">{{ detail.beginTime && detail.beginTime.substring(0, detail.beginTime.length - 3) }}</div>
        </div>

        <div class="cards">
          <div class="cards-left">活动人数</div>
          <div class="cards-right" @click="toSignUser()">
            <span style="color: #1c6bdf">
              <span v-if="detail.realNum != 0">{{ detail.realNum }}</span>
              <span v-else>不限</span>
            </span>
            <u-icon name="arrow-right" color="#DDDDDD" size="28" style="margin-left: 8px"></u-icon>
          </div>
        </div>

        <div class="cards">
          <div class="cards-left">活动地点</div>
          <div class="cards-right" style="width: 75%; text-align: right">{{ detail.address }}</div>
        </div>
      </div>

      <div class="header-bottom">
        <!-- v-if="detail.status == 1 || detail.status == 2 || detail.status == 3" -->
        <div class="tab-title">
          <span :class="current == 0 ? 'active' : ''" @click="change(0)">活动详情</span>
          <span :class="current == 1 ? 'active' : ''" @click="change(1)">活动动态</span>
        </div>
        <!-- <div class="info-title" v-else>活动详情</div> -->
        <div class="content-details" v-if="current == 0">
          <div v-html="detail.content"></div>
        </div>

        <div class="content-trends" v-if="current == 1">
          <div class="details" v-if="activeList.length > 0">
            <div class="card" v-for="(item, index) in activeList" :key="index">
              <div class="card-nav">
                <div class="avatar">
                  <img :src="item.avatar" alt="" style="width: 100%; height: 100%" v-if="item.avatar" />
                  <span v-else>
                    <span v-if="item.name">{{ item.name.substring(item.name.length, item.name.length - 2) }}</span>
                  </span>
                </div>

                <div class="right">
                  <span class="name">{{ item.name }}</span>
                  <span class="time">{{ item.createTime }}</span>
                </div>
              </div>

              <div class="card-font">
                {{ item.content }}
              </div>

              <div class="card-img">
                <img :src="e.url" v-for="(e, i) in imgList[index]" :key="i" alt="" @click.stop="previewImage(info.images, item.url)" />
              </div>

              <!-- <div class="card-icon">
                <div>
                  <i class="iconfont">&#xe69d;</i>
                  <span>{{ item.viewNum ? item.viewNum : 0 }}</span>
                </div>

                <div>
                  <i class="iconfont">&#xe6a2;</i>
                  <span>{{ item.replyNum ? item.replyNum : 0 }}</span>
                </div>

                <div>
                  <i class="iconfont">&#xe698;</i>
                  <span>{{ item.supportNum ? item.supportNum : 0 }}</span>
                </div>
              </div> -->
            </div>

            <!-- <div class="card-bottom"></div> -->
          </div>

          <AiEmpty v-else />
        </div>
      </div>

      <div class="fixedBtns" v-if="this.current == 0 && detail.status == 0 && this.createUserId == this.user.id" @click="toAdd">编辑活动</div>
    </div>

    <AiFixedBtn v-if="this.createUserId == this.user.id">
      <div class="addBtn iconfont iconfont-iconfangda" @tap.stop="AddPosts()" />
    </AiFixedBtn>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'Detail',
  computed: {
    ...mapState(['user']),
  },
  data() {
    return {
      id: '',
      createUserId: '',
      detail: {},
      activeList: [],
      imgList: [],
      list: [
        {
          name: '活动详情',
        },
        {
          name: '活动动态',
        },
      ],
      current: 0,
      timeEndTime: '',
    }
  },
  onLoad(option) {
    this.id = option.id
    this.createUserId = option.createUserId
    this.$dict.load(['villageActivityStatus']).then(() => {
      this.getDetail()
    })

    uni.$on('refresh', () => {
      this.getListInit()
    })
  },
  onShow() {
    document.title = '活动报名'
  },
  methods: {
    getDetail() {
      this.$http.post(`/app/appvillageactivityinfo/queryDetailById?id=${this.id}`).then((res) => {
        if (res?.data) {
          this.detail = res.data

          if (this.detail) {
            if (this.detail.url) {
              this.detail.url = JSON.parse(res.data.url || '[]')
            }
          }
        }
      })
    },

    getListInit() {
      this.current == 1
      this.getActiveList()
    },

    getActiveList() {
      this.$http.post(`/app/appvillageactivitypost/list?activityId=${this.id}`).then((res) => {
        if (res?.data) {
          this.activeList = res.data.records
          if (this.activeList) {
            let imagesList = []
            this.activeList.map((item) => {
              if (item.images) {
                item.images = JSON.parse(item.images || '[]')
                imagesList.push(item.images)
              }
              return item
            })
            this.imgList = imagesList
          }
        }
      })
    },

    change(index) {
      this.current = index
      if (this.current == 1) {
        this.getActiveList()
      }
    },

    toAdd() {
      uni.navigateTo({ url: `./Add?id=${this.id}` })
    },

    AddPosts() {
      uni.navigateTo({ url: `./AddPosts?id=${this.id}` })
    },

    previewImage(images, img) {
      uni.previewImage({
        urls: images.map((v) => v.url),
        current: img,
      })
    },
  },
}
</script>
<style scoped lang="scss">
.page {
  width: 100%;
  height: 100%;
  background-color: #fff;

  .info-title {
    padding-left: 32px;
    line-height: 108px;
    font-size: 32px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333;
  }
  .tab-title {
    line-height: 108px;
    font-size: 32px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333;
    span {
      display: inline-block;
      width: 192px;
      text-align: center;
    }
    .active {
      color: #3671ee;
      border-bottom: 4px solid #3671ee;
    }
  }
  .status0 {
    background: #000;
  }
  .status1 {
    background: #ff883c;
  }
  .status3 {
    background: #1aaaff;
  }
  .status2 {
    background: #42d784;
  }
  .status4,
  .status5 {
    background: #e4e4e4;
  }
  .header-content {
    // padding-bottom: 80px;
    .header-top {
      width: 100%;
      height: 440px;
      img {
        width: 100%;
        height: 100%;
      }
    }

    .header-middle {
      padding: 32px 32px 0 32px;

      .img-title {
        font-size: 36px;
        font-weight: 600;
      }

      .header-middle-bottom {
        display: flex;
        justify-content: space-between;
        margin-top: 32px;
        .left {
          .left-btn {
            padding: 4px 8px;
            border-radius: 8px;

            font-size: 26px;
            color: #ffffff;
            text-align: center;
          }
        }
        .right {
          img {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            vertical-align: text-top;
            margin-right: 8px;
          }
        }
      }

      .cards {
        display: flex;
        justify-content: space-between;
        border-bottom: 2px solid #eee;
        padding: 36px 0;
        line-height: 40px;
        font-size: 28px;

        .cards-left {
          color: #999;
        }

        .cards-right {
          color: #333;
        }
      }
    }

    .header-bottom {
      // background: #fff;

      .content-details {
        padding: 32px 32px 130px 32px;
        .font {
          margin-top: 32px;
          font-size: 30px;
          line-height: 1.5;
        }
        .font-img {
          margin-top: 26px;
          width: 100%;
          height: 480px;
        }
      }

      .content-trends {
        // padding-bottom: 40px;
        background: #f3f6f9;
        .details {
          .card {
            background: #fff;
            padding: 26px 32px 28px 32px;
            margin-bottom: 20px;
            .card-nav {
              display: flex;
              .avatar {
                width: 64px;
                height: 64px;
                line-height: 60px;
                background: #4e8eee;
                border-radius: 50%;
                text-align: center;

                font-size: 24px;
                font-weight: 500;
                color: #ffffff;
                margin-right: 16px;
              }
              .right {
                // display: inline;
                display: flex;
                flex-direction: column;

                .name {
                  font-size: 26px;
                  font-weight: 500;
                }
                .time {
                  font-size: 22px;
                  color: #999999;
                }
              }
            }

            .card-font {
              margin-top: 36px;
              line-height: 1.6;
              text-overflow: -o-ellipsis-lastline;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              line-clamp: 2;
              -webkit-box-orient: vertical;
            }

            .card-img {
              margin-top: 16px;
              img {
                width: 224px;
                height: 224px;
                margin-right: 8px;
              }
              img:last-child {
                margin-right: 0;
              }
            }

            .card-icon {
              display: flex;
              justify-content: space-between;
              margin-top: 28px;
              div {
                display: flex;
                align-items: center;
                span {
                  font-size: 24px;
                }
              }
            }
          }
        }

        ::v-deep .emptyWrap {
          // background-color: pink;
          padding-bottom: 50px;
        }

        .noDeatil {
          background-color: #f3f6f9;
          img {
            width: 400px;
            height: 240px;
            transform: translate(50%, 25%);
            padding-bottom: 156px;
          }
        }

        .card-bottom {
          height: 20px;
          background-color: #f3f6f9;
        }
      }
    }

    .fixedBtns {
      position: fixed;
      bottom: 0;
      width: 100%;
      height: 112px;
      line-height: 112px;
      background: #1365dd;
      text-align: center;
      font-size: 32px;
      font-weight: 500;
      color: #ffffff;
    }
  }

  .AiFixedBtn {
    .movableArea {
      .addBtn {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 96px;
        height: 96px;
        flex-shrink: 0;
        background: #fff;
        box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
        font-size: 48px;
        color: #1365dd;
        border-radius: 50%;
      }
    }
  }
}
</style>
