<template>
	<view>
		<my-coursedetail :item="course" :location="location" :marker="marker" :timeAM="timeAM" :timePM="timePM" :timeEvening="timeEvening" buttonMessage="以此为模板新发布" :isShowCollect="false" :isShowPrivate="true"></my-coursedetail>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				course: {},
				teacherInfo: {},
				courseWeekday: [],
				location: [],
				marker: [{
					id: 1,
					joinCluster:true,
					latitude: 0,
					longitude: 0,
					width: 40,
					height: 40,
					iconPath: '/static/location.png',
				}],
				// 上课时间
				// 上午
				timeAM: [{
						value: 'A1',
						name: '1',
						checked: false
					},
					{
						name: '2',
						value: 'A2',
						checked: false
					},
					{
						name: '3',
						value: 'A3',
						checked: false
					},
					{
						name: '4',
						value: 'A4',
						checked: false
					},
					{
						name: '5',
						value: 'A5',
						checked: false
					},
					{
						name: '6',
						value: 'A6',
						checked: false
					},
					{
						name: '7',
						value: 'A7',
						checked: false
					}
				],
				// 下午
				timePM: [{
						value: 'P1',
						name: '1',
						checked: false
					},
					{
						name: '2',
						value: 'P2',
						checked: false
					},
					{
						name: '3',
						value: 'P3',
						checked: false
					},
					{
						name: '4',
						value: 'P4',
						checked: false
					},
					{
						name: '5',
						value: 'P5',
						checked: false
					},
					{
						name: '6',
						value: 'P6',
						checked: false
					},
					{
						name: '7',
						value: 'P7',
						checked: false
					}
				],
				// 晚上
				timeEvening: [{
						name: '1',
						value: 'E1',
						checked: false
					},
					{
						name: '2',
						value: 'E2',
						checked: false
					},
					{
						name: '3',
						value: 'E3',
						checked: false
					},
					{
						name: '4',
						value: 'E4',
						checked: false
					},
					{
						name: '5',
						value: 'E5',
						checked: false
					},
					{
						name: '6',
						value: 'E6',
						checked: false
					},
					{
						name: '7',
						value: 'E7',
						checked: false
					}
				],
			};
		},
		created() {
			this.getTeachInfo()
		},
		onLoad(option) {
			this.course = JSON.parse(decodeURIComponent(option.item))
			this.location = this.course.locationAl.split(",")
			this.marker[0].latitude = Number(this.location[0])
			this.marker[0].longitude = Number(this.location[1])
			this.courseWeekday = this.course.teachTime.split(",")
			// console.log("选中的日期：" + this.courseWeekday)
			for (let i = 0; i < this.courseWeekday.length; i++) {
				for (let x = 0; x < this.timeAM.length; x++) {
					if (this.courseWeekday[i] == this.timeAM[x].value) {
						this.timeAM[x].checked = true
					}
				}
				
				for (let y = 0; y < this.timePM.length; y++) {
					if (this.courseWeekday[i] == this.timePM[y].value) {
						// console.log(this.timePM[y].value)
						this.timePM[y].checked = true
					}
				}
				
				for (let z = 0; z < this.timeEvening.length; z++) {
					if (this.courseWeekday[i] == this.timeEvening[z].value) {
						this.timeEvening[z].checked = true
					}
				}
			}
			
		},
		methods:{
			// 获取最近成交时间和成交次数
			async getCountAndLastTime() {
				const query = {
					uid: this.teacherCourse.uid
				}
				const { data: result } = await uni.$http.get('/education/teacher-courses/queryCountAndLastTime', query)
				this.teacherCourse.count = result.data.count
				this.teacherCourse.latest = result.data.time
			},
			// 根据uid获取该老师学校学历等
			async getInfosByUid() {
				const { data: result } = await uni.$http.get('/education/teacher-certifications/findInfosByUid', { uid: this.teacherCourse.uid })
				this.teacherCourse.education = result.data.one.education
				this.teacherCourse.major = result.data.one.major
				this.teacherCourse.nativePlace = result.data.one.nativePlace
				this.teacherCourse.school = result.data.one.school
			},
			// 获取老师认证信息
			async getTeachInfo() {
				const { data: result } = await uni.$http.get('/education/teacher-certifications/getInfos')
				// console.log("hh", result)
				this.teacherInfo = result.data
				this.teacherInfo.imgUrl = 'data:image/png;base64,' + this.teacherInfo.imgUrl
				this.course.name = this.teacherInfo.name
				this.course.education = this.teacherInfo.education
				this.course.profilePhoto = this.teacherInfo.imgUrl
				this.course.sex = this.teacherInfo.sex
				console.log(this.course)
			}
			
		}
	}
</script>

<style lang="scss" scoped>
</style>
