<template>
	<view class="content">
		<view class="order-item">
			<scroll-view v-if="listStyle == 1" class="goods-box" scroll-x>
				<view v-for="(goodsItem, goodsIndex) in item.cartInfo" :key="goodsIndex" class="goods-item">
					<image class="goods-img" :src="goodsItem.productInfo.image" mode="aspectFill"></image>
				</view>
			</scroll-view>
<!-- 			<view v-if="listStyle == 2" class="goods-box-single" v-for="(goodsItem, goodsIndex) in item.cartInfo" :key="goodsIndex">
				<image class="goods-img" :src="goodsItem.productInfo.image" mode="aspectFill"></image>
				<view class="right">
					<text class="title clamp">{{ goodsItem.productInfo.store_name }}</text>
					<text class="attr-box">{{ goodsItem.attrInfo ? goodsItem.attrInfo.suk : '' }} x {{ goodsItem.cart_num }}</text>
					<text class="price">{{ goodsItem.productInfo.price }}</text>
				</view>
			</view> -->
			<view class="good" v-if="listStyle == 2" v-for="(goodsItem, goodsIndex) in item.cartInfo" :key="goodsIndex">
				<view class="img-wrapper"><image :src="goodsItem.productInfo.image" mode=""></image></view>
				<view class="good-infoo">
					<view class="good-name ellipsis">{{ goodsItem.productInfo.store_name }}</view>
					<view class="create-time">下单时间：{{item.add_time_y}}</view>
				</view>
				<view class="good-infot">
					<view class="good-price">￥{{ goodsItem.productInfo.attrInfo.price }}</view>
					<view class="good-num">X{{ goodsItem.cart_num }}</view>
				</view>
			</view>
		</view>
		<view class="row b-b">
			<text class="tit">退款原因</text>
			<picker mode="selector" :range="status" @change="bindChange">
				<view class="refund" v-if="refundStatus">{{ refundStatus || '请选择' }}</view>
				<view class="noRefund" v-else>请选择退款原因</view>
			</picker>
		</view>
		<view class="pushpic">
			<view class="up-title">上传凭证：</view>
			<view class="up" @click="putImg()">
				<view class="up-bg" v-if="upImg == ''">
					<image src="../../static/icon/uping.png" mode=""></image>
					<view class="up-tap">上传图片</view>
				</view>
				<view class="up-img" v-else>
					<image :src="upImg" mode=""></image>
				</view>
			</view>
		</view>
		<view class="row b-b">
			<text class="tit">备注说明</text>
			<input class="input" type="text" v-model="reason" placeholder="如果请填写" placeholder-class="placeholder" />
		</view>
		<button class="add-btn" @click="confirm">提交申请</button>
	</view>
</template>

<script>
import { refund, refundReason, orderDetail,upload } from '@/api/order.js';
export default {
	data() {
		return {
			refundStatus: '', //退款理由
			refundMethods: '', //退款方式
			reason: '', //退款理由
			status: ['代付款', '待发货', '待收货', '已完成'],
			orderId: '',
			item: {},
			listStyle: 2,
			refundNum: 0,
			methods: ['余额'],
			isUp: true,
			upImg: ''
		};
	},
	onLoad(option) {
		this.orderId = option.id;
		this.refundReason();
		this.loadOrder();
	},
	methods: {
		// 切换选中事件
		bindChange(e) {
			this.refundStatus = this.status[e.detail.value];
			console.log('this.refundStatus',this.refundStatus)
		},
		bind2Change(e) {
			this.refundMethods = this.methods[e.detail.value];
		},
		// 加载退款理由
		refundReason() {
			refundReason({}).then(e => {
				this.status = e.data;
			});
		},
		loadOrder() {
			orderDetail({}, this.orderId).then(e => {
				this.item = e.data;
				console.log(this.item)
			});
		},
		//提交
		confirm() {
			let obj = this;
			if (!obj.refundStatus) {
				uni.showModal({
					title: '错误',
					content: '请填写退货理由',
					showCancel: false
				});
				return false;
			}
			uni.showLoading({
				title: '提交中...',
				mask: true
			})
			refund({
				text: obj.refundStatus,
				uni: obj.orderId,
				refund_reason_wap_explain: obj.reason,
				refund_reason_wap_img: obj.upImg
			}).then(function(e) {
				uni.showToast({
					title: '提交成功',
					duration: 1500
				});
				setTimeout(function() {
					uni.navigateBack();
				}, 800);
			}).catch( err => {
				console.log(err)
			});
		},
		putImg() {
			console.log('dianji')
			// this.isUp = !this.isUp
			upload({
				filename: ''
			}).then(data => {
				console.log(data,'6666666666')
				this.upImg = data[0].url
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background: $page-color-base;
	padding-top: 16rpx;
}
.orderDetial {
	.row {
		.input {
			text-align: right;
		}
	}
}
.row {
	display: flex;
	align-items: center;
	position: relative;
	padding: 0 30rpx;
	height: 110rpx;
	background: #fff;
	.refund {
		font-size: 30rpx;
		color: $font-color-dark;
		padding-left: 128rpx;
	}
	.noRefund {
		font-size: 30rpx;
		color: $font-color-light;
		padding-left: 128rpx;
	}
	.tit {
		flex-shrink: 0;
		width: 120rpx;
		font-size: 30rpx;
		color: $font-color-dark;
	}
	.input {
		flex: 1;
		font-size: 30rpx;
		color: $font-color-dark;
		padding-left: 128rpx;
		&.payColor {
			color: $color-red;
		}
	}
	.iconlocation {
		font-size: 36rpx;
		color: $font-color-light;
	}
}
.add-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 690rpx;
	height: 80rpx;
	margin: 60rpx auto;
	font-size: $font-lg;
	color: #fff;
	background-color: $base-color;
	border-radius: 10rpx;
	// box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
}

/* 多条商品 */
.order-item {
	display: flex;
	flex-direction: column;
	// padding-left: 30rpx;
	background: #fff;
	margin-top: 16rpx;
	.goods-box {
		height: 160rpx;
		padding: 20rpx 0;
		white-space: nowrap;
		.goods-item {
			width: 120rpx;
			height: 120rpx;
			display: inline-block;
			margin-right: 24rpx;
		}
		.goods-img {
			display: block;
			width: 100%;
			height: 100%;
		}
	}
	/* 单条商品 */
	.goods-box-single {
		display: flex;
		padding: 20rpx 0;
		.goods-img {
			display: block;
			width: 120rpx;
			height: 120rpx;
		}
		.right {
			flex: 1;
			display: flex;
			flex-direction: column;
			padding: 0 30rpx 0 24rpx;
			overflow: hidden;
			.title {
				font-size: $font-base + 2rpx;
				color: $font-color-dark;
				line-height: 1;
			}
			.attr-box {
				font-size: $font-sm + 2rpx;
				color: $font-color-light;
				padding: 10rpx 12rpx;
			}
			.price {
				font-size: $font-base + 2rpx;
				color: $font-color-dark;
				&:before {
					content: '￥';
					font-size: $font-sm;
					margin: 0 2rpx 0 8rpx;
				}
			}
		}
	}
}
.refund-num {
	margin: 20rpx 0;
	width: 750rpx;
	height: 100rpx;
	background: #ffffff;
	line-height: 100rpx;
	view {
		display: inline-block;
	}
	.num-title {
		font-size: 30rpx;
		font-family: PingFangSC;
		font-weight: 500;
		color: #333333;
		padding-left: 30rpx;
	}
	.num {
		padding-left: 133rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #901b21;
	}
}
.good {
	// margin-top: 21rpx;
	margin-bottom: 18rpx;
	width: 750rpx;
	height: 220rpx;
	background: #ffffff;
	padding: 30rpx 29rpx;
	display: flex;
	position: relative;
	.img-wrapper {
		width: 160rpx;
		height: 160rpx;
		image {
			width: 100%;
			height: 100%;
			border-radius: 5rpx;
		}
	}
	.good-infoo {
		padding-left: 20rpx;
		.good-name {
			width: 282rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #1d2023;
			line-height: 40rpx;
			margin-bottom: 40rpx;
		}
		.create-time {
			height: 21rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #999999;
		}
	}
	.good-infot {
		position: absolute;
		right: 29rpx;
		text-align: right;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #666666;
		.good-num {
			font-size: 22rpx;
		}
	}
}
.pushpic {
	margin-top: 20rpx;
	width: 750rpx;
	height: 284rpx;
	background: #FFFFFF;
	padding: 30rpx 0 0 30rpx;
	.up-title {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #3F454B;
		line-height: 1;
		padding-bottom: 35rpx;
	}
	.up {
		.up-bg {
			width: 160rpx;
			height: 160rpx;
			background: #fff;
			border: 2rpx #999999 dashed; 
			border-radius: 10rpx;
			position: relative;
			image {
				width: 36rpx;
				height: 36rpx;
				position: absolute;
				top: 44rpx;
				left:64rpx;
			}
			.up-tap {
				position: absolute;
				// width: 94rpx;
				height: 23rpx;
				font-size: 24rpx;
				font-family: PingFangSC;
				font-weight: 500;
				color: #888888;
				top: 93rpx;
				left:33rpx;
			}
		}
		.up-img {
			width: 160rpx;
			height: 160rpx;
			background: #fff;
			// border: 2rpx #999999 dashed; 
			border-radius: 10rpx;
			image {
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
			}
		}
	}
}
</style>
