<template>
	<view class="content">
		<view class="top">
			<view v-if="pageData.refund_status == 1">
				<view class="state">请处理退款申请</view>
				<view class="subTitle">如果您同意，请点击“同意退款”</view>
			</view>
			<view v-if="pageData.refund_status == 3">
				<view class="state">您拒绝了退款申请</view>
			</view>
			<view v-if="pageData.refund_status == 2">
				<view class="state">您同意了退款申请</view>
			</view>
		</view>
		<view class="center">
			<view class="box" v-if="pageData.user">
				<view class="box_title">买家信息</view>
				<view class="hflex jbetween cell">
					<view class="left">买家昵称</view>
					<view class="right text_hide" style="max-width: 500rpx;">{{pageData.user.nickname}}</view>
				</view>
				<view class="hflex jbetween cell">
					<view class="left">联系电话</view>
					<view class="right">{{pageData.user.phone}}</view>
				</view>
			</view>
			<view class="box">
				<view class="box_title">退款信息</view>
				<view >
					<block v-for="(item,index) in pageData.goods_item" :key="index">
						<view class="items hflex acenter">
							<image :src="item.goods_cover" class="item-img"></image>
							<view class="item-right">
								<view class="hflex acenter jbetween">
									<view class="item_name text_hide">{{item.goods_name}}</view>
									<view class="item_price">￥<span style="font-size: 30rpx;">{{item.price_selling}}</span></view>
								</view>
								<view class="hflex jbetween" style="padding: 20rpx 0 0;">
									<view class="norm text_hide">{{item.goods_spec}}</view>
									<view class="left_text">X{{item.stock_sales}}</view>
								</view>
							</view>
						</view>
					</block>
				</view>
				<view class="hflex acenter jbetween cell">
					<view class="left">退款状态</view>
					<view class="right text-red" v-if="pageData.refund_status == 1">待商家处理</view>
					<view class="right text-red" v-if="pageData.refund_status == 2">同意退款</view>
					<view class="right text-red" v-if="pageData.refund_status == 3">拒绝退款</view>
				</view>
				<view class="hflex acenter jbetween cell">
					<view class="left">退款原因</view>
					<view class="right">{{pageData.refund_reason}}</view>
				</view>
				<view class="hflex acenter jbetween cell">
					<view class="left">退款金额</view>
					<view class="right">￥<span style="font-size: 32rpx;color: #222;">{{pageData.refund_money}}</span></view>
				</view>
				<view class="hflex acenter jbetween cell">
					<view class="left">申请时间</view>
					<view class="right">{{pageData.refund_time}}</view>
				</view>
				<view class="hflex acenter jbetween cell">
					<view class="left">订单编号</view>
					<view class="hflex acenter">
						<view class="right">{{pageData.order_no}} | </view>
						<view class="right" @click="copy(pageData.order_no)">复制</view>
					</view>
				</view>
			</view> 
			<view class="box">
				<view class="box_title">申请信息</view>
				<view class="hflex jbetween cell">
					<view class="left">是否收货</view>
					<view class="right">未收到货</view>
				</view>
			<!-- 	<view class="hflex jbetween cell">
					<view class="left">售后类型</view>
					<view class="right">{{pageData.refund_type}}</view>
				</view> -->
				<view class="hflex jbetween cell">
					<view class="left">售后说明</view>
					<view class="right">{{pageData.refund_desc}}</view>
				</view>
				<view class="hflex cell">
					<view class="left">图片凭证</view>
					<view class="hflex acenter fwrap img_list">
						<block v-for="(item,index) in pageData.refund_nr" :key="index">
							<image :src="item" class="refund_img"></image>
						</block>
					</view>
				</view>
			</view>
		</view>
		<view class="bottom hflex acenter jend" v-if="pageData.refund_status == 1 || pageData.refund_status == 3">
			<view class="btn1 hflex acenter jcenter" style="color: #9A9A9A;" v-if="pageData.refund_status == 3">已拒绝申请</view>
			<view class="hflex acenter jend" style="height: 100%;" v-if="pageData.refund_status == 1">
				<view class="btn1 hflex acenter jcenter" @click="apply1(2)">拒绝申请</view>
				<view class="btn1 btn2 hflex acenter jcenter" @click="apply1(1)">同意退款</view>
			</view>
		</view>
		<u-popup :show="show_refuse" round="10" mode="center" @close="close" :safeAreaInsetBottom="false">
			<view class="popu">
				<view class="popu_title hflex acenter jcenter">拒绝原因</view>
				<u-textarea v-model="reason" confirmType="done" placeholder="请填写拒绝原因" border="none" ></u-textarea>
				<view class="popu_bottom hflex acenter jcenter">
					<view class="btn1 hflex acenter jcenter" @click="close">取消</view>
					<view class="btn1 btn2 hflex acenter jcenter" @click="refuse">提交</view>
				</view>
			</view>
		</u-popup>
		<u-popup :show="show_agree" round="10" mode="center" @close="close" :safeAreaInsetBottom="false">
			<view class="popu">
				<view class="popu_title hflex acenter jcenter">确认退款</view>
				<view class="popu_bottom hflex acenter jcenter">
					<view class="btn1 hflex acenter jcenter" @click="close">取消</view>
					<view class="btn1 btn2 hflex acenter jcenter" @click="agree">确认</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				id: '',
				pageData: {},
				time: 0,
				timeData: {},
				show_refuse: false,
				reason: '',
				show_agree: false,
			}
		},
		onLoad(options) {
			that = this
			that.id = options.id
			that.getData()
		},
		methods: {
			getData() {
				$api.req({
					url: '/data/api.business.Order/order_info',
					method: 'POST',
					data: {
						order_id: that.id
					}
				}, function(res) {
					if(res.code == 1) {
						for(var i=0;i<res.data.goods_item.length;i++) {
							var temp = res.data.goods_item[i].goods_cover.split('|')
							res.data.goods_item[i].goods_cover = temp[0]
						}
						that.pageData = res.data
						console.log('jujueyuany ',that.pageData);
						for(var i=0;i<that.pageData.goods_item.length;i++) {
							that.pageData.goods_item[i].goods_spec = $api.resetspec(that.pageData.goods_item[i].goods_spec)
						}
						// console.log(that.pageData);
						that.pageData.refund_nr = that.pageData.refund_nr.split('|')
					}
				})
			},
			copy(value) {
				uni.setClipboardData({
					data: value,
					success: function () {
						$api.info('复制成功')
					}
				});
			},
			apply1(type) {
				if(type == 1) {
					that.show_agree = true
				} else {
					that.show_refuse = true
				}
			},
			close() {
				that.show_refuse = false
				that.show_agree = false
			},
			refuse() {
				$api.req({
					url: '/data/api.business.Order/examine_refund',
					method: 'POST',
					data: {
						order_id: that.id,
						type: 2,
						reason: that.reason
					}
				}, function(res) {
					if(res.code == 1) {
						that.getData()
						that.close()
					}
				})
			},
			agree() {
				
				$api.req({
					url: '/data/api.business.Order/examine_refund',
					method: 'POST',
					data: {
						order_id: that.id,
						type: 1,
						
					}
				}, function(res) {
					if(res.code == 1) {
						$api.info('已同意退款，支付金额原路返回。')
						setTimeout(() => {
							that.getData()
						}, 1000)
						that.close()
					}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.content::v-deep {
		background: #F4F4F4;
		.top {
			width: 690rpx;
			margin: 20rpx auto 0;
			padding: 20rpx 30rpx 24rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			.state {
				font-size: 36rpx;
				font-weight: bold;
				color: #222222;
				line-height: 50rpx;
				padding-right: 24rpx;
			}
			.blue_bg {
				// width: 124rpx;
				padding: 0 14rpx;
				height: 32rpx;
				background: #506DFF;
				border-radius: 18rpx 0px 18rpx 18rpx;
				font-size: 16rpx;
				text-align: center;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 32rpx;
			}
			.blue_bg2 {
				// width: 256rpx;
				padding: 0 14rpx;
				height: 32rpx;
				background: #E7EBFF;
				border-radius: 18rpx;
				font-size: 16rpx;
				font-weight: bold;
				color: #222222;
				line-height: 32rpx;
			}
			.time {
				padding-left: 16rpx;
			}
			.subTitle {
				font-size: 24rpx;
				font-weight: 400;
				color: #888888;
				line-height: 34rpx;
			}
			.top_bg {
				width: 100%;
				box-sizing: border-box;
				padding: 0 20rpx;
				background: #F4F4F4;
				border-radius: 20rpx;
				.top_cell {
					padding: 24rpx 0;
					.left {
						font-size: 28rpx;
						font-weight: 400;
						color: #333333;
						line-height: 40rpx;
					}
				}
			}
		}
		.center {
			width: 100%;
			box-sizing: border-box;
			padding: 0 30rpx;
			.box {
				width: 100%;
				background: #FFFFFF;
				border-radius: 20rpx;
				box-sizing: border-box;
				padding: 0 20rpx;
				margin-top: 20rpx;
				.box_title {
					font-size: 32rpx;
					font-weight: 600;
					color: #222222;
					line-height: 44rpx;
					padding: 28rpx 0 24rpx;
				}
				.cell {
					padding-bottom: 24rpx;
					.left {
						width: 140rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #222222;
						line-height: 36rpx;
					}
					.right {
						font-size: 26rpx;
						font-weight: 400;
						color: #555555;
						line-height: 36rpx;
					}
					.text-red {
						color: #FF2020;
					}
					.right1 {
						font-size: 26rpx;
						font-weight: 400;
						color: #333333;
						line-height: 36rpx;
					}
					.img_list {
						// max-width: 280rpx;
						.refund_img {
							width: 146rpx;
							height: 146rpx;
							border-radius: 16rpx;
							margin: 0 18rpx 20rpx 0;
						}
						.refund_img:nth-child(3n+3) {
							margin: 0 0 20rpx;
						}
					}
					
				}
				.items {
					padding: 20rpx 0 32rpx;
					border-bottom: 1rpx solid #F4F4F4;
					.item-img {
						width: 160rpx;
						height: 160rpx;
						border-radius: 24rpx;
					}
					.item-right {
						width:calc(100% - 160rpx);
						padding-left: 20rpx;
						.item_name {
							font-size: 30rpx;
							font-weight: 400;
							color: #222222;
							line-height: 42rpx;
						}
						.item_price {
							font-size: 20rpx;
							font-weight: 600;
							color: #222222;
							line-height: 24rpx;
						}
						.norm {
							width: max-content;
							max-width: 300rpx;
							// height: 42px;
							background: #F5F5F5;
							border-radius: 12rpx;
							box-sizing: border-box;
							padding: 12rpx;
							font-size: 20rpx;
							font-weight: 400;
							color: #888888;
							line-height: 28rpx;
						}
						.left_text {
							font-size: 24rpx;
							font-weight: 500;
							color: #888888;
							line-height: 28rpx;
						}
					}
				}
				.items:nth-last-child(1) {
					border: none;
				}
			}
			.box:nth-last-child(1) {
				margin-bottom: 186rpx;
			}
		}
		.bottom {
			width: 100%;
			height: 166rpx;
			background: #FFFFFF;
			box-sizing: border-box;
			padding: 0 30rpx;
			position: fixed;
			z-index: 99;
			bottom: 0;
			.btn1 {
				width: 208rpx;
				height: 86rpx;
				border-radius: 38rpx;
				// border: 1rpx solid #787878;
				font-size: 30rpx;
				font-weight: 400;
				color: #506DFF;
				line-height: 76rpx;
				margin-left: 20rpx;
				border: 1rpx solid #506DFF;
			}
			.btn2 {
				background: #506DFF;
				border: none;
				color: #FFFFFF;
			}
		}
		.popu {
			width: 570rpx;
			margin: 0 auto;
			background: #FFFFFF;
			border-radius: 20rpx;
			box-sizing: border-box;
			padding: 0 30rpx;
			.popu_title {
				font-size: 36rpx;
				font-weight: 500;
				color: #222222;
				line-height: 50rpx;
				padding: 44rpx 0 36rpx;
			}
			.u-textarea {
				background: #F2F2F2 !important;
				border-radius: 20rpx !important;
				margin-bottom: 54rpx;
			}
			.popu_bottom {
				padding-bottom: 52rpx;
				.btn1 {
					width: 220rpx;
					height: 76rpx;
					border-radius: 38rpx;
					border: 2rpx solid #506DFF;
					font-size: 32rpx;
					font-weight: 400;
					color: #506DFF;
					line-height: 44rpx;
				}
				.btn2 {
					background: #506DFF;
					color: #FFFFFF;
					margin-left: 50rpx;
				}
			}
			
		}
	}
</style>