
<template>
	<view class="box">
		<view class="content">
			<view class="viewBg">
				<image src="../../static/img/icon_xinghao.png" mode="" style="width: 14rpx; height: 14rpx;"></image>
				<view class="leftTitle">退款原因</view>
				<picker class="width70" mode="selector" :range="reasonNameArray" @change="reasonChange">
					<view class="blackColor" :class="{grayColor: reason==''}">
						{{reason == '' ? '请选择' : reason}}
				
					</view>
				</picker>

				<image src="../../static/img/rightArrow.png" mode="" style="width: 13rpx; height: 23rpx;"></image>
			</view>

			<view class="moneyBg">
				<view class="viewBg2">
					<image src="../../static/img/icon_xinghao.png" mode="" style="width: 14rpx; height: 14rpx;"></image>
					<view class="leftTitle">退款金额</view>
					<input class="blackColor" type="number" v-model="digit" :placeholder="'最大可退 ￥'+maxMoney"
						placeholder-style="color:#999999" />

				</view>
				<view class="grayColor">如全额退款，优惠券会退回到您的账户</view>
			</view>


			<view class="contentBg">
				<view class="leftTitle">补充描述</view>

				<textarea placeholder-style="color:#999999" placeholder="选填，请输入补充描述" v-model="exeContent"
					class="textareaCont" maxlength="-1" auto-height="true" @confirm="feedDone" />

			</view>

			<view class="bottom">
				<view class="shoreDz" @click="submit">提交</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sheetId: '',
				reasonArray: [],
				reasonNameArray: [],
				reasonId: '',
				reason:'',
				maxMoney: '',
				money: '',
				exeContent: '',
				edit: '', //修改申请
				editId: '',
			}
		},
		onLoad(opt) {
			this.sheetId = opt.sheetId;
			this.maxMoney = opt.maxMoney;
			this.getRefundData();
			
			//修改申请
			this.edit = opt.edit;
			this.editId = opt.editId;
			this.money = opt.money;
			this.reasonId = opt.reasonId;
			this.reason = opt.reason;
			
			this.exeContent = opt.exeContent;
			if (opt.exeContent == null || opt.exeContent == 'null') {
				this.exeContent = ''
			}
			
			
		},
		methods: {
			submit() {
				if (this.reasonId == '') {
					uni.showToast({
						title: '请选择退款原因',
						icon: 'none',
						duration: 2000,
					});
					return ;
				}
				if (this.money==0) {
					uni.showToast({
						title: '请输入退款金额',
						icon: 'none',
						duration: 2000,
					});
					return ;
				}
				if (this.money > this.maxMoney) {
					uni.showToast({
						title: '退款金额不能大于最大可退金额',
						icon: 'none',
						duration: 2000,
					});
					return ;
				}
				
				if (this.edit == 'true') {
					console.log('修改申请');
					this.editUrl();
				} else {
					this.addUrl();
				}
				
			},
			addUrl(){
				uni.showLoading({});
				
				this.$http('worldKeepCar/orderRefund/applyRefund', {
					sheetId:this.sheetId,
					applyReasonId:this.reasonId,
					applyReason:this.reason,
					money:this.money,
					reasonComment: this.exeContent,
					
				}, 'POST').then(res => {
					uni.hideLoading();
					if(res.code==0){
						uni.showModal({
						    title: '退款申请成功，请等待平台处理',
						    content: '您可以在【我的-退款申请记录】列表里具体查看申请的处理进度哦~',
							showCancel:false,
							confirmText:'知道了',
						    success: function (res) {
						        if (res.confirm) {
						           uni.navigateBack({
						           	
						           })
						        } 
						    }
						});
							
					}
					
							
				})
			},
			editUrl(){
				uni.showLoading({});
				
				this.$http('worldKeepCar/orderRefund/editApply', {
					
					applyReasonId:this.reasonId,
					applyReason:this.reason,
					money:this.money,
					reasonComment: this.exeContent,
					id:this.editId,
					
				}, 'POST').then(res => {
					uni.hideLoading();
					if(res.code==0){
						uni.showModal({
						    title: '退款申请成功，请等待平台处理',
						    content: '您可以在【我的-退款申请记录】列表里具体查看申请的处理进度哦~',
							showCancel:false,
							confirmText:'知道了',
						    success: function (res) {
						        if (res.confirm) {
						           uni.navigateBack({
						           	
						           })
						        } 
						    }
						});
					}
					
					
							
				})
			},
			getRefundData() {
				uni.showLoading({
					title: '加载中'
				})
				let url = 'worldKeepCar/orderRefund/refuseReasonList',
					params = {
						type: 3,

					}
				this.$http(url, params, 'GET').then(res => {

					uni.hideLoading();


					this.reasonArray = res.data
					
					this.reasonArray.forEach((item, index) => {
						this.reasonNameArray.push(item.contents)
					});

				})
			},
			feedDone(e) {
				this.exeContent = e.target.value

			},
			reasonChange(e) {

				this.reasonId = this.reasonArray[e.target.value].id
				this.reason = this.reasonArray[e.target.value].contents

			},
		}
	}
</script>

<style scoped>
	.box {
		min-height: 100vh;
		background: #F4F5F7;
		padding-top: 20rpx;
	}

	.content {
		background-color: #FFFFFF;
		border-radius: 10rpx;
		margin: 20rpx 24rpx;
		padding: 0 20rpx;
	}

	.viewBg {
		display: flex;
		align-items: center;
		padding: 30rpx 0;
		border-bottom: 1rpx solid #EEEEEE;
	}

	.width70 {
		width: 70%;
	}

	.moneyBg {
		padding: 30rpx 0;
		border-bottom: 1rpx solid #EEEEEE;
	}

	.viewBg2 {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.leftTitle {
		color: #333333;
		font-size: 28rpx;
		width: 130rpx;
		margin-right: 50rpx;
	}

	.blackColor {
		color: #333333;
		font-size: 28rpx;
	}

	.grayColor {
		color: #999999;
		font-size: 28rpx;
	}

	.textareaCont {

		width: 70%;
		font-size: 28rpx;
		color: #333333;

	}

	.contentBg {
		display: flex;
		align-items: center;
		padding: 30rpx 0;

	}

	.bottom {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		box-shadow: 0px -4px 8px 0px rgba(153, 153, 153, 0.08);
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		justify-content: space-around;
	}

	.shoreDz {
		width: 702rpx;
		height: 74rpx;

		background: linear-gradient(135deg, #FD5300 0%, #FF270A 100%);
		border-radius: 37rpx;
		text-align: center;
		line-height: 74rpx;
		color: #FFFFFF;
		font-size: 30rpx;
		margin-top: 24rpx;
	}

</style>
