<template>
	<view class="pageBg">
		<view class="pageBgImg">
			<view class="status_bar"></view>
			<topNavbar title="学员退款"></topNavbar>
			<view class="pad">
				<view class="navBox">
					<cardNav :navData="navData" :currentNav="params.status" @changeNav="changeNav" />
				</view>
			</view>
		</view>
		
		<view class="pad con">
			<view class="list">
				<view class="card" v-for="(item,index) in list" :key="index">
					<refundItem :item="item">
						<template>
							<view class="btn_row" v-if="item.auditStatus==0">
								<view class="btnBg" @click="passFn(item)">审核通过</view>
								<view class="btnBg" @click="noPassClick(item)">审核不通过</view>
							</view>
						</template>
					</refundItem>
				</view>
			</view>
		</view>
		<view style="padding-bottom: 20rpx;" v-if="list.length">
			<u-loadmore :status="status" />
		</view>
		<nodata v-if="!list.length&&status=='nomore'"></nodata>

		<u-popup :show="show" :round="16" mode="center" @close="show=false" @open="show=true" closeable>
			<view class="popCon">
				<view class="inputBox">
					<!-- <input type="text" placeholder="请输入不通过原因" > -->
					<!-- <u--textarea v-model="value3" placeholder="请输入内容" autoHeight ></u--textarea> -->
					<textarea placeholder="请输入不通过原因" maxlength="40" v-model.trim="schoolFailReason"></textarea>
				</view>
				<view class="footBox">
					<view class="btn">取消</view>
					<view class="btn blue" @click="noPass">确定</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import refundItem from './comp/item'
	import {
		headmasterPage,
		updateRefundStatusOpend,
		updateRefundStatusOut
	} from '@/config/api.js'
	export default {
		components: {
			refundItem
		},
		data() {
			return {
				show: false,
				navData: [{
						text: '待审核',
						id: 0
					},
					{
						text: '已审核',
						id: 1
					}
				],
				params: {
					pageNo: 1,
					pageSize: 20,
					status: 0,
				},
				status: 'loading',
				list: [],
				schoolFailReason: '',
				curRefundId: '',
			}
		},
		onLoad() {
			this.headmasterPageFn()
		},
		methods: {
			changeNav(val) {
				if (this.params.status == val) return
				this.params.status = val
				this.listInit()
			},
			async headmasterPageFn() {
				const {
					data: res
				} = await headmasterPage(this.params)
				this.params.pageNo++
				this.list.push(...res.list)
				this.total = res.total
				if (this.list.length >= this.total) {
					this.status = 'nomore'
				} else {
					this.status = 'loading'
				}
				console.log(res)
			},
			listInit() {
				this.list = []
				this.params.pageNo = 1
				this.headmasterPageFn()
			},
			// 点击不通过
			noPassClick(item) {
				this.schoolFailReason = ''
				this.show = true
				this.curRefundId = item.refundId
			},
			// 不通过
			async noPass() {
				console.log(this.schoolFailReason)
				if (!this.schoolFailReason) return this.$u.toast('请输入不通过原因')
				const res = await updateRefundStatusOut({
					id: this.curRefundId,
					schoolFailReason: this.schoolFailReason
				})
				if (res.code == 0) {
					this.$u.toast('已驳回')
					this.schoolFailReason = ''
					this.show = false
					this.listInit()
				}
				console.log(res)
			},
			// 审核通过
			passFn(item) {
				let _this = this
				uni.showModal({
					title: '审核通过',
					content: `学员${item.studentName}的申请确定审通过吗？`,
					success: async function(res) {
						if (res.confirm) {
							const reslut = await updateRefundStatusOpend({
								id: item.refundId
							})
							if (reslut.code == 0) _this.$u.toast('已通过')
							_this.listInit()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pageBgImg {
		height: auto;
		padding-bottom: 110rpx;
	}
	.navBox {
		padding: 0 0 24rpx 0;
	}
	
	.card {
		padding: 0 28rpx;
		margin-bottom: 24rpx;
	}
	.con {
		// transform: translateY(-100rpx);
		margin-top: -100rpx;
	}
	.popCon {
		width: calc(100vw - 100rpx);

		.inputBox {
			width: 100%;
			// height: 200rpx;
			padding: 90rpx 44rpx 24rpx 44rpx;

			textarea {
				border: 1rpx solid #eee;
				border-radius: 20rpx;
				display: block;
				width: 100%;
				height: 180rpx;
				padding: 20rpx 20rpx 0 20rpx;
				box-sizing: border-box;
				font-size: 30rpx;
			}
		}

		.footBox {
			width: 100%;
			height: 112rpx;
			display: flex;
			border-top: 1rpx solid #eee;

			.btn {
				flex: 1;
				text-align: center;
				line-height: 112rpx;
				font-size: 34rpx;
				color: #999;

				&.blue {
					color: $themC;
					border-left: 1rpx solid #eeeeee;
				}
			}
		}
	}

	.btn_row {
		display: flex;
		justify-content: center;
		padding: 10rpx 0 30rpx 0;

		.btnBg {
			width: 188rpx;
			margin: 0 26rpx;

			&:first-child {
				width: 168rpx;
			}
		}
	}
</style>