<template>
	<view class="app">
		<view class="content">
			<view class="item">退款类型
				<span style='right: 0; color: #000000;'>{{typename}}</span>
			</view>
			<view class="item" @tap='show=true'>退款原因
				<span v-if="dictname==''">请选择</span>
				<span v-else style='color: #000000;'>{{dictname}}</span>
				<image src="../../static/pic.png" mode=""></image>
			</view>
			<view class="priceinfo">退款金额
				<view class="priceback">￥{{order.godTotalPrice}}
				</view>
				<view class="words">
					已修改，最多{{order.godTotalPrice}}，含发货邮费 0.00
				</view>
			</view>
		</view>
		<view class="discribe">
			<view class="voucher">补充描述和凭证</view>
			<view class="supplement">
				<u-input v-model="order.refundReasonRemark" type="textarea" height="100" :auto-height="true"
					placeholder="补充描述，有助于商家更好的处理售后问题" />
			</view>
		</view>
		<view class="Submit" @tap='refundinfo'>提交</view>
		<!-- 弹框 -->
		<view class="frame">
			<u-popup v-model="show" mode="bottom" length="48%" border-radius="20">
				<image class="image" @tap="show = false" src="../../static/gb.png" mode=""></image>
				<view class="payment">
					请选择退款原因
				</view>
				<view class="elderly" v-for="(item,index) in reasonlist" :key="index" @tap='tapreason(item)'>
					{{item.dictLabel}}
				</view>
			</u-popup>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		refundReason,
		refund
	} from '@/api/Applforrefund/index.js'
	export default {
		data() {
			return {
				show: false, //退款原因开关
				typename: '', //退款name
				order: {}, //订单
				reasonlist: [], //退款原因list
				dictname: '', //页面退款原因字段
			}
		},
		methods: {
			//退款
			refundinfo() {
				refund(this.order).then(
					res => {
						console.log(res)
						if (res.code == 500) {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							})
						} else {
							this.$refs.uToast.show({
								title: '退款申请提交成功',
								type: 'success',
								duration: '1500'
							})
							setTimeout(() => {
								// uni.navigateTo({
								// 	url: '/pages/Aftersalesdetails/Aftersalesdetails'
								// })
								uni.navigateTo({
									url: '/pages/CommodityOrder/CommodityOrder'
								})
							}, 1500);
						}
					})
			},
			//退款原因
			refundReasoninfo() {
				refundReason().then(res => {
					this.reasonlist = res.rows
				})
			},
			//点击退款原因
			tapreason(item) {
				console.log(item)
				this.order.refundReasonDictId = item.dictCode
				this.dictname = item.dictLabel
				this.show = false;
			}
		},
		//开局获取传值
		onLoad(options) {
			this.refundReasoninfo();
			this.order = JSON.parse(options.order)
			this.order.id = this.order.goodsOrderId
			this.typename = options.typename
			if (this.typename == '我要退款(无需退货)') {
				this.order.refundType = "ONLY_REFUND_MONEY"
			} else {
				this.order.refundType = "REFUND_MONEY_GOODS"
			}
		}
	}
</script>

<style lang="scss">
	.app {
		padding: 3%;

		.frame {
			.image {
				position: absolute;
				right: 30rpx;
				top: 40rpx;
				width: 31rpx;
				height: 31rpx;
			}

			.payment {
				width: 95%;
				font-size: 42rpx;
				color: #000000;
				line-height: 110rpx;
				text-align: center;
				margin: 0 auto;
			}

			.elderly {
				width: 95%;
				margin: 0 auto;
				padding: 15rpx 0 15rpx 40rpx;
				font-size: 40rpx;
				line-height: 68rpx;
				border-top: 1rpx solid #D8D4D4;
			}
		}

		.Submit {
			width: 217rpx;
			height: 68rpx;
			background: #4C7BC9;
			border-radius: 26rpx;
			text-align: center;
			line-height: 68rpx;
			color: #FFFFFF;
			margin-left: 65%;
			margin-top: 45%;
		}

		.discribe {
			margin-top: 3%;
			width: 99%;
			height: 342rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 9rpx 31rpx 9rpx rgba(0, 0, 0, 0.03);
			border-radius: 20rpx;
			padding: 3%;

			.supplement input {
				margin-top: 3%;
				margin-left: 5%;
				font-size: 26rpx;
				color: #BAB7B8;
				line-height: 67rpx;
			}

			.voucher {
				height: 70rpx;
				border-bottom: 1rpx solid #D8D4D4;
			}
		}

		.content {
			width: 99%;
			height: 342rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 9rpx 31rpx 9rpx rgba(0, 0, 0, 0.03);
			border-radius: 20rpx;
			margin: 0 auto;
			line-height: 60rpx;
			padding: 3%;
			font-size: 30rpx;

			.priceinfo {
				.words {
					font-size: 26rpx;
					color: #BAB7B8;
				}

				.priceback {
					font-size: 38rpx;
					color: #D43953;
				}
			}

			.item {
				border-bottom: 1rpx solid #D8D4D4;
				height: 70rpx;
				position: relative;

				image {
					width: 16rpx;
					height: 25rpx;
					position: absolute;
					right: 0;
					top: 50%;
					transform: translateY(-60%);
				}

				span {
					position: absolute;
					right: 5%;
					color: #BAB7B8;
				}
			}
		}
	}
</style>
