<template>
	<view>
		<!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
		<view class="u-page">
            <u-list
                @scrolltolower="getList('add')"
            >
                <u-list-item
                    v-for="(item, index) in recordList"
                    :key="index"
                >
                    <u-cell @click="navTo(`/pageMy/setUserBase/subPage/mailboxDetail?id=${item.id}`)" isLink center>
                        <view slot="title" class="title_style pro_warp2"> {{item.consultTopic}} </view>
                        <view slot="label" class="label_style pro_warp2"> {{item.consultContent}} </view>
                    </u-cell>
                </u-list-item>
            </u-list>
        </view>
        <view class="btn_add" >
            <u-button type="primary" size="large" text="添加信件" @click="addConsult"></u-button>
        </view>
	</view>
</template>

<script>
import { getConsultMailboxInfo } from '@/api/content.js'
export default {
	data() {
		return {
            recordList: [],
            pageNumber: 1,
            pageSize: 10,
		};
	},
    onReady() {
        this.getList("refresh")
    },
    created() {
    },
    onReachBottom() {
      console.log('触底了')  
    },
	methods: {
        addConsult() {
            this.navTo(`/pageMy/setUserBase/subPage/mailboxDetail`)
        },
        async getList(type) {
            if (type === "refresh") {
              this.pageNumber = 1;
            }
            let params = {
              page: this.pageNumber,
              size: 10,
            };
            if (this.status) {
            }
            uni.showLoading({ title: '加载中' })
            let resData = await getConsultMailboxInfo({})
            uni.hideLoading()
            if (resData.data?.code === 200) {
              const { records, total, current, size } = resData.data.data;
              if (!records.length) {
                return this.$Api.msg("没有更多");
              }
              switch (type) {
                case "add":
                  this.recordList = [...this.recordList, ...records];
                  break;
                case "refresh":
                  this.recordList = records;
                  break;
              }
              console.log(this.recordList)
              this.pageNumber += 1;
            }
        },
	},
};
</script>

<style lang="scss" scoped>
    .label_style{
        width: 440rpx;
    }
    .title_style{
        width: 400rpx;
        font-weight: bold;
        font-size: 36rpx;
    }
    .btn_add{
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 110rpx;
        background-color: $uni-bg-color-grey;
        padding: 24rpx 24rpx calc(10px + env(safe-area-inset-bottom) / 2) 24rpx;
        text-align: center;
        line-height: 110rpx;
    }
</style>