<template>
	<view>
		<view class="w100 bgff h-200 pl-24 pr-34 rows rowsm rowsb relative">
			<view class="rows rowsm rowsl w100">
				<view class="rows rowsm rowsb">
					<view class="rows rowsm">
						<image class="w-52 h-52 mr-20" src="/static/images/01_13wz.png" mode=""></image>
						<view class="rows rowsl">
							<view class="fw-b fs-30 col333 two_overflow">
								{{infor.address}}
							</view>
							<view class="rows fs-26 col333 mt-12">
								<text class="mr-16">{{infor.name}}</text>
								<text>{{infor.mobile}}</text>
							</view>
						</view>
					</view>
					<image class="w-20 h-20 ml-60" src="/static/images/yjt.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="w100 rows rowsc mt-20">
			<view class="w-710 bgff br-20 p-all-20">
				<scroll-view scroll-y="true" style="max-height: 450rpx;">
					<view class="rows mb-10 mt-10" v-for="(item,index) in infor.shop" :key="index">
						<image class="w-176 h-176 br-8 mr-28" :src="$tools.oss(item.image)" mode="aspectFill"></image>
						<view class="rows rowsl rowsb">
							<view class="rows rowsb w-430">
								<text class="fs-28 fw-b col333">{{item.shop_name}}</text>
							</view>
							<view class="rows rowsm">
								<text class="fs-24 col666">x{{item.num}}</text>
							</view>
							<text class="fs-28 fw-b mt-42" style="color: #E61818;">￥{{item.price}}</text>
						</view>
					</view>
				</scroll-view>
				<view class="w100 rows rowsl mt-20" style="border-top: 1rpx solid #f5f5f5;">
					<view class="w100 rows rowsm rowsb mt-20">
						<text class="fs-26">实付金额</text>
						<text class="fs-26">￥{{infor.total_amount}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="w100 rows rowsc mt-20">
			<view class="w-710 h-92 bgff br-20 rows rowsm rowsb pl-24 pr-20">
				<text class="fs-28">备注</text>
				<text class="fs-28">{{infor.remark?infor.remark:'无'}}</text>
			</view>
		</view> -->
		<view class="rows rowsl rowsm">
			<!-- <view class="w-710 bgff p-all-20 br-20 rows rowsl mt-20" v-if="infor.exNumber&&infor.exCode">
				<view class="w100 fs-28 fw-b">快递信息</view>
				<view class="w100 rows rowsm rowsb mt-20">
					<text class="fs-28 col666">快递名称</text>
					<text class="fs-28">{{infor.exNumber}}</text>
				</view>
				<view class="w100 rows rowsm rowsb mt-20">
					<text class="fs-28 col666">快递单号</text>
					<text class="fs-28">{{infor.exCode}}</text>
				</view>
			</view> -->
			<view class="w-710 bgff p-all-20 br-20 rows rowsl mt-20">
				<view class="w100 fs-28 fw-b">订单信息</view>
				<view class="w100 rows rowsm rowsb mt-20">
					<text class="fs-28 col666">订单编号</text>
					<text class="fs-28">{{infor.order_number}}</text>
				</view>
				<view class="w100 rows rowsm rowsb mt-20">
					<text class="fs-28 col666">订单时间</text>
					<text class="fs-28">{{infor.createtime}}</text>
				</view>
			</view>
		</view>
		<view class="w100 h-190"></view>
		<view class="w100 rows rowse rowsm bgff h-170 fixed pl-20 pr-20" style="bottom: 0;">
			<view class="w-212 h-72 br-100 bg rows rowsm rowsc fs-28 fw-b ml-20 colfff" v-if="infor.status==0"
			@click="open">
				去支付
			</view>
			<view class="w-212 h-72 br-100 bg rows rowsm rowsc fs-28 fw-b ml-20 colfff" v-if="infor.status==0"
			@click="cancelOrder(infor.id)">
				取消订单
			</view>
			<view class="w-212 h-72 br-100 bg rows rowsm rowsc fs-28 fw-b ml-20 colfff" v-if="infor.status==2"
			@click="deliveryOrder(infor.id)">
				确认收货
			</view>
		</view>
		<uni-popup ref="popup" type="bottom" :is-mask-click="false" :safe-area="false">
			<view class="w100 p-all-24 bgff">
				<text class="fs-30 fw-b">选择支付方式</text>
				<view class="w100 rows rowsm rowsl">
					<view class="w-710 bgff br-20 p-all-24">
						<view class="rows rowsl">
							<view class="w100 rows rowsm rowsb mt-20" v-for="(item,index) in payList" :key="index" @click="selpay(item)">
								<view class="rows rowsm">
									<image class="w-72 h-72 mr-20" :src="item.icon" mode=""></image>
									<text class="fs-28 col333">{{item.name}}</text>
								</view>
								<image class="w-36 h-36 mr-15" :src="item.status?'/static/images/03_qou.png':'/static/images/03_w.png'" mode=""></image>
							</view>
						</view>
					</view>
				</view>
				<view class="w100 rows rowsm rowsa">
					<view class="w-300 h-80 rowsm rows rowsc col br-100 fs-28" style="border: 2rpx solid #F8222A;" @click="close">
						取消
					</view>
					<view class="w-300 h-80 bg rowsm rows rowsc colfff br-100 fs-28" @click="create">
						确定
					</view>
				</view>
				<view class="w100 h-30"></view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				ids:'',
				infor:{},
				payList:[
					{id:1,name:'微信支付',status:true,icon:'/static/images/icon_7wx.png'},
					{id:2,name:'余额支付',status:false,icon:'/static/images/044vef.png'},
				],
				payId:1
			}
		},
		onShow() {this.orderDetails()},
		onLoad(e) {
			this.ids = e.id
		},
		methods:{
			selpay(item){
				this.payId = item.id
				this.payList.forEach(item => { 
					item.status = false
				})
				item.status = true
			},
			orderDetails(){
				this.$tools.axiosFromToken("POST","order/orderDetails",{id:this.ids}).then(res => {
					this.infor = res.data
				})
			},
			// 取消订单
			cancelOrder(id){
				let _this = this
				uni.showModal({
					title: '提示',
					content: '确定要取消订单吗？',
					success: function (res) {
						if (res.confirm) {
							_this.$tools.axiosFromToken("POST","order/cancelOrder",{id}).then(res => {
								_this.$tools.showtt(res.msg)
								if(res.code!=1) return
								_this.orderDetails()
							})
						} 
					}
				})
			},
			// 确认收货
			deliveryOrder(id){
				let _this = this
				uni.showModal({
					title: '提示',
					content: '确定要确认收货吗？',
					success: function (res) {
						if (res.confirm) {
							_this.$tools.axiosFromToken("POST","order/deliveryOrder",{id}).then(res => {
								_this.$tools.showtt(res.msg)
								if(res.code!=1) return
								_this.orderDetails()
							})
						} 
					}
				})
			},
			open(){
				this.$refs['popup'].open()
			},
			close() {
				this.$refs.popup.close()
			},
			create(){
				this.$refs.popup.close()
				let _this = this
				uni.showModal({
					title: '提示',
					content: '确定要支付吗？',
					success: function (res) {
						if (res.confirm) {
							_this.$tools.axiosFromToken("POST","pay/shopPay",{order_number:_this.infor.order_number,pay_type:_this.payId}).then(res => {
								if(res.code==1){
									if(_this.payId==1){
										uni.requestPayment({
											timeStamp: res.data.info.timeStamp,
											nonceStr: res.data.info.nonceStr,
											package: res.data.info.package,
											signType: res.data.info.signType,
											paySign: res.data.info.paySign,
											success(res) {
												_this.$tools.showtt('支付成功')
												_this.orderDetails()
											},
											fail(res) {
												_this.$tools.showtt('支付失败')
											}
										})
									}else {
										_this.$tools.showtt(res.msg)
										if (res.code!=1)  return
										_this.orderDetails()
									}
								}else{
									_this.$tools.showtt(res.msg)
								}
							})
						} 
					}
				})
			},
		}
	}
</script>

<style>
	page{
		background-color: #F7F8FA;
		padding-bottom: 50rpx;
	}
</style>