<template>
  <div class="photo-list">
    <div class="photo-list__wrapper">

      <div class="photo-item" v-for="(item, index) in list" :key="index">
        <u-swipe-action @content-click="$linkTo('./PhotoDetail?id=' + item.id)" :index="item.id"
                        :options="itemOptions" @click="handleDelete">
          <div class="photo-item__top">
            <h2>{{ item.content }}</h2>
            <div class="photo-item__top--info">
              <div class="photo-item__top--info-item">
                <label>事件类型</label>
                <span>{{ item.groupName }}</span>
              </div>
              <div class="photo-item__top--info-item">
                <label>所属网格</label>
                <span>{{ item.girdName }}</span>
              </div>
            </div>
          </div>
          <div class="photo-item__bottom flex">
            <div class="flex fill">
              <i :class="'status-' + item.eventStatus"></i>
              <span :class="'status-' + item.eventStatus">{{ item.statusName }}</span>
            </div>
            <AiEvaluation :bid="item.id" v-if="item.eventStatus>1">
              <div class="itemBtn">去评价</div>
              <div slot="finish" class="finish">已评价</div>
            </AiEvaluation>
          </div>
        </u-swipe-action>
      </div>
      <AiEmpty v-if="!list.length"/>
    </div>
    <div class="btn-wrapper">
      <div class="btn" @click="toReport" hover-class="text-hover">我要上报</div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: "AppPhotoReport",
  appName: "随手拍",
  data() {
    return {
      list: [],
      pageShow: false,
      current: 1,
      total: 0,
      isMore: false,
      itemOptions: [
        {text: '删除', style: {backgroundColor: '#f46'}}
      ]
    }
  },

  computed: {
    ...mapState(['user'])
  },

  onLoad() {
    this.$loading()
    this.$dict.load(['clapEventStatus']).then(() => {
      this.getList()
    })

    uni.$on('update', () => {
      this.current = 1
      this.isMore = false

      this.getList()
    })
  },

  methods: {
    toReport() {
      this.$linkTo('./PhotoForm')
    },

    getList() {
      if (this.isMore) return

      this.$instance.post(`/app/appclapeventinfo/listByWxApplet`, null, {
        params: {
          current: this.current,
          size: 15
        }
      }).then(res => {
        if (res.code == 0) {
          this.total = res.data.total
          if (this.current > 1) {
            this.list = [...this.list, ...res.data.records].map(v => {
              return {
                ...v,
                statusName: this.$dict.getLabel('clapEventStatus', v.eventStatus)
              }
            })
          } else {
            this.list = res.data.records.map(v => {
              return {
                ...v,
                statusName: this.$dict.getLabel('clapEventStatus', v.eventStatus)
              }
            })
          }
          uni.hideLoading()
          this.pageShow = true
          if (res.data.records.length < 15) {
            this.isMore = true

            return false
          }

          this.current = this.current + 1
        } else {
          uni.hideLoading()
        }
      }).catch(() => {
        uni.hideLoading()
      })
    },
    handleDelete(ids) {
      this.$dialog.confirm({content: "是否要进行删除?"}).then(() => {
        this.$instance.post("/app/appclapeventinfo/delete", null, {
          params: {ids}
        }).then(res => {
          if (res?.code == 0) {
            this.$u.toast("删除成功!")
            this.current = 1
            this.isMore = false
            this.getList()
          }
        })
      }).catch(() => 0)
    }
  },

  onReachBottom() {
    this.getList()
  }
}
</script>

<style lang="scss">
.photo-list {
  padding: 24px 0 150px 0;

  .photo-item {
    width: 686px;
    margin: 0 32px 24px;
    background: #FFFFFF;
    box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.02);
    border-radius: 16px;
    overflow: hidden;

    .photo-item__top {
      padding: 32px;
      text-align: justify;

      h2 {
        margin-bottom: 32px;
        line-height: 1.4;
        color: #333333;
        font-size: 32px;
        font-weight: 600;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }

      .photo-item__top--info-item {
        display: flex;
        align-items: center;

        &:last-child {
          margin-bottom: 8px;
        }

        label {
          margin-right: 32px;
          color: #999999;
          font-size: 26px;
        }

        span {
          color: #333333;
          font-size: 26px;
        }
      }
    }

    .photo-item__bottom {
      display: flex;
      align-items: center;
      height: 104px;
      padding: 0 32px;
      border-top: 1px solid #DDDDDD;

      i {
        width: 8px;
        height: 8px;
        margin-right: 8px;
        border-radius: 50%;
        background: #FF883C;
      }

      .itemBtn {
        border: 1px solid #4181FF;
        border-radius: 8px;
        color: #4181FF;
        padding: 8px 22px;


      }

      .finish {
        color: #42D784;
        font-size: 28px;
      }

      span {
        color: #FF883C;
        font-size: 28px;
        background: transparent !important;
      }

      .status-1 {
        color: #1AAAFF;
        background: #1AAAFF;
      }

      .status-2 {
        color: #42D784;
        background: #42D784;
      }

      .status-3 {
        color: #FF4466;
        background: #FF4466;
      }
    }
  }
}
</style>
