<template>
	<view>
		<view class="box">
			<view class="top">
				<text class="title">业务订单</text>
			</view>
		</view>
<!-- 		<u-sticky offset-top="0">
			<u-tabs :list="tabs" @change="change" :current="current" :is-scroll="false"></u-tabs>
		</u-sticky> -->
		<view class="card-box">
			<view class="card" v-for="(businessItem,index) in businessItemList" :key="index">
				<view class="t">
					<image class="icon" src="../../static/home-icon-01.png"></image>
					<text class="title">{{businessItem.customerName}}</text>
				</view>
				<view style="line-height: 60rpx;">
					<view class="title">录入时间：{{businessItem.createTime}}</view>
					<view class="title">订单号：{{businessItem.no}}</view>
				</view>

				<view class="c">
					<view class="item car-num-item">
						<text class="car-num">{{businessItem.cardNo}}</text>
					</view>

					<view class="item">
						<text class="p1">车型:</text>
						<text class="p2">{{businessItem.cardSize}}(米)</text>
					</view>
					<view class="item">
						<text class="p1">载重:</text>
						<text class="p2">{{businessItem.netWeight}}(吨)</text>
					</view>
					<view class="item">
						<text class="p1">车辆状态:</text>
						<text class="p2">
							<text v-if="businessItem.realInTime==null">未入场</text>
							<text v-if="businessItem.realInTime!=null">已入场</text>
							<text v-if="businessItem.outDayTime!=null">已离场</text>
						</text>
					</view>
					<view class="item">
						<text class="p1">账单确认:</text>
						<text class="p2">
							<text v-if="businessItem.confirmInput==0">未确认</text>
							<text v-else>已确认</text>
						</text>
					</view>
					<view class="item">
						<text class="p1">支付状态:</text>
						<text class="p2">
							<text v-if="businessItem.payStatus==1">未支付</text>
							<text v-if="businessItem.payStatus==2">已支付(未确认)</text>
							<text v-if="businessItem.payStatus==3">已支付(已确认)</text>
						</text>
					</view>
				</view>
				<view class="b">
					<view class="btn b3" v-if="businessItem.confirmInput==0
								&&businessItem.payStatus==1
								&&businessItem.outDayTime!=null
								&&perList.indexOf('tb-business-confirm')!=-1
								&&customemrId!='1'" @click="sureZdFn(businessItem)">
						确认账单</view>
					<view class="btn b3" v-if="perList.indexOf('tb-business-pay')!=-1
								&&businessItem.payStatus==1&&businessItem.confirmInput==1&&customemrId!='1'" @click="fkFn(businessItem)">
						马上支付</view>
						<view class="btn b3" v-if="perList.indexOf('tb-business-pay')!=-1&&
									customemrId=='1'&&businessItem.payStatus<3&&businessItem.outDayTime!=null" @click="fkFn(businessItem)">
							确认支付</view>
					<view class="btn b1" v-if="customemrId=='1'&&businessItem.realInTime==null"
						@click="rcFn(businessItem)">确认入场</view>
					<view class="btn b1" v-if="customemrId=='1'&&businessItem.outDayTime==null&&businessItem.realInTime!=null" @click="cc(businessItem)">确认出场</view>
					<view class="btn b1" v-if="customemrId=='1'
							&&businessItem.confirmInput==0
							&&businessItem.realInTime==null
							&&businessItem.outDayTime==null" @click="editFn(businessItem)">修改</view>
					<view class="btn b3" @click="toDetail(businessItem)">详情</view>
					<view class="btn b4" v-if="businessItem.payStatus==1
								&&businessItem.confirmInput==0
								&&businessItem.realInTime==null
								&&businessItem.outDayTime==null
								&&perList.indexOf('tb-business-add')!=-1" @click="deleteFn(businessItem)">删除</view>
				</view>
			</view>
		</view>
			<noData v-if="businessItemList.length==0"></noData>
		<u-loadmore style="margin: 30rpx;" :status="status" />
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				p: {
					pageNo: 1,
					pageSize: 3,
					dataCount: 0
				},
				customemrId: '1',
				fk: {
					ids: '',
				},
				rc: {
					id: '',
					inChannel: '',
					showTime: false,
					visible: false,
					realInTime: ''
				},
				current: 0,
				status: 'loadmore',
				page: 0,
				tabs: [{
					name: '进场',
				}, {
					name: '出场',
				}],
				businessItemList: [],
				perList:[]
			}
		},
		created() {
			this.customemrId = uni.getStorageSync('customerId')
			this.perList=uni.getStorageSync('perList')
		},
		onShow() {
			this.getBusinessList();
		},
		methods: {
			toDetail(data){
				this.$common.to('/pages/business-entering/business-detail?id='+data.id)
			},
			editFn(data){
				this.$common.to('/pages/business-entering/business-edit?id='+data.id)
			},
			deleteFn(data){
				let that=this;
			 uni.showModal({
			 	title:"警告",
				content:"是否删除该业务？",
				success(res) {
					if(res.confirm){
						that.$api.deleteBusiness({id:data.id}).then(resp=>{
							that.$common.toast('已删除');
							that.getBusinessList();
						})
					}
				}
			 })	
			},
			sureZdFn(data){
				this.$common.to('/pages/business-order/sureOrder?id='+data.id)
			},
			fkFn(data) {
				this.$common.to('/pages/business-order/surePay?id='+data.id)
			},
			rcFn(data) {
				this.$common.to('/pages/business-order/sureIn?id='+data.id)
			},
			cc(data) {
			this.$common.to('/pages/business-order/sureOut?id='+data.id)
			},
			getBusinessList() {
				this.$api.getBusinessList(this.p).then(resp => {
					this.status = 'loadmore';
					this.p.pageNo = resp.pageNo;
					this.p.pageSize = resp.pageSize;
					this.p.dataCount = resp.dataCount;
					this.businessItemList = resp.data;
				})
			},
			//点击上方切换栏，根据点击项重新加载数据
			change(index) {
				this.current = index;
				if (index == 0) {
					//只加载进场订单
				}
				if (index == 1) {
					//只加载出场订单
				}
			},
			//点击按钮
			//------------------------------------------
			
			fkconfirm() {
				this.$api.adminConfirmPay(this.fk).then(resp => {
					this.$refs.fkpopup.close();
					this.getBusinessList();
				})
			},
		
			rcconfirm() {
				if (!this.rc.inChannel) {
					this.$common.toast('请填写入场通道');
					return false;
				}
				this.$api.adminConfirmIn(this.rc).then(resp => {
					this.$refs.rcpopup.close();
					this.getBusinessList();
				})
			},
		
			ccconfirm(index) {
				console.log('出场')
				this.$refs.ccpopup.close()
			},
			zd() {
				this.$refs.zdpopup.open('center')
			},
			zdconfirm(index) {
				this.$refs.zdpopup.close()
			},
			//------------------------------------------
			//上拉加载更多，分页模拟数据
			onReachBottom() {
				if (parseInt(this.p.dataCount) > parseInt(this.p.pageSize) * parseInt(this.p.pageNo)) {
					this.status = 'loading';
					this.p.pageSize += 5;
					this.getBusinessList();
				} else {
					this.status = 'nomore';
				}
			}
		}
	}
</script>

<style lang="scss">
	.card-box {
		display: flex;
		width: 100%;
		flex-direction: column;

		.card {
			background-color: #fff;
			border-radius: 20rpx;
			margin: 20rpx 20rpx 0 20rpx;
			padding: 30rpx;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;

			.t {
				width: 100%;
				display: flex;
				align-items: center;
				padding-bottom: 30rpx;
				border-bottom: 1rpx solid #f5f5f5;

				.icon {
					width: 40rpx;
					height: 40rpx;
				}

				.title {
					font-size: 30rpx;
					font-weight: bold;
					margin-left: 20rpx;
				}
			}

			.c {
				padding: 15rpx 0 30rpx 0;
				display: flex;
				flex-wrap: wrap;
				border-bottom: 1rpx solid #f5f5f5;

				.item {
					width: 50%;
					padding: 20rpx 0;

					.car-num {
						background-color: #edf6ff;
						color: #0080ff;
						font-size: 44rpx;
						padding: 15rpx 0;
						text-align: center;
						width: 100%;
						border-radius: 10rpx;
						font-weight: bold;
						letter-spacing: 20rpx;
					}

					.p1 {
						font-size: 28rpx;
						color: #999;
					}

					.p2 {
						font-size: 28rpx;
						color: #191919;
						font-weight: bold;
						margin-left: 20rpx;
					}
				}

				.car-num-item {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}

			.b {
				display: flex;
				width: 100%;
				align-items: center;
				justify-content: space-between;

				.btn {
					height: 70rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					width: calc(50% - 15rpx);
					margin: 30rpx 0 0 0;
					border-radius: 10rpx;
					border-width: 1rpx;
					box-sizing: border-box;
				}

				.b1 {
					background-color: #0080ff;
					color: #fff;
				}

				.b2 {
					background-color: #f7f7f7;
					color: #191919;
				}

				.b3 {
					background-color: #fff;
					color: #0080ff;
					border: 1rpx solid #0080ff;
				}
				.b4 {
					background-color: #ff0000;
					color: #fff;
				}
			}
		}
	}

	@import '@/common/common.scss'
</style>
