<template>
	<view>
		<!--promote/team/team.wxml-->
		<view class="top">
			<view class="topc">
				<view class="info">
					<view class="userlogo">
						<image :src="info.avatar" mode="aspectFit" class="photo"></image>
					</view>
					<view class="infos">
						<view>{{info.nickName}}</view>
						<text v-if="info.state==1">审核中</text>
						<block v-if="info.state==2">
							<text v-if="user.pid == 0">手机号 {{user.mobile}}</text>
							<text v-else>推荐人 {{user.pname?user.pname:user.pid}}</text>
						</block>
					</view>
					<navigator url="/promote/invite/invite" hover-class="none" open-type="navigate" class="copy">
						<image src="../static/promote/images/ma.png"></image>
						我要推广
					</navigator>
					<!-- 	  <view class="thmbtn" @tap="showCode">
	  	<image src="/static/pages/images/ewmico.png"></image>
	  </view> -->
				</view>
				<view class="shouyi">
					<view class="money">
						<view class="dflex qian">
							<view class="qians" @click="jumpUrl('/promote/withdrawal/income/income')">{{info.total?info.total:'0.00'}}<text>元</text></view>
							<text class="tixian" @tap="gotixian">立即提现</text>
						</view>
						<view class="dflex titleSet" @click="jumpUrl('/promote/withdrawal/income/income')">
							<view class="ye-text dflex">
								<image src="../static/promote/images/fxico1.png"></image>累计收益
							</view>
						</view>
					</view>
					<view class="m-datas ddflex">
						<view class="li" @click="jumpUrl('/promote/settleDetail/settleDetail?tabIndex=' + 1 + '&timeIndex=' + 0 + '&state=1')">
							<view><text>￥</text>{{info.wjMoney?info.wjMoney:'0.00'}}</view>待结算
						</view>
						<view class="li" @click="jumpUrl('/promote/settleDetail/settleDetail?tabIndex=' + 1 + '&timeIndex=' + 0 + '&state=2')">
							<view><text>￥</text>{{info.balance?info.balance:'0.00'}}</view>可提现
						</view>
						<view class="li" @click="jumpUrl('/promote/withdrawal/record/record')">
							<view><text>￥</text>{{info.cumulative?info.cumulative:'0.00'}}</view>累计提现
						</view>
						<!-- <view class="li">
							<view><text>￥</text>{{info.todayTotal? info.todayTotal : '0'}}</view>今日收益
						</view> -->
						<!-- <view class="li">
							<view><text>￥</text>{{total ? total : '0'}}</view>推广业绩
						</view> -->
					</view>
				</view>
				<!-- <view class="shouyi">
					<view class="money">
						<view class="dflex qian">
							<view class="qians">{{info.balance? info.balance : '0'}}<text>元</text></view>
							<text class="tixian" @tap="gotixian">立即提现</text>
						</view>
						<view class="dflex titleSet">
							<view class="ye-text dflex">
								账户余额
							</view>
						</view>

					</view>
					<view class="status">
						<view class="li dflex">
							<view class="ye-text dflex">
								待结算：{{info.wjMoney? info.wjMoney : '0'}}<text>元</text>
							</view>
							<view class="title" v-if="distr.commissionSettleTimE">
								<image src="../static/promote/images/tip.png" class="tip" @tap="titleShow"></image>
								<view class="hint" v-if="hint">
									<view>
										订单签收确认后，待结算将自动转入账户余额
									</view>
								</view>
							</view>
						</view>
						<view class="li">
							<view class="ye-text dflex">
								累计收益：{{total ? total : '0'}}<text>元</text>
							</view>
						</view>
					</view>
				</view> -->
			</view>
		</view>
		<view class="myteam bgfff">
			<!-- <navigator :url="'/promote/teamList/teamList?tab=0&IS_secondary_members=' + IS_secondary_members" hover-class="none" class="titr"> -->
			<view class="titr">
				<view class="tit dflex">
					<view class="flex">我的业绩</view>
					<!-- <text>查看详情</text>
					<image src="/static/pages/images/more.png" class="rico"></image> -->
				</view>
			</view>
			<!-- </navigator> -->
			<view class="data dflex">
				<navigator :url="'/promote/teamList/teamList?tab=0&IS_secondary_members=' + IS_secondary_members" hover-class="none" class="li">
					<view>{{count.total ? count.total : '0'}}</view>所有客户
				</navigator>
				<navigator url="/promote/sales/sales" hover-class="none" class="li">
					<view><text>￥</text>{{info.salesVolume  ? info.salesVolume  : '0.00'}}</view>销售额
				</navigator>
				<navigator url="/promote/sales/sales" hover-class="none" class="li">
					<view>{{info.orderCount ? info.orderCount : '0'}}</view>成交订单
				</navigator>
				<navigator :url="'/promote/settleDetail/settleDetail?timeIndex=' + 5 + '&state=2'" hover-class="none" class="li">
					<view><text>￥</text>{{info.monthTotal  ? info.monthTotal  : '0.00'}}</view>本月收入
				</navigator>
				<!-- <block v-if="IS_secondary_members!=1">
					<navigator :url="'/promote/teamList/teamList?tab=0&IS_secondary_members=' + IS_secondary_members"
						hover-class="none" class="li"><text>{{count.total ? count.total : '0'}}</text>所有客户
					</navigator>
					<navigator url="/promote/teamList/teamList?tab=2" hover-class="none" class="li">
						<text>{{count.monthTotal ? count.monthTotal : '0'}}</text>本月新增
					</navigator>
				</block>
				<block v-else>
					<navigator :url="'/promote/teamList/teamList?tab=0&IS_secondary_members=' + IS_secondary_members"
						hover-class="none" class="li"><text>{{count.total ? count.total : '0'}}</text>一级成员
					</navigator>
					<navigator
						:url="'/promote/teamList/teamList?tab=1&IS_secondary_members=' + IS_secondary_members + '&isDirect=' + false"
						hover-class="none" class="li">
						<text>{{count.monthTotal ? count.monthTotal : '0'}}</text>二级成员
					</navigator>
				</block> -->

			</view>
		</view>
		<view class="mine-nav">
			<!-- <view class='li' @tap="isshop!=0?goshop():applyshop()" v-if="distr.distributionSmallShopOpen==1">
				<image src="../static/promote/images/fxico9.png" class="mineico"></image>
				<text>我的小店</text>
				<image src="/static/pages/images/more.png" class="rico"></image>
			</view> -->
			<navigator url="/promote/products/products" class="li" hover-class="none">
				<image src="../static/promote/images/fxico4.png" class="mineico"></image>
				<text>分销商品</text>
				<image src="/static/pages/images/more.png" class="rico"></image>
			</navigator>
			<navigator url="/promote/invite/invite" class="li" hover-class="none">
				<image src="../static/promote/images/fxico5.png" class="mineico"></image>
				<text>推广二维码海报</text>
				<image src="/static/pages/images/more.png" class="rico"></image>
			</navigator>
			<!-- <navigator url="/promote/balance/balance" class="li" hover-class="none">
				<image src="../static/promote/images/fxico6.png" class="mineico"></image>
				<text>业绩订单</text>
				<image src="/static/pages/images/more.png" class="rico"></image>
			</navigator> -->
			<navigator url="/promote/service/service" class="li" hover-class="none" v-if="user.listShopBase.length>0">
				<image src="../static/promote/images/fxico8.png" class="mineico"></image>
				<text>小店服务费</text>
				<image src="/static/pages/images/more.png" class="rico"></image>
			</navigator>
			<!-- <navigator url="/promote/withdrawal/record/record" class="li" hover-class="none">
				<image src="../static/promote/images/fxico7.png" class="mineico"></image>
				<text>提现记录</text>
				<image src="/static/pages/images/more.png" class="rico"></image>
			</navigator> -->

		</view>
	</view>
</template>

<script>
	// promote/team/team.js
	const app = getApp();
	const req = require("../../utils/request.js");

	export default {
		data() {
			return {
				isshow: 0,
				IS_secondary_members: 0,
				count: "",
				user: {},
				distr: "",
				condition: "",
				hint: false,
				info: {}
			};
		},

		components: {},
		props: {},

		onLoad() {
			this.isshop()
		},

		onShow() {
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: req.public.titleTopBgColor
			});
			this.getuser();

			if (JSON.parse(req.getStorage('configRes')).IS_secondary_members) {
				let IS_secondary_members = JSON.parse(req.getStorage('configRes')).IS_secondary_members;
				this.setData({
					IS_secondary_members: IS_secondary_members
				});
			}
		},
		onHide() {
			this.hint = false
		},

		methods: {
			getData() {
				req.getRequest('/api/distribution/info?v=1.2', {}, data => {
					// data.info.nickName = req.excludeSpecial(data.info.nickName);
					this.info = data;
					// this.setData(data);
					// console.log(this, "yyyyyyyyyyyyyy", data);
				});
			},
			titleShow() {
				this.hint = !this.hint
			},

			getCount() {
				req.getRequest('/api/distribution/partner/count', {}, data => {
					this.setData({
						count: data
					});
				});
			},
			// Promise.all([this.getuser])
			//获取用户个人中心的信息
			getuser() {
				req.getRequest('/api/user/info', {}, res => {
					this.setData({
						user: res
					});
					// console.log(this, "qqqq", res);
					// if (req.getStorage('distribution')) {
					//   let dist = req.getStorage('distribution');
					//   this.setData({
					//     distr: dist
					//   });
					//   console.log(dist);

					//   if (dist.distributionApply == 0) {
					//     this.apply();
					//   } else {
					//     this.getData();
					//     this.getCount();
					//   }

					//   let user = this.user;
					//   let arr = [];

					//   if (dist.distributionNeedParam.indexOf('1') != -1) {
					//     if (user.nickName = '') {
					//       arr.push("姓名");
					//     }
					//   }

					//   if (dist.distributionNeedParam.indexOf('2') != -1) {
					//     console.log(user.mobile);

					//     if (user.mobile == null) {
					//       arr.push("电话");
					//     }
					//   }

					//   if (dist.distributionNeedParam.indexOf('3') != -1) {
					//     if (user.cardNo == null) {
					//       arr.push("身份证号码");
					//     }
					//   }

					//   if (dist.distributionNeedParam.indexOf('5') != -1) {
					//     console.log(res.birthday);

					//     if (user.birthday == null) {
					//       arr.push("生日");
					//     }
					//   }

					//   if (dist.distributionNeedParam.indexOf('6') != -1) {
					//     if (user.gender == '') {
					//       arr.push("性别");
					//     }
					//   }

					//   this.setData({
					//     condition: arr
					//   });

					//   if (arr.length > 0) {
					//     this.getshow();
					//   }
					// } else {

					req.postRequest('/api/distribution/config', {}, res => {
						this.setData({
							distr: res
						});

						if (res.distributionApply == 0 && this.user.isDistriUser == 0) {
							this.apply();
						} else {
							this.getData();
							this.getCount();
						}

						let user = this.user;
						let arr = [];

						if (res.distributionNeedParam.indexOf('1') != -1) {
							if (user.nickName = '') {
								arr.push("姓名");
							}
						}

						if (res.distributionNeedParam.indexOf('2') != -1) {
							// console.log(user.mobile);

							if (user.mobile == null) {
								arr.push("电话");
							}
						}

						if (res.distributionNeedParam.indexOf('3') != -1) {
							if (user.cardNo == null) {
								arr.push("身份证号码");
							}
						}

						if (res.distributionNeedParam.indexOf('5') != -1) {
							// console.log(user.birthday);

							if (user.birthday == null) {
								arr.push("生日");
							}
						}

						if (res.distributionNeedParam.indexOf('6') != -1) {
							if (user.gender == '') {
								arr.push("性别");
							}
						}

						this.setData({
							condition: arr
						});

						if (arr.length > 0) {
							this.getshow();
						}
					});
					// }
				});
			},

			//对话框
			getshow() {
				uni.showModal({
					title: '提示',
					content: '请您先完善必要的信息：' + this.condition,
					confirmText: '去完善',

					success(res) {
						if (res.confirm) {
							uni.redirectTo({
								url: "/mine/userinfo/userinfo"
							});
						} else if (res.cancel) {
							uni.switchTab({
								url: "/pages/user/user"
							});
						}
					}

				});
			},

			gotixian() {
				uni.navigateTo({
					url: '/promote/withdrawal/index/index'
				});
			},

			apply() {
				// console.log(this.distr);
				req.postRequest('/api/distribution/applymap', {
					distributionApply: this.distr.distributionApply
				}, data => {
					// console.log(data);
					this.getData();
					this.getCount();
				});
			},
			// 去小店
			goshop() {
				wx.navigateTo({
					url: '/mine/shop/shop?shopId=' + this.user.listShopBase[0].id+'&merchantId='+this.user.listShopBase[0].merchant_id
				})
			},
			// 申请小店
			applyshop() {
				req.postRequest('/api/shopBase/save', {}, data => {
					req.msg("申请成功，等待管理员同意")
					this.isshop()
				})
			},
			// 是否已经拥有小店
			isshop() {
				req.postRequest('/api/shopBase/isOpenShop', {}, data => {
					this.setData({
						isshop: data
					})
					console.log(data)
				})
			},
			jumpUrl(url){
				uni.navigateTo({
					url: url
				})
			}


		}
	};
</script>
<style>
	@import "./team.css";
</style>
