<template>
	<view>
		<!-- <mescroll-body ref="mescrollRef" @down="downCallback" :down="downOpt" style="min-height: 645px;"> -->

			<!-- 商品信息 -->
			<self-line/>
			<view class="bg-white padding-tb-sm">
				<skeleton :loading="skeletonLoading" :row="2" :showAvatar="false" :showTitle="true">

					<view class="flex justify-between align-start padding-top-sm padding-lr">
						<image v-if="orderDetails.goods.cover" :src="orderDetails.goods.cover" mode="aspectFill" style="width: 150rpx; height: 150rpx;"></image>
						<view class="flex-sub padding-left-sm">
							<view class="bref-box margin-top-xs">
								{{orderDetails.goods.name}}
							</view>
							<view class="flex justify-between">
								<text class="block margin-top-sm text-gray text-sm">数量</text>
								<view class="flex align-center margin-top-sm">
									<text class="cuIcon-move" @tap="reduce"></text>
									<input type="number" v-model="num" class="text-center margin-lr-sm radius" style="width: 60rpx; height: 50rpx;background-color: #f7f7fb;" />
									<text class="cuIcon-add" @tap="add"></text>
								</view>
							</view>
							
							<view class="flex justify-between margin-top-sm">
								<view class="text-red text-price text-lg">
									<amount :value="Number(orderDetails.goods.specs[0].selling_price || 0)" :is-round-up="false" :precision="2" :duration="800" transition></amount>
								</view>
								<!-- <view>
									<button v-if="true" class="cu-btn line-orange round margin-left-sm text-sm">申请退款</button>
									<button v-else class="cu-btn line-gray bg-gray round margin-left-sm text-sm">退款中</button>
								</view> -->
							</view>
						</view>
					</view>

				</skeleton>
			</view>
			
			<self-line/>
			<skeleton :loading="skeletonLoading" :row="1" :showAvatar="false" :showTitle="true">
				<view class="bg-white">
					<view class="cu-bar padding-lr solid-bottom">
						<text class="text-gray">优惠</text>
						<text>暂无优惠</text>
					</view>
				</view>
			</skeleton>
			<self-line/>
		<!-- </mescroll-body> -->
		
		<skeleton :loading="skeletonLoading" :row="13" :showAvatar="false" :showTitle="true">
			<view class="btn-bottom">
				<view class="padding flex justify-around align-center" v-if="orderDetails.agreement.tips">
					<checkbox-group class="block" @change="CheckboxChange">
						<view class="margin-right">
							<checkbox @change="CheckboxChange" :class="checkbox[0].checked?'checked':''" :checked="checkbox[0].checked?true:false" value="A"></checkbox>
						</view>
					</checkbox-group>
					<view class="text-sm text-gray">{{orderDetails.agreement.tips}}</view>
				</view>
				<self-line/>
				<view class="padding-lr padding-tb-sm bg-white flex justify-between align-center solid-top shadow">
					<view class="flex align-center">
						<text class="">应付款：</text>
						<view class="text-lg text-price text-red">
							<amount :value="Number(orderDetails.goods.specs[0].selling_price*num  || 0)" :is-round-up="false" :precision="2" :duration="800" transition></amount>
						</view>
					</view>
					<button class="cu-btn block bg-orange round shadow" @tap="submit">
						<text class="cuIcon-loading2 cuIconfont-spin  margin-right-xs text-white" v-if="loading"></text>
						<text class="text-df text-white">{{ loading ? '支付中...' : '下单付款' }}</text>
					</button>
				</view>
			</view>
		</skeleton>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				num: 1,
				base64Img: '',	//
				skeletonLoading: true,
				loading: false,
				checkbox: [{
					value: 'A',
					checked: true
				}],
				goods_id: 1,
				goods_specs_id: 1,
				orderDetails: {},
				ifchoose: true
			}
		},
		computed: {
			total(){
				return this.num * this.price
			}
		},
		onLoad(e) {
			this.goods_id = e.goods_id
			this.goods_specs_id = e.goods_specs_id
		},
		methods: {
			getConfirmOrder() {
				this.$http(this.API.API_COFIRMORDER_DETAILS, {goods_id: this.goods_id,goods_specs_id: this.goods_specs_id}).then(res => {
					if(res.code == 0) {
						this.orderDetails = res.data
						this.skeletonLoading = false
						this.mescroll.endSuccess(); // 请求成功,隐藏加载状态
					}
					
				}).catch(err => {
					// this.mescroll.endErr();
				});
			},
			reduce() {
				if (this.num === 1) return
				this.num--
			},
			add() {
				this.num++
			},
			CheckboxChange(e) {
				if(e.detail.value != '') {
					this.ifchoose = true
				}else {
					this.ifchoose = false
				}
			},
			// 点击复制
			copy(text) {
				uni.setClipboardData({
					data: text
				});
			},
			submit(){
				if(this.ifchoose == true) {
					this.$routerGo('/pages/order/pay-success')
				}else {
					this.$msg('请认真阅读并同意协议!')
					return
				}
			},
			//下拉刷新
			downCallback() {
				this.getConfirmOrder()
			},
		},
		created() {
			this.getConfirmOrder()
		}
	}
</script>

<style lang="scss" scoped>
	.address-box {
		// background-image: url(../../static/images/shop/envelope.png);
		background-repeat: repeat-x;
		background-position: left bottom;
		background-size: auto 8rpx;
	}

	.self-img-sm {
		width: 40rpx;
		height: 40rpx;
	}

	.bref-box {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.order-bottom {
		position: relative;

		.cuIcon-fold {
			position: absolute;
			right: 50rpx;
			top: -19rpx;
			color: rgba(0, 0, 0, 0.1)
		}
	}
</style>
