<template>
    <!-- pages/me.wxml -->
    <view class="container">
        <tabs :list="tabs" tab-class="tab-class" :showBadge="true" :swiper="true" activeColor="#07c160" normalColor="#000000" @change="tabChange">
            <tab-page :slot="item.name" v-for="(item, index) in tabs" :key="index">
                <view v-if="index == 0" class="container">
                    <view class="rnwdList">
                        <view class="list" @tap="goDetails(item1.id)" v-for="(item1, index1) in allQuestion" :key="index1">
                            <span class="listTitle">{{ item1.title }}</span>
                            <view class="onePic" v-if="item1.paths!=null&&item1.paths.length == 1">
                                <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in item1.paths" :key="index2"></image>
                            </view>
                            <view class="twoPic" v-if="item1.paths!=null&&item1.paths.length == 2">
                                <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in item1.paths" :key="index2"></image>
                            </view>

                            <view class="threePic" v-if="item1.paths!=null&&item1.paths.length == 3">
                                <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in item1.paths" :key="index2"></image>
                            </view>

                            <view class="jlSj">
                                <span class="jf">
                                    {{ item1.score }}
                                    <em class="iconfont icon-jifen"></em>
                                </span>
                                <view class="ck">
                                    <span>
                                        <em class="iconfont icon-pinglun"></em>
                                        {{ item1.comment }}
                                    </span>
                                    <span>
                                        <em class="iconfont icon-chakan"></em>
                                        {{ item1.browse }}
                                    </span>
                                    <span>
                                        <em class="iconfont icon-shoucang"></em>
                                        {{ item1.collect }}
                                    </span>
                                </view>
                            </view>

						</view>
                    </view>
                </view>

                <view v-if="index == 1" class="rnwdList">
                    <view class="rnwdList">
                        <view class="list" @tap="goDetails(item1.id)" v-for="(item1, index1) in excitingAnswersList" :key="index1">
                            <span class="listTitle">{{ item1.title }}</span>
                            <view class="onePic" v-if="item1.paths!=null&&item1.paths.length == 1">
                                <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in item1.paths" :key="index2"></image>
                            </view>
                            <view class="twoPic" v-if="item1.paths!=null&&item1.paths.length == 2">
                                <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in item1.paths" :key="index2"></image>
                            </view>
                        
                            <view class="threePic" v-if="item1.paths!=null&&item1.paths.length == 3">
                                <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in item1.paths" :key="index2"></image>
                            </view>
                        
                            <view class="jlSj">
                                <span class="jf">
                                    {{ item1.score }}
                                    <em class="iconfont icon-jifen"></em>
                                </span>
                                <view class="ck">
                                    <span>
                                        <em class="iconfont icon-pinglun"></em>
                                        {{ item1.comment }}
                                    </span>
                                    <span>
                                        <em class="iconfont icon-chakan"></em>
                                        {{ item1.browse }}
                                    </span>
                                    <span>
                                        <em class="iconfont icon-shoucang"></em>
                                        {{ item1.collect }}
                                    </span>
                                </view>
                            </view>
                        
                        </view>
                    </view>
                </view>

                <view v-if="index == 2" class="rnwdList">
                    <view class="rnwdList">
                        <view class="list" @tap="goDetails(item1.id)" v-for="(item1, index1) in maxScoreList" :key="index1">
                            <span class="listTitle">{{ item1.title }}</span>
                            <view class="onePic" v-if="item1.paths!=null&&item1.paths.length == 1">
                                <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in item1.paths" :key="index2"></image>
                            </view>
                            <view class="twoPic" v-if="item1.paths!=null&&item1.paths.length == 2">
                                <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in item1.paths" :key="index2"></image>
                            </view>
                        
                            <view class="threePic" v-if="item1.paths!=null&&item1.paths.length == 3">
                                <image :src="loadImgSrcLocalhost(path)" v-for="(path, index2) in item1.paths" :key="index2"></image>
                            </view>
                        
                            <view class="jlSj">
                                <span class="jf">
                                    {{ item1.score }}
                                    <em class="iconfont icon-jifen"></em>
                                </span>
                                <view class="ck">
                                    <span>
                                        <em class="iconfont icon-pinglun"></em>
                                        {{ item1.comment }}
                                    </span>
                                    <span>
                                        <em class="iconfont icon-chakan"></em>
                                        {{ item1.browse }}
                                    </span>
                                    <span>
                                        <em class="iconfont icon-shoucang"></em>
                                        {{ item1.collect }}
                                    </span>
                                </view>
                            </view>
                        
                        </view>
                    </view>
                </view>

			</tab-page>
        </tabs>
    </view>
</template>

<script>
import tabs from '@/components/tabs/tabs.vue';
import tabPage from '@/components/tab-page/tab-page.vue';
import {getAllQuestionByType,getExcitingAnswersList,getMaxScoreList} from '@/api/asking/questionlist.js';
// pages/me.js
var localData = require('@/data/json');
const app = getApp();
export default {
    components: {
        tabs,
        tabPage
    },
    data() {
        return {
			form:{},
			allQuestion: [],
			excitingAnswersList: [],
			maxScoreList: [],
            currentIndex: 0,
            //默认是活动项
            tabs: [
                {
                    name: '全部问答'
                },
                {
                    name: '精彩问答'
                },
                {
                    name: '最多悬赏'
                }
            ]
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
			this.getAllQuestionByType(uni.getStorageSync('id'))
			this.getExcitingAnswersList(uni.getStorageSync('id'))
			this.getMaxScoreList(uni.getStorageSync('id'))
			uni.setNavigationBarTitle({
			  title: options.type
			});
    },
    methods: {
        tabChange: function (e) {
		},
		 //按类型获取全部问题列表
		getAllQuestionByType(id){
			this.form.id = id
			getAllQuestionByType(this.form).then(res =>{
				this.allQuestion = res.rows
			})
		},
		 //按类型获取精彩问题列表
		getExcitingAnswersList(id){
			this.form.id = id
			getExcitingAnswersList(this.form).then(res =>{
				this.excitingAnswersList = res.rows
			})
		},
		 //按类型获取最多悬赏问题列表
		getMaxScoreList(id){
			this.form.id = id
			getMaxScoreList(this.form).then(res =>{
				this.maxScoreList = res.rows
			})
		},
        goDetails(id) {
            uni.navigateTo({
                url: '/pages/asking/questiondetails?id='+id
            });
        }
    }
};
</script>
<style>
@import '@/pages/asking/questionlist.css';
</style>
