<template>
	<view class="page__view highlight">

		<navbar :title="liveInfo.title" leftClick @leftClick="$utils.navigateBack" />

    <view class="header">
      <image class="cover-img" :src="liveInfo.url" mode="widthFix"></image>
      <view class="flex" style="padding: 40rpx 40rpx 0 40rpx;">
        <view class="flex flex-column">
          <view class="title">{{ liveInfo.title }}</view>
          <view class="tag">{{ liveInfo.createTime }}</view>
        </view>
        <view v-if="isManager" class="flex operate">
          <view class="btn btn-add" @click="onMark">标记有我</view>
          <view class="btn btn-add" @click="onAdd">新增记录</view>
        </view>
      </view>
    </view>

    <view class="main">

      <view class="section" v-for="item in list" :key="item.id">
        <view class="flex section-header">
          <view class="avatar">
            <image class="avatar-img" :src="item.user.headImage" mode="scaleToFill"></image>
          </view>
          <view class="info">
            <view class="flex title">
              <view>{{ item.user.nickName }}</view>
              <image class="icon" src="@/static/image/icon-location.png" mode="widthFix"></image>
              <view class="address text-ellipsis">{{ item.address }}</view>
            </view>
            <view class="desc">{{ item.createTime }}</view>
          </view>
        </view>
        <view class="section-content record">
          <view class="record-item" v-for="(image, imgIdx) in item.images" :key="imgIdx">
            <image class="img" :src="image" mode="aspectFill" @click="previewImage(item.images, imgIdx)"></image>
          </view>
        </view>
      </view>

    </view>

    <formPopup ref="formPopup" @submitted="getData"></formPopup>

    <markPopup ref="markPopup"></markPopup>

  </view>
</template>

<script>
	import { mapState } from 'vuex'

	import mixinsList from '@/mixins/list.js'

  import SYStackedCarousel from '@/uni_modules/SY-StackedCarousel/components/SY-StackedCarousel/SY-StackedCarousel.vue'
  import formPopup from './formPopup.vue'
  import markPopup from '@/pages_order/growing/activity/markPopup.vue'

  export default {
		mixins: [mixinsList],
    components: {
      SYStackedCarousel,
      formPopup,
      markPopup,
    },
    data() {
      return {
        current: 0,
        activityId: '',
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          imageId: '',
        },
				mixinsListApi: 'queryImageContentList',
        // todo: fetch
        isManager: true,
      }
    },
    computed: {
			...mapState(['liveInfo']),
    },
    onLoad(arg) {
      const { imageId, activityId } = arg

      this.queryParams.imageId = imageId
      this.activityId = activityId
      this.getData()
    },
    methods: {
			getCoverImage(image) {
				return image?.split?.(',')?.[0]
			},
      getDataThen(records) {
        this.list = records.map(item => {
          const { id, user, address, image, createTime } = item

          return {
            id,
            user,
            address,
            images: image?.split?.(',') || [],
            createTime,
          }
        })
      },
      setData(e) {
        console.log('setData', e)
        this.mixinsListApi = ''
      },
      onAdd() {
        this.$refs.formPopup.open(this.queryParams.imageId, this.activityId)
      },
      onMark() {
        this.$refs.markPopup.open(this.activityId)
      },
      previewImage(arr, index) {
        uni.previewImage({
          urls: arr,
          current: arr[index], // 当前显示图片的链接
        });
      },
    },
  }
</script>

<style lang="scss" scoped>

  .header {
    margin-top: 40rpx;
    font-size: 0;

    .cover-img {
      width: 100%;
      height: auto;
      border-radius: 40rpx;
    }

    .title {
      font-size: 28rpx;
      font-weight: 600;
      color: #252545;
    }

    .tag {
      margin-top: 4rpx;
      padding: 2rpx 8rpx;
      font-size: 24rpx;
      color: #00A9FF;
      background: #E0F5FF;
      border-radius: 8rpx;
    }

    .operate {
      flex: 1;
      justify-content: flex-end;
      column-gap: 16rpx;
      
      .btn-add {
        padding: 6rpx 22rpx;
        font-family: PingFang SC;
        font-size: 28rpx;
        font-weight: 500;
        line-height: 1.5;
        color: #FFFFFF;
        background: linear-gradient(to right, #21FEEC, #019AF9);
        border: 2rpx solid #00A9FF;
        border-radius: 30rpx;
      } 
    }
  }

  .main {
    padding: 0 40rpx 40rpx 40rpx;
  }

  .section {
    margin-top: 40rpx;

    &-header {
      column-gap: 24rpx;

      .avatar {
        flex: none;
        width: 100rpx;
        height: 100rpx;
        border: 4rpx solid #FFFFFF;
        border-radius: 50%;
        overflow: hidden;

        &-img {
          width: 100%;
          height: 100%;
        }
      }

      .info {
        flex: 1;
        min-width: 0;

        .title {
          column-gap: 8rpx;
          white-space: nowrap;
          font-size: 36rpx;
          font-weight: 600;
          color: #252545;

          .icon {
            width: 32rpx;
            height: 32rpx;
          }

          .address {
            flex: 1;
            font-weight: 400;
            font-size: 24rpx;
            color: #00A9FF;
          }
        }

        .desc {
          margin-top: 8rpx;
          font-size: 24rpx;
          font-weight: 400;
          color: #8B8B8B;
        }
      }

    }

    &-content {
      margin-top: 24rpx;
    }
  }

  .record {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16rpx;

    &-item {
      height: 300rpx;
      border: 2rpx solid #CDCDCD;
      border-radius: 12rpx;
      overflow: hidden;

      .img {
        width: 100%;
        height: 100%;
      }
    }
  }
</style>