<template>
	<view class="center">
		<view class="head">
			<view class="left">
				<image :src="$globalData.publicUrl + infoData.cPortrait" mode=""></image>
			</view>
			<view class="middle">
				<view class="name">
					{{ infoData.cNickName || infoData.cName }}
				</view>
				<view class="address">
					{{ infoData.address }} {{ infoData.name }}
				</view>
			</view>
			<view class="right" @click="goAddress">
				更换位置
			</view>
		</view>
		<view class="jsdata">
			<view class="num" v-if="money">
				<view class="item">
					<text>余额</text>
					<text class="amount"><span>{{ money.dBalance}}</span>元</text>
				</view>
				<view class="item">
					<text>可提现</text>
					<text class="amount"><span>{{ money.getAmount || 0 }}</span>元</text>
				</view>
				<view class="item">
					<view class="withdraw" @click="goWithdraw">申请提现</view>
				</view>
			</view>
			<u-line margin="20rpx 0" />
			<view class="num">
				<view class="item" @click="toIncome">
					<text>我的收益</text>
					<text class="amount"><span>{{ myIncome.tAmount }}</span>元</text>
				</view>
				<view class="item" @click="toIncome">
					<text>待结算</text>
					<text class="amount"><span>{{ myIncome.wAmount }}</span>元</text>
				</view>
				<view class="item" @click="toIncome">
					<text>已结算</text>
					<text class="amount"><span>{{ myIncome.yAmount }}</span>元</text>
				</view>
				<view class="item" @click="toWithdraw">
					<text>已提现</text>
					<text class="amount"><span>{{ myIncome.gAmount }}</span>元</text>
				</view>
			</view>
		</view>
		<view class="jsdata">
			<view class="num">
				<view class="item">
					<text>本月订单数</text>
					<text class="amount"><span>{{ jsData.orderNum }}</span>单</text>
				</view>
				<view class="item">
					<text>本月在线时长</text>
					<text class="amount"><span>{{ onLine }}</span>时</text>
				</view>
				<view class="item">
					<text>本月营业额</text>
					<text class="amount"><span>{{ jsData.turnover }}</span>元</text>
				</view>
			</view>
		</view>
		<view class="warn">
			<view class="top">
				<view class="work is_work" v-if="isWork">
					<image src="/static/identify/work.png" mode=""></image>
					在线中
				</view>
				<view class="work" v-else>
					<image src="/static/identify/rest.png" mode=""></image>
					休息中
				</view>

				<view class="goWork" @click="onWork">
					{{ isWork ? '下线' : '上线' }}
				</view>
			</view>
			<view class="bottom" @click="onWarning">
				<!-- <image src="/static/other/warn.png" mode=""></image> -->
				报警/求助
			</view>
		</view>
		<view class="other">
			<view class="title">
				其他功能
			</view>
			<view class="fun_box">
				<u-grid :border="false" col="5">
					<u-grid-item>
						<view class="function" @click="goOrder">
							<u-badge absolute :value="orderNum" :offset="[-4, -10]"
								:customStyle="{ zIndex: 1 }"></u-badge>
							<image src="/static/other/icon-order.png" mode=""></image>
							<text>订单</text>
						</view>
					</u-grid-item>
					<u-grid-item>
						<view class="function" @click="goFree">
							<image src="/static/other/icon-set.png" mode=""></image>
							<text>设置免车费</text>
						</view>
					</u-grid-item>
					<u-grid-item>
						<view class="function" @click="goEdit">
							<image src="/static/other/icon-edit.png" mode=""></image>
							<text>编辑资料</text>
						</view>
					</u-grid-item>
					<u-grid-item>
						<view class="function" @click="qrCodeShow">
							<image src="/static/other/icon-code.png" mode=""></image>
							<text>我的分销码</text>
						</view>
					</u-grid-item>
					<u-grid-item>
						<view class="function" @click="qrCodeShow">
							<image src="/static/other/icon-contract.png" mode=""></image>
							<text>合同签订</text>
						</view>
					</u-grid-item>
					<u-grid-item>
						<view class="function" @click="goDiscover">
							<image src="/static/discover/my-dynamic.png" mode=""></image>
							<text>我的动态</text>
						</view>
					</u-grid-item>
				</u-grid>
			</view>
		</view>
		<view class="work"></view>
		<!-- 分销码弹窗 -->
		<view class="qr_code" @click="qrCodeShow" v-if="isQrcodeShow">
			<view class="img_box">
				<view class="logo">
					<image src="/static/other/code_logo.png" mode=""></image>
				</view>
				<view class="title">扫码下单 一键预约</view>
				<image :src="qrCode" mode=""></image>
				<view class="foot">多名技师｜在线接单</view>
			</view>
		</view>
		<!-- 添加银行卡提示弹窗 -->
		<view class="add_blankcard" v-if="isAddBlank">
			<view class="popup">
				<view class="popup_title">
					申请提现
				</view>
				<view class="popup_center">
					您还没有绑定银行卡，<br />
					请先去添加银行卡再进行提现
				</view>
				<view class="btn">
					<view class="cancel" @click="isAddBlank = false">
						取消
					</view>
					<view class="add" @click="addBlank">
						添加银行卡
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="order">
			<view class="tab-box">
				<u-tabs keyName="label" lineColor="#03C8BE" :list="tabList" @change="onTabChange"></u-tabs>
			</view>
			<z-paging ref="paging" :fixed="false"
				:paging-style="{'height': '30vh'}"
				v-model="orderList"
				@query="queryList">

			</z-paging>
		</view> -->


		<!-- 未入驻提示 -->
		<u-popup :show="showModal" mode="center" border-radius="16rpx" :mask-close-able="false">
			<view class="modal-wrap">
				<!-- 标题居中 -->
				<view class="title">提示</view>
				<!-- 正文 -->
				<view class="content">
					请提交入驻资料并由后台人员审核通过后,<br>即可开通操作权限
				</view>
				<!-- 底部双按钮（必显示） -->
				<view class="btn-box">
					<view class="btn left" @click="cancel">我在想想</view>
					<view class="btn right" @click="goEnter">立即入驻</view>
				</view>
			</view>
		</u-popup>
		<!-- <u-modal 
			:show="showModal" 
			title="" 
			content="请提交入驻资料并由后台人员审核通过后,即可开通操作权限" 
			showCancelButton
			confirmColor="#1ecbc3"
			@confirm="onDelete"
			@cancel="isShow = false"
		></u-modal> -->
	</view>
</template>

<script>
import {
	getInfo,
	alertOrder,
	getwxQrCode,
	getWaitOrder,
	getJsLocation,
	getMerchantData,
	netStaffWork,
	getStaffWorkData,
	myIncome
} from '@/api/index';
export default {
	data() {
		return {
			showModal: false, // 控制弹窗显隐
			isWork: false,
			// 二维码
			qrCode: '',
			isQrcodeShow: false,
			money: {},
			jsData: {},
			infoData: {},
			cJsId: '',
			onLine: '',
			orderNum: 0,
			isAddBlank: false,
			active: 0,
			tabList: [
				{
					label: '全部',
					value: 1
				},
				{
					label: '进行中',
					value: 2
				},
				{
					label: '已完成',
					value: 3
				},
				{
					label: '已取消',
					value: 5
				},
				{
					label: '售后',
					value: 6
				}
			],
			orderList: [],
			myIncome: {
				yAmount: '',
				wAmount: '',
				tAmount: '',
				gAmount: ''
			}
		}
	},
	onLoad() {

	},
	onShow() {
		// setTimeout(() => {
		// 	console.log('666')
		// 	this.showModal = true
		// }, 500);
		this.getData()
		this.getWork()
		this.getInfo()
		this.getwxQrCode()
		this.getMyIncome()
	},
	methods: {
		// 我在想想：关闭弹窗
		cancel() {
			console.log('5555')
			this.showModal = false
		},
		// 立即入驻：跳转入驻页
		goEnter() {
			this.showModal = false
			uni.navigateTo({
				url: '/pages/join/applyJoin' // 替换你的入驻页面路径
			})
		},
		getMyIncome() {
			myIncome().then(res => {
				if (res.data.code == 200) {
					this.myIncome = res.data.data
				}
			})
		},
		getData() {
			let params = {
				cOpenId: uni.getStorageSync('wx_copenid')
			}
			getMerchantData(params).then(res => {
				if (res.data.code == 200 && res.data.data) {
					this.cJsId = res.data.data.id
					this.infoData = res.data.data
					if (res.data.data.nStatus2 == '-1') { //未上岗
						this.isWork = false
					} else if (res.data.data.nStatus2 == '0') { //以上
						this.isWork = true
					}
					// 获取待接单数量
					getWaitOrder({ cJsId: this.cJsId }).then(res => {
						this.orderNum = res.data.data
					})
				}
			})
		},
		getInfo() {
			getInfo().then(res => {
				this.money = res.data.data
			})
		},
		getWork() {
			let params = {
				openId: uni.getStorageSync('wx_copenid')
			}
			getStaffWorkData(params).then(res => {
				if (res.data.code === 200) {
					this.jsData = res.data.data
					this.onLine = (this.jsData.onLine / 60).toFixed(2)
				}
			});
		},
		getwxQrCode() {
			getwxQrCode({ openId: uni.getStorageSync('wx_copenid') }).then(res => {
				let TICKET = res.data.ticket
				this.qrCode = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' + TICKET
			})
		},
		// 获取数据
		queryList(pageNo, pageSize) {
			let params = {
				current: pageNo,
				size: pageSize,
				openId: uni.getStorageSync('wx_copenid'),
			}
			// getAddrList(params).then(res => {
			// 	if (res.data.code === 200) {
			// 		this.selected = res.data.data.find(item => item.type == 1)?.id;
			// 		this.$refs.paging.complete(res.data.data);
			// 	} else {
			// 		this.$refs.paging.complete(false);
			// 	}
			// });
		},
		// 添加银行卡
		addBlank() {
			uni.navigateTo({
				url: '/pages/my/add_blank'
			})
			this.isAddBlank = false
		},
		// 更换位置
		goAddress() {
			let str = uni.$u.queryParams({
				id: this.cJsId,
				name: this.infoData.cNickName,
				phone: this.infoData.cPhone
			});
			uni.navigateTo({
				url: `/pages/address/virtual${str}`
			});
		},
		// 报警
		onWarning() {
			alertOrder({ jsId: this.cJsId }).then(res => {
				if (res.data.code == 200) {
					uni.showToast({
						title: '已通知地区负责人',
						icon: 'none'
					})
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
				}
			})
		},
		goWithdraw() {
			if (this.money.getAmount <= 0) {
				uni.showToast({
					title: '暂无可提现金额',
					icon: 'none'
				})
			} else {
				uni.navigateTo({
					url: '/pages/my/withdraw'
				})
			}
		},

		// 跳转收入明细
		toIncome() {
			uni.navigateTo({
				url: '/pages/staff/income'
			})
		},
		// 跳转提现明细
		toWithdraw() {
			uni.navigateTo({
				url: '/pages/staff/withdraw'
			})
		},

		onWork() {
			netStaffWork({
				id: this.cJsId,
				nStatus2: this.isWork ? '-1' : '0'
			}).then(res => {
				if (res.data.code == 200) {
					uni.showToast({
						title: '设置成功',
						icon: 'none'
					})
					this.getData()
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
				}
			})
		},
		qrCodeShow() {
			this.isQrcodeShow = !this.isQrcodeShow
		},
		goDiscover() {
			uni.navigateTo({
				url: '/pages/my/dynamic/index'
			})
		},
		goEdit() {
			uni.navigateTo({
				url: '/pages/my/indent?title=编辑资料'
			})
		},
		goOrder() {
			uni.navigateTo({
				url: '/pages/my/js_order'
			})
		},
		goFree() {
			uni.navigateTo({
				url: '/pages/settings/fare'
			})
		},
		onTabChange(e) {
			console.log(e)
			// this.active = e.index;
		},
	}
}
</script>

<style lang="scss" scoped>
// 弹窗
.modal-wrap {
	width: 620rpx;
	background: #fff;
	border-radius: 16rpx;
	overflow: hidden;
}

.title {
	font-size: 42rpx;
	text-align: center;
	padding: 40rpx 30rpx 20rpx;
	font-weight: 500;
	color: #333;
}

.content {
	font-size: 36rpx;
	color: #333;
	padding: 0 40rpx 40rpx;
	line-height: 1.7;
}

.btn-box {
	display: flex;
	border-top: 1rpx solid #eee;
}

.btn {
	flex: 1;
	height: 90rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 36rpx;
}

.left {
	color: #333;
	border-right: 1rpx solid #eee;
}

.right {
	color: #007aff;
}






.center {
	width: 100vw;
	height: 100vh;
	padding: 30rpx 38rpx;
	background: linear-gradient(152deg, #DCFFF8 0%, #F1FEFF 100%);
}

.head {
	width: 100%;
	display: flex;
	align-items: center;
	background: #FFFFFF;
	box-shadow: 0px 4rpx 12rpx 0px rgba(88, 209, 187, 0.1);
	border-radius: 24rpx;
	padding: 24rpx;

	.left {
		border-radius: 100px;
		overflow: hidden;
		width: 80rpx;
		height: 80rpx;
		margin-right: 32rpx;
		background-color: #ccc;
		// margin-bottom: 20rpx;

		image {
			width: 80rpx;
			height: 80rpx;
		}
	}

	.middle {
		width: 344rpx;
		margin-right: 28rpx;

		.name {
			font-size: 28rpx;
			color: #2F3437;
			line-height: 33rpx;
		}

		.address {
			font-size: 24rpx;
			color: #666666;
			line-height: 32rpx;
			margin-top: 8rpx;
		}
	}

	.right {
		width: 152rpx;
		height: 52rpx;
		background: linear-gradient(135deg, #1AD8CF 0%, #21C8C0 100%);
		border-radius: 98rpx;
		font-size: 26rpx;
		color: #FFFFFF;
		line-height: 52rpx;
		text-align: center;
	}
}

.jsdata {
	width: 100%;
	padding: 24rpx;
	margin-top: 24rpx;
	background: #FFFFFF;
	border-radius: 20rpx;
	box-shadow: 0px 4rpx 12rpx 0px rgba(88, 209, 187, 0.1);

	.num {
		display: flex;
		justify-content: space-between;

		.item {
			width: 33.3%;
			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: center;

			text {
				color: #2F3437;
				font-size: 26rpx;
				display: inline-block;
			}

			.amount {
				font-size: 24rpx;
				color: #5E686E;
				line-height: 30rpx;
				margin-top: 10rpx;

				span {
					font-size: 26rpx;
					color: #03C8BE;
					margin-right: 4rpx;
				}
			}

		}

		.address_title {
			width: 18%;
		}

		.address {
			width: 60%;
			font-size: 30rpx;
		}

		.update_address {
			// width: 25%;
			width: 70px;
			height: 50rpx;
			text-align: center;
			background: linear-gradient(to right, #35c99d, #27aea7);
			border-radius: 10rpx;
			color: #ffffff;
			padding: 10rpx;
		}

		.withdraw {
			width: 80%;
			height: 52rpx;
			color: #fff;
			border-radius: 98rpx;
			text-align: center;
			padding: 0px 10rpx;
			line-height: 52rpx;
			background: linear-gradient(135deg, #FF8B66 0%, #EE5B2D 100%);
		}

	}

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

		.item {
			// flex: 1;
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;

			text {
				margin-top: 5px;
				color: #999;
				font-size: 26rpx;
			}
		}

		.withdraw {
			width: 70px;
			height: 50rpx;
			text-align: center;
			background: linear-gradient(to right, #35c99d, #27aea7);
			border-radius: 10rpx;
			// margin-left: -50px;
			margin-right: -30px;
			padding: 10rpx;
			color: #fff;
		}
	}
}

.warn {
	width: 100%;
	height: auto;
	margin: 10px auto 0px;
	border-radius: 20rpx;
	padding: 26rpx 24rpx;
	background-color: #fff;

	.top {
		width: 100%;
		display: flex;
		justify-content: space-between;
		// margin: 0 auto;
		padding-bottom: 22rpx;
		border-bottom: 1px solid #eeeeee;
		margin-bottom: 20rpx;

		text {
			color: #a6482c;
		}

		.goWork {
			height: 50rpx;
			color: #fff;
			text-align: center;
			line-height: 50rpx;
			flex-shrink: 0;
			padding: 0 32rpx;
			border-radius: 98rpx;
			background: linear-gradient(to right, #35c99d, #27aea7);
		}

		.work {
			display: flex;
			align-items: center;
			font-size: 32rpx;
			color: #999999;
			line-height: 24rpx;

			image {
				width: 44rpx;
				height: 44rpx;
				margin-right: 12rpx;
			}
		}

		.is_work {
			color: #02CEC4;
		}
	}

	.bottom {
		width: 100%;
		height: 72rpx;
		background: #F24F62;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx;

		image {
			width: 50rpx;
			height: 50rpx;
			margin-right: 10rpx;
		}
	}

}

.other {
	width: 100%;
	height: auto;
	margin: 10px auto 0px;
	border-radius: 20rpx;
	padding: 26rpx 24rpx;
	background-color: #fff;

	.title {
		margin-bottom: 24rpx;
		font-size: 28rpx;
		color: #2F3437;
		line-height: 33rpx;
		font-weight: 600;
	}

	.fun_box {
		width: 100%;

		.function {
			font-size: 24rpx;
			color: #2F3437;
			line-height: 28rpx;
			display: flex;
			align-items: center;
			flex-direction: column;
			position: relative;

			image {
				width: 64rpx;
				height: 64rpx;
				margin-bottom: 8rpx;
			}
		}
	}
}

.qr_code {
	width: 100vw;
	height: 100vh;
	// background-color: rgba(0, 0, 0, 0.8);
	background-image: url('/static/other/code_bg.png');
	background-size: cover;
	/* 完全覆盖，可能裁剪 */
	background-position: center;
	/* 图片居中（避免裁剪关键部分） */
	z-index: 999999;
	position: absolute;
	top: 0;
	left: 0;
	display: flex;
	justify-content: center;
	align-items: center;

	.img_box {
		width: 598rpx;
		height: 724rpx;
		background-color: #fff;
		// height: 800rpx;
		border-radius: 16rpx;
		// overflow: hidden;
		position: relative;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 160rpx;

		.logo {
			position: absolute;
			top: 0;
			left: 50%;
			z-index: 99999;
			transform: translate(-50%, -50%);

			image {
				width: 144rpx;
				height: 144rpx;
			}
		}

		image {
			width: 400rpx;
			height: 400rpx;
		}
	}

	.title {
		font-size: 36rpx;
		margin-bottom: 32rpx;
	}

	.foot {
		width: 316rpx;
		height: 48rpx;
		background: #F4F5F7;
		border-radius: 4rpx;
		margin-top: 32rpx;
		font-size: 28rpx;
		color: #788096;
		display: flex;
		justify-content: center;
		align-items: center;
	}
}

.work {
	width: 100%;
}

.add_blankcard {
	width: 100vw;
	height: 100vh;
	z-index: 999999;
	position: absolute;
	top: 0;
	left: 0;
	background: rgba(0, 0, 0, 0.4);
	padding: 0px 60rpx;

	// display: flex;
	// align-items: center;
	.popup {
		width: 630rpx;
		height: 420rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		margin-top: 564rpx;
		display: flex;
		flex-direction: column;

		.popup_title {
			width: 100%;
			height: 92rpx;
			background: #F8EDE6;
			border-radius: 24rpx 24rpx 0px 0px;
			font-size: 32rpx;
			color: #000000;
			font-weight: 700;
			text-align: center;
			line-height: 92rpx;
		}

		.popup_center {
			flex: 1;
			background-color: #fff;
			font-size: 28rpx;
			color: #333333;
			line-height: 39rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			text-align: center;
		}

		.btn {
			height: 116rpx;
			background: #FFFFFF;
			border-radius: 0px 0px 24rpx 24rpx;
			border-top: 2rpx solid #EEEEEE;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.cancel {
				width: 182rpx;
				height: 68rpx;
				border-radius: 106rpx;
				border: 2rpx solid #BBBBBB;
				font-size: 32rpx;
				color: #999999;
				text-align: center;
				line-height: 68rpx;
			}

			.add {
				width: 268rpx;
				height: 68rpx;
				background: linear-gradient(135deg, #FF8B66 0%, #EE5B2D 100%);
				border-radius: 44rpx;
				font-size: 32rpx;
				line-height: 68rpx;
				text-align: center;
				color: #FFFFFF;
			}
		}
	}
}

.order {
	margin-top: 24rpx;
	background: #FFFFFF;
	box-shadow: 0px 4rpx 12rpx 0px rgba(88, 209, 187, 0.1);
	border-radius: 20rpx;

	.tab-box {
		padding: 0 32rpx;
		border-bottom: 2rpx solid #EEEEEE;

		.state {
			// flex: 1;
			padding: 0px;
			text-align: center;
			font-size: 28rpx;
			padding-bottom: 20rpx;
		}

		.active {
			font-size: 30rpx;
			color: #03C8BE;
			border-bottom: 1px solid #03C8BE;

		}
	}
}
</style>
