<template>
	<view class="app-content">
		<view v-if="!$util.isEmpty(detailInfo)" class="info-content_box">
			<view class="title">
				单据信息
			</view>
			<view class="bills-info_box content-box">
				<view class="order-info_box">
					<view>订单日期：</view>
					<view>{{ detailInfo.addTime.substr(5,11) }}</view>
				</view>
				<view class="order-info_box">
					<view>订单编码：</view>
					<view>{{ detailInfo.orderSn }}</view>
					<view class="price">
						<button @click="copy(detailInfo.orderSn)" class="admin-button-com default" > 复制 </button>
					</view>
				</view>
				<view class="order-info_box" v-if="detailInfo.status==2">
					<view>支付方式：</view>
					<view>{{ detailInfo.payWay==0?'微信':detailInfo.payWay==1?'支付宝':detailInfo.payWay==4?'现金':detailInfo.payWay==5?'银行卡':'其它' }}</view>
				</view>
				<view class="order-info_box">
					<view>操作人员：</view>
					<view>{{ detailInfo.operator }}</view>
				</view>
				<view class="order-info_box" v-if="detailInfo.status == 1">
					<view>过期时间：</view>
					<view>{{ detailInfo.deadline.substr(5,11) }}</view>
				</view>
				<view class="order-info_box">
					<view>订单状态：</view>
					<view style="color:red;font-weight:bold;">{{detailInfo.status == 1 ?'待结账':detailInfo.status==2?'已结账':detailInfo.status==3?'已取消':'待结账'}}</view>
				</view>
			</view>
			<view class="title">
				订单列表
			</view>
			<view class="module-com content-box">
				<view class="commodity-view">
					<view class="commodity-list">
						<view v-for="(s, idx) in detailInfo.orderList" :key="idx" class="commodity-item" >
							<view class="item-info" @click="pageTo({url: '/pagesPurchase/purDetails',query: {id: s.id,}})" >
								<view class="info-line">
									<text class="item-name">{{ s.orderSn }} 时间 {{s.addTime.substr(5,11)}}</text>
									<text class="item-price">
										<text class="unit">¥</text>
										<text class="price">{{ s.orderPrice?parseFloat(s.orderPrice):0 }}</text>
									</text>
								</view>
								<view class="info-line">
									<text class="item-type">
										<text v-if="Number(s.bigNum)>0">{{s.bigNum}}扎</text>
										<text v-if="Number(s.smallNum)>0">{{s.smallNum}}支</text>
										<text style="margin-left:20upx;color:red;font-weight:bold;" v-if="Number(s.tkPrice)>0">退款¥{{parseFloat(s.tkPrice)}} 实付¥{{parseFloat(s.actPrice)}}</text>
									</text>
									<text class="item-count" style="color: #3385ff;">查看明细</text>
								</view>
							</view>
						</view>
					</view>
					<view class="summary-bar">
						<view class="operate-view" ></view>
						<view class="describe-view">
							共{{ detailInfo.orderNum || 0 }}个订单
						</view>
					</view>
				</view>
			</view>
			<view class="content-box price-detail">
				<div class="module-com input-line-wrap">
					<tui-list-cell class="line-cell" :hover="false">
						<div class="tui-title">总金额</div>
						<div class="detail-price_box" style="font-size: 28upx;">¥{{ detailInfo.prePrice ? parseFloat(detailInfo.prePrice) : 0 }}</div>
					</tui-list-cell>
					<tui-list-cell class="line-cell" :hover="false" v-if="detailInfo.discountAmount > 0">
						<div class="tui-title">扣除</div>
						<div class="detail-price_box" style="font-size: 28upx;">¥{{ detailInfo.discountAmount ? parseFloat(detailInfo.discountAmount) : 0 }}</div>
					</tui-list-cell>
					<tui-list-cell class="line-cell" :hover="false">
						<div class="tui-title">实际金额</div>
						<div class="detail-price_box" style="font-size: 28upx;">¥{{ detailInfo.realPrice ? parseFloat(detailInfo.realPrice) : 0 }}</div>
					</tui-list-cell>
				</div>
			</view>
			<view class="content-box price-detail" v-if="detailInfo.remark && detailInfo.remark.length > 0">
				<div class="module-com input-line-wrap">
					<tui-list-cell class="line-cell" :hover="false">
						<div class="tui-title">备注</div>
						<input :disabled="true" v-model="detailInfo.remark" placeholder-class="phcolor" class="tui-input" name="name" maxlength="50" type="text" />
					</tui-list-cell>
				</div>
			</view>

		</view>
		<view class="app-footer">
			<button class="admin-button-com default" v-if="detailInfo.status == 1 && detailInfo.clearStyle==1" @click="cancelFn(detailInfo)">取消</button>
			<button class="admin-button-com default" v-if="detailInfo.status == 1" @click="toClear(detailInfo)">付款结清</button>
		</view>
	</view>
</template>
<script>
import { getDetail,detail,cancel } from "@/api/clear/index";
import productMins from "@/mixins/product";
import TuiListCell from "@/components/plugin/list-cell";
export default {
	name: "info",
	components: {
		TuiListCell
	},
	mixins: [productMins],
	data() {
		return {
			pageType: "order_change",
			autoLoad: false,
			stepActive: 0,
			form: {
				name: ""
			},
			detailInfo: {},
			loading: false
		};
	},
	methods: {
		cancelFn(info){
			let that = this
			that.$util.confirmModal({content:'确认取消？'},() => {
				cancel({id:info.id}).then(res=>{
					if(res.code == 1){
						that.$msg('取消成功')
						that.init()
					}
				})
			})
		},
		toClear(info){
			let that = this
			detail({ id:info.id }).then(res => {
				if(res.code == 1) {
					that.pageTo({ url: '/pagesPurchase/gatherPay?orderSn=' + res.data.orderSn + '&actPrice=' + res.data.actPrice+'&remainSecond='+res.data.remainSecond})
				}
			})
		},
		copy(val) {
			const self = this;
			uni.setClipboardData({
				data: val,
				success: function() {
					self.$msg("复制成功");
				}
			});
		},
		callUp(mobile) {
			uni.makePhoneCall({
				phoneNumber: mobile
			});
		},
		init() {
			let id = 0
			if(this.option.id){
				id = this.option.id
			}else{
				//扫码打印结账单
				//https://api.shop.huaml.com/#/admin/clear/info?id=322
				if(this.option.q){
					let currentUrl = decodeURIComponent(this.option.q);
					id = currentUrl.substring(currentUrl.lastIndexOf("?id=") + 4)
				}
			}
			if(Number(id)>0){
				this.getInfo(Number(id))
			}
		},
		getInfo(id){
			let that = this
			getDetail({id}).then(res=>{
				if(res.code == 1){
					that.detailInfo = res.data
				}
			})
		}
	}
};
</script>
<style lang="scss" scoped>
.info-content_box {
	padding: 0 20upx 100upx;
	& > .title {
		color: #666666;
		font-size: 28upx;
		font-weight: 600;
		padding: 30upx 3upx;
	}
	& .address-des_bx {
		display: flex;
		padding: 20upx 10upx 30upx 20upx;
		& > view:nth-child(1) {
			flex: 1;
			margin-top: 10upx;
			& > view:nth-child(1) {
				color: #333333;
				font-size: 32upx;
				font-weight: bold;
			}
			& > view:nth-child(2) {
				color: #666666;
				font-size: 28upx;
				font-weight: 400;
				margin-top: 20upx;
			}
		}
		& > view:nth-child(2) {
			display: flex;
			& .icondianhua1 {
				font-size: 50upx;
				color: #3385ff;
				margin-left: 0upx;
			}
		}
	}
	.bills-info_box {
		padding: 30upx 20upx 30upx;
		& > .order-info_box {
			display: flex;
			align-items: center;
			font-size: 26upx;
			font-weight: 400;
			margin-bottom: 5upx;
			& > view:nth-child(1) {
				color: #999999;
				width: 135upx;
				text-align: right;
			}
			& > view:nth-child(2) {
				color: #333333;
			}
			& > .price {
				flex: 1;
				font-size: 30upx;
				color: #333333;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				& .iconxiangyou {
					color: #999999;
					font-size: 25upx;
					margin-left: 12upx;
				}
			}
		}
	}
	.content-box {
		background-color: #ffffff;
		border-radius: 10upx;
	}
	.commodity-view {
		display: flex;
		flex-direction: column;
		.commodity-list {
			padding: 20upx;
			.commodity-item {
				display: flex;
				margin-bottom: 20upx;
				.item-icon {
					flex-shrink: 0;
					width: 140upx;
					height: 140upx;
				}
				.item-info {
					display: flex;
					flex-direction: column;
					justify-content: center;
					flex: 1;
					margin-left: 20upx;
					.info-line {
						margin-bottom: 20upx;
						display: flex;
						justify-content: space-between;
						align-items: flex-end;
						.item-name {
							color: #666;
							font-size: 28upx;
						}
						.item-price {
							color: #333;
							font-size: 22upx;
							.price {
								font-size: 32upx;
								font-weight: bold;
							}
						}
						.item-type {
							color: #999;
							font-size: 24upx;
						}
						.item-count {
							color: #666;
							font-size: 24upx;
						}
					}
				}
			}
		}
		.summary-bar {
			padding: 0 20upx;
			height: 90upx;
			display: flex;

			align-items: center;
			justify-content: space-between;
			border-top: 1px solid #eeeeee;
			.operate-view {
				display: flex;

				align-items: center;
				color: #3385ff;
				font-size: 26upx;
				.iconfont {
					margin-right: 20upx;
					font-size: 40upx;
				}
			}
			.describe-view {
				display: flex;

				align-items: center;
				color: #333;
				font-size: 24upx;
				.price {
					font-weight: bold;
					font-size: 36upx;
				}
			}
		}
	}
	.shipping-address {
		display: flex;
		align-items: center;
		margin-top: 20upx;
		& > view:nth-child(1) {
			color: #999999;
			font-size: 28upx;
			font-weight: 400;
			display: inline-block;
			padding: 30upx 0 30upx 20upx;
			flex: 1;
			& > text {
				color: #333333;
				font-weight: 600;
			}
		}
		& > view:nth-child(2) {
			font-size: 60upx;
			color: #d6e7ff;
			margin-right: 10upx;
		}
	}
	.price-detail {
		margin-top: 20upx;
		margin-bottom: 20upx;
	}
	.detail-price_box {
		color: #333333;
		font-size: 22upx;
		text-align: right;
		flex: 1;
		font-weight: 600;
		&.red {
			color: #ff2842;
		}
	}
}
.app-footer {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	& .admin-button-com {
		padding: 0;
		margin-right: 15upx;
		width: 140upx;
		height: 70upx;
		line-height: 70upx;
		text-align: center;
		color: #3385ff;
		border: 1px solid #3385ff;
		&.active{
			color: #666666;
			border: 1px solid #ccc;
		}
	}
}
</style>