<template>
	<view class="app">
		<view class="bodys">
			<view class="addressinfo">
				<view class="namephone">
					{{updata.receiver}},{{updata.phone}}
				</view>
				<view class="picture">
					<span @tap='upaddress()'>修改地址</span>
					<u-icon name="arrow-right" color="#ffffff" size="32"></u-icon>
				</view>
				<view class="address">
					{{updata.receiveAddress}}
				</view>
			</view>
		</view>
		<view class="commodity">
			<view class="commodityInfo">
				<!-- <image src="../../static/fuwutu.png" mode=""></image> -->
				<view class="infos">
					<view class="detail">
						<view class="spangoodsName">
							{{updata.goodsName}}
						</view>
						<view class="spanprice"> ￥{{updata.goodsPrice}}</view>
					</view>
					<view class="model">
						型号:<span>{{updata.goodsAttributeName}}</span>
					</view>
				</view>
			</view>
			<view class="quantity">
				<view class="header">
					数量
				</view>
				<view class="number">
					<u-number-box :min="1" :max="updata.goodsStock" v-model="updata.goodsCount" @minus='delnumber'
						@plus='addnumber'>
					</u-number-box>
				</view>
			</view>
		</view>
		<view class="integral">
			<view class="header">
				积分抵扣
			</view>
			<view class="number">
				共5积分，满100可用
			</view>
		</view>
		<view class="price">
			<view class="priceinfo">
				<view class="header money">
					商品金额
				</view>
				<view class="number money">
					￥{{updata.totalPrice}}
				</view>
			</view>
			<view class="priceinfo">
				<view class="header money">
					运费
				</view>
				<view class="number money">
					+￥0.0
				</view>
			</view>
			<view class="freight">
				<view class="number total">
					￥{{updata.totalPrice}}
				</view>
			</view>
		</view>
		<view class="bottom">
			<view class="moneys">
				￥{{updata.totalPrice}}
			</view>
			<view class="submit" @tap='show=true'>
				提交订单
			</view>
		</view>
		<!-- 弹框 -->
		<view class="frame">
			<u-popup v-model="show" mode="bottom" length="45%" border-radius="30">
				<view class="payment">
					<span>请选择支付方式</span>
					<view class="cencel" @tap="show = false">
						<image src="../../static/gb.png" mode=""></image>
					</view>
				</view>
				<view class="chat">
					<image src="/static/chat.png" mode=""></image>
					<span>微信支付</span>
				</view>
				<view class="submits" @tap='buy'>
					<span>确认支付</span><span>￥{{updata.totalPrice}}</span>
				</view>
			</u-popup>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import baseurl from '@/api/baseurl.js'
	import {
		addStationGoodsOrder
	} from '@/api/confirmOrder/index.js'
	import {
		goodPatientInfo
	} from '@/api/modifyAddress/modifyAddress.js';
	export default {
		data() {
			return {
				show: false,
				updata: {},
				Patient: {},
			}
		},
		methods: {
			buy() {
				addStationGoodsOrder(this.updata).then(res => {
					console.log(res)
					if (res.code == 500) {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error'
						})
					}
				})
			},
			delnumber(e) {
				this.updata.totalPrice = (e.value * this.updata.goodsPrice).toFixed(2)
			},
			addnumber(e) {
				this.updata.totalPrice = (e.value * this.updata.goodsPrice).toFixed(2)
			},
			upaddress() {
				uni.navigateTo({
					url: `/pages/modifyAddress/modifyAddress?updata=${JSON.stringify(this.updata)}`
				})
			},
			// 收件人
			goodsList() {
				goodPatientInfo(this.updata.patientId).then(res => {
					res.data.forEach(e => {
						e.address = e.sysAreaVOList[0].provinceName + e.sysAreaVOList[0].cityName + e
							.sysAreaVOList[0].regionName + e.sysAreaVOList[0].streetName + e.receiveAddress
					})
					this.updata.receiver = res.data[0].receiveName
					this.updata.receiveAddress = res.data[0].address
					this.updata.phone = res.data[0].receivePhone
				})
			},
		},
		onLoad(options) {
			this.updata = JSON.parse(options.updata)
			if (options.useritem) {
				let useritem = JSON.parse(options.useritem)
				this.updata.receiver = useritem.receiveName
				this.updata.phone = useritem.receivePhone
				this.updata.receiveAddress = useritem.address
			} else {
				this.goodsList()
			}
		}
	}
</script>

<style lang="scss">
	@import './confirmOrder.scss'
</style>
