<template>
	<view class="setComments-box">
		<view class="setComments-add" @click="addComments">
			<van-icon name="plus" /><text>创建评价</text> 
		</view>
		<view class="index-student-information">
			<view class="setComments-content-box" v-if="dataList.length>0">
				<template v-for="(item,index) in dataList">
					<view class="setComments-content" @click="goComment(item)">
						<view class="center-line"></view>
						<view class="setComments-title flex">
							<text class="setComments-title-left">第{{item.Times}}次评价</text>
							<view class="setComments-title-right">
								<view class="setComments-options flex">
									<view class="setComments-options-title flex" @click.stop="showActionHandler(item)">
										<view class="point"></view>
										<text>{{item.ShowTypeStr}}</text>
										<van-icon :name="item.optionsShow?'arrow-down':'arrow'" />
									</view>
									<view v-if="item.optionsShow" class="setComments-options-text flex">
										<text v-for="(subItem,index) in optionsList" :key="index" @click="clickoptions(item,subItem)">
											{{subItem.text}}
										</text>
									</view>
								</view>
							</view>
						</view>
						<view class="setComments-source flex">
							<text>来源:{{item.CreateTypeStr}}</text>
							<view>时间:{{item.CreateTime}}</view>
						</view>
					</view>
				</template>
			</view>
            <view class="noData" v-else>
				<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1653902791000_806.png" mode="widthFix"></image>
				<view>暂无评价规则数据</view>
			</view>
		</view>
		<van-action-sheet
		  :show="showAction"
		  :actions="actions"
		  @close="closeAction"
		  @select="selectAction"
		  description="修改本期评语的可见状态"
		/>
	</view>
</template>
<script>
	import {
		reactive,
		toRefs,
		onMounted,
		getCurrentInstance,
		inject,
		watch
	} from "vue";
	import navbar from '../../components/navbar.vue'
	export default {
		props: ["CourseCommentTimesList","courseId"],
		emits: ['refreshData'],
		components: {
			navbar,
		},
		setup(props, context) {
			let {
				proxy
			} = getCurrentInstance();
			let data = reactive({
				actions: [{name:'全部可见',type:1},{name:'全部不可见', color: '#ee0a24',type:3}],
				dataList: [],
				showAction:false,
				currentAction:null
			});
			let methods = {
				addComments(){
					console.log(props.courseId)
					uni.navigateTo({
						url: '/pages/setComments/teacher-commit?courseId=' + props.courseId
					})
				},
				showActionHandler(item){
					data.currentAction=item
					data.showAction=true
				},
				closeAction(){
					data.showAction=false
					data.currentAction=null
				},
				selectAction(e){
					let x=e.detail
					methods.clickoptions(x.type)
				},
				goComment(item){
					uni.navigateTo({
						url: '/pages/setComments/commentDetails?comment='+ encodeURIComponent(JSON.stringify(item))
					})
				},
				// clickOptionsShow(item) {
				// 	item.optionsShow = !item.optionsShow;
				// },
				clickoptions(type) {
					
					let showTypeMsg = {
						CourseId: data.currentAction.CourseId,
						Times: data.currentAction.Times,
						ShowType: type
					};
					proxy.$request("/Teacher/SetStuCommentShowTypeByTimes", showTypeMsg).then(res => {
						if (res.Code==1) {
							 console.log(res)
							 context.emit('refreshData');
						}else{
							uni.showToast({
								title:"设置失败，请重试",
								duration:2000
							})
						}
					})
			 
				}
			};
			//监听属性数组
			watch(() => props["CourseCommentTimesList"], (newValue, oldValue) => {
				 
				if (newValue != oldValue && newValue && newValue.length > 0) {
					data.dataList = newValue;
				}
			}, {
				deep: true,
			});
			return {
				...toRefs(data),
				...methods
			};
		}
	};
</script>
<style scoped>
    .noData {
		text-align: center;
		flex: 1;
		width: 100%;
	}

	.noData image {
		width: 200rpx;
		margin-bottom: 40rpx;
	}

	.noData view {
		font-size: 24rpx;
		color: #cecece;
		text-align: center;
	}
    .setComments-Evaluation view text:first-child{
        border-right: 1px solid #E5E5E5;
        padding: 0 16rpx 0 0;
    }
    .setComments-Evaluation view text:last-child{
        margin-left: 16rpx;
    }
    .setComments-Evaluation view text{
        display: inline-block;
        letter-spacing: 1rpx;
    }
    .setComments-Evaluation view{
        float: right;
        margin-top: 25rpx;
        margin-bottom: 27rpx;
        font-size: 24rpx;
        font-weight: 500;
        color: #CE8086;
    }
    .setComments-Evaluation{
        height: 85rpx;
        border-top: 1rpx solid #E5E5E5;
    }
    .setComments-source{
        font-size: 20rpx;
        color: #C2BCBA;
        font-weight: 500;
        justify-content: space-between;
        padding: 26rpx 0 25rpx 0;
    }
    .point{
        width: 8rpx;
        height: 8rpx;
        background: #E64150;
        border-radius: 50%;
    }
    .setComments-options-title,.setComments-options-text{
        font-size: 24rpx;
        font-weight: 500;
        color: #CE8086;
        text-align: center;
        font-weight: bold;
    }
    .setComments-options-text text{
        padding: 5rpx 0;
    }
    .setComments-options-text{
        flex-direction: column;
        margin-top: 10rpx;
        position: absolute;
        left: 0;
        right: 0;
        top: 35rpx;
		z-index: 2;
        background: #FCEEEF;
        padding: 20rpx 0 20rpx 0;
        border-radius: 0 0 25rpx 25rpx;
    }
    .setComments-options-title text{
        margin-right: 10rpx;
        margin-left: 10rpx;
    }
    .setComments-options-title{
        justify-content: center;
        align-items: center;
    }
    .setComments-options{
        flex-grow: 1;
        border-radius: 25rpx;
        background: #FCEEEF;
        flex-direction: column;
        padding: 14rpx 17rpx 15rpx 17rpx;
        letter-spacing: 1rpx;
        position: relative;
    }
    .setComments-title-right{
        width: 190rpx;
        flex-shrink: 0;
    }
    .setComments-title-left{
        letter-spacing: 1rpx;
        flex-grow: 1;
        color: #282828;
        font-size: 26rpx;
        font-weight: bold;
        margin-right: 20rpx;
    }
    .center-line{
        position: absolute;
        left: 0;
        top: 30rpx;
        width: 4rpx;
        height: 23rpx;
        background: #282828;
    }
    .setComments-content{
        position: relative;
        background: #FFFFFF;
        padding: 21rpx 27rpx 0 22rpx;
        box-shadow: 0rpx 6rpx 29rpx 0rpx rgba(76, 76, 76, 0.09);
        border-radius: 30rpx;
		margin-bottom: 40rpx;
    }
    .setComments-content-box{
        padding: 0 50rpx;
    }
    .setComments-add van-icon{
        font-size: 25rpx;
        margin-right: 20rpx;
    }
    .setComments-add{
        width: 190rpx;
        margin: auto;
        border-radius: 27rpx;
        border: 1rpx solid #FB6087;
        color: #FB6087;
        font-size: 24rpx;
        letter-spacing: 1rpx;
        padding: 10rpx 0;
        margin-bottom: 47rpx;
        text-align: center;
    }
    .index-student-information{
        min-height: 800rpx;
		background: #FFFFFF;
		border-radius: 50rpx 50rpx 0 0;
		padding: 71rpx 0 30rpx 0;
        flex-direction: column;
    }
</style>
