<template>
  <div class="photo-list">
    <u-navbar back-icon-color="#000" title="居民上报" title-color="#000" title-width="300" title-size="32" 
      :title-bold="true" :background="backgroundNavbar" :is-fixed="true" height="44"></u-navbar>
    <div class="header-content-bg">
      <img src="https://cdn.sinoecare.com/i/2024/07/12/6690a1303d423.png" alt="">
    </div>
    <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 class="footer" @click="toReport">
      <div class="btn">我要上报</div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: "AppPhotoReport",
  appName: "居民上报",
  customNavigation: true,
  data() {
    return {
      list: [],
      current: 1,
      pages: 2,
      total: 0,
      itemOptions: [
        {text: '删除', style: {backgroundColor: '#f46'}}
      ],
      backgroundNavbar: {
        background: 'url(https://cdn.sinoecare.com/i/2024/07/12/6690a1309c7d3.png) no-repeat',
        backgroundSize: 'cover',
      },
    }
  },

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

  onShow() {
    this.current = 1
    this.pages = 2
    this.getList()
  },
  onLoad() {
    this.$dict.load(['clapEventStatus'])
  },
  methods: {
    toReport() {
      this.$linkTo('./PhotoForm')
    },
    getList() {
      if (this.current > this.pages) return 
      this.$loading()
      this.$instance.post(`/app/apppatrolreportinfov2/listByApplet`, null, {
        params: {
          current: this.current, size: 15
        }
      }).then(res => {
        if (res?.data) {
          const list = res.data.records.map(v => ({...v, statusName: this.$dict.getLabel('clapEventStatus', v.eventStatus)}))
          this.list = this.current == 1 ? list : [this.list, list].flat()
          this.total = res.data.total
          this.pages = res.data.pages
          this.current++
        }
      }).finally(() => uni.hideLoading())
    },
    handleDelete(ids) {
      this.$dialog.confirm({content: "确定删除该数据?"}).then(() => {
        this.$instance.post("/app/apppatrolreportinfov2/delete", null, {
          params: {ids}
        }).then(res => {
          if (res?.code == 0) {
            this.$u.toast("删除成功!")
            this.current = 1
            this.pages = 2
            this.getList()
          }
        })
      }).catch(() => 0)
    }
  },
  onReachBottom() {
    this.getList()
  }
}
</script>

<style lang="scss">
.photo-list {
  // padding: 24px 0 150px 0;
  .header-content-bg {
    width: 100%;
    position: fixed;
    z-index: -1;
    img {
      width: 100%;
      height: 592px;
    }
  }

  .photo-list__wrapper {
    padding: 0 0 252px 0;
  }

  .photo-item {
    width: calc(100% - 64px);
    margin: 0 0 32px 32px;

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

      h2 {
        width: 100%;
        line-height: 44px;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        font-size: 32px;
        color: #333;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        margin-bottom: 24px;
      }

      .photo-item__top--info-item {
        line-height: 40px;
        font-family: PingFangSC-Regular;
        font-size: 28px;
        margin-bottom: 8px;

        label {
          display: inline-block;
          margin-right: 24px;
          color: #999;
        }
        span {
          color: #333;
        }
      }
    }

    .photo-item__bottom {
      display: flex;
      align-items: center;
      height: 104px;
      padding: 0 32px;
      border-top: 1px solid #DDDDDD;
      font-family: PingFangSC-Regular;
      font-size: 24px;
      line-height: 40px;
      i {
        display: inline-block;
        width: 16px;
        height: 16px;
        margin-right: 16px;
        border-radius: 50%;
        background: #FF883C;
      }

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

      .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;
      }
    }
  }

  ::v-deep .u-swipe-action {
    border-radius: 16px;
  }

  .footer {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    background-color: #F4F5FA;
    padding: 64px 64px 68px 64px;
    z-index: 9;
    .btn {
      width: calc(100% - 128px);
      line-height: 88px;
      background: #026AF2;
      border-radius: 44px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 34px;
      color: #FFF;
      text-align: center;
    }
  }
}
</style>
