<template>
	<view class="content">
		<view class="navbar">
			<view v-for="(item, index) in navlist" :key="index" class="nav-item"
				:class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.title }}</view>
		</view>
		<swiper :current="tabCurrentIndex" :style="{ height: height }" class="swiper-box" duration="300" disable-touch>
			<swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navlist" :key="tabIndex">
				<scroll-view scroll-y="true" class="list-scroll-content" @scrolltolower="loadData" :style="{ height: height }">
					<!-- 空白页 -->
					<u-empty text="暂无数据" mode="list" v-if="tabItem.loaded && tabItem.list.length == 0"></u-empty>

					<!-- 订单列表 -->
					<view class="dd-wrap" v-for="yyitem in tabItem.list" @click="goPage('/pagesS/order/orderinfo?id=' + yyitem.id)">
						<view class="dd-id-status">
							<view class="dd-stata">
								{{yyitem.status == 1 ?'已完成': '待服务'}}
							</view>
							<view class="dd-id">
								{{yyitem.order_id}}
							</view>
							<view class="dd-status">
								已预约
							</view>
						</view>
						<view class="dd-info" style="margin-top: 20rpx;">
							客户名称<text>{{yyitem.customer | showname}}</text>
						</view>
						<view class="dd-info">
							下单时间<text>{{$utils.formatDate(yyitem.createTime)}}</text>
						</view>
						<view class="dd-info">
							预约时间<text class="chs" style="color:#FF5600;">{{$utils.formatDate(yyitem.time)}}</text>
						</view>
						<view class="dd-btm">
							<view class="btm-price">
								订单金额： <text>￥{{yyitem.to_price}}</text>
							</view>
							<!-- <view class="btm-btn btm-btn-lx" @click.stop="goCall(yyitem.customer_mobile)">
								联系客户
							</view> -->
							<view class="btm-btn btm-btn-sm" @click.stop="wcdd(yyitem)" v-if="yyitem.status == 0">
								完成订单
							</view>
						</view>
						<!-- <view class="add-dd" @click.stop="goPage('/pagesS/order/addorder?id=' + yyitem.id)" v-if="yyitem.status == 0">
							<image src="../../static/img/add-dd.png" mode=""></image>
							<view class="">
								添加项目
							</view>
						</view> -->
					</view>
					<u-loadmore :status="tabItem.loadingType" />
				</scroll-view>
			</swiper-item>
		</swiper>
		<u-modal :show-cancel-button="true" confirm-color="#3b73de" v-model="modal_show" :content="content"
			@confirm="confirmEdit" @cancel="cancelEdit"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				modal_show: false,
				content: '确认订单已完成？',
				height: '',
				tabCurrentIndex: 0,
				navlist: [{
						status: '',
						title: '全部',
						list: [],
						page: 1,
						pageSize: 10,
						loaded: false,
						loadingType: 'loadmore'
					},
					{
						status: 2,
						title: '待服务',
						list: [],
						page: 1,
						pageSize: 10,
						loaded: false,
						loadingType: 'loadmore'
					},
					{
						status: 3,
						title: '已完成',
						list: [],
						page: 1,
						pageSize: 10,
						loaded: false,
						loadingType: 'loadmore'
					}
				],
				wcid: '',
			}
		},
		onLoad(opt) {

		},
		onShow() {
			this.loadData()
		},
		onReachBottom() {

		},
		onReady() {
			var _this = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.swiper-box').boundingClientRect();
					query.exec(function(res) {
						_this.height = resu.windowHeight - res[0].top + 'px';
						console.log('打印页面的剩余高度', _this.height);
					});
				},
				fail: res => {}
			});
		},
		filters: {
			showname(val) {
				
				function maskString(inputString) {
				  const length = inputString.length;
				  const visiblePart = length > 4 ? inputString.slice(-4) : inputString;
				  const maskedPart = "*".repeat(length - visiblePart.length);
				  
				  return maskedPart + visiblePart;
				}
				const originalString = val + '';
				const maskedString = maskString(originalString);
				return maskedString
				// console.log(maskedString); // 输出：******7890
		
			}
		},
		methods: {
			goCall(phone) {
				uni.makePhoneCall({
					phoneNumber:phone+''
				})
			},
			wcdd(item) {
				this.wcid = item.id
				this.modal_show = true
			},
			confirmEdit(e) {
				// console.log(e,'确认')
				this.$u.api.completeYy({
					id: this.wcid
				}).then(({data})=> {
					this.$u.toast('订单完成');
					this.loadData('reload')
				})
			},
			cancelEdit(e) {
				// console.log(e,'失败')
				this.wcid = ''
			},
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
				this.loadData('tab')
			},
			// 获取数据
			loadData(type) {
				let that = this
				let index = that.tabCurrentIndex
				let item = that.navlist[index]
				if (type == 'reload') {
					item.loaded = false
					item.loadingType = 'more'
					item.page = 1
					item.list = []
				}
				if (type == 'tab' && item.loaded) {
					return
				}
				if (item.loadingType == 'loading' || item.loadingType == 'nomore') {
					return
				}

				item.loadingType = 'loading'
				that.$u.api.getYgYyList({
					page: item.page, //分页页码，数字类型
					pageSize: item.pageSize,
					name: "", //搜索条件
					type: item.status
				}).then(({
					data
				}) => {
					item.list = item.list.concat(data)
					item.page++
					if(item.pageSize == data.length) {
						item.loadingType = 'loadmore'
					}else {
						item.loadingType = 'nomore'
					}
					item.loaded = true
				})

			},
		}
	}
</script>

<style lang="scss">
	.navbar {
		display: flex;
		height: 88rpx;
		padding: 0 5px;
		background: #fff;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
		position: relative;
		z-index: 10;

		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 15px;
			color: #999999;
			position: relative;

			&.current {
				color: #000;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid #4076d6;
				}
			}
		}
	}

	.dd-wrap {
		margin: auto;
		width: 713rpx;
		height: 314rpx;
		border-radius: 20rpx;
		background-color: #fff;
		padding-top: 35rpx;
		position: relative;
		margin-bottom: 27rpx;

		.dd-id-status {
			height: 40rpx;
			display: flex;
			align-items: center;
			width: 100%;
			font-size: 24rpx;
			padding: 0 23rpx 0 43rpx;

			.dd-stata {
				flex-shrink: 0;
				width: 123rpx;
				height: 39rpx;
				background: #FF5600;
				border-radius: 5rpx;
				text-align: center;
				line-height: 39rpx;

				font-weight: 400;
				color: #FFFFFF;
			}

			.dd-id {
				margin-left: 15rpx;
				flex-grow: 1;
				color: #1e395a;

			}

			.dd-status {
				flex-shrink: 0;
				font-weight: 400;
				color: #FCA930;
			}
		}

		.dd-info {
			font-size: 28rpx;
			font-weight: 500;
			color: #A0A0A0;
			padding-left: 42rpx;

			text {
				padding-left: 32rpx;
				font-size: 26rpx;
				font-weight: 500;
				color: #173456;
			}

		}

		.dd-btm {
			position: absolute;
			bottom: 0;
			height: 90rpx;
			width: 713rpx;
			background: linear-gradient(to right, #fbf5eb, #ffffff);
			border-radius: 0 0 20rpx 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 20rpx 0 42rpx;

			.btm-price {
				font-size: 26rpx;
				color: #56687f;
				flex-grow: 1;
				text {
					color: #ff1e00;
				}
			}

			.btm-btn {
				width: 126rpx;
				height: 48rpx;
				line-height: 48rpx;
				background: #ebccae;
				border-radius: 10rpx;
				font-size: 24rpx;
				font-weight: 400;
				text-align: center;
			}
			.btm-btn-sm {
		
				background: #4D74CF;
				margin-left: 10rpx;
				color: #fff;
			}
			.btm-btn-lx {
				background-color: #fff;
				border: 1px solid #65676A;
				color: #56585C;
			}

		}

		.add-dd {
			position: absolute;
			bottom: 90rpx;
			right: 20rpx;
			width: 110rpx;
			height: 100rpx;
			font-size: 24rpx;
			font-weight: 500;
			color: #FF5600;
			text-align: center;

			image {
				display: block;
				margin: auto;
				width: 36rpx;
				height: 45rpx;
			}

		}
	}
</style>
