<template>
	<view>
		<!-- <view class="block">订单信息:</view> -->
		<view class="block">
			<view class="nominal">订单状态:</view>
			<view style="margin-left:auto">
				<uni-tag v-if="row.pay_status==0" text='待付款' :inverted="true" type="default" size="small"></uni-tag>
				<uni-tag v-if="row.pay_status==2" text='付款确认失败' :inverted="true" type="error" size="small"></uni-tag>
				<uni-tag style="margin-left:4upx" v-if="row.pay_status==1 && row.shipping_status==0" text='待发货' :inverted="true" type="default" size="small"></uni-tag>
				<uni-tag style="margin-left:4upx" v-if="row.invoice_status==2 && row.if_invoice!=0" text='待开票' :inverted="true" type="default" size="small"></uni-tag>
				<uni-tag style="margin-left:4upx" v-if="row.shipping_status==1 && row.receive_status==0" text='待收货' :inverted="true" type="default" size="small"></uni-tag>
				<uni-tag style="margin-left:4upx" v-if="row.receive_status>0" text="已完成" :inverted="true"type="default" size="small"></uni-tag>
			</view>
		</view>
		<view class="block">
			<view class="marginBottom20"> <view class="buyer">{{row.linkman}}</view> {{row.telphone}}</view>
			<view class="grayColor address"> 地址：{{row.address}}</view>
		</view>
		<view class="block">
			<view class="order-info" v-for="row in row.shop_db" v-bind:key="row.id" @click="toGoods(row)">
				<view class="left">
					<image :src="row.picurl"></image>
				</view>
				<view class="right">
					<view class="name">
						{{row.full_title}}
					</view>
					<view class="price-number">
						<view class="number">数量：{{row._num}}</view>
						<view class="price">单价：￥<text style="font-size: 26upx;">{{row._price}}</text></view>
					</view>
				</view>
			</view>
		</view>
		<view class="block">
			<view class="marginBottom20"><view class="grayColor">订单编号:</view>{{row.order_sn}}</view>
			<view><view class="grayColor">下单时间:</view>{{row.create_time}}</view>
			<!-- <view v-if="hasLogs"><view class="grayColor">物流信息:</view>{{logistics}}</view>
			<view v-if="row.shipping_status==1&&!hasLogs" class="viewLogistics" @click="viewLogistic">查看物流信息</view>
		 -->
		</view>
		<view class="block">
			<view :class="[row.if_invoice!==0?'marginBottom20':'']"><view class="grayColor">发票类型:</view> <text v-if="row.if_invoice==0">无</text> <text v-else-if="row.if_invoice==1">普票</text> <text v-else>专票</text></view>
			<view v-if="row.if_invoice!==0"><view class="grayColor">开票状态:</view>  <text v-if="row.invoice_status==1" style="color:green">已开</text><text v-else style="color:gray">待开</text></view>
		</view>
		<view class="block">
			<view class="marginBottom20 flexSpaceBetween"><view class="grayColor">商品总额:</view><text>￥{{goodMoney}}</text></view>
			<view class="marginBottom20 flexSpaceBetween"><view class="grayColor">运费:</view><text>￥{{row.real_freight}}</text></view>
			<view class="marginBottom20" style="text-align: right;"><text>合计:</text><text style="color: red;font-weight: bold;">￥{{row.totalmoney}}</text></view>
			<view class="btns">
				<view class="default" @tap="cancelOrder" v-if="row.pay_status!=0&&row.shipping_status==0">取消订单</view>
				<view class="pay" @tap="toUppay" v-if="row.pay_status==0||row.pay_status==2">上传付款凭证</view></block>
				<view class="default" @tap="qrsh" v-if="row.shipping_status==1 && row.receive_status==0">确认收货</view>
					<view class="default" @tap="seeImg" v-if="row.voucher_url!=''">查看付款</view>
					<view class="primary" @tap="applayInvoice" v-if="row.if_invoice==0&&row.voucher_url==''">提交开票</view>
					<view class="primary" @tap="qrfp" v-if="row.invoice_status ==1 && row.receive_invoice_status ==0">确认收票</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				amount: 0,
				goodMoney:0.00,
				orderName: '',
				paytype: 'alipay', //支付类型
				imageValue: [],
				row: {},
				count: 1,
				name: 'file',
				url: '',
				filepath: [],
				rpath:[],
				logistics:'lalalala',
				hasLogs:false,
			};
		},
		onLoad(e) {
			uni.getStorage({
				key: 'orderDetail',
				success: (res) => {
					// debugger;
					let row = JSON.parse(res.data);
					this.row = row;
					this.goodMoney = (row.totalmoney-row.real_freight).toFixed(2)
					this.url = this.vuex_host +
						'index.php/index/attachment/upload?dir=images&from=base64&module=index'
				}
			})
		},
		methods: {
			toGoods(row) {
				uni.navigateTo({
					url: '../../goods/goods?id='+row.id
				});
			},
			doDeposit() {
				//模板模拟支付，实际应用请调起微信/支付宝
				uni.showLoading({
					title: '支付中...'
				});
				setTimeout(() => {
					uni.hideLoading();
					uni.showToast({
						title: '支付成功'
					});
					setTimeout(() => {
						uni.redirectTo({
							url: '../../pay/success/success?amount=' + this.amount
						});
					}, 300);
				}, 700)
			},
			//查看物流信息
			viewLogistic(){
				var that = this;
				that.hasLogs = true;
				/* that.$u.api(that.row.id).then(res=>{
					if(res.data){
						that.hasLogs = true;
						uni.showToast({
						    title: '查询成功',
						    icon:'none'
						});
						 
					}else{}
					
				}) */
			},
			cancelOrder(){	
				var that = this;
				uni.showModal({
				    content: '确认取消订单吗?',
				    success: function (res) {
				        if (res.confirm) {
				           that.$u.api.qxdd(that.row.id).then(res=>{
				           	uni.showToast({
				           	    title: '取消成功',
				           	    icon:'none'
				           	});
							uni.navigateBack();
				           })
				        }
				    }
				});
				
			},
			qrsh(){
				var that = this
				uni.showModal({
				    content: '确认收货吗?',
				    success: function (res) {
				        if (res.confirm) {
				           that.$u.api.qrsh(that.row.id).then(res=>{
				           	uni.showToast({
				           	    title: '确认成功',
				           	    icon:'none'
				           	});
				           })
				        }
				    }
				});
			},
			seeImg(){
				let urls = this.row.voucher_url.split(',')
				for(var i=0;i<urls.length;i++){
					urls[i] = this.vuex_host + '/public/' + urls[i];
				}
				uni.previewImage({
					current:urls[0],
					urls: urls
				});
			},
			applayInvoice(){
				uni.showLoading({
					title:'正在获取订单...'
				})
				setTimeout(()=>{
					uni.setStorage({
						key:'paymentOrder',
						data:this.row,
						success: () => {
							uni.hideLoading();
							uni.navigateTo({
								url:'/pages/invoice/apply'
							})
						}
					})
				},500)
			},
			toUppay(){
				uni.showLoading({
					title:'正在获取订单...'
				})
				setTimeout(()=>{
					uni.setStorage({
						key:'paymentOrder',
						data:this.row,
						success: () => {
							uni.hideLoading();
							uni.navigateTo({
								url:'../../pay/payment/uppayment'
							})
						}
					})
				},500)
			},
			
		}
	}
</script>

<style lang="scss">
	page{
		background: #f9f9f9;
	}
	.block {
		width: 94%;
		box-sizing: border-box;
		background: #ffffff;
		margin: 0 3% 10px;
		padding: 30upx 20upx;
		border-radius: 10px;
		font-size: 28upx;
		.marginBottom20{
			margin-bottom: 20upx;
		}
		.flexSpaceBetween{
			    display: flex;
			    justify-content: space-between;
		}
		.buyer{
			color: #000000;
			font-weight: bold;
			margin-right: 10px;
			display: inline-block;
		}
		.grayColor{
			display: inline-block;
			margin-right: 20upx;
			font-size: 26upx;
			color:#666666;
			width: 130rpx;
		}
		.address{
			width: 100%;
		}
		.title {
			width: 100%;
			font-size: 34upx;
		}
		.viewLogistics{
			      height: 50upx;
			      padding: 0 20upx;
			      border-radius: 30upx;
			      font-size: 26upx;
			      display: inline-block;
			      line-height: 50upx;
				  color: #0055ff;
			      border: 1upx solid #0055ff;
		}
		.content {
			.nominal {
				color: gray;
			}

			.orderinfo {
				width: 100%;
				border-bottom: solid 1upx #eee;

				.order-info {
					width: 100%;
					display: flex;
					margin-top: 4upx;

					.left {
						flex-shrink: 0;
						width: 25vw;
						height: 20vw;

						image {
							width: 25vw;
							height: 20vw;
							border-radius: 10upx;
						}
					}

					.right {
						width: 100%;
						margin-left: 10upx;
						position: relative;

						.name {
							width: 100%;
							font-size: 28upx;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							-webkit-line-clamp: 2;
							overflow: hidden;
						}

						.spec {
							color: #a7a7a7;
							font-size: 22upx;

						}

						.price-number {
							position: absolute;
							bottom: 0;
							width: 100%;
							display: flex;
							justify-content: flex-end;
							font-size: 22upx;
							color: #333;
							display: flex;
							align-items: flex-end;

							.price {
								font-size: 24upx;
								margin-right: 5upx;
							}

						}
					}
				}
			}

			.pay-list {
				width: 100%;
				border-bottom: solid 1upx #eee;

				.row {
					width: 100%;
					height: 120upx;
					display: flex;
					align-items: center;

					.left {
						width: 100upx;
						flex-shrink: 0;
						display: flex;
						align-items: center;

						image {
							width: 80upx;
							height: 80upx;
						}
					}

					.center {
						width: 100%;
						font-size: 30upx;
					}

					.right {
						width: 100upx;
						flex-shrink: 0;
						display: flex;
						justify-content: flex-end;
					}
				}
			}
		}
	}
	.order-info{
			width: 100%;
			display: flex;
			margin-top: 4upx;
			.left{
				flex-shrink: 0;
				width: 25vw;
				height: 20vw;
				image{
					width: 25vw;
					height: 20vw;
					border-radius: 10upx;
				}
			}
			.right{
				width: 100%;
				margin-left: 10upx;
				position: relative;
				.name{
					width: 100%;
					font-size: 28upx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
				}
				.spec{
					color: #a7a7a7;
					font-size: 22upx;
	
				}
				.price-number{
					position: absolute;
					bottom: 0;
					width: 100%;
					// display: flex;
					// justify-content: flex-end;
					font-size: 22upx;
					color: #333;
					// display: flex;
					// align-items: flex-end;
					.price{
						color: #333333;
						font-size: 24upx;
						margin-right: 5upx;
					}
					
				}
			}
		}
		.detail{
			display: flex;
			justify-content: flex-end;
			align-items: flex-end;
			height: 46upx;
			font-size: 26upx;
			.sum{
				padding: 0 8upx;
				display: flex;
				align-items: flex-end;
				.price{
					font-size: 30upx;
				}
			}
			
		}
		.btns{
			height: 80upx;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			view{
				min-width: 120upx;
				height: 50upx;
				padding: 0 20upx;
				border-radius: 30upx;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 28upx;
				margin-left: 20upx;
			}
			.default{
				border: solid 1upx #ccc;
				color: #666;
			}
			.primary{
				border: solid 1upx #0055ff;
				color: #0055ff;
			}
			.pay{
				border: solid 1upx #ec652f;
				color: #ec652f;
			}
		}
	
</style>

