<template>
	<view class="container cashier">
		<view class="pay-content">
			<view class="pay-list" v-for="(list, index) in list" :key="index">
				<view class="pay-list-title">{{ list.shopName }}</view>
				<view class="pay-list-goods" v-for="(pros, prosIndex) in list.orderProductList" :key="prosIndex">
					<view class="pay-list-image"> <image :src="pros.image" class="image" mode=""></image> </view>
					<view class="pay-list-info">
						<view class="info-title">{{ pros.name }}</view>
						<view class="info-view" v-if="pros.productUnit != ''">
							规格:{{ pros.productUnit ? pros.productUnit : '' }}
						</view>
						<view class="info-view" v-if="pros.productCode != '' && pros.productCode != null">
							商品编码:{{ pros.productCode ? pros.productCode : '' }}
						</view>
						<view class="info-price">
							<view class="price">￥{{ pros.price | NumFormat }}</view>
							<view class="count"><text class="sm">X</text> {{ pros.num }}</view>
						</view>
					</view>
				</view>
				<view class="pay-list-msg">
					<view class="list-msg" v-if="list.shopPostFee > 0"
						>运费:<text class="text">￥{{ list.shopPostFee | NumFormat }}</text></view
					>
					<view class="list-msg" v-if="list.receiptAmount > 0">
						已付:
						<text class="text">
							￥{{ list.receiptAmount | NumFormat }}
							<text> 余额抵扣：(￥{{ list.canRefundAmount | NumFormat }}) </text>
						</text>
					</view>
					<view class="list-msg" v-if="list.eachDiscount > 0"
						>优惠:<text class="text">￥{{ list.eachDiscount | NumFormat }}</text></view
					>
				</view>
				<view class="pay-list-btn">
					<view
						class="btn"
						v-if="list.onlinePay === 0 || list.onlinePay === 2 || list.onlinePay === 3"
						@click="handlePayunder(list.shopOrderId)"
						>线下转账</view
					>
					<view
						class="btn"
						v-if="list.onlinePay === 0 || list.onlinePay === 1"
						@click="handlePayOrder(list.shopOrderId)"
						>线上支付</view
					>
					<view class="list-msg" v-if="list.obligation > 0"
						>待付:<text class="text red">￥{{ list.obligation | NumFormat }}</text></view
					>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			orderId: 0,
			showPayUnder: false,
			list: []
		}
	},
	onLoad(option) {
		this.initData(option)
	},
	filters: {
		NumFormat(value) {
			//处理金额
			if (value) {
				return Number(value).toFixed(2)
			} else {
				return '0.00'
			}
		}
	},
	methods: {
		initData(e) {
			console.log(e)
			this.orderId = e.orderId
			this.payOrderId = '#' + e.orderId + '#'
			this.PayOrderShoporders(this.orderId)
		},
		PayOrderShoporders(orderId) {
			this.PayService.PayOrderShoporders({ orderId: orderId })
				.then(response => {
					this.list = response.data
					this.PayOrderCheckoutCounter(orderId)
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		PayOrderCheckoutCounter(orderId) {
			this.PayService.PayOrderCheckoutCounter({ orderId: orderId })
				.then(response => {
					let data = response.data
					if (data.discernReceipt.length > 0) {
						this.showPayUnder = true
					}
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		handlePayOrder(shopOrderId) {
			this.$api.navigateTo(`/pages/user/pay/card-order?shopOrderId=${shopOrderId}`)
		},
		handlePayunder(shopOrderId) {
			this.$api.navigateTo(`/pages/user/order/order-payunder?orderId=${this.orderId}`)
		}
	},
	onShow() {}
}
</script>

<style lang="scss">
page {
	height: auto !important;
	background-color: #f7f7f7;
}
.cashier {
	width: 100%;
}
.pay-content {
	width: 100%;
	height: auto;
	.pay-list {
		width: 100%;
		height: auto;
		padding: 30rpx 24rpx 30rpx 24rpx;
		box-sizing: border-box;
		background-color: #ffffff;
		margin-bottom: 20rpx;
		.pay-list-title {
			width: 100%;
			height: 42rpx;
			line-height: 42rpx;
			font-size: $font-size-30;
			color: #333333;
			margin-bottom: 20rpx;
		}
		.pay-list-goods {
			width: 100%;
			height: 180rpx;
			margin-bottom: 30rpx;
			.pay-list-image {
				width: 180rpx;
				height: 180rpx;
				box-sizing: border-box;
				border: 1px solid #e1e1e1;
				border-radius: 8rpx;
				float: left;
				margin-right: 13rpx;
				.image {
					width: 100%;
					height: 100%;
					display: block;
					border-radius: 8rpx;
				}
			}
			.pay-list-info {
				width: 508rpx;
				height: 100%;
				float: right;
				.info-title {
					width: 100%;
					display: inline-block;
					height: auto;
					text-overflow: ellipsis;
					display: -webkit-box;
					word-break: break-all;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
					line-height: 38rpx;
					font-size: $font-size-28;
					color: #333333;
				}
				.info-view {
					height: 40rpx;
					line-height: 40rpx;
					color: #999999;
					text-overflow: ellipsis;
					display: -webkit-box;
					word-break: break-all;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
					font-size: $font-size-22;
					color: #999999;
				}
				.info-price {
					height: 40rpx;
					width: 100%;
					float: left;
					line-height: 40rpx;
					font-size: $font-size-26;
					.price {
						color: #333333;
						float: left;
					}
					.count {
						float: right;
						color: #666666;
						.sm {
							font-size: $font-size-22;
						}
					}
				}
			}
		}
		.pay-list-msg {
			width: 100%;
			height: 40rpx;
			line-height: 40rpx;
			font-size: $font-size-26;
			margin-bottom: 30rpx;
			.list-msg {
				float: right;
				margin-left: 30rpx;
				font-size: $font-size-26;
				color: #333333;
				font-weight: bold;
				.text {
					font-weight: normal;
					&.red {
						color: #f94b4b;
					}
				}
			}
		}
		.pay-list-btn {
			width: 100%;
			height: 64rpx;
			.btn {
				width: 160rpx;
				height: 64rpx;
				line-height: 64rpx;
				background: $btn-confirm;
				font-size: $font-size-26;
				text-align: center;
				float: right;
				color: #ffffff;
				border-radius: 32rpx;
			}
			.list-msg {
				float: right;
				line-height: 64rpx;
				margin-right: 40rpx;
				font-size: $font-size-26;
				color: #333333;
				font-weight: bold;
				.text {
					font-weight: normal;
					&.red {
						color: #f94b4b;
					}
				}
			}
		}
	}
}
</style>
