<template>
	<view>
		<van-radio-group >
		   <van-cell-group 
		   v-for="(item, index) in list"
		   :key="index"
		   >
			 <van-cell
			   :border="false"
		       :title="item.title"
			   @click="onChange(index)" 
		     >
			 <template slot="right-icon">
			    <van-radio-group style="width: 20upx;" :value="radio" >
			      <van-radio checked-color="#D9332E" :name="index" >
				  </van-radio>
			    </van-radio-group>
			 </template>
		     </van-cell>
		   </van-cell-group>
		 </van-radio-group>
		 
		 <view v-if="radio === 0"
		  style="border-top: 15upx solid #F5F5F5;
		  border-bottom: 15upx solid #F5F5F5;
		  "
		 >
		  <van-field 
		     :value="username"
		     label="酒店"
		     placeholder="请输入酒店"
		   />
		   
		   <van-field
		      :value="username"
		      label="房间号"
		      placeholder="请输入房间号"
		    />
			<van-field
			   :value="username"
			   label="收货人"
			   placeholder="请输入收货人"
			 />
			<van-field
			   :value="username"
			   label="手机号"
			   placeholder="请输入手机号"
			 />
		 			 
		    </view>
			
		 <view v-if="radio === 2"
		  style="border-top: 15upx solid #F5F5F5;
		  border-bottom: 15upx solid #F5F5F5;
		  "
		 >
		  <van-field 
		     :value="username"
		     label="预定酒店"
		     placeholder="请输入预定酒店"
		   />
		   
		   <van-field
		      :value="username"
		      label="入住人"
		      placeholder="请输入入住人"
		    />
			<van-field
			   :value="username"
			   label="手机号"
			   placeholder="请输入手机号"
			 />
			 <van-field
			    :value="username"
			    label="备注"
			    placeholder="请输入备注"
			  />
		    </view>
		 <van-cell v-if="radio === 1&&choseadress == '' " @click="goAdress" class="LinkAdress" title="选择地址"  is-link/>
		  <view v-if="radio === 1&&choseadress != ''" class="wrapper">
		  	<view class="u-box" @click="goAdress" >
		  		<text class="name" style="padding-right: 20upx;">{{choseadress.address_realname}}</text>
		  		<text class="mobile">{{choseadress.address_mob_phone}}</text>
		  	</view>
		  	<view class="u-box">
		  		<text class="address">{{choseadress.area_info}} {{choseadress.address_detail}}</text>
		  	</view>
		  </view>
		  
		 <view @tap="goDetail()" class="cart-list">
		  <view class="topTip">
			   <view style="display: flex;align-items: center;border-bottom: 1px solid #F5F5F5;">
				<image :src="pictureUrl+'/uploads/home/store/'+store.store_id+'/'+store.store_logo" style="border-radius: 50%;
				width: 50upx;height: 50upx;"></image>
				<span style="padding-left: 8upx;">{{store.store_name}}</span>
			   </view>
		  </view>
		  
		  <view v-for="(item,index) in pricelist" :key="index" class="shoplist" style="background-color: #fff;">
			  <view>
				  <van-card
					title-class="changewidth"
					price-class ="priceClass"
					:price="item.goods_price"
					:desc="item.desarray[1]+'X'+item.goods_num"
					:title="item.desarray[0]"
					:thumb="pictureUrl + '/uploads/home/store/goods/' + item.goods_image.substr(0, item.goods_image.indexOf('\_')) + '/' + item.goods_image"
				  >
				  </van-card>
			  </view>
		  </view>
			   <view class="topTip"  v-if="radio === 1">
				  <view style="font-size: 28upx;">运费：{{ralodprice}}</view>
			   </view>
		 </view>
		 <!-- 底部付款 -->
		 <view class="adressbutton">
		 		<view class="buttonStatus">
		 			<view @click="estimate" class="deleteOrder">应付<span>￥{{prices}}</span></view>
		 			<view class="payOrder" @click="goPay">付款</view>
		 		</view>
		 </view>
		 
		</view>
</template>

<script>
	
	export default {
		data() {
			return {
				ralodprice: 0,
				prices:'',
				pictureUrl: this.pictureUrl,
				list:[
					{title:'请送到我的房间'},
					{title:'快递到我的地址'},
					{title:'处理我的客房预定'}
				],
				username:'',
				shipping_type: 0,
				radio: 0,
				store: {},
				pricelist: [],
				choseadress: '',
				order_id:''
			}
		},
		onLoad(options) {
			this.order_id = options.order_id;
			this.store = JSON.parse(options.store);
			this.pricelist = JSON.parse(options.pricelist);
			let prices =  Number((options.prices/100).toFixed(2));
			this.prices = prices; 
			 uni.$on("getadress",(adress)=>{
			        this.choseadress = adress;
					this.address_id = this.choseadress.address_id;
					this.getralodprice();
			 })
		},
		methods: {
			// 付款
			goPay() {
				this.request({
					url:'/v1/order/create',
					method: 'post',
					data: {
						gorderid: this.order_id,
						address_id: this.address_id,
						store_id: this.store.store_id,
						shipping_type: this.shipping_type
					},
					success: (res) => {
						console.log(res);
						let order_id = res.data.data.order_id; // 订单id
						let prices = this.prices;
						uni.navigateTo({
							url:`/pages/myOrder/paymoment?order_id=${order_id}&prices=${prices}`
						})
					}
				})
			},
			// 核算运费
			getralodprice() {
				this.request({
					url: '/v2/entry/orderFreight',
					method: 'POST',
					data: {
						order_id: this.order_id,
						address_id:　this.address_id
					},
					success:(res) => {
						    this.ralodprice = res.data.data.shipping_fee;
					}
				})
			},
			onChange(index) {
				this.radio = index;
					
				if(index == 1) {
					this.shipping_type = 0; // 订单付款快递类型
				}else {
					this.shipping_type = 1;
				}
			},
			goAdress() {
				console.log("dddd")
				uni.navigateTo({
				                   url: '../myOrder/adress',
				               }); 
			}
		}
	}
	
</script>

<style lang="scss">
	.LinkAdress /deep/ .van-cell {
		border-top: 15upx solid #F5F5F5;
		border-bottom: 15upx solid #F5F5F5;
	}
	.wrapper{
		border-top: 15rpx solid #F5F5F5;
		border-bottom: 15rpx solid #F5F5F5;
        padding: 0 32upx;
	}
	.u-box {
		padding: 15upx 0;
	}
	.topTip {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20upx 36upx;
		border-bottom: 1px solid #F5F5F5;
	}
	.changewidth {
		color: #303133;
		font-size: 32upx;
		font-weight: 100!important;
	}
	.priceClass {
		color:#303133!important;
		font-weight: 100!important;
		font-size: 36upx;
	}
	.van-card {
		background-color: #fff!important;
	}
	.shoplist {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.adressbutton {
		position: fixed;
		bottom: 0;
		width: 100%;
		.buttonStatus {
			display: flex;
			text-align: left;
			.deleteOrder {
				flex: 3;
				color: #303133;
				font-size: 32upx;
				background-color: #fff;
				padding: 10px 0;
			}
			.payOrder {
				flex: 1;
				font-size: 32upx;
				color: #fff;
				background-color: #D9332E;
				padding: 10px 0;
				text-align: center;
			}
		}
	}
</style>
