<template>
    <view class="AlreadyAudit">
        <scroll-view 
        class="scroll-view"
        :style="{height: scrollViewHeight}"
        :scroll-y="true" 
        enable-back-to-top
        refresher-enabled
        :refresher-threshold="100"
        :refresher-triggered="refresherStatus"
        @scrolltolower="scrolltolower"
        @refresherrefresh="onRefresh"
        >
        <!-- :style="{height: aa}" -->
            <view class="AlreadyAudit-list" >
                <view   
                :style="{paddingBottom: index === total - 1  ? '200rpx' : '0rpx'}"
                class="a" 
                v-for="(item,index) in alreadyAuditData" 
                :key="item.id" >
                <a-card  :item="item">
                    <view class="show-status">
                        {{item.state === 1 ? '已通过' : '未通过'}} 
                    </view>
                </a-card>
                </view>
            </view>
        </scroll-view>
    </view>
</template>

<script>
import Card from './card.vue'
import { getalreadyAudit  } from '@/api/audit.js'
import Tip from '@/utils/tip.js'
export default {
  name: 'AlreadyAudit',
  components: {
    ACard:  Card
  },
  props: {
      height: Number
  },
  computed: {
      scrollViewHeight  () {
        return  this.$store.state.systemInfo.windowHeight - this.height - 44 + 'px'
      }
  },
  onReady () {
      this.getalreadyAudit()
  },
  data () {
      return {
          alreadyAuditData: [],
          pegation: {
              page: 1
          },
          total: 0,
          refresherStatus: false,
          _freshing: false
      } 
  },
  methods: {

    //   下拉刷新
     onRefresh (item) {
        // if (item.detail.dy < 45) return
        if (this.__freshing) return
        this._freshing = true
        this.refresherStatus = true
        this.pegation.page = 1
        
        setTimeout( async () => {
             this.alreadyAuditData = []
             await this.getalreadyAudit() 
        }, 1000)
    
    },
    //   上拉加载
    scrolltolower () {
        this.pegation.page ++ 
        this.getalreadyAudit()
   
    },
    //   获取已经审核的园所
      async getalreadyAudit () {
        const { data ,status}  = await getalreadyAudit({...this.pegation})
        if (status === 200) {
            this.refresherStatus = false
            this.__freshing = false
       
            const {total, entityList} = data
            if (entityList.length === 0) {
              this.pegation.page--
              Tip.error('暂无内容')
              return
            }
            this.total = total
            this.alreadyAuditData.push(...Object.freeze(entityList))
        }
      }
  }
}
</script>
<style scoped lang="less">
.AlreadyAudit {
    height: 100%;
    background-color: #F5F6FA;
    .AlreadyAudit-list {
        width: 100%;
        // height: 1122rpx;
        // padding-bottom: 400px;
        // box-sizing: border-box;
        .a {
            background-color: #F5F6FA;
            .show-status {
                width: 120rpx;
                height: 52rpx;
                border-radius: 200rpx;
                opacity: 0.5;
                border: 2rpx solid #1677FF;
                display: flex;
                justify-content: center;
                align-items: center;
                font-size: 24rpx;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #1677FF;
            }
        }
    }
}

.scroll-view {
    height: 100vh;
}
</style>