<template>
	<view class="user-center" :style="winHeight">
		<view class="top">
			<image class="bg-img" src="@/static/image/usercenter_bg.png" mode="aspectFill"></image>
			<view class="userinfo">
				<image class="avatar" src="@/static/image/avatar@3x.png" mode=""></image>
				<view class="nick-block">
					<text class="nick-block--name">{{userBpData.USER_NAME || '--'}}</text>
					<text class="nick-block--no">编号：{{userInfo.code*1}}</text>
				</view>
			</view>
			<view class="amount-card">
				<view class="amount-card--order">
					<text class="amount-card--order_num">{{bpPrice.ORDER_PRICE}}</text>
					<text class="amount-card--order_text">订单金额</text>
				</view>
				<i class="divider"></i>
				<view class="amount-card--order amount-card--bill">
					<text class="amount-card--order_num">{{bpPrice.ZHIPIAO_PRICE}}</text>
					<text class="amount-card--order_text">开票金额</text>
				</view>
			</view>
		</view>
		<view class="middle">
			<view class="entry-block" @click="goPage('purchase-plan')"  v-if='!isChildCustomer'>
				<view class="entry-bill">
					<image class="entry-bill-icon" src="@/static/image/usercenter_purchaseplan@3x.png" mode=""></image>
					<!-- <text class="entry-bill-dot">25</text> -->
				</view>
				<text class="entry-bill-text">销售计划</text>
			</view>
			<view class="entry-block" @click="goPage('my-order')"  v-if='!isChildCustomer'>
				<view class="entry-bill">
					<image class="entry-bill-icon" src="@/static/image/uc_company@3x.png" mode=""></image>
				</view>
				<text class="entry-bill-text">销售订单</text>
			</view>

			<view class="entry-block" @click="goPage('billing-invoice')">
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/usercenter_billinginvoice@3x.png" mode="">
					</image>
				</view>
				<text class="entry-bill-text">账票管理</text>
			</view>
			<view class="entry-block" @click="goPage('ticket-order')"  v-if='!isChildCustomer'>
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/usercenter_ticketorder@3x.png" mode=""></image>
				</view>
				<text class="entry-bill-text">制票通知单</text>
			</view>

			<!-- <view class="entry-block" @click="goPage('produce-order')">
				<view class="entry-bill">
					<image class="entry-bill-icon" src="@/static/image/usercenter_produceorder@3x.png" mode=""></image>
				</view>
				<text class="entry-bill-text">生产计划</text>
			</view>

			<view class="entry-block" @click="goPage('produce-material')">
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/usercenter_producematerial@3x.png" mode="">
					</image>
				</view>
				<text class="entry-bill-text">包材计划</text>
			</view> -->

			<view class="entry-block" @click="goPage('my-purchase')">
				<view class="entry-bill">
					<image class="entry-bill-icon" src="@/static/image/usercenter_mypurchase@3x.png" mode=""></image>
				</view>
				<text class="entry-bill-text">要货单查询</text>
			</view>

			<!-- <view class="entry-block" @click="goPage('market-order')">
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/usercenter_billinginvoice@3x.png" mode="">
					</image>
				</view>
					<text class="dot" v-if="num">{{num}}</text>
					<text class="entry-bill-text">市场秩序</text>
			</view> -->
			<view class="entry-block" @click="goPage('order-trends')"  v-if='!isChildCustomer'>
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/trends.png" mode="">
					</image>
				</view>
				<text class="entry-bill-text">订单动态</text>
			</view>
			<view class="entry-block" @click="goPage('terminal')"  v-if='!isChildCustomer'>
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/terminal.png" mode="">
					</image>
				</view>
				<text class="entry-bill-text">终端</text>
			</view>
			<view class="entry-block" @click="goPage('loan-query')"  v-if='!isChildCustomer'>
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/salesDiscount.png" mode="">
					</image>
				</view>
				<text class="dot" v-if="dhkNum - 0 >0">{{dhkNum}}</text>
				<text class="entry-bill-text">销售折扣</text>
			</view>
			<view class="entry-block" @click="goPage('terminal-list')"  v-if='!isChildCustomer'>
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/terminalIn.png" mode="">
					</image>
				</view>
				<text class="dot" v-if="zdzpNum - 0 >0">{{zdzpNum}}</text>
				<text class="entry-bill-text">直配订单查询</text>
			</view>
			<view class="entry-block" @click="goPage('integral-manage')"  v-if='!isChildCustomer'>
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/uc_company@3x.png" mode="">
					</image>
				</view>
				<text class="entry-bill-text">积分管理</text>
			</view>
			<!-- <view class="entry-block" @click="goPage('brand-recommend')">
				<view class="entry-bill">
					<image class="entry-bill-icon entry-bill-icon_billing"
						src="@/static/image/usercenter_ticketorder@3x.png" mode=""></image>
				</view>
				<text class="entry-bill-text">品牌推荐官</text>
			</view> -->
		</view>
		<view class="bottom">
			<view class="cell-list">
				<!-- <view class="cell-list-block" @click="logOut">
					<image class="icon-address" src="@/static/image/uc_address@3x.png" mode="aspectFit"></image>
					<text class="cell-list-block__title">退出登录</text>
				</view> -->
					<!-- <image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode="aspectFit"></image> -->
				<!-- 	<view class="cell-list-block">
					<image class="icon-address" src="@/static/image/uc_setting@3x.png" mode="aspectFit"></image>
					<text class="cell-list-block__title">设置</text>
					<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode="aspectFit"></image>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		getDhkDbsl
	} from '@/servers/loan.js'
	import {
		apiGetBpPrice
	} from '@/servers/common.js'
	import {
		apiGetMissionList,
	} from '@/servers/breakwords.js'
	import {
		apiLogOut
	} from '@/servers/user.js'
	import {
		getTermianlCountAll
	} from '@/servers/terminal.js'
	export default {
		onLoad() {
			this.winHeight = `height:${this.sysinfo.safeArea.height}px`
		},
		data() {
			return {
				winHeight: '',
				bpPrice: {
					ORDER_PRICE: '--',
					ZHIPIAO_PRICE: '--'
				},
				condition: {
					currentPage: 1,
					pageSize: 100,
					distributer: true,
					userId: '',
					type: 0, // 全部9 代办0 已办2
				},
				agentNum: 0,
				dhkNum: 0,
				zdzpNum: 0
			}
		},
		computed: {
			...mapState(['sysinfo', 'userInfo','userBpData','isChildCustomer']),
			num() {
				return this.agentNum - 0 > 0 ? this.agentNum - 99 > 0 ? '99+' : this.agentNum.toString() : ''
			},
		},
		async created() {
			this.getBpPrice()
		},
		onShow() {
			this.condition.userId = this.userInfo.code
			this.apiGetMissionList()
			this.getUsercenterNum()
		},
		methods: {
			async getTermianlCountAll(){
				let params = {"demandType":"ZDZG","isReview":0,"signDateNotNull":true}
				let res = await getTermianlCountAll(params)
				this.zdzpNum = res.data || 0
				const allDot = Number(this.zdzpNum + this.dhkNum)
				if(allDot - 0 < 1){
					uni.removeTabBarBadge({
						index:3
					})
					return
				}
				uni.setTabBarBadge({
				  index:3,
				  text: allDot.toString()
				})
			},
			async getUsercenterNum(){
				let params = {
					user_bp: this.userInfo.code,
					role: "WLY001",
				}
				let res = await getDhkDbsl(params)
				this.dhkNum = res.dbsl || 0
				this.getTermianlCountAll()
			},
			async apiGetMissionList(){
				const params = {
					...this.condition,
				}
				try{
					const res = await apiGetMissionList(params)
					this.agentNum = res && res.data && res.data.count || 0
					if(res.result === "F"){
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 1500
						});
					}
				}catch(e){
					uni.showToast({
						title: '服务异常',
						icon: 'none',
						duration: 1500
					});
				}
				
			},
			async getBpPrice() {
				const res = await apiGetBpPrice({
					PARTNER: this.userInfo.code
				})
				this.bpPrice = res.DATA
			},
			goPage(page) {
				// if (page === 'terminal') {
				// 	uni.showToast({
				// 		title: '功能开发中...',
				// 		icon: 'none',
				// 		duration: 1500
				// 	});
				// 	return
				// }
				uni.navigateTo({
					url: `/pages/${page}/${page}`
				})
			},
			checkApplyOrder() {
				uni.navigateTo({
					url: "/pages/apply-order/apply-order"
				})
			},
			logOut() {
				apiLogOut().then((res) => {
					uni.setStorageSync('lifeData', {});
					uni.reLaunch({
						url: "/pages/login/login"
					})
				}).catch(() => {
					uni.showToast({
						title: '登出异常',
						icon: 'none',
						duration: 1500
					});
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.user-center {
		flex: 1;
		background: #f8f8f8;
		flex-direction: column;
		font-size: 24rpx;
	}

	.top {
		position: relative;
		height: 400rpx;
		overflow: hidden;
	}

	.bg-img {
		position: absolute;
		left: 0;
		top: 0;
		z-index: 2;
		flex: 1;
		width: 750rpx;
		height: 400rpx;
	}

	.userinfo {
		display: flex;
		position: absolute;
		left: 48rpx;
		bottom: 170rpx;
		z-index: 4;
	}

	.avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
	}

	.nick-block {
		flex-direction: column;
		justify-content: center;
		margin-left: 30rpx;
	}

	.nick-block--name {
		font-size: 32rpx;
		color: $text-base-color;
		font-weight: 500;
		margin-bottom: 12rpx;
		width: 440rpx;
	}

	.nick-block--no {
		width: 280rpx;
		height: 40rpx;
		line-height: 40rpx;
		font-size: 24rpx;
		background: #fff;
		border-radius: 20rpx;
		color: #555555;
		padding: 0 16rpx;
	}

	.amount-card {
		display: flex;
		align-items: center;
		position: absolute;
		left: 32rpx;
		right: 32rpx;
		bottom: 0;
		z-index: 4;
		height: 130rpx;
		background: linear-gradient(270deg, #2e2c2d, #5b5759);
		border-radius: 24rpx 24rpx 0 0;
	}

	.amount-card--order {
		flex: 1;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.amount-card--order_num {
		font-size: 36rpx;
		font-family: PingFangSC, PingFangSC-Medium;
		font-weight: 500;
		color: #fde5e1;
	}

	.amount-card--order_text {
		color: #fde5e1;
		font-size: 24rpx;
	}

	.divider {
		width: 1px;
		height: 27px;
		opacity: 0.34;
		border: 1px solid #fde5e1;
	}

	.middle {
		display: flex;
		flex-direction: row;
		background-color: #fff;
		padding: 50rpx 48rpx 0;
		flex-wrap: wrap;
	}

	.entry-block {
		width: 160rpx;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-bottom: 48rpx;
	}

	.entry-block-tail {}

	.entry-bill {
		position: relative;
	}

	.entry-bill-icon {
		width: 48rpx;
		height: 48rpx;
		margin-bottom: 20rpx;
	}

	.entry-bill-icon_billing {
		width: 38rpx;
		height: 42rpx;
	}

	.entry-bill-dot {
		position: relative;
		z-index: 2;
		width: 44rpx;
		height: 36rpx;
		line-height: 36rpx;
		text-align: center;
		color: #ffffff;
		background: $wly-primary-color;
		border-radius: 9px;
		font-size: 24rpx;
		margin-left: -20rpx;
		margin-top: -10rpx;
	}

	.entry-bill-text {
		font-size: 28rpx;
		color: $text-base-color;
	}

	.bottom {
		margin-top: 24rpx;
	}

	.cell-list {
		flex-direction: column;
	}

	.cell-list-block {
		width: 750rpx;
		height: 100rpx;
		padding: 0 32rpx;
		margin-bottom: 4rpx;
		background-color: #fff;
		align-items: center;
	}

	.icon-address {
		width: 32rpx;
		height: 32rpx;
		margin-right: 8rpx;
	}

	.cell-list-block__title {
		color: #333;
		font-size: 28rpx;
		flex: 1;
		align-items: center;
	}

	.icon-arrow {
		width: 18rpx;
		height: 32rpx;
	}
	::v-deep  .uni-badge{
		position: relative;
	}
	.dot {
		top:0;
		width: 36rpx;
		height: 36rpx;
		line-height: 36rpx;
		background: #ff0f00;
		border-radius: 18rpx;
		color: #fff;
		font-size: 22rpx;
		margin-right: -76rpx;
		text-align: center;
		position: absolute;
	}
</style>
