<template>
	<div class="hw-container">
		<Loading :top="200" bgColor="rgba(103, 103, 103, 0.27)" type="1" v-show="isLoading"></Loading>
		<div class="hw-box dark-iview-split">
			<Split v-model="split1" ref="leftSplit">
				<div slot="left" class="demo-split-pane">
					<!-- 投票活动列表 -->
					<div class="hw-col hw-list-box" v-if="!isFromRecord">
						<div class="hw-box-header">
							<span>{{ this.$t('vote.list') }}</span>
							<span>
								<Icon type="md-trash" class="to-create-icon" @click="isAreaVote ? delAreaTrain() : onDeleteVote()"
									style="margin-left:10px"
									v-if="voteList.length && ($access.can('admin.*|schoolAc-upd') || isPrivate) && !canNotDeleteVote(currentVote.owner)" />
								<Icon type="md-add" class="to-create-icon" @click="goToCreate"
									v-if="($access.can('admin.*|schoolAc-upd') || isPrivate)  || isAreaVote" />
							</span>
						</div>
						<vuescroll>
							<Loading :top="200" bgColor="rgba(103, 103, 103, 0.27)" type="1" v-show="isLoadList">
							</Loading>
							<div class="hw-item-wrap">
								<div v-if="voteList.length === 0">
									<EmptyData :top="50"></EmptyData>
								</div>
								<div style="width:100%" v-else>
									<div :class='["hw-item",index === activeVoteIndex ? "item-active":""]'
										v-for="(item,index) in voteList" :key="index" @click="onVoteClick(item,index)">
										<p class="hw-item-name">
											<span class="owner-tag" v-if="item.owner === 'school'">校</span>
											<span class="owner-tag" v-if="item.owner === 'area'" style="background-color: #dc6f28;">区</span>
											{{ item.name }}
										</p>
										<div class="hw-item-info">
											<span class="hw-item-nums">
												<Icon type="md-time" size="14" style="margin-right:5px" />
												{{ $tools.formatTime(item.startTime || item.createTime,'yyyy-MM-dd hh:mm') }}
											</span>
											<span class="hw-item-status"
												:style="{ background: (item.progress === 'pending' ? '#0BADD4' : item.progress === 'going' ? '#1fb06d' : '#949594')}">{{ item.progress === 'pending' ? $t('vote.pending') : item.progress === 'going' ? $t('vote.going') : $t('vote.finish') }}</span>
										</div>
									</div>
								</div>

							</div>
						</vuescroll>
					</div>
				</div>
				<div slot="right" class="demo-split-pane">
					<Split v-model="split2">
						<div slot="left" class="demo-split-pane" ref="voteFormBox">
							<!-- 投票基础信息展示 -->
							<div class="hw-col hw-info-box">
								<div class="hw-box-header">
									<span>{{ $t('vote.voteDetails') }}</span>
									<div class="hw-box-header-tools">
										<span class="hw-box-header-tools-tool"
											v-show="currentVote.progress === 'pending'">
											<Icon type="md-create" size="18" :title="$t('vote.edit')"
												@click="onEditVote"
												v-if="($access.can('admin.*|schoolAc-upd') || isPrivate) && !isAreaVote && currentVote.owner === 'school'" />
										</span>
									</div>
								</div>
								<vuescroll ref="voteFormScroll">
									<div v-show="voteList.length === 0">
										<EmptyData :top="50"></EmptyData>
									</div>
									<div class="hw-info-wrap" v-show="voteList.length !== 0">
										<BaseVoteForm :editItem="currentVote" @onAddSuccess="onAddSuccess"
											ref="voteForm" @onCancelVote="onCancelVote"></BaseVoteForm>
									</div>
								</vuescroll>
							</div>
						</div>
						<div slot="right" class="demo-split-pane">
							<!-- 投票提交数据 -->
							<div class="hw-col hw-data-box">
								<div class="hw-box-header">
									<span>{{ $t('vote.voteResult') }}</span>
									<div class="hw-box-header-tools">
										<div v-if="!isAreaVote">
											<span class="hw-box-header-tools-tool" @click="changeTableView" v-if="!currentVote.secret">
												<Icon type="md-podium" />
												{{ isOptionView ? $t('vote.stuListView') : $t('vote.optionView') }}
											</span>
										</div>
										<div>
											<Button class="btn-save" v-if="isFromRecord" icon="md-arrow-round-back"
												@click="goBackRecord">{{ $t('survey.backToRecord') }}</Button>
										</div>
										
									</div>
								</div>
								<div v-if="voteList.length === 0 || hasNewAdd || currentVote.progress === 'pending'">
									<EmptyData :top="50"></EmptyData>
								</div>
								<div class="hw-data-wrap" style="height:90%;padding-top: 10px;" ref="baseQnRef" v-else>
									<vuescroll>
										<div v-if="isAreaVote && currentVote.progress !== 'pending'">
											<Select v-model="areaSchIndex" style="width:200px;margin: 10px 20px;" @on-change="getAreaRecord">
												<Option v-for="(item,index) in areaSchList" :value="index" :key="index">{{ item }}</Option>
											</Select>
										</div>
										<div style="display:flex;background-color: #f8f8f9;margin: 0 20px 20px 20px;" v-if="tableData.length || isAreaVote">
											<BaseVotePie pieId="votePie" :pieData="studentsTable"
												v-show="tableData.length || isAreaVote"></BaseVotePie>
											<BaseVoteBar pieId="votePie2" v-if="tableData.length" :pieData="tableData">
											</BaseVoteBar>
										</div>
										<BaseVoteTable :tableDatas="tableData" v-show="isOptionView && !isAreaVote"></BaseVoteTable>
										<BaseVoteSsTable :tableDatas="studentsTable" v-show="!isOptionView && !isAreaVote" :isSecret="currentVote.secret">
										</BaseVoteSsTable>
									</vuescroll>
								</div>
							</div>
						</div>
					</Split>
				</div>
			</Split>
		</div>
	</div>
</template>
<script>
	import BaseVoteForm from '@/components/vote/BaseVoteForm'
	import BaseVoteTable from '@/components/vote/BaseVoteTable'
	import BaseVoteSsTable from '@/components/vote/BaseVoteSsTable'
	import BaseVotePie from '@/components/vote/BaseVotePie'
	import BaseVoteBar from '@/components/vote/BaseVoteBar'
	export default {
		components: {
			BaseVoteForm,
			BaseVoteTable,
			BaseVoteBar,
			BaseVotePie,
			BaseVoteSsTable
		},
		data() {
			return {
				split1: 0.2,
				split2: 0.35,
				tabIndex: 0,
				hasNewAdd: false,
				isLoading: false,
				isLoadList: false,
				isOptionView: false,
				isEdit: false,
				editable: false,
				voteList: [],
				studentsList: [],
				studentsTable: [],
				currentVote: {},
				editItem: null,
				activeVoteIndex: 0,
				voteTableData: [],
				tableData: [],
				addHwModal: false,
				isFromRecord: false,
				areaId: sessionStorage.getItem('areaId'),
				areaVoteTeachers: [],
				areaRecord:[],
				areaSchIndex:0,
				areaSchList:[],
			}
		},
		created() {},
		methods: {

			// 校本课纲与个人课纲切换
			handleTabClick(index) {
				this.tabIndex = index
				setTimeout(() => {
					this.getVoteList(index === 0 ? 'school' : 'private')
				}, 500)
			},

			goBackRecord() {
				this.$router.back(-1)
			},

			/** 新增投票 */
			goToCreate() {
				let hasNoSaveVote = this.voteList.filter(i => !i.id).length
				if (hasNoSaveVote) {
					this.$Message.warning(this.$t('vote.isExistTip'));
				} else {
					let defaultVote = {
						name: this.$t('vote.defaultName'),
						code: this.tabIndex === 0 ? this.$store.state.userInfo.schoolCode : this.$store.state.userInfo
							.TEAMModelId,
						classes: [],
						stuLists:[],
						targets:[],
						owner: this.isAreaVote ? 'area' : 'school',
						options: [{
							code: 'A',
							value: ''
						}, {
							code: 'B',
							value: ''
						}],
						publishModel: '0',
						selectMax: 1,
						isImmediate: this.isAreaVote ? true : false,
						endTime: new Date(new Date().toLocaleDateString()).getTime() + 2 * 24 * 60 * 60 * 1000 - 1,
						startTime:new Date().getTime(),
						description: '',
						secret: false,
						progress: 'pending'
					}
					this.voteList.unshift(defaultVote);
					this.currentVote = defaultVote;
					this.activeVoteIndex = 0;
					this.editable = true
					this.hasNewAdd = true
					this.$refs.voteForm.voteFormEdit = true
					this.$refs.voteForm.classTargets = []
					this.$EventBus.$emit('onCreateVote')
				}

				this.$nextTick(() => {
					this.$refs.voteFormBox.scrollIntoView();
				})
			},


			changeTableView() {
				this.isOptionView = !this.isOptionView
				this.$nextTick(() => {
					this.$refs.baseQnRef && this.$refs.baseQnRef.scrollIntoView()
				})
			},

			/** 获取投票列表 */
			getVoteList(type) {
				this.isLoadList = true
				let params = {
					code: this.getCurCode,
					scope: this.getCurScope
				}
				this.getVoteListByType(params).then(res => {
					if (!res.error && res.votes) {
						if (res.votes.length) {
							let list = res.votes.reverse()
							this.voteList = list
							let queryId = this.$route.query.acId
							if(queryId && list.filter(i => i.id === queryId).length === 0){
								this.$Modal.confirm({
									title: this.$t('survey.questionaire.confirmTitle'),
									content: this.$t('survey.noFoundAc'),
									cancelText: ' ',
									onOk: () => {
										this.goBackRecord()
									},
									onCancel: () => {}
								});
							}
							let queryVote = queryId && list.filter(i => i.id === queryId).length ? list.filter(i =>
								i.id === queryId)[0] : list[0]
							let queryIndex = queryId ? list.indexOf(queryVote) : 0
							this.isFromRecord = Boolean(queryId)
							this.onVoteClick(queryVote, queryIndex)
						} else {
							this.voteList = []
						}
						this.isLoadList = false
					} else {
						this.$Message.error(this.$t('vote.getDataFailTip'))
					}
				}).catch(err => {
					this.$Message.error(this.$t('vote.serverErrorTip'))
					this.isLoadList = false
				})
			},
			
			/* 根据类型v来查询校级或者区级的投票活动数据 */
			getVoteListByType(data) {
				return new Promise((r, j) => {
					console.log()
					if (this.isAreaVote) {
						this.$api.ability.getAreaVotes({ id: this.areaId }).then(res => {
							if (!res.error) {
								r(res)
							} else {
								j(res.error)
							}
						})
					} else {
						this.$api.learnActivity.FindVote(data).then(res => {
							if (!res.error) {
								r(res)
							} else {
								j(res.error)
							}
						})
					}
				})
			},

			/**
			 * 投票点击事件
			 * @param item
			 * @param index
			 */
			async onVoteClick(item, index) {
				console.log(item)
				let fullItem = item.id ? await this.getVoteDetails(item) : item
				console.log(fullItem)
				this.currentVote = fullItem
				this.activeVoteIndex = index
				/* 如果是区级的活动 则需要根据recordUrl去换取区级活动的作答数据 */
				if (this.isAreaVote && item.id) {
					this.areaVoteTeachers = []
					this.areaSchIndex = 0
					this.areaSchList = this.areaRecord.map(i => i.name)
					this.areaRecord.length && this.getAreaRecord(0)
				}else{
					/* 其余类型活动则需要去根据发布对象获取对应的作答数据 */
					if (item.id && item.progress !== 'pending'){
						if(fullItem.targetType === 'research'){
							this.getVoteTeachers(fullItem, fullItem.tchLists)
						}else{
							this.getVoteStudents(fullItem, fullItem.classes)
						}
					} 
				}
				this.$refs.voteForm && (this.$refs.voteForm.voteFormEdit = false)
				this.$refs.voteFormScroll.scrollTo({
						y: 0,
					},
					200,
					"easeInQuad"
				);
				this.hasNewAdd = false
				this.isOptionView = true
			},
			
			/* 获取区级活动的作答数据 */
			async getAreaRecord(schoolIndex){
				let curSchoolInfo = this.areaRecord[schoolIndex]
				let schoolSas = await this.$evTools.getBlobSchoolSas(curSchoolInfo.code)
				let fullPath = this.$evTools.getBlobHost() + '/' + curSchoolInfo.code + curSchoolInfo.url + schoolSas
				let recordJson = JSON.parse(await this.$tools.getFile(fullPath))
				console.log(curSchoolInfo)
				/* 区级活动获取某个学校的作答数据 */
				if(recordJson.options.length){
					let arr = []
					recordJson.options = this._.orderBy(recordJson.options,'code')
					recordJson.options.forEach((item, index) => {
						arr.push({
							option: item.code ? this.$t('vote.option') + (index +
								1) : this.$t('vote.noVote'),
							key: item.code || '',
							result: new Array(item.count).fill('1')
						})
					})
					this.tableData = arr
				}else{
					this.tableData = []
				}
				if(recordJson.records.length){
					/* 饼图数据 */
					let answerdArr = recordJson.records.map(i => { return { option:'A' }})
					let noAnswerArr = new Array(curSchoolInfo.count - recordJson.records.length).fill({ option : null })
					this.studentsTable = answerdArr.concat(noAnswerArr)
				}else{
					this.studentsTable = new Array(curSchoolInfo.count).fill({ option : null })
				}
				console.log(this.studentsTable)
			},

			/* 获取投票活动的详细数据 */
			getVoteDetails(voteItem) {
				return new Promise((r, j) => {
					if(this.isAreaVote){
						this.$api.ability.getAreaVoteById({
							id: voteItem.id,
							areaId: this.areaId
						}).then(res => {
							if (!res.error) {
								if(res.status === 404){
									this.$Message.error('未查询到当前活动！')
									r(null)
								}else{
									this.areaRecord = res.code
									r(res.vote)
								}
							}
						}).catch(err => {
							j(err)
						})
					}else{
						this.$api.learnActivity.FindVoteById({
							id: voteItem.id,
							code: voteItem.code
						}).then(res => {
							if (!res.error) {
								if(res.status === 404){
									this.$Message.error('未查询到当前活动！')
									r(null)
								}else{
									r(res.vote)
								}
							}
						}).catch(err => {
							j(err)
						})
					}
					
				})
			},

			/* 获取正在进行中的投票活动的投票数据 */
			async getVoteRecord(voteItem) {
				return new Promise(async (r, j) => {
					try {
						if(!voteItem.recordUrl){
							console.log('xxxxx')
							r({})
						}else{
							let curItemRecord = await this.getBlobJsonFile(voteItem.scope, voteItem
								.recordUrl)
							r(curItemRecord)
						}
						
					} catch (e) {
						j(e)
					}
					// 如果是进行中的活动 则从cosmos获取实时作答数据
					// if (voteItem.progress === 'going') {
					// 	this.$api.learnActivity.FindVoteRecord({
					// 		id: voteItem.id,
					// 		code: voteItem.code,
					// 	}).then(res => {
					// 		if (!res.error) {
					// 			r(res)
					// 		}
					// 	}).catch(err => {
					// 		j(err)
					// 	})
					// } else { // 如果是已结束的活动 则从blob读取作答数据 
						
					// }

				})
			},

			/* 根据已结束的RecordUrl来获取投票结果数据 */
			getBlobJsonFile(scope, url) {
				return new Promise(async (resolve, reject) => {
					let blobHost = scope === 'private' ? JSON.parse(decodeURIComponent(localStorage
						.user_profile, "utf-8")).blob_uri : JSON.parse(decodeURIComponent(localStorage
						.school_profile, "utf-8")).blob_uri
					// 根据试卷的Blob地址 去读取JSON文件
					let sasString = scope === 'private' ? await this.$tools.getPrivateSas() : await this.$tools
						.getSchoolSas()
					try {
						let itemJson = JSON.parse(await this.$tools.getFile(blobHost + url + sasString.sas))
						resolve(itemJson)
					} catch (e) {
						reject(e)
					}
				})
			},


			/* 取消编辑投票（无ID状态） */
			onCancelVote() {
				this.voteList.splice(this.voteList.indexOf(this.currentVote), 1)
				if (this.voteList.length > 0) {
					this.onVoteClick(this.voteList[0], 0)
				} else {
					this.voteList = [];
					this.currentVote = {}
					this.activeVoteIndex = 0;
				}
			},
			
			/* 删除区级活动 */
			delAreaTrain() {
				if (this.currentVote.id) {
					this.$Modal.confirm({
						title: '删除区级投票活动',
						content: '删除区级活动后，相关学校将无法参与此活动，确认删除活动吗？',
						onOk: () => {
							this.isLoading = true
							let params = {
								id: this.currentVote.id,
								areaId: this.areaId,
								pk: this.currentVote.pk
							}
							this.$api.train.delAreaTrain(params).then(
								res => {
									setTimeout(() => {
										this.isLoading = false
										this.$Message.success(this.$t('vote.deleteSuc'))
										this.handleTabClick(this.$route.name === 'manageVote' ?
											0 : 1)
									}, 1000)
								},
								err => {
									this.$Message.error('删除失败')
								}
							)
						}
					})
				}else{
					this.voteList.splice(this.voteList.indexOf(this.currentVote), 1)
					this.isLoading = false
					this.$Message.success(this.$t('vote.deleteSuc'))
					if (this.voteList.length) this.onVoteClick(this.voteList[0], 0)
				}
				
			},

			/** 删除当前投票 */
			onDeleteVote() {
				this.$Modal.confirm({
					title: this.$t('vote.deleteVote'),
					content: this.$t('vote.deleteConfirmTip'),
					onOk: () => {
						this.isLoading = true
						if (this.currentVote.id) {
							this.$api.learnActivity.DeleteVote({
								id: this.currentVote.id,
								code: this.currentVote.code,
								scope: this.getCurScope
							}).then(res => {
								if (!res.error && res.flag) {
									console.log(this.voteList.indexOf(this.currentVote))
									this.voteList.splice(this.voteList.reverse().indexOf(this
										.currentVote), 1)
									setTimeout(() => {
										this.isLoading = false
										this.$Message.success(this.$t('vote.deleteSuc'))
										this.handleTabClick(this.$route.name === 'manageVote' ?
											0 : 1)
									}, 1000)

									// this.isLoading = false
									// this.$Message.success(this.$t('vote.deleteSuc'))
									// if (this.voteList.length) this.onVoteClick(this.voteList[0], 0)
								} else {
									this.isLoading = false
									this.$Message.error(this.$t('vote.deleteFail'))
								}
							}).catch(err => {
								this.isLoading = false
								this.$Message.error(this.$t('vote.deleteFail'))
							})
						} else {
							this.voteList.splice(this.voteList.indexOf(this.currentVote), 1)
							this.isLoading = false
							this.$Message.success(this.$t('vote.deleteSuc'))
							if (this.voteList.length) this.onVoteClick(this.voteList[0], 0)
						}
					}
				})
			},
			
			/**
			 * 获取投票关联的学生清单
			 * @param voteId 投票ID
			 */
			async getVoteTeachers(voteItem) {
				this.isLoading = true
				try {
					let records = await this.getVoteRecord(voteItem)
					//  先查找 投票发布对象关联的学生清单 然后再去判断学生的作答情况
					console.log('当前投票的作答数据======', records)
					this.$api.learnActivity.findResearchList({
						school_code: this.$store.state.userInfo.schoolCode,
						ids: voteItem.tchLists,
					}).then(res => {
						if (!res.error) {
							let list = [] //学生清单 
							let arr = [] //选项清单
							res.list.forEach(classStus => {
								classStus.class.stuInfos.forEach(i => {
									if(!list.find(j => j.id === i.id)){
										list.push({
											id: i.id,
											name: i.name,
											no: i.no || 0,
											classroomName: classStus.class.name
										})
									}
								})
								classStus.class.tmdInfos.forEach(i => {
									if(!list.find(j => j.id === i.id)){
										list.push({
											id: i.id,
											name: i.name,
											no: i.no || 0,
											classroomName: classStus.class.name
										})
									}
								})
							})
							this.studentsTable = list
							
							// 要根据作答情况 结合两张表 处理表格显示的数据 
							if (records.options && records.options.length) {
								records.options = this._.orderBy(records.options,'code')
								records.options.forEach((item, index) => {
									arr.push({
										option: item.code ? this.$t('vote.option') + (index +
											1) : this.$t('vote.noVote'),
										key: item.code || '',
										result: new Array(item.count).fill('1')
									})
								})
								this.studentsTable.forEach(i => {
									let matchList = records.records.filter(j => j.userid === i.id)
									i.option = matchList.length ? Object.keys(matchList[0].opt).join(
										',') : null
								})
								this.tableData = arr
								console.log(arr)
								console.log(this.studentsTable)
							} else {
								// 如果是还没有投票作答数据 则默认显示0
								// this.currentVote.forEach((item, index) => {
								// 	arr.push({
								// 		option: item.code ? this.$t('vote.option') + (index +
								// 			1) : this.$t('vote.noVote'),
								// 		key: item.code || '',
								// 		result: 0
								// 	})
								// })
								this.tableData = []
							}
						} else {
							this.$Message.error(this.$t('vote.getDataFailTip'))
						}
					}).catch(err => {
						this.$Message.error(this.$t('vote.getClassDataFailTip'))
					}).finally(() => {
						this.isLoading = false
					})
				} catch (e) {
					this.isLoading = false
				}
			},


			/**
			 * 获取投票关联的学生清单
			 * @param voteId 投票ID
			 */
			async getVoteStudents(voteItem) {
				this.isLoading = true
				try {
					let records = await this.getVoteRecord(voteItem)
					//  先查找 投票发布对象关联的学生清单 然后再去判断学生的作答情况
					console.log('当前投票的作答数据======', records)
					this.$api.schoolSetting.getStusByClassId({
						school_code: this.$store.state.userInfo.schoolCode,
						ids: voteItem.classes.length ? voteItem.classes : voteItem.stuLists,
					}).then(res => {
						if (!res.error) {
							let list = [] //学生清单 
							let arr = [] //选项清单
							res.list.forEach(classStus => {
								classStus.class.stuInfos.forEach(i => {
									list.push({
										id: i.id,
										name: i.name,
										no: i.no || 0,
										classroomName: classStus.class.name
									})
								})
								classStus.class.tmdInfos.forEach(i => {
									list.push({
										id: i.id,
										name: i.name,
										no: i.no || 0,
										classroomName: classStus.class.name
									})
								})
							})
							this.studentsTable = list
							
							// 要根据作答情况 结合两张表 处理表格显示的数据 
							if (records.options && records.options.length) {
								records.options = this._.orderBy(records.options,'code')
								records.options.forEach((item, index) => {
									arr.push({
										option: item.code ? this.$t('vote.option') + (index +
											1) : this.$t('vote.noVote'),
										key: item.code || '',
										result: new Array(item.count).fill('1')
									})
								})
								this.studentsTable.forEach(i => {
									let matchList = records.records.filter(j => j.userid === i.id)
									i.option = matchList.length ? Object.keys(matchList[0].opt).join(
										',') : null
								})
								this.tableData = arr
								console.log(arr)
								console.log(this.studentsTable)
							} else {
								// 如果是还没有投票作答数据 则默认显示0
								// this.currentVote.forEach((item, index) => {
								// 	arr.push({
								// 		option: item.code ? this.$t('vote.option') + (index +
								// 			1) : this.$t('vote.noVote'),
								// 		key: item.code || '',
								// 		result: 0
								// 	})
								// })
								this.tableData = []
							}
						} else {
							this.$Message.error(this.$t('vote.getDataFailTip'))
						}
					}).catch(err => {
						this.$Message.error(this.$t('vote.getClassDataFailTip'))
					}).finally(() => {
						this.isLoading = false
					})
				} catch (e) {
					this.isLoading = false
				}
			},


			// 提取富文本内容中的文本
			getSimpleText(html) {
				var r = /<(?!img|video|audio).*?>/g;
				return html.replace(r, "");
			},

			/** 投票编辑事件 */
			onEditVote() {
				this.editItem = this.currentVote
				console.log(this.editItem)
				this.isEdit = true
				this.editable = true
				if (this.$refs.voteForm.voteFormEdit) {
					this.onVoteClick(this.currentVote, this.activeVoteIndex)
				}
				this.$refs.voteForm.voteFormEdit = !this.$refs.voteForm.voteFormEdit

			},


			/** 新增投票成功回调 */
			onAddSuccess() {
				//this.addHwModal = false
				this.handleTabClick(this.$route.name === 'manageVote' ? 0 : 1)
				this.hasNewAdd = false
			},
			
			/* 获取当前教师的所有个人课程以及学校分配的课程 */
			getMyCourse(){
				// if(this.$store.state.user.userCourses.length) return
				this.$api.courseMgmt.findAllByTeahcer({
					code:this.$store.state.userInfo.TEAMModelId,
					scope:'private',
					schoolId:this.$store.state.userInfo.schoolCode,
				}).then((res) => {
					if(res.obj.length){
						res.obj.forEach(i => {
							i.classes.forEach(j => {
								j.courseId = i.id
								j.id = i.id + '/' + j.id
							})
						})
						let myCourses = res.obj.map(j =>  {
							return { 
								id:j.id,
								name:j.name,
								scope:j.scope,
								children:j.scope === 'private' ? j.classes : [
									{
										id:'class',
										name:this.$t('stuAccount.adminClass'),
										children:j.classes.filter(k => k.type === 'class')
									},
									{
										id:'stuList',
										name:this.$t('stuAccount.teachClass'),
										children:j.classes.filter(k => k.type === 'stuList')
									}
								]
							}
						})
						this.$store.commit('user/setUserCourses', myCourses)
					}
				}).catch((err) => {
					console.log(err)
				});
			}
		},
		mounted() {
			if (this.$route.query.acId) {
				this.isFromRecord = true
				this.split1 = 0
				this.split2 = 0.3
				this.$refs.leftSplit.$el.getElementsByClassName('ivu-split-trigger-con')[0].style.display = 'none'
			}
			this.isPrivate && this.getMyCourse()
		},
		computed: {
			getCurCode() {
				return this.$route.name === 'personalVote' ? this.$store.state.userInfo.TEAMModelId : this.$store.state
					.userInfo.schoolCode
			},
			getCurScope() {
				return this.$route.name === 'personalVote' ? 'private' : 'school'
			},
			isPrivate() {
				return this.$route.name === 'personalVote'
			},
			isAreaVote() {
				return this.$route.name === 'manageAreaVote'
			},
			canNotDeleteVote(){
				return owner => {
					return this.$route.name !== 'manageAreaVote' && owner === 'area'
				}
			}
			
		},
		watch: {
			$route: {
				handler: function(to, from) {
					this.handleTabClick(this.$route.name === 'manageVote' ? 0 : 1)
				},
				immediate: true
			}
		}
	}
</script>
<style lang="less" scoped>
	@import "./ManageVote.less";
</style>
<style>
	.hw-container .dark-iview-split .ivu-split-trigger{
		border-color: #dadada !important;
		background:none;
	}
	.hw-modal {
	  .ivu-modal-content {
	    background: #454545;
	  }
	  .ivu-modal-body {
	    padding: 0;
	  }
	  .ivu-modal-header {
	    border-bottom: none;
	  }
	  .hw-modal-box {
	    height: 600px;
	    max-height: 600px;
	    padding: 15px;
	  }
	}
	.hw-modal .ivu-modal-header p,
		.hw-modal .ivu-modal-header-inner {
	  color: #fff;
	  font-size: 18px;
	  font-weight: bold;
	}

</style>
