<template>
    <!-- pages/fuwu/fuwu.wxml -->
    <view class="contain">
        <!-- 问答类别 -->
		<ul class="wendaFL" v-for="(e,idx) in typeList" :key="idx" style="width: 48%;">
				<li class="sanNong" style="width: 100%;">
					<image :src="loadImgSrcLocalhost(e.path)" class="lbBj" @tap="goType(e.id,e.type)"></image>
					<h2>{{e.type}}</h2>
					<span>{{e.questionNum}}</span>
				</li>
		</ul>
		<!-- 问答列表 -->
		<view class="rnwdList" v-for="(item, index) in hotQuestionList" :key="index" @tap="goDetails(item.id)">
			<span class="lb">{{ item.type }}</span>
			<view class="list">
				<span class="listTitle">{{ item.title }}</span>
				<view class="jlSj">
					<span class="jf">
						{{ item.score }}
						<em class="iconfont icon-jifen"></em>
					</span>
					<view class="ck">
						<span>
							<em class="iconfont icon-pinglun"></em>
							{{ item.comment }}
						</span>
						<span>
							<em class="iconfont icon-chakan"></em>
							{{ item.browse }}
						</span>
						<span>
							<em class="iconfont icon-shoucang"></em>
							{{ item.collect }}
						</span>
					</view>
				</view>
			</view>
			<em class="iconfont icon-xiangyoujiantou"></em>
		</view>
		<button type="primary" @click="goAddQuestion()" v-if="form.id==null">新增</button>
    </view>
</template>

<script>
import upload from '@/components/upload/index.vue'
import {getTypeList,getHotQuestionList} from '@/api/asking/asking.js'
export default {
	components: {
		upload
	},
    data() {
        return {
			imageList:[
				'/profile/upload/2024/03/02/D5hjxYkldNxIef093ae65b2128b1293b86a7b537ed98_20240302170757A001.png',
				'/profile/upload/2024/03/02/D5hjxYkldNxIef093ae65b2128b1293b86a7b537ed98_20240302170757A001.png'
			],
            typeList: [
                {
                    type: null,
					path: null
                }
            ],
            hotQuestionList: [{}],
			// 查询参数
		  queryParams: {
			pageNum: 1,
			pageSize: 6,
		  },
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        this.getTypeList();
        this.getHotQuestionList();
    },
    methods: {
         //获取类型列表
        getTypeList(){
            getTypeList(this.queryParams).then(res =>{
                this.typeList = res.rows
            })
        },
         //获取热门问答列表
        getHotQuestionList(){
            getHotQuestionList().then(res =>{
                this.hotQuestionList = res.rows
            })
        },
		//按类型跳转问题列表
        goType(id,type) {
			uni.setStorageSync('id', id)
            uni.navigateTo({
                url: '/pages/asking/questionlist?type='+type
            });
        },
		//新增问题
        goAddQuestion() {
            uni.navigateTo({
                url: '/pages/asking/addquestion'
            });
        },

        goDetails(id) {
            uni.navigateTo({
                url: '/pages/asking/questiondetails?id=' + id
            });
        },

		updateImg(imgList){
			this.imageList = imgList;
		}
    }
};
</script>
<style scoped>
@import '@/pages/asking/asking.css';
.contain {
    height: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0rpx 20rpx;
    box-sizing: border-box;
	flex-wrap: wrap;
}
</style>
