<template>
	<view class="container">
		<!-- #ifdef H5 -->
		<!-- 	<view style="color: #fff;">
			<tn-nav-bar :isBack="false" backgroundColor="#26B3A0" :bottomShadow="false" @rightClick="jumpScoreRed">数趣AI
			</tn-nav-bar>
			<view :style="{ height: tobheight + 'px' }"></view>
		</view> -->
		<!-- #endif -->


		<view class="content">
			<view class="scoreMainTitle">
				课程
			</view>

			<view class="scoreMainBox" v-for="(item,index) in courseList" @click="goScoreDetail(item.id)">
				<view class="topImg">
					<image :src="item.cover_image?item.cover_image:'../../static/posImg.png'" mode=""></image>
				</view>
				<view class="bottom">
					<view class="labelAndPrice   item">
						<view class="label" style="font-weight: 600;">
							{{item.name }}
						</view>
						<view class="right">

							<view class="price">
								￥{{item.price }}
							</view>
							<view class="selOut" style="color:#999">
								已售出：{{item.orders_count+2376 }}份
							</view>
						</view>
					</view>
					<view class="scoreDes">
						{{item.intro }}
					</view>
					<view class="stuBtn">
						立即学习
					</view>
				</view>
			</view>

			<view class="taskTitle">
				新用户专享任务
			</view>
			<ul>
				<li v-for="(item,index) in tuskList" @click="goDetail(item.id)">

					<view class="leftPicBox">
						<image :src="item.cover_image?item.cover_image:'../../static/posImg.png'" mode="aspectFit">
						</image>
					</view>


					<view class="right">
						<view class="title mb30" style="font-weight: 600;font-size: 34rpx;">
							<!-- Chat GPT应用场景 -->
							{{item.name }}
						</view>
						<view class="des2 mb30">
							<!-- 主要完成应用场景的填写，查找，上传，学习后将收获对open ai的了解更加多元。 -->
							{{item.intro }}
						</view>
						<view class="bottom">
							<view class="money">
								<text style="color: #666;font-size: 26rpx;">佣金：</text>￥{{item.task_commission}}
							</view>
							<view class="btn" @click="goDetail(item.id)" style="font-weight: 500;">
								立即报名
							</view>
						</view>
					</view>
				</li>
			</ul>
			<!-- <button @click="test">测试</button> -->
		</view>
		<empty v-if="tuskList.length==0"></empty>
		<u-loadmore v-if="tuskList.length!=0" :status="status" />

		<wike-tabbar></wike-tabbar>
	</view>
</template>

<script>
	import {
		taskList
	} from '@/api/tusk/index.js'

	import {
		sendGpt
	} from '@/api/my/index.js'
	import {
		courseList
	} from '@/api/score/index.js'
	import http from "@/common/request/index";
	export default {
		components: {},
		data() {
			return {
				tobheight: 45,
				tuskList: [],
				courseList: [],

				page: 1,
				pagesize: 10,
				totalElements: '',
				// loadstatus: "noMore"
				status: 'nomore',

			};
		},
		computed: {

		},
		watch: {

		},
		async onPullDownRefresh() {
			// uni.reLaunch({
			// 	url: '/pages/index/index'
			// })
			let ress = await taskList({
				is_new: 1,
				page: this.page,
				per_page: this.pagesize
			})
			if (ress.code == 0) {
				this.totalElements = ress.data.total
				this.tuskList = ress.data.data
			}
			// console.log('课程学习页任务列表返回值', ress);



			let ress1 = await courseList()
			if (ress1.code == 0) {
				this.courseList = ress1.data.data
			}
			// console.log('课程学习页课程列表返回值', ress1);

			if (ress.code == 0 && ress1.code == 0) {
				uni.stopPullDownRefresh()
			}
		},

		async onLoad() {
			if (!uni.getStorageSync('token')) {
				uni.redirectTo({
					url: '/pages/user/signin'
				})
			}

		},
		async onShow() {
			if (uni.getStorageSync('clickStudyBtn')) {
				uni.removeStorageSync('clickStudyBtn')
			}
			if (uni.getStorageSync('myScoreId')) {
				uni.removeStorageSync('myScoreId')
			}

			let ress = await taskList({
				is_new: 1,
				page: this.page,
				per_page: this.pagesize
			})
			if (ress.code == 0) {
				this.totalElements = ress.data.total
				this.tuskList = ress.data.data
			}
			console.log('课程学习页任务列表返回值', ress);



			let ress1 = await courseList()
			if (ress1.code == 0) {
				this.courseList = ress1.data.data
			}
			console.log('课程学习页课程列表返回值', ress1);

			if (ress.code == 0 && ress1.code == 0) {
				uni.stopPullDownRefresh()
			}
		},
		async onReachBottom() {
			let allTotal = this.page * this.pagesize
			if (allTotal < this.totalElements) {
				console.log('onReachBottom()------------------');
				this.page++;
				this.status = "loading"

				let parms = {
					page: this.page,
					per_page: this.pagesize,
					name: '',
					type: '',
					is_new: 1
				}

				console.log('每次传递的参数', parms);
				let res = await taskList(parms)
				if (res.code == 0) {
					this.tuskList = [...this.tuskList, ...res.data.data]
					this.status = "nomore"
				}
			} else {
				this.status = "nomore"
			}
		},
		onReady() {

		},
		onUnload() {

		},

		methods: {


			async test() {
				let res = await sendGpt({
					message: '中国的首都是'
				})
				console.log('提交问答返回值', res);
			},

			goDetail(id) {
				uni.navigateTo({
					url: '/pages/tusk/tuskDetail/index?id=' + id
				})
			},
			goScoreDetail(id) {
				uni.setStorageSync('from', 'index')
				uni.navigateTo({
					url: '/pages/index/scoreDetail/index?id=' + id
				})
			},
			goTuskDetail() {
				uni.navigateTo({
					url: '/pages/tusk/tuskDetail/index'
				})
			}
		}
	};
</script>

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