<template>
	<view class="container">
		<view class="classInfo">
			<course-item :thumbnailPath="courseInfoItem.displayImage" :title="courseInfoItem.fileTitle" :summaryBox="courseInfoItem.fileSynopsis" :dataList="{coursePrice:courseInfoItem.coursePrice,salesNumber:courseInfoItem.salesNumber}" :fileLecturerId="courseInfoItem.fileLecturerId"></course-item>
		</view>
		<!-- 订单支付明细 -->
		<view class="payInfoBox">
			<h4>订单支付明细</h4>
			<view>
				<text>积分抵扣：</text>
				<text class="price">￥{{dropInfo.integralExchange}}</text>
			</view>
			<view>
				<text>实际支付：</text>
				<text>￥{{dropInfo.paymentAmount}}</text>
			</view>
		</view>
		<!-- 退款明细 -->
		<view class="dropDetailInfoBox">
			<h4>退款明细</h4>
			<view>
				<text>支付违约金：<i class="iconfont icon-31tishi" @click="showModal()"></i></text>
				<text class="price">￥{{dropInfo.breachCommission}}</text>
			</view>
			<view>
				<text>退款到账金额：</text>
				<text>￥{{dropInfo.refundFee}}</text>
			</view>
			<view>
				<text>退还积分：</text>
				<text>{{dropInfo.refundIntegralExchange}}</text>
			</view>
		</view>
		<!-- 退款原因 -->
		<view class="dropInfoBox">
			<view class="dropBox">
				<h4>退款原因</h4>
				<view class="pickerBox">
					<picker @change="bindPickerChange" :value="dropIndex" :range="dropReasons" :range-key="'dropOptionName'">
						<view class="uni-input" style="height: 80rpx;">{{dropReasons[dropIndex]['dropOptionName']}}</view>
					</picker>
					<i class="iconfont icon-youjiantou"></i>
				</view>
			</view>
		</view>
		<!-- 提交申请 -->
		<view class="submitApply" @click="submit()">
			<text>提交申请</text>
		</view>
		<!-- 弹窗 -->
		<uni-popup ref="popup" type="bottom" background-color="#fff">
			<view class="popup-content">
				<view class="title">
					<text></text>
					<h3>违约金规则</h3>
					<i class="iconfont icon-guanbi" @click="closePopup()"></i>
				</view>
				<view class="">
					1.购买后14天内未点开学习全额退费； 
				</view>
				<view class="">
					<view class="">2.购买后15-30天未点开学习则：</view>
					<view class="">假如：一个初级课程8000，报名费45 ，违约金比例：15%，那么违约金的费用一共是：8045*15% =1206.75； </view>
				</view>
				<view class="">
					3.已点开课程学习或购买30天后不予退费。
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import api from "@/api/api";
	import courseItem from "@/components/courseItem/courseItem.vue";
	export default {
		components:{
			courseItem
		},
		data() {
			return {
				courseInfoItem:{},
				fileId:null,
				orderId:null,
				userId: uni.getStorageSync('cffp_userId'),
				dropInfo:{},
				dropIndex:0,
				dropReasons:['']
			};
		},
		methods:{
			bindPickerChange(e){
				this.dropIndex = e.detail.value;
			},
			showModal(){
				this.$refs.popup.open()
			},
			closePopup(){
				this.$refs.popup.close()
			},
			// 课程详情页面
			courseDetail(){
				api.courseDetail({fileId:this.fileId,userId:this.userId}).then(res=>{
					console.log('课程详情',res);
					if(res['success']){
						this.courseInfoItem =  res['data']['data'];
					}
				})
			},
			// 退款明细
			userRefundCourseDtl(){
				api.userRefundCourseDtl({userId:this.userId,orderId:this.orderId}).then(res=>{
					if(res['success']){
						this.dropInfo = res['data']
					}
				})
			},
			// 提交申请
			submit(){
				const param = {
					orderNo:this.dropInfo.orderNo,
					paymentMethod:this.dropInfo.paymentMethod,
					userId:this.userId,
					totalFee:this.dropInfo.orderPrice,
					refundFee:this.dropInfo.refundFee,
					integralExchange:this.dropInfo.integralExchange,
					refundIntegralExchange:this.dropInfo.refundIntegralExchange,
					refundReason:this.dropReasons[this.dropIndex]['dropOptionName']
				}
				api.unifiedRefund(param).then(res=>{
					if(res['success']){
						uni.navigateTo({
							url:`/pages/afterSaleDetail/afterSaleDetail?orderNo=${this.dropInfo.orderNo}&afterSalesFlag=3`
						})
					}else{
						uni.showToast({
							title: res['message'],
							duration: 2000
						});
					}
				})
			},
			// 退款原因
			dropOptionsQuery(){
				api.dropOptionsQuery({code:'REFUND_REASON'}).then(res=>{
					console.log(res)
					if(res['success']){
						this.dropReasons = res['data']['dropMasterInfoList'][0]['dropOptionsInfoList']
					}
				})
			}
		},
		onLoad(option) {
			this.orderId = option.id;
			this.fileId = option.fileId;
			this.courseDetail();
			this.userRefundCourseDtl();
			this.dropOptionsQuery()
		}
	}
</script>

<style lang="scss">
	.container{
		padding: 10rpx 20rpx;
		height: 100%;
		position: relative;
		.classInfo{
			background-color: #fff;
			padding: 20rpx 14rpx 14rpx 20rpx;
		}
		.payInfoBox,.dropDetailInfoBox,.dropInfoBox{
			padding: 30rpx 14rpx 14rpx 20rpx;
			margin-bottom: 10rpx;
			background-color: #fff;
			view{
				margin-top: 22rpx;
				display: flex;
				justify-content: space-between;
			}
			text{
				&.price{
					color: #FA6900;
				}
			}
			
		}
		.submitApply{
			position: fixed;
			bottom: 20rpx;
			left: 0;
			width: 100%;
			text{
				display: flex;
				color: #fff;
				background: #20269B;
				border-radius: 80rpx;
				height: 80rpx;
				width: 60%;
				justify-content: center;
				align-items: center;
				margin: 0 auto;
				
			}
		}
		.popup-content{
			view{
				font-size: 30rpx;
				color: #666;
				margin-bottom: 10rpx;
			}
			.title{
				display: flex;
				justify-content: space-between;
				align-items: center;
				color: #333;
				font-size: 32rpx;
			}
		}
		.dropBox{
			display: flex;
			justify-content: space-between;
			align-items: baseline;
			height: 80rpx;
			.pickerBox{
				display: flex;
				align-items: baseline;
				.iconfont{
					transform: rotate(90deg);
					margin-left: 20rpx;
					color: #666;
				}
			}
		}
	}
</style>
