<template>
  <view class="mian">
	  <view class="faqlist" v-for="(item,index) in List" :key="index">
		  <view class="shop_ask shop_padding"><text>{{item.title}}</text></view>
		  <view class="shop_answer shop_padding"><text>{{item.content}}</text></view>
	  </view>
  </view>
</template>

<script setup>
import { computed,ref,onMounted,onUnmounted,getCurrentInstance,nextTick } from 'vue';
import { useCounterStore } from '@/store/counter'; // 引入 Pinia Store
import { storeToRefs } from 'pinia';//实现解构付值
import { onLoad,onShow,onPullDownRefresh,onPageScroll,onReachBottom,onReady } from "@dcloudio/uni-app"
import { frontproblem } from '@/server/api'
const counterStore = useCounterStore(); // 使用 Store
const { proxy } = getCurrentInstance();
//使用pinia：storeToRefs方法包裹(保持响应式更新，不使用视图无法更新)
const { token } = storeToRefs(counterStore);
const List = ref([]);
const total = ref(0);
const decs = ref('');
const pages = ref(0);
const limits = ref(10);
const productIds = ref('');
const api_frontproblem=()=>{
		pages.value = pages.value + 1;
		decs.value = "—— 加载中... ——";
		if(List.value.length > 0 && List.value.length >= total.value){
			decs.value = "—— 嗷呜，已经到底啦 ——";
			return false
		}
		const params = {
			page:pages.value,
			limit:limits.value
		}
		return frontproblem(productIds.value,params).then(({data}) => {
			total.value = data.total;
			decs.value = '—— 上拉加载更多 ——'
			List.value = List.value.concat(data.list);
			if(List.value < List.value){
				decs.value = '—— 上拉加载更多 ——'
			}else{
				decs.value = '—— 嗷呜，已经到底啦 ——';
			}
		}).catch(({message}) => {
			uni.showModal({
				content:message,
				showCancel: false
			})
		})
	}
onLoad((options) => {
	const { productId } = options;
	if(productId){
		productIds.value = productId
	}
	api_frontproblem()
});
onShow(() => {});
onReady(()=>{})
onPullDownRefresh(()=>{
	List.value = [];
	total.value = 0;
	decs.value = '';
	pages.value = 0;
	api_frontproblem();
	uni.stopPullDownRefresh();
})
onReachBottom(()=>{
	api_frontproblem();
})
</script>

<style lang="scss">
	@import './style.scss';
</style>