<template>
	<view class="order-pages">
		<view class="order-info">
			<!-- 订单状态 -->
			<view class="order-status">
				<view class="status-title">{{orderInfo.orderFlag}}</view>
				<view v-if="orderInfo.orderFlag=='待支付'" class="status-care">
					请在 <text>2020-10-30</text>前付款，过期系统将自动取消订单
				</view>
				<view v-if="orderInfo.orderFlag=='已取消'" class="status-care">
					超时未支付，系统已自动取消订单
				</view>
			</view>
			<u-gap height="10" bg-color="#f8f8f8"></u-gap>
			<!-- 地址 -->
			<view class="order-address">
				<view>
					<text class="address-title">{{orderInfo.address}}</text>
				</view>
				<view>
					<text style="margin-right: 30upx;">{{orderInfo.userName}}</text>
					<text>{{orderInfo.phone}}</text>
				</view>
			</view>
			<u-gap height="10" bg-color="#f8f8f8"></u-gap>
			<!-- 商品列表 -->
			<view class="bundle-list" v-for="item in orderInfo.itemList" :key="item.id">
				<view class="img-cont">
					<image :src="item.icon?item.icon:'../../static/goods.png'"></image>
				</view>
				<view >
					<view class="ellipsis-two">{{item.name}}</view>
					<view class="bundle-num">
						<view ><text class="price-num">{{item.price}}</text> <text class="price-text">乐豆</text></view>
						<view >X {{item.number}}</view>
					</view>
				</view>
			</view>
			<u-gap height="10" bg-color="#f8f8f8"></u-gap>
			<!-- 订单信息 -->
			<u-cell-group>
				<u-cell-item title="订单编号" :value-style="{color: '#000',fontSize: '28upx'}" :arrow="false" >
					{{orderInfo.orderNo}}
				</u-cell-item>
				<u-cell-item title="下单时间" :value-style="{color: '#000',fontSize: '28upx'}" :arrow="false" >
					{{orderInfo.orderTime}}
				</u-cell-item>
				<u-cell-item v-if="orderInfo.payTime" title="支付时间" :value-style="{color: '#000',fontSize: '28upx'}" :arrow="false">
					{{orderInfo.payTime}}
				</u-cell-item>
				<u-gap height="10" bg-color="#f8f8f8"></u-gap>
				<u-cell-item title="商品合计" :value-style="{color: '#000',fontSize: '28upx'}" :arrow="false">
					<text class="price-num">{{orderInfo.amount}}</text> <text class="price-text">乐豆</text>
				</u-cell-item>
				<u-cell-item title="运费" :value-style="{color: '#000',fontSize: '28upx'}" :arrow="false">
					免运费
				</u-cell-item>
				<u-cell-item :title="(orderInfo.orderFlag=='待支付'||orderInfo.orderFlag=='已取消') ? '待支付':'实际支付'" :value-style="{color: '#000',fontSize: '28upx'}" :arrow="false">
					<text class="price-num">{{orderInfo.amount}}</text> <text class="price-text">乐豆</text>
				</u-cell-item>
			</u-cell-group>
		</view>
		<view v-if="orderInfo.orderFlag=='待支付'" class="footer">
			<u-button @click="cancleOrder" type="error" >去支付</u-button>
		</view>
	</view>
</template>

<script>
	import {orderDetail, cancleOrder} from '@/api/order.js'
	import {getLookUpDatas} from '@/api/data.js'
	export default{
		data() {
			return {
				orderInfo: {
					address: '陕西省西安市未央区常青二路大明宫小区',
					userName: '王明',
					phone: '18792701023',
					orderTime: "2020-10-28 11:15:59",
					orderFlag: "待支付",
					orderNo: 121245465748,
					payedAmount: 0,
					id: 11,
					amount: 450,
					totalNum: 3,
					itemList: [
						{
							name: "八九箭冠",
							id: 76435,
							number: 1,
							price: 150,
							icon: ''
						},
						{
							name: "数据库的合法身份觉得很附近发生纠纷解决",
							id: 76436,
							number: 2,
							price: 150,
							icon: ''
						}
					]
				},
				src: '',
				orderStatusList: []
			}
		},
		onLoad(options) {
			if (options.id) {
				console.log(options.id)
				this.getOrderDetail(options.id)
				this.orderStatusList = this.$store.state.vuex_payStatus
			}
		},
		methods:{
			getOptionName (list,val) {
			  if(val){
				  let p = list.find((item) => {
				  				  return item.code == val
				  })
				  return p ? p.dispName : '-'
			  }
			  return '-'
			},
			// 获取订单详情
			getOrderDetail (id) {
				let payTypeList = this.$store.state.vuex_payType
				orderDetail({id:id}).then(res =>{
					if (res.status == 200) {
						this.orderInfo = res.data
						this.orderInfo.payType = this.orderInfo.payType ? this.getOptionName(payTypeList,this.orderInfo.payType) : ''
					} else {
					}
				})
			},
			// 取消订单
			cancleOrder (){
				cancleOrder({id:this.orderInfo.id}).then(res=>{
					if (res.status==200) {
						this.toashMsg(res.message)
						setTimeout(()=>{
							uni.navigateBack()
						},500)
					}
				})
			},
			// 图片预览
			showImage (url) {
				uni.previewImage({
					urls: [url],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			}
		},
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		background-color: #fff;
	}
	.order-pages{
		width: 100%;
		height: 100%;
		padding: 0 24upx;
		display: flex;
		flex-direction: column;
		.order-info{
			width: 100%;
			flex: 1;
			overflow-y: scroll;
			// 状态
			.order-status{
				padding: 30upx 0;
				text-align: center;
				.status-title{
					font-size: 36upx;
					color: #000;
				}
				.status-care{
					font-size: 24upx;
					margin-top: 10upx;
					color: #a9aaac;
					>text {
						color: red;
					}
				}
			}
			// 地址
			.order-address {
				font-size: 32upx;
				padding: 20upx 0;
				>view {
					line-height: 60upx;
				}
				.address-title {
					color: #000;
				}
			}
			// 订单中商品列表
			.bundle-list {
				display: flex;
				padding: 20upx 10upx;
				font-size: 28upx;
				border-bottom: 1px solid #F8F8F8;
				.img-cont {
					width: 158rpx;
					height: 140upx;
					border-radius: 15upx;
					overflow: hidden;
					>image {
						width: 100%;
						height: 100%;
					}
				}
				
				>view {
					&:last-child {
						flex: 1;
						margin-left: 20upx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
					}
				}
				.bundle-num {
					display: flex;
					justify-content: space-between;
				}
			}
			.price-text{
				font-size: 20upx;
				margin-left: 10upx;
			}
			.price-num{
				font-size: 32upx;
				color: red;
			}
			.u-cell{
				padding:10rpx 32rpx;
			}
		}
		.footer{
			padding: 20rpx;
		}
		
	}
</style>
