<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">
					<view class="title clamp">
						<text>{{ goodsItem.productInfo.store_name }}</text>
						<view class="time">下单时间：{{ item.add_time_y }}</view>
					</view>
					<view class="right-row">
						<text class="price">{{ goodsItem.productInfo.price }}</text>
						<text class="attr-box">{{ goodsItem.attrInfo ? goodsItem.attrInfo.suk : '' }} x {{ goodsItem.cart_num }}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="row b-b">
			<text class="tit">货物状态</text>
			<picker mode="selector" :range="value" @change="bindChange">
				<view class="refund" v-if="refund">{{ refund || '请选择' }}</view>
				<view class="noRefund" v-else>请选择</view>
			</picker>
			
		</view> -->
		<view class="orderDetial">
			<view class="row b-b flex">
				<text class="tit">退款原因</text>
				<picker mode="selector" :range="value" @change="bindChange">
					<view class="refund" v-if="refund">{{ refund || '请选择' }}</view>
					<view class="noRefund" v-else>请选择</view>
				</picker>
				<!-- <view class="input"><input class="uni-input" @input="onKeyInput" placeholder="请输入退款原因	"/></view> -->
			</view>
			<view class="row b-b">
				<text class="tit">备注说明</text>
				<input class="input" type="text" v-model="reason" placeholder="请填写备注" placeholder-class="placeholder" />
			</view>
			<!-- <view class="row b-b flex">
				<text class="tit">订单总价</text>
				<view class="input">￥{{ item.total_price }}</view>
			</view>
			<view class="row b-b flex">
				<text class="tit">邮费</text>
				<view class="input">{{ item.pay_postage > 0 ? '￥' +item.pay_postage : '免邮费' }}</view>
			</view>
			<view class="row b-b flex" v-if="item.coupon_id > 0">
				<text class="tit">优惠券</text>
				<view class="input">-￥{{ item.coupon_price }}</view>
			</view>
			<view class="row b-b flex" v-if="item.use_integral > 0">
				<text class="tit">积分抵扣</text>
				<view class="input">-￥{{ item.use_integral }}</view>
			</view>
			<view class="row b-b flex">
				<text class="tit ">实付</text>
				<view class="input payColor">￥{{ item.pay_price }}</view>
			</view> -->
		</view>
		<!-- <view class="row b-b">
			<text class="tit">退款方式</text>
			<picker mode="selector" :range="value" @change="bindChange">
				<view class="refund" v-if="refund">{{ refund || '请选择' }}</view>
				<view class="noRefund" v-else>请选择</view>
			</picker>
		</view> -->
		<view class="row b-b" style="margin: 20rpx 0;">
			<text class="tit">退款金额</text>
			<text class="red">￥{{item.pay_price}}</text>
		</view>
		<!-- <view class="row b-b">
			<text class="tit">退款理由</text>
			<picker mode="selector" :range="value" @change="bindChange">
				<view class="refund" v-if="refund">{{ refund || '请选择退款理由' }}</view>
				<view class="noRefund" v-else>请选择退款理由</view>
			</picker>
		</view> -->
		<view class="add_box">
			<view class="add_name">上传凭证</view>
			<view class="add-img-box flex_item">
				<view class="add-img-item" v-for="(item, index) in imgList" :key="index">
					<image class="add-img" @click.stop="imgInfo(index)" :src="item.url" mode="aspectFill"></image>
					<image class="add-img-del" @click.stop="delImg(index)" src="/static/img/delete.png"></image>
				</view>
				<view v-if="imgList.length < 9" class="add-img-item" @click.stop="scImg()">
					<image class="add-img" src="https://mmz.liuniu946.com/statics/img/add.jpg"></image>
				</view>
			</view>
		</view>
		
		<button class="add-btn" @click="confirm">提交申请</button>
	</view>
</template>

<script>
import { refund, refundReason, orderDetail,upload } from '@/api/order.js';
export default {
	data() {
		return {
			selector:'',//理由
			refund: '', //退款理由
			reason: '', //备注
			value: ['1', '2', '3', '4', '5', '6', '7', '8', 9, 10, 11, 12, 13],
			orderId: '',
			item: {},
			listStyle: 2,
			imgList: [],
			imgCount: 6 ,//最多支持9张上传，可以修改
			cloudimgList: []
		};
	},
	onLoad(option) {
		this.orderId = option.id;
		this.refundReason();
		this.loadOrder();
	},
	methods: {
		// 切换选中事件
		bindChange(e) {
			this.refund = this.value[e.detail.value];
		},
		// 加载退款理由
		refundReason() {
			refundReason({}).then(e => {
				this.value = e.data;
			});
		},
		loadOrder() {
			orderDetail({}, this.orderId).then(e => {
				this.item = e.data;
			});
		},
		//单张上传图片
		scImg() {
			let obj = this;
			if (obj.imgCount == 0) {
				uni.showToast({
					title: '最多添加6张图片',
					icon: 'none'
				});
				return;
			}
			upload({
				file: ''
			})
				.then(e => {
					console.log(e,'e')
					obj.imgList = [...obj.imgList, ...e];
					obj.imgCount = 6 - obj.imgList.length;
				})
				.catch(e => {});
		},
		//提交
		confirm() {
			let obj = this;
			if (!obj.refund) {
				obj.$api.msg('请选择退货理由');
				return false;
			}
			for (let i = 0; i < obj.imgList.length; i++) {
				obj.cloudimgList.push(obj.imgList[i].url);
			}
			let arr = obj.cloudimgList.join(',');
			refund({
				text: obj.refund,
				uni: obj.orderId,
				refund_reason_wap_explain: obj.reason,
				refund_reason_wap_img:arr
			}).then(function(e) {
				console.log(e,'e')
				obj.$api.msg('提交成功');
				setTimeout(function() {
					uni.navigateTo({
						url:'/pages/order/order?state=-3'
					})
				}, 1000);
				// uni.showToast({
				// 	title:'提交成功',
				// 	duration:1500,
				// 	icon:'none'
				// })
			});
		},
		//点击图片显示大图
		imgInfo(i) {
			let tempList = [];
			this.imgList.forEach(e => {
				tempList.push(e.url);
			});
			console.log(tempList);
			//显示图片
			uni.previewImage({
				current: i,
				loop: false,
				urls: tempList,
				indicator: 'default'
			});
		},
		//删除图片
		delImg(i) {
			uni.showModal({
				content: '确定删除这张吗',
				success: res => {
					if (res.confirm) {
						this.imgList.splice(i, 1);
						this.imgCount++;
					} else if (res.cancel) {
					}
				}
			});
		},
	}
};
</script>

<style lang="scss">
page {
	background: $page-color-base;
	padding-top: 16rpx;
}
.orderDetial {
	.row {
		
		.input {
			text-align: left;
		}
	}
}
//图片
.add_box{
	background-color: #ffffff;
	padding: 25rpx 0rpx;
	border-bottom: 1px solid #e4e7ed;
	.add_name{
		font-size: 30rpx;
		padding-left: 25rpx;
	}
}
.add-img-box {
	width: 100%;
	flex-direction: row;
	flex-wrap: wrap;
	margin-top: 50rpx;
}
.add-img-item {
	width: 150rpx;
	height: 150rpx;
	border-radius: 24rpx;
	position: relative;
	margin-bottom: 80rpx;
	margin-left: 55rpx;
	.add-img {
		width: 100%;
		height: 100%;
		border-radius: 24rpx;
	}
}
.add-img-camera {
	flex: 1;
}
.add-img-del {
	position: absolute;
	width: 40rpx;
	height: 40rpx;
	left: 135rpx;
	bottom: 135rpx;
	//background-color: rgba(238, 0, 0, 1);
	border-radius: 20rpx;
}
.address-time {
	width: 484rpx;
	height: 88rpx;
	background-color: rgba(245, 245, 245, 1);
	opacity: 1;
	border-radius: 24rpx;
	text-align: center;

	font-size: 35rpx;
	font-weight: 500;
	color: rgba(51, 51, 51, 1);
}
.line {
	width: 750rpx;
	height: 1px;
	transform: scaleY(0.3);
	background-color: rgba(0, 0, 0, 0.5);
}
.row {
	display: flex;
	align-items: center;
	position: relative;
	padding: 0 30rpx;
	height: 110rpx;
	background: #fff;
	image{
		width: 13rpx;
		height: 24rpx;
	}
	.refund {
		font-size: 30rpx;
		color: $font-color-dark;
	}
	.noRefund {
		font-size: 30rpx;
		color: $font-color-light;
		padding-left: 20rpx;
	}
	.tit {
		flex-shrink: 0;
		width: 160rpx;
		font-size: 30rpx;
		color: $font-color-dark;
	}
	.red{
		font-size:30rpx;
		font-weight:500;
		color:rgba(252,65,65,1);
		line-height:100rpx;
	}
	.input {
		flex: 1;
		font-size: 30rpx;
		color: $font-color-dark;
		padding-left: 20rpx;
		&.payColor {
			color: $color-red;
		}
	}
	.iconlocation {
		font-size: 36rpx;
		color: $font-color-light;
	}
}
.add-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 560rpx;
	height: 80rpx;
	margin: 60rpx auto;
	font-size: $font-lg;
	color: #fff;
	background-color: $base-color;
	border-radius: 40rpx;
	// 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;
			justify-content: space-between;
			// flex-direction: column;
			padding: 0 30rpx 0 24rpx;
			overflow: hidden;
			.title {
				font-size: $font-base + 2rpx;
				color: $font-color-dark;
				line-height: 1;
				margin-top: 10rpx;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				.time{
					font-size:22rpx;
					font-weight:400;
					color:#999999;
					margin-top: 50rpx;
				}
			}
			.right-row{
				display: flex;
				align-items: flex-end;
				justify-content: flex-end;
				flex-direction: column;
				.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;
					}
				}
			}
			
		}
	}
}
</style>
