<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/huijiantou.png" mode=""></image>
			</view>
			<view class="priceinfo">
				<span v-if="order.orderType=='DIRECT_BUY'||order.orderType =='HEALTH_CONSULTATION'">退款金额</span>
				<span v-if="order.orderType=='INTEGRAL_EXCHANGE'">退款健康豆</span>
				<view class="priceback" v-if="order.orderType=='DIRECT_BUY'||order.orderType =='HEALTH_CONSULTATION'">
					￥{{order.totalPrice}}
				</view>
				<view class="priceback" v-if="order.orderType=='INTEGRAL_EXCHANGE'">{{order.integralExchangeSill}}健康豆
				</view>
				<!-- <view class="words">
					已修改，最多{{order.totalPrice}}，含发货邮费 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" :closeable='true'>
				<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/pagesB/Applforrefund/index.js'
	export default {
		data() {
			return {
				show: false, //退款原因开关
				typename: '', //退款name
				order: {}, //订单
				reasonlist: [], //退款原因list
				dictname: '', //页面退款原因字段
				timer: null,
			}
		},
		methods: {
			//退款
			refundinfo() {
				this.order.updateTime = null
				refund(this.order).then(
					res => {
						if (res.code == 500) {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							})
						} else {
							uni.setStorageSync("Refresh", 'Refresh')
							this.$refs.uToast.show({
								title: '退款申请提交成功',
								type: 'success',
								duration: '1500'
							})
							if (this.timer) {
								clearTimeout(this.timer)
							}
							this.timer = setTimeout(e => {
								uni.navigateBack({
									delta: 3
								})
							}, 1500)
						}
					})
			},
			//退款原因
			refundReasoninfo() {
				refundReason().then(res => {
					this.reasonlist = res.rows
				})
			},
			//点击退款原因
			tapreason(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">
	@import "./Applforrefund.scss";
</style>
