<template>
<view>
	<view v-if="isShow">
		<view class="orderWrapper">
		    <!-- 头部区域：订单号、头像 -->
		    <view class="orderHead">
		        <view class="orderHeadTitle">
		            <view>
		                <text>订单号</text>
		                <text class="orderDetail">{{info.orderId}}</text>
		            </view>
		            <view>
		                <text>对方</text>
		                <text class="orderDetail">{{info.teacherName}}教员</text>
		            </view>
		        </view>
		    </view>
		    <!-- 中部区域：订单详情 -->
		    <view class="orderMid">
		        <view>
		            <text>对方ID</text>
		            <text class="orderDetail">{{info.teacherId}}</text>
		        </view>
		        <view>
		            <text>需求号</text>
		            <text class="courseNum" @click="toNeedDetail">{{info.requireId}}</text>
		        </view>
		        <view>
		            <text>课程号</text>
		            <text class="courseNum" @click="toCourseDetail">{{info.courseId}}</text>
		        </view>
		        <view>
		            <text>需求金额</text>
		            <text class="orderDetail">{{info.requireSalary/100}}</text>
		        </view>
		    </view>
		    <view class="orderBottom">
		        <view>
		            <text>订单内容</text>
		            <text class="orderDetail">{{info.requireDetail}}</text>
		        </view>
		        <view>
		            <text>支付日期</text>
		            <text class="orderDetail">{{info.datetime}}</text>
		        </view>
		        <view>
		            <text>订单状态</text>
		            <text class="orderPayStatus">{{info.status}}</text>
		        </view>
		    </view>
			
			<uni-popup ref="popup" type="dialog">
				<uni-popup-dialog type="success" title="联系方式" message="成功消息" cancelText="复制手机号" confirmText="复制微信号" :content="content" @close="close" @confirm="confirm"></uni-popup-dialog>
			</uni-popup>
			
			<uni-popup ref="popup1" type="message">
				<uni-popup-message type="success" message="复制成功" :duration="1500"></uni-popup-message>
			</uni-popup>
		</view>
		

	  </view>
	  
	  <view class="requires2">
	  	<uni-row >
	  			<text>当前为：{{index2}} / {{total}} </text>
	  	</uni-row>
	  </view>
	  
	  <view class="submitBtnWrapper" v-if="isShow">
		  <view class="paidSucceed">
			  <button class="submitBtn" @click="getPhone" type="primary">联系方式</button>
			  <button class="submitBtn" :disabled="buttonDisabled" @click="applyForRefund">{{refundButton}}</button>
		  </view>
	  </view>
	  
	  <view class="submitBtnWrapper" v-if="isShow">
		  <view class="paidSucceed">
			  <button class="submitBtn" @click="backone" type="primary">上一条</button>
			  <button class="submitBtn" @click="nextone" type="primary">下一条</button>
		  </view>
	  </view>
	  
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	
	export default {
		computed: {
			...mapState('m_user', ['token', 'userinfo'])
		},
		data() {
			return {
				isShow: false,
				index: 0,
				index2: 0,
				total:0,
				datas:{},
				phone: '',
				weixin: '',
				content: '',
				refundButton: '同意退款',
				info: {},
				buttonDisabled: false,
			};
		},
		onLoad(option) {
			// if (option.orderId !== undefined) {
			// 	this.getOne(decodeURIComponent(option.orderId))
			// }
			this.findAllRefundingOrderList()
		},
		methods: {
			close() {
				wx.setClipboardData({
					data: this.phone,
					success: res => {
						wx.hideToast()
						this.$refs.popup1.open()
					}
				})
			},
			confirm() {
				wx.setClipboardData({
					data: this.weixin,
					success: res => {
						wx.hideToast()
						this.$refs.popup1.open()
					}
				})
			},
			toNeedDetail() {
				uni.navigateTo({
					url: '/subpkg/student/require/student_require_all_detail?requireId=' + encodeURIComponent(this.info.requireId)
				})
			},
			toCourseDetail() {
				uni.navigateTo({
					url: '/subpkg/teacher/course/teacher_course_all_detail?courseId=' + encodeURIComponent(this.info.courseId)
				})
			},
			// 同意退款
			async applyForRefund() {
				this.buttonDisabled = true
				const constorderid = this.info.orderId
				const queryObj = {
					orderNo: this.info.orderId,
					reason: '管理员同意' + this.userinfo.uid
				}
				const {data: result} = await uni.$http.get('/payment/wx-pay/refunds', queryObj)
				//console.log(result)
				if (result.message === '成功') {
					// this.timer = setInterval(() => {
					// 	this.queryIsRefundOrder(constorderid)
					// }, 4000)
					uni.$showMsg('退款申请已提交给微信后台，注意查看微信通知',3000)
					this.mysleep(()=>{
						this.findAllRefundingOrderList()
						this.buttonDisabled = false
					},3000)
				}else{
					uni.$showMsg('退款失败，请通过投诉通道，通知平台',3000)
					//this.findAllRefundingOrderList()
				}
								
			},

            mysleep(callback,ms) {
                setTimeout(callback, ms)
            },

			// 获取手机号
			async getPhone() {
				const {data: result} = await uni.$http.get('/education/student-requirements/getStuNeedPhoneAndWeixin', {uid: this.info.studentId})
				this.phone = result.data.phone
				this.weixin = result.data.weixin
				this.$refs.popup.open()
				this.content = '手机号：'+ this.phone + '\n\n微信号：' + this.weixin
			},
			// 获取订单信息
			// async getOne(id) {
			// 	const queryObj = {
			// 		orderId: id
			// 	}
			// 	const {data: result} = await uni.$http.get('/payment/order-info/getOrderInfoByOrderId', queryObj)
			// 	this.info = result.data.one
			// 	if (this.info.isRefund === 1) this.buttonDisabled = false
			// 	if (this.info.status === '已退款') this.payment = true
			// 	this.showPage = true
			// },
			// async queryIsRefundOrder(orderId) {
			// 	const {data: result} = await uni.$http.get('/payment/order-info/queryIsRefundOrder', {orderId: orderId})
			// 	if('已退款' === result.message) {
			// 		clearInterval(this.timer)
			// 		this.buttonDisabled = true
			// 		this.info.status = '已退款'
			// 		uni.$showMsg('退款成功',1000)
			// 		this.findAllRefundingOrderList()
			// 	}
			// },
				async findAllRefundingOrderList() {
					this.index = 0
					this.index2 = 0
					this.isShow = false
					this.info = {}
					const { data: result } = await uni.$http.get('/payment/order-info/findAllRefundingOrderList')
			      //  console.log(result)
					this.total = result.data.list.length
						if(this.total > 0){
							this.datas = result.data
							this.info = this.datas.list[this.index ]
							this.isShow = true
							this.index2 = this.index + 1
						}
									//console.log(this.item)
					},
					backone(){
							if(this.index == 0){
								uni.$showMsg("没有上条了", 1000)
							}else{
								this.index = this.index - 1
								this.info = this.datas.list[this.index]
								this.index2 = this.index + 1
							}
						},
						nextone(){
								if(this.index == (this.total - 1)){
									uni.$showMsg("没有下条了", 1000)
								}else{
									this.index = this.index + 1
									this.info = this.datas.list[this.index]
									this.index2 = this.index + 1
								}
							},
			
		}
	}
</script>

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

<style lang="scss" scoped>
/* 设置全局边距 */
.orderWrapper{
	width: 90%;
	padding: 20rpx;
	margin-left: 20rpx;
	border-radius: 30rpx;
	background-color: #FFF;
	font-size: 30rpx;
}

/* 头部区域 */
.orderHead{
    display: flex;
    position: relative;
    height: 200rpx;
    padding-top: 20rpx;
}

/* 头像 */
.headImg{
    width: 160rpx;
    height: 160rpx;
    border-radius: 30rpx;
    position: absolute;
    right: 30rpx;
}

.orderHeadTitle{
    display: flex;
    flex-direction: column;
    height: 80px;
    justify-content: space-around;
}

/* 设置内容样式 */
.orderDetail,
.courseNum,
.orderPayStatus{
    margin-left: 20rpx;
    font-weight: bold;
}

.courseNum{
    color: #00B0F0;
    text-decoration: underline;
}

/* 支付状态字体样式 */
.orderPayStatus{
    color: red;
}

/* 中部区域 */
.orderMid{
    height: 220rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

/* 底部区域 */
.orderBottom{
    margin-top: 40rpx;
    height: 260rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

/* 支付倒计时 */
.orderPay{
    margin-top: 40rpx;
    display: flex;
    align-items: baseline;
}
/* 倒计时时间格式 */
.orderPayTime{
    padding-left: 20rpx;
    font-weight: bold;
    font-size: 40rpx;
    color: red;    
}

/* 提醒信息 */
.warning{
    display: flex;
    justify-content: center;    
    margin-top: 60rpx;
}
/* 提醒信息详情 */
.warningDetail{
    width: 80%;
    display: flex;
    flex-direction: column;
    font-size: 44rpx;
    font-weight: bold;
    color: red;
}

/* 支付及查看信息按钮居中排列 */
.payWrapper{
    display: flex;
    justify-content: center;
}

.payYesButton,
.payNoButton{
	border-radius: 50rpx;
	color: white;
}
.payYesButton{
	background-color: #35b882;
}
.payNoButton{
	background-color: #3ed598;
}

.paidSucceed{
    display: flex;
    width: 100%;
    justify-content: space-around;
}

.pay{
    /* display: flex; */
    width: 100%;
}

	.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;
		
	}

	// 提交按钮样式
	.submitBtnWrapper{
		margin-top: 60rpx;
		height: 100rpx;
		align-items: center;
	}
	.submitBtn{
		width: 300rpx;
		border-radius: 50rpx;
		// margin-bottom: 40rpx;
		background-color: #35b882;
		font-size: 30rpx;
		color: #fff;
	}

::v-deep .uni-button-color{
	color: #1aad19 !important;
}
</style>
