<template>
	<view>
		
	<view>
		<my-coursedetail v-if="isShow" :item="item" :location="location" :marker="marker" :timeAM="timeAM" :timePM="timePM" :timeEvening="timeEvening" buttonMessage="用做模板" :isShowCollect="false" :isShowPrivate="true" :isShowBtn="showButton" @publishButton="publishButton"></my-coursedetail>
	</view>
	
	<view class="requires2">
		<uni-row >
				<text>待审条数：{{current}}</text>
		</uni-row>
	</view>
		<!-- 取消和提交按钮 -->
		<view class="suggestBtn" v-if="isShow">
		    <button class="cancelBtn" @click="toRefuse">拒绝</button> 
				<modal v-if="areaShow" title="拒绝原因必填" confirm-text="提交" cancel-text="取消" @cancel="cancelAdd" @confirm="confirmAdd">
				  <input type="text" v-model="areaTxt" placeholder="至少5个字" maxlength="50" />
				</modal>
		    <button class="confirmBtn" :disabled="disableButton" @click="toConfirm">同意</button>
		</view>
	</view>	
</template>

<script>	
import { mapState } from 'vuex';
	import formTime from '@/mixins/form-time.js'
	
	export default {
		mixins: [formTime],
		computed: {
			...mapState('m_user', ['token', 'userinfo'])
		},
		data() {
			return {
				areaShow: false,
				areaTxt:'',
				index: 0,
				current:0,
				item: {},
				datas: {},
				showButton: false,
				isShow: false,
				
				location: [],
				marker: [{
					id: 1,
					joinCluster:true,
					latitude: 0,
					longitude: 0,
					width: 40,
					height: 40,
					iconPath: '/static/location.png',
				}],
			};
		},
		onLoad(option) {			
                this.getAllCheckingCourseInfo()
		},
		methods:{
			checkIsHaveNext(){
					 this.current = this.current - 1
					 this.index = this.index + 1
					if(this.current == 0){
						this.isShow = false
					}else{
						this.item = this.datas.list[this.index]
						this.formatForm()
					}
				},
				toConfirm(){
					// 开始向后端提交数据
					this.submitToBack(this.item.courseId,"已通过",this.userinfo.uid + "已通过","上架")
					this.checkIsHaveNext()
				},
				toRefuse(){
				   this.areaShow = true	
				},
			cancelAdd(){
				this.areaShow = false
			},
			confirmAdd(){
				this.areaShow = false
				var strRefuse = this.areaTxt.replace(/\ +/g,"")
				strRefuse = strRefuse.replace(/[\r\n]/g,"")
				if(strRefuse.length < 5){
					uni.$showMsg("有效字数少于5个，请增加！")
				}else{
					strRefuse = this.userinfo.uid + strRefuse
					// 开始向后端提交数据
					this.submitToBack(this.item.courseId,"未通过",strRefuse,"下架")
					this.checkIsHaveNext()
				}
			},
				async submitToBack(courseid,checkstatus,checktext,display) {
					// 准备参数对象
					const query = {
						courseid: courseid,
						checkstatus: checkstatus,
						checktext: checktext,
						display: display,
					}
					const {
						data: result
					} = await uni.$http.get('/education/teacher-courses/updateTeacherCourseInfo',query)
					//console.log(result)
					uni.$showMsg(result.message , 2000)
				},
			async getAllCheckingCourseInfo() {
				const { data: result } = await uni.$http.get('/education/teacher-courses/getAllCheckingCourseInfo')
			  // console.log(result)
				this.current = result.data.list.length
					if(this.current > 0){
						this.datas = result.data
						this.item = this.datas.list[this.index ]
					//	this.getPhotoes()
					    this.formatForm()
						this.isShow = true
					}
								//console.log(this.item)
				},
			// // 获取课程详情
			// async getCourseDetailById(id) {
			// 	const {data: result} = await uni.$http.get('/education/teacher-courses/getPersonCourseDetailById', {courseId: id})
			// 	this.course = result.data.one
			// 	this.formatForm()
			// },
			// 上课表格格式化
			formatForm() {
				this.location = this.item.locationAl.split(",")
				this.marker[0].latitude = Number(this.location[0])
				this.marker[0].longitude = Number(this.location[1])
				this.courseWeekday = this.item.teachTime.split(",")
				this.parseCourseWeekday()
			},

		}
	}
</script>

<!-- 设置页面背景 -->
<style lang="scss">
	page{
		height: 100%;
		// background-color: #FFF;
	}
</style>

<style lang="scss" scoped>
	.requires2 {
		background-color: #FFF;
		margin: 20rpx 20rpx;
		border-radius: 50rpx;
		font-size: 30rpx;
		padding: 20rpx 20rpx;
		//font-weight: bold;
		color: gray;
		display: flex;
		align-items: center;
		justify-content: center;
		
	}
	
	/* 下方按钮 */
	.suggestBtn{
	    display: flex;
	    padding: 60rpx;
	    justify-content: space-around;
	}
	
	.confirmBtn,
	.cancelBtn{
	    font-size: 30rpx;
	    height: 85rpx;
	    width: 200rpx;
	    line-height: 85rpx;
	    border-radius: 50rpx;
	    text-align: center;
	    color: white;
		margin-top: 5rpx;
	}
	
	.confirmBtn{
		background-color: #35b882;
	}
	.cancelBtn{
		background-color: #3ed598;
	}
	
</style>
