<template>
  <view class="main">
	<view class="main_title">{{detail.title}}</view>
	<view class="main_detail">
		<text>{{detail.content}}</text>
	</view>
	<view class="bott">
		<view class="bott_item" :class="detail.usefulNum ? 'bott_item_arr':''" @click="btnClick(1)"><image class="bott_item_img" :src="usefulNum"></image>已解决</view>
		<view class="bott_item" :class="detail.uselessNum ? 'bott_item_arr':''" @click="btnClick(2)"><image class="bott_item_img"  :src="uselessNum"></image>未解决</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 { helpinfo,helppraise } from '@/server/api'
const counterStore = useCounterStore(); // 使用 Store
const { proxy } = getCurrentInstance();
const detailId = ref('');
const detail = ref({});
const usefulNum = ref('');
const uselessNum = ref('');
//使用pinia：storeToRefs方法包裹(保持响应式更新，不使用视图无法更新)
const {statusHeight,headerHeight,statusBartop,ButtonWidth,ButtonHeight } = storeToRefs(counterStore);
const id = ref('');
const api_helpinfo = () => {
	let params = {
		id:detailId.value
	}
	return helpinfo(params).then(({data})=>{
		detail.value = data;
		if(data.usefulNum){
			usefulNum.value = "../../static/resolved_arr.png"
		}else{
			usefulNum.value = "../../static/resolved.png"
		}
		if(data.uselessNum){
			uselessNum.value = "../../static/unsolved_arr.png"
		}else{
			uselessNum.value = "../../static/unsolved.png"
		}
	})
}
const btnClick = (type) => {
	const params = {
		id:detailId.value,
		type
	}
	return helppraise(params).then(({message})=>{
		uni.showToast({
			title:message,
			icon:'success',
			success: () => {
				setTimeout(()=>{
					api_helpinfo();
				},1000)
			}
		})
	})	
	.catch(({message}) => {
		if(i == 1){uni.hideLoading()}
		uni.showModal({
			content:message,
			showCancel: false
		})
	})
}
onLoad((options) => {
	const { id } = options;
	detailId.value = id;
	api_helpinfo();
});
onShow(() => {});
onReady(()=>{})
onPullDownRefresh(()=>{})
onReachBottom(()=>{})
</script>

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