<template>
	<view class="pages-mine" v-if="isLoad">
		<!-- #ifndef H5 -->
		<uni-nav-bar :fixed="true" :shadow="false" :statusBar="true"
			:title="userPageType == 2?'我是'+$t('action.attendantName'):'我的'" color="#ffffff"
			:backgroundColor="primaryColor">
		</uni-nav-bar>
		<view :style="{height:`${configInfo.navBarHeight}px`}"></view>
		<!-- #endif -->
		<image mode="aspectFill" lazy-load class="mine-bg abs" :src="configInfo[image_type[userPageType]]"></image>

		<!-- 用户 -->
		<!-- coach_status 1申请中，2已通过，3已取消授权，4已拒绝 -->
		<block v-if="userPageType == 1">
			<view class="pd-lg" style="height: 212rpx">
				<view class="pt-lg rel"
					:class="[{ 'flex-warp':userInfo && userInfo.nickName }, { 'flex-center': !userInfo || (userInfo && !userInfo.nickName) } ]">
					<auth :needAuth="true" :must="true" :haveGo="false" class="avatar_view" style="width:120rpx">
						<view class="avatar_view">
							<image mode="aspectFill" class="avatar radius"
								:src="userInfo.avatarUrl || `/static/mine/default_user.png`">
							</image>
							<view class="text" :style="{color:primaryColor}"
								v-if="userInfo.id && mineInfo.is_admin == 1">
								代理商
							</view>
						</view>
					</auth>
					<auth :needAuth="true" :must="true" :haveGo="false" class="flex-1"
						v-if="!userInfo || (userInfo && !userInfo.nickName)">
						<view class="f-md-title text-bold ml-md" :style="{color:configInfo[font_type[userPageType]]}">
							立即登录
						</view>
					</auth>
					<view class="flex-1 ml-md mt-sm rel" :style="{color:configInfo[font_type[userPageType]]}" v-else>
						<view class="flex-between">
							<auth :needAuth="true" :must="true" :haveGo="false">
								<view class="flex-y-center f-title text-bold">
									<view class="mr-sm max-300 ellipsis">
										{{ userInfo.nickName || '默认用户' }}
									</view>
								</view>
							</auth>
							<view @tap.stop="$util.goUrl({url:`/user/pages/setting`})" class="notice-item ml-md">
								<i class="iconfont icon-xitong text-bold"></i>
							</view>
						</view>
						<view class="flex-center">
							<view class="member-tag flex-center mt-sm pl-md pr-md f-caption radius ">
								<i class="iconfont iconhuiyuanka mr-sm"></i>
								{{ mineInfo.coach_status === 2 ?  mineInfo.coach_level && mineInfo.coach_level.length > 0 && mineInfo.coach_level.title ? mineInfo.coach_level.title : $t('action.attendantName') : '普通用户' }}
							</view>
							<view class="flex-1"></view>
						</view>
					</view>
				</view>
			</view>

			<!-- 我的余额 -->
			<auth :needAuth="userInfo && (!userInfo.phone || !userInfo.nickName)" :must="true"
				:type="!userInfo.phone ? 'phone' : 'userInfo'" @go="$util.toCheckLogin({url:`/user/pages/stored/list`})"
				v-if="configInfo.recharge_status">
				<view class="space-ht mine-menu-list pd-lg radius-16 rel">
					<image mode="aspectFill" class="vip-img" src="/static/mine/balance.png"></image>
					<view class="flex-warp rel">
						<image mode="aspectFill" class="flex-center vip" src="/static/mine/vip.png"></image>
						<view class="flex-center f-title c-vip ml-sm">尊享VIP会员</view>
					</view>
					<view class="flex-between mt-sm rel">
						<view>
							<view class="f-icontext c-vip">账户余额</view>
							<view class="f-sm-title c-vip">￥{{ mineInfo.balance || '0.00' }}</view>
						</view>
						<view
							style="background-color: rgb(243, 204, 161); width: 72px; height: 26px; border-radius: 13px; position: relative;">
							<view class="flex-center vip-base f-icontext">立即充值</view>
							<image mode="aspectFill" class="flex-center vip-fx" src="/static/mine/fx.png"></image>
						</view>
					</view>
				</view>
			</auth>

			<!-- 我的卡券/我的收藏 -->
			<view class="share-list flex-between mt-md">
				<view @tap.stop="$util.toCheckLogin({ url: `/user/pages/collect` })"
					class="flex-between ml-lg mr-sm pt-lg pb-lg pl-lg pr-sm fill-base f-caption c-desc box-shadow radius-16"
					style="width: 50%">
					<view class="share-list flex-between" style="width: 32%">
						<view class="item-icon rel flex-center">
							<image mode="aspectFill" class="flex-center column-img" src="/static/mine/guanzhu.png">
							</image>
						</view>
					</view>
					<view class="flex-column ml-lg" style="width: 100%">
						<view class="f-title">我的收藏</view>
						<view class="f-desc mb-sm" :style="{ color: primaryColor }">{{ mineInfo.collect_count || 0 }}
							<span class="c-grey">人</span>
						</view>
					</view>
				</view>
				<view @tap.stop="$util.toCheckLogin({ url: `/user/pages/coupon/list` })"
					class="flex-between ml-sm mr-lg pt-lg pb-lg pl-lg pr-sm fill-base f-caption c-desc box-shadow radius-16"
					style="width: 50%">
					<view class="share-list flex-between" style="width: 32%">
						<view class="item-icon rel flex-center">
							<image mode="aspectFill" class="flex-center column-img" src="/static/mine/youhui.png">
							</image>
						</view>
					</view>
					<view class="flex-column ml-lg" style="width: 100%">
						<view class="f-title">我的优惠劵</view>
						<view class="f-desc mb-sm" :style="{ color: primaryColor }">{{ mineInfo.coupon_count || 0 }}
							<span class="c-grey">张</span>
						</view>
					</view>
				</view>
			</view>

			<!-- <auth :needAuth="userInfo && (!userInfo.phone || !userInfo.nickName)" :must="true"
				:type="!userInfo.phone ? 'phone' : 'userInfo'" @go="toAtv" style="width: 100%"
				v-if="mineInfo.is_atv_status === 1">
				<view style="height: 14rpx;"></view>
				<image mode="aspectFill" class="share-atv-img" src="/static/mine/coupon.png"></image>
			</auth> -->

			<view class="mine-menu-list box-shadow fill-base radius-16">
				<view class="menu-title flex-between pl-lg pr-md b-1px-b">
					<view class="f-st-title c-title text-bold">常用工具</view>
				</view>
				<view class="flex-warp pb-sm pt-lg pb-lg" v-if="toolLoad">
					<block v-for="(item, index) in toolList" :key="index">
						<!-- #ifdef MP-WEIXIN -->
						<button style="width: 25%;margin:10rpx 0 20rpx 0"
							:open-type="configInfo.im_type == 2 ?'contact':''"
							class="item-child flex-center flex-column f-caption c-title clear-btn"
							v-if="item.text == '联系客服' && configInfo.im_type == 2">
							<image mode="aspectFill" class="mine-img radius" src="/static/mine/lianxikefu.png"></image>
							<view class="mt-sm">{{ item.text }}</view>
						</button>
						<block v-else>
							<view class="item-child flex-center flex-column f-caption c-title">
								<auth :needAuth="userInfo && (!userInfo.phone || !userInfo.nickName)" :must="true"
									:type="!userInfo.phone ? 'phone' : 'userInfo'" @go="toJump('toolList', index)">
									<image mode="aspectFill" class="mine-img" :src="item.cover" v-if="item.cover">
									</image>
									<view class="mt-sm">{{ item.text }}</view>
								</auth>
							</view>
						</block>
						<!-- #endif -->
						<!-- #ifndef MP-WEIXIN -->
						<view @tap.stop="toJump('toolList', index)"
							class="item-child flex-center flex-column f-caption c-title"
							style="width: 25%;margin:10rpx 0 20rpx 0">
							<image mode="aspectFill" class="mine-img" :src="item.cover" v-if="item.cover"></image>
							<view class="mt-sm">{{ item.text }}</view>
						</view>
						<!-- #endif -->
					</block>
					<view @tap.stop="$util.goUrl({url:`/agent/pages/index?agent=0`})"
						class="item-child flex-center flex-column f-caption c-title"
						style="width: 25%;margin:10rpx 0 20rpx 0" v-if="mineInfo.mobilenode_auth">
						<image mode="aspectFill" class="mine-img radius" src="/static/mine/guanli.png"></image>
						<view class="mt-sm">切换管理员</view>
					</view>
					<view v-if="infoInitData.is_show == 1" style="width: 25%;margin:10rpx 0 20rpx 0" class="item-child flex-center flex-column f-caption c-title">
						<view @tap.stop="toChange" class="item-child flex-center flex-column f-caption c-title"
						style="width: 100%;"
						v-if="mineInfo.coach_status == 2 || mineInfo.coach_status == 3">
						<image mode="aspectFill" class="mine-img radius" src="/static/mine/qiehuan.png"></image>
						<view class="mt-sm">切换{{$t('action.attendantName')}}端</view>
					</view>
						</view>
				
				</view>
			</view>
		</block>
		<!-- 技-师 -->
		<block v-if="userPageType == 2">
			<view class="addr-time-help-list flex-x-center f-desc rel"
				:style="{color:configInfo[font_type[userPageType]]}">
				<view @tap.stop="toChooseLocation()" class="flex-center flex-column">
					<i class="iconfont iconweizhigengxin1"></i>
					<view>位置更新</view>
				</view>
				<view @tap.stop="$util.goUrl({url:`/technician/pages/time-manage`})" class="flex-center flex-column">
					<i class="iconfont icon-shijian"></i>
					<view>时间管理</view>
				</view>
				<view @tap.stop="toHelp" class="flex-center flex-column">
					<i class="iconfont iconyijianbaojing"></i>
					<view>一键报警</view>
				</view>
			</view>

			<view class="coach-info fill-base ml-lg mr-lg pt-lg pl-lg pr-lg pb-sm radius-16 rel" v-if="coachInfo.id">
				<view class="flex-center pb-lg">
					<!-- #ifdef H5 -->
					<view class="avatar radius">
						<view @tap.stop="toPreviewImage(index,1)" class="h5-image avatar radius"
							:style="{ backgroundImage : `url('${coachInfo.work_img}')`}">
						</view>
					</view>
					<!-- #endif -->
					<!-- #ifndef H5 -->
					<image mode="aspectFill" class="avatar radius" :src="coachInfo.work_img"></image>
					<!-- #endif -->
					<view class="flex-1 ml-md">
						<view class="flex-between">
							<view class="coach-name text-bold max-300 ellipsis">{{coachInfo.coach_name}}</view>
							<view @tap.stop="toEditInfo" class="coach-text f-paragraph flex-y-center">个人信息<i
									class="iconfont icon-right"></i>
							</view>
						</view>
						<view class="flex-warp mt-sm">
							<view class="tag-item flex-center mr-sm"
								:style="{color:primaryColor,border:`1rpx solid ${primaryColor}`}"
								v-if="coachInfo.auth_status==2">
								已认证</view>
							<view class="tag-item flex-center mr-sm"
								:style="{color:coachInfo.is_work?primaryColor:'#5A677E',border:`1rpx solid ${coachInfo.is_work?primaryColor:`#5A677E`}`}"
								v-if="mineInfo.coach_status === 2">
								{{coachInfo.is_work ? textType[coachInfo.text_type] : '请假中'}}
							</view>
							<view class="tag-item flex-center"
								:style="{color:primaryColor,border:`1rpx solid ${primaryColor}`}">
								{{coachInfo.coach_level.title}}
							</view>
						</view>
						<view class="flex-between mt-sm" v-if="coachInfo.auth_status!=2">
							<view class="f-desc">
								{{coachInfo.auth_status==0?'补充剩余资料才可以上线接单哟':coachInfo.auth_status==1?'认证审核中':'认证已驳回'}}
							</view>
							<view>
								<view @tap.stop="toEditInfo" class="tag-item flex-center"
									:style="{color:primaryColor,border:`1rpx solid ${primaryColor}`}"
									v-if="!coachInfo.fdd_auth_status || (coachInfo.fdd_auth_status && coachInfo.fdd_status != 2)">
									去认证</view>
							</view>
						</view>
					</view>
				</view>
				<view class="map-addr-info pt-lg b-1px-t">
					<view class="flex-center">
						<view class="map-addr flex-center rel">
							<view class="map-addr radius abs" :style="{background:primaryColor}"></view>
							<view class="flex-y-center f-desc" :style="{color:primaryColor}">
								<i class="iconfont icondangqianweizhi"></i>
								当前
							</view>
						</view>
						<view class="flex-1 text ml-md ellipsis">
							{{coachInfo.address}}
						</view>
					</view>
					<view class="location-change flex-between pt-sm">
						<view class="text f-paragraph">实时定位</view>
						<i @tap.stop="toChangeLocation" class="iconfont"
							:class="[{'icon-switch':!userInfo.coach_position},{'icon-switch-on':userInfo.coach_position}]"
							:style="{color:userInfo.coach_position?primaryColor:'#ddd'}"></i>
					</view>
				</view>
			</view>

			<view class="mine-count-list flex-between mt-md rel">
				<view class="cancel-auth iconfont icon-biaoqian c-caption flex-center abs"
					v-if="mineInfo.coach_status == 3">
					<view class="text-bold f-icontext abs">取消授权</view>
				</view>

				<view @tap.stop="$util.goUrl({ url: `/technician/pages/income/index`})"
					class="item-child ml-lg mr-sm fill-base f-caption box-shadow radius-16">
					<view class="flex-y-baseline" :style="{color:primaryColor}">¥<view class="f-sm-title">
							{{coachInfo.service_price || 0}}
						</view>
					</view>
					<view class="flex-between mt-sm">
						<view class="text f-paragraph">服务收入</view>
						<view class="cash-btn flex-center f-desc c-base radius"
							:style="{background: `linear-gradient(68deg, ${primaryColor}, ${subColor})`}">去提现
						</view>
					</view>
				</view>
				<view @tap.stop="$util.goUrl({ url: `/user/pages/cash-out?type=carfee` })"
					class="item-child ml-sm mr-lg pt-lg pb-lg pl-md pr-sm fill-base f-caption c-desc box-shadow radius-16 ">
					<view class="flex-y-baseline" :style="{color:primaryColor}">¥<view class="f-sm-title">
							{{coachInfo.car_price || 0}}
						</view>
					</view>
					<view class="flex-between mt-sm">
						<view class="text f-paragraph">车费</view>
						<view class="cash-btn flex-center f-desc c-base radius"
							:style="{background: `linear-gradient(68deg, ${primaryColor}, ${subColor})`}">
							去提现</view>
					</view>
				</view>
			</view>

			<view class="mine-menu-list box-shadow fill-base radius-16">
				<view class="menu-title flex-between pl-lg pr-sm">
					<view class="f-paragraph c-title text-bold">我的订单</view>
				</view>
				<view class="flex-warp pb-lg">
					<view @tap.stop="toJump('orderList2', index)"
						class="item-child flex-center flex-column f-caption c-title" v-for="(item, index) in orderList2"
						:key="index">
						<view class="item-img rel flex-center radius">
							<view class="abs dot-unread-number flex-center"
								:style="{width: item.number>99 ? '44rpx': item.number > 9 ? '34rpx' :'',right: item.number>99 ? '-32rpx': item.number > 9 ? '-22rpx' :'-12rpx'}"
								v-if="item.number > 0">
								{{item.number < 100 ? item.number : '99+'}}
							</view>
							<view class="item-img radius abs" :style="{background:primaryColor}"></view>
							<i class="iconfont c-title" :class="item.icon" :style="{color:primaryColor}"></i>
						</view>
						<view class="mt-sm">{{ item.text }}</view>
					</view>
				</view>
			</view>

			<view class="mine-menu-list box-shadow fill-base radius-16">
				<view class="menu-title flex-between pl-lg pr-sm">
					<view class="f-paragraph c-title text-bold">其他功能</view>
				</view>
				<view class="flex-warp pb-sm">
					<view @tap.stop="toJump('toolList2', index)"
						class="item-child flex-center flex-column f-caption c-title rel" style="margin:10rpx 0 20rpx 0"
						v-for="(item, index) in toolList2" :key="index">
						<image mode="aspectFill" class="mine-img" :src="item.cover" v-if="item.cover"></image>
						<view class="mt-sm">{{ item.text }}</view>
						<view class="fdd-sign flex-center c-base abs radius"
							v-if="item.text =='电签合同' && coachInfo.fdd_status != 2">
							待签约</view>
					</view>
				</view>
			</view>
		</block>

		<view class="space-footer"></view>
		<view :style="{height: `${configInfo.tabbarHeight}px`}"></view>
		<tabbar :cur="5"></tabbar>

		<!-- #ifdef APP-PLUS -->
		<login-info></login-info>
		<!-- #endif -->
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	import tabbar from "@/components/tabbar.vue"
	export default {
		components: {
			tabbar
		},
		data() {
			return {
				isLoad: false,
				toolLoad: false,
				options: {},
				textType: {
					1: '可服务',
					2: '服务中',
					3: '可预约',
					4: '不可预约'
				},
				is_share: true,
				// 我的订单
				orderList: [],
				orderList2: [{
					icon: 'icon-kdd2',
					text: '待接单',
					url: '/technician/pages/order/list',
					number: 0
				}, {
					icon: 'iconyijiedan',
					text: '待服务',
					url: '/technician/pages/order/list?tab=1',
					number: 0
				}, {
					icon: 'icon-kll',
					text: '服务中',
					url: '/technician/pages/order/list?tab=2',
					number: 0
				}],
				commissionList: [],
				// 其他
				toolList: [{
					cover: '/static/mine/dizhiguanli.png',
					text: '地址管理',
					url: '/user/pages/address/list'
				}, {
					cover: '/static/mine/yijianfank.png',
					text: '问题反馈',
					url: '/user/pages/feedback/box'
				}, {
					cover: '/static/mine/pingjia.png',
					text: '我的评价',
					url: '/pages/order?tab=4'
				}, {
					cover: '/static/mine/tuikuan.png',
					text: '退款售后',
					url: '/user/pages/refund/list'
				}, {
					cover: '/static/mine/tel.png',
					text: '联系客服',
					url: ''
				}],
				toolList2: [{
						cover: '/static/mine/dengji.png',
						text: '等级管理',
						url: '/technician/pages/level'
					},
					// {
					// 	cover: '/static/mine/Wallet.png',
					// 	text: '储值返佣明细',
					// 	url: '/technician/pages/income/cash-integral',
					// 	number: 0
					// },
					// {
					// 	cover: '/static/mine/fencheng.png',
					// 	text: '分成明细',
					// 	url: '/technician/pages/income/commission-list',
					// 	number: 0
					// },
					{
						cover: '/static/mine/cfmx.png',
						text: '车费明细',
						url: '/technician/pages/car-fare'
					},
					{
						cover: '/static/mine/cftx.png',
						text: '车费提现记录',
						url: '/user/pages/distribution/record?type=3'
					},
					{
						cover: '/static/mine/shop.png',
						text: '物料商城',
						url: '/technician/pages/shop/list'
					},
					{
						cover: '/static/mine/shens.png',
						text: '差评申诉',
						url: '/technician/pages/bad-comments/box'
					},
					{
						cover: '/static/mine/pingbi.png',
						text: '屏蔽用户',
						url: '/technician/pages/shield'
					},
					{
						cover: '/static/mine/setTime2.png',
						text: '出行配置',
						url: '/technician/pages/time-set',
					},
					{
						cover: '/static/mine/qiehuan.png',
						text: '切换用户端',
						url: 'change'
					}
				],
				image_type: {
					1: 'user_image',
					2: 'coach_image' 
				},
				font_type: {
					1: 'user_font_color',
					2: 'coach_font_color'
				},
				showAuth: false,
				offsetL: 360,
				offsetT: 0,
				infoInitData:{
					is_show:0
				}
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			configInfo: state => state.config.configInfo,
			commonOptions: state => state.user.commonOptions,
			userInfo: state => state.user.userInfo,
			userPageType: state => state.user.userPageType,
			locationChange: state => state.user.locationChange,
			location: state => state.user.location,
			mineInfo: state => state.user.mineInfo,
			coachInfo: state => state.user.coachInfo,
		}),
		onLoad(options) {
			this.options = options
			let {
				type = 1
			} = options
			if (type) {
				this.updateUserItem({
					key: 'userPageType',
					val: type
				})
			}
			let {
				id: mine_id = -1
			} = this.mineInfo
			if (mine_id == -1) {
				this.$util.showLoading()
			}
			this.initIndex();
			this.initInfoList()
		},
		async onShow() {
			if (this.userPageType == 2) {
				await Promise.all([this.getCoachInfo(), this.getOrderNumCall()])
			}
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh();
			uni.stopPullDownRefresh()
		},
		methods: {
			...mapActions(['getConfigInfo', 'getUserInfo', 'getMineInfo', 'getCoachInfo',
				'updateCommonOptions',
			]),
			...mapMutations(['updateUserItem']),
			async initIndex(refresh = false) {
				// #ifdef H5
				if (!refresh && this.$jweixin.isWechat()) {
					await this.$jweixin.initJssdk();
					this.$jweixin.wxReady(() => {
						this.$jweixin.hideOptionMenu()
					})
				}
				// #endif 
				if (!this.configInfo.id || refresh || (this.configInfo.id && !this.configInfo.hasOwnProperty(
						'recharge_status'))) {
					await this.getConfigInfo()
				}
				await this.getMineInfo()
				this.isLoad = true

				let {
					fx_check,
					plugAuth = {}
				} = this.configInfo
				let {
					coach_status,
					is_admin = 0,
					is_fx = 0
				} = this.mineInfo

				if (coach_status == 2 || coach_status == 3) {
					await this.getCoachInfo()
				}
				this.updateUserItem({
					key: 'userPageType',
					val: coach_status == 2 || coach_status == 3 ? this.userPageType : 1
				})

				// 
				let arr = ['coach_status', 'salesman_status']
				let applyText = '申请' + this.$t('action.attendantName')
				let textArr = {
					coach_status: {
						text: applyText,
						list: {
							cover: '/static/mine/jishizhaopin.png',
							text: applyText,
							url: '/user/pages/apply'
						}
					},
					channel_status: {
						text: '申请渠道商',
						list: {
							cover: '/static/mine/qudao.png',
							text: '申请渠道商',
							url: '/user/pages/channel/apply'
						},
						list2: {
							cover: '/static/mine/qudao.png',
							text: '我是渠道商',
							url: '/user/pages/channel/income'
						}
					},
					salesman_status: {
						text: '申请业务员',
						list: {
							cover: '/static/mine/yewu.png',
							text: '申请业务员',
							url: '/user/pages/salesman/apply'
						},
						list2: {
							cover: '/static/mine/yewu.png',
							text: '我是业务员',
							url: '/user/pages/salesman/income'
						}
					}
				}
				arr.map(item => {
					if (this.mineInfo[item] != 2) {
						let arr = this.toolList.filter(aitem => {
							return aitem.text === textArr[item].text
						})
						if (arr.length === 0 && (item != 'salesman_status' || (item == 'salesman_status' &&
								this.mineInfo[item] != -1))) {
							this.toolList.unshift(textArr[item].list)
						}
						if (item !== 'coach_status') {
							let aindex = this.toolList.findIndex(aitem => {
								return aitem.text === textArr[item].list2.text
							})
							if (aindex != -1) {
								this.toolList.splice(aindex, 1)
							}
						}
					} else {
						this.toolList.map((aitem, aindex) => {
							if (aitem.text === textArr[item].text) {
								this.toolList.splice(aindex, 1)
							}
						})
						if (item !== 'coach_status') {
							let arr = this.toolList.filter(aitem => {
								return aitem.text === textArr[item].list2.text
							})
							if (arr.length === 0) {
								this.toolList.unshift(textArr[item].list2)
							}
						}
					}
				})

				// let agentInd = this.toolList.findIndex(item => {
				// 	return item.text == '我是代理商' || item.text == '招商加盟'
				// })

				// if (agentInd == -1) {
				// 	this.toolList.unshift({
				// 		cover: '/static/mine/Add.png',
				// 		text: is_admin ? '我是代理商' : '招商加盟',
				// 		url: is_admin ? `/agent/pages/index?agent=1` : `/agent/pages/apply`
				// 	})
				// }

				// if (agentInd !== -1) {
				// 	this.toolList[agentInd] = {
				// 		cover: '/static/mine/Add.png',
				// 		text: is_admin ? '我是代理商' : '招商加盟',
				// 		url: is_admin ? `/agent/pages/index?agent=1` : `/agent/pages/apply`
				// 	}
				// }

				let fxInd = this.toolList.findIndex(item => {
					return item.text == '申请分销商' || item.text == '分销商管理'
				})

				if (fxInd != -1) {
					this.toolList.splice(fxInd, 1)
				}
				this.toolList.unshift({
					cover: '/static/mine/fenxiao.png',
					text: is_fx ? '分销商管理' : '申请分销商',
					url: is_fx ? '/user/pages/distribution/income' : '/user/pages/distribution/apply'
				})

				if (this.userPageType == 2) {
					this.getOrderNumCall()
				}

				let {
					dynamic = false
				} = plugAuth

				if (dynamic) {
					let dynamicInd = this.toolList2.findIndex(item => {
						return item.text == '动态发布'
					})
					if (plugAuth.dynamic && dynamicInd == -1) {
						let badInd = this.toolList2.findIndex(item => {
							return item.text == '差评申诉'
						})
						// this.toolList2.splice(badInd + 1, 0, {
						// 	cover: '/static/mine/jishizhaopin.png',
						// 	text: '动态发布',
						// 	url: '/dynamic/pages/technician/list'
						// })
					}
				}
				let {
					fdd_auth_status
				} = this.coachInfo

				// console.log(12321312, this.coachInfo)
				// console.log(12321312, fddInd)

				let fddInd = this.toolList2.findIndex(item => {
					return item.text == '电签合同'
				})
				if (fdd_auth_status && fddInd == -1) {
					this.toolList2.unshift({
						cover: '/static/mine/hetong.png',
						text: '电签合同',
						url: ''
					})
				}
				// this.toolList2.unshift({
				// 	cover: '/static/mine/hetong.png',
				// 	text: '电签合同',
				// 	url: ''
				// })

				if (!fdd_auth_status && fddInd !== -1) {
					this.toolList2.splice(fddInd, 1)
				}
				this.toolLoad = true
				this.$util.hideAll()
			},
			initRefresh() {
				this.initIndex(true)
			},
			async getOrderNumCall() {
				let data = await this.$api.technician.getOrderNum()
				this.orderList2[0].number = data.wait //待接单
				this.orderList2[1].number = data.start //待服务
				this.orderList2[2].number = data.progress //服务中
			},
			async  initInfoList(){
				
			
				
		          let res  = await this.$api.mine.isShowwx()
			    
		         this.infoInitData = res
					
				
			
			},
			// 选择地区
			async toChooseLocation() {
				let {
					coach_status
				} = this.mineInfo
				if (coach_status != 2) return
				await this.$util.checkAuth({
					type: 'userLocation'
				})
				let {
					lat: locaLat = '',
					lng: locaLng = ''
				} = this.coachInfo
				let param = {}
				// #ifndef MP-WEIXIN
				param = {
					latitude: locaLat,
					longitude: locaLng
				}
				// #endif
				let [, {
					address = '',
					longitude,
					latitude
				}] = await uni.chooseLocation(param);
				if (!address) return
				await this.coachUpdate(latitude,longitude,address);
				this.$util.showToast({
					title: `更新成功`
				})
			},
			async coachUpdate(latitude,longitude,address){
				
				await this.$api.technician.coachUpdate({
					address,
					lng: longitude,
					lat: latitude
				})
				let data = this.$util.deepCopy(this.coachInfo)
				data.address = address
				this.updateUserItem({
					key: 'coachInfo',
					val: data
				})
				this.updateUserItem({
					key: 'locationChange',
					val: true
				})
			},
			// 实时定位
			async toChangeLocation() {
				let {
					coach_status
				} = this.mineInfo
				if (coach_status != 2) return
				let {
					coach_position = 0
				} = this.userInfo
				let cur = coach_position == 0 ? 1 : 0
				await this.$api.technician.coachUpdate({
					coach_position: cur
				})
				await this.getUserInfo()
				this.$util.showToast({
					title: `操作成功`
				})
				this.updateUserItem({
					key: 'locationChange',
					val: cur == 1
				})
			},
			toJump(key, index) {
				let {
					url,
					text
				} = this[key][index]
				let applyText = '申请' + this.$t('action.attendantName')
				if ([applyText, '申请分销合伙人', '申请渠道商', '申请业务员'].includes(text)) {
					this.toApply(text == applyText ? 1 : text == '申请分销合伙人' ? 2 : text == '申请渠道商' ? 3 : 4)
					return
				}
				if (text == '切换用户端') {
					this.toChange()
					return
				}
				if (text == '联系客服') {
					let {
						mobile: url,
						im_type
					} = this.configInfo
					// #ifdef MP-WEIXIN
					if (im_type == 2) return
					// #endif
					this.$util.goUrl({
						url,
						openType: 'call'

					})
					return
				}
				if (text == '电签合同') {
					this.toFddSign()
					return
				}
				let openType = key == 'orderList' && index !== 4 ? `reLaunch` : 'navigateTo'
				this.$util.log(url)
				this.$util.toCheckLogin({
					url,
					openType
				})
			},
			toEditInfo() {
				let {
					status,
					fdd_auth_status,
					fdd_status
				} = this.coachInfo
				if (status == 2 && fdd_auth_status && fdd_status != 2) {
					this.$util.showToast({
						title: `请先签订合同哦`
					})
					return
				}
				this.$util.goUrl({
					url: `/technician/pages/edit`
				})
			},
			async toFddSign() {
				this.updateUserItem({
					key: 'fddExtsign',
					val: ''
				})
				let {
					status: coach_status,
					admin_id = 0,
					fdd_agreement = {}
				} = this.coachInfo

				let {
					viewpdf_url = ''
				} = fdd_agreement && fdd_agreement.hasOwnProperty('viewpdf_url') ? fdd_agreement : {
					viewpdf_url: ''
				}
				if (!viewpdf_url) {
					if (coach_status == 3) {
						this.$util.showToast({
							title: `平台管理员已取消授权，不能签约哦`
						})
						return
					}

					let fddRecord = await this.$api.technician.getFddRecord();
					if (!fddRecord) {
						this.updateUserItem({
							key: 'authUrl',
							val: ''
						})
						// let {
						// 	status,
						// 	authUrl
						// } = await this.$api.technician.getAttestationInfo()
						const resaa = await this.$api.technician.getAttestationInfo()
						console.log(resaa);
						// console.log(personVerifyUrl)
						this.updateUserItem({
							key: 'authUrl',
							// val: resaa.actorSignTaskEmbedUrl
							// val: 'https://80000501.uat-e.fadada.com/signtask/preview?signTaskId=1702006200189165140&redirectUrl='
							val: resaa.data.fdd_link
						})
						// personVerifyUrl
						window.location.href = resaa.data.fdd_link
						return

						if (status < 2) {
							let personVerifyUrl = await this.$api.technician.getPersonVerifyUrl()
							console.log(personVerifyUrl)
							this.updateUserItem({
								key: 'authUrl',
								val: authUrl
							})
							// personVerifyUrl
							this.$util.goUrl({
								url: `/user/pages/common/web?url=authUrl`
							})
							return
						} else {
							// let Extsign = await this.$api.technician.Extsign({
							// 	admin_id
							// })
							// viewpdf_url = Extsign
							this.$util.goUrl({
								url: `/technician/pages/edit`
							})
						}
					}
				}
				this.updateUserItem({
					key: 'fddExtsign',
					val: viewpdf_url
				})
				this.$util.goUrl({
					url: `/user/pages/common/web?url=fddExtsign`
				})
			},
			async toAtv() {
				if (!this.mineInfo.is_atv) {
					this.$util.showToast({
						title: `暂无活动`
					})
					return
				}
				let options = this.commonOptions
				options.coupon_atv_id = 0
				await this.updateCommonOptions(options)
				this.$util.toCheckLogin({
					url: `/user/pages/coupon/share`
				})
			},
			// 申请技-师/分销合伙人/渠道商/业务员
			async toApply(type) {
				let {
					coach_status = -1,
						fx_status = -1,
						channel_status = -1,
						salesman_status = -1,
				} = this.mineInfo

				let statusArr = {
					1: coach_status,
					2: fx_status,
					3: channel_status,
					4: salesman_status
				}
				let status = statusArr[type]
				let page = {
					1: `/technician/pages/apply`,
					2: `/user/pages/distribution/apply`,
					3: `/user/pages/channel/apply`,
					4: `/user/pages/salesman/apply`
				}
				// -1未申请，1审核中，2审核通过，3取消授权，4审核失败
				let url = status == -1 ? page[type] :
					`/user/pages/apply-result?type=${type}`
				this.$util.log(url)
				this.$util.toCheckLogin({
					url
				})
			},
			onShareAppMessage(e) {
				let {
					id: pid = 0
				} = this.userInfo
				let path = `/pages/service?pid=${pid}`
				this.$util.log(path)
				return {
					title: '',
					imageUrl: '',
					path,
				}
			},
			// 切换用户/技-师端
			async toChange() {
				uni.pageScrollTo({
					duration: 500,
					scrollTop: 0
				})
				let {
					userPageType = 1
				} = this
				
				// if(userPageType == 1){
				// 	console.log(userPageType)
				// 	// 调起其他小程序页面
				// 	uni.navigateToMiniProgram({
				// 	    appId: 'wx38591f38ef87f0ce', // 目标小程序的appid
				// 	    path: '/pages/service', // 打开的页面路径，需要包含完整路径（不能为空）
				// 	    // extraData: {
				// 	    //     foo: 'bar' // 额外参数，可选项
				// 	    // },
				// 	    success(res) {
				// 	        console.log('成功跳转到其他小程序');
				// 	    }
				// 	});
				// 	return
				// }
				await this.getCoachInfo()
				// console.log('userPageType',userPageType)
				if (userPageType == 1) {
					this.getOrderNumCall()
					this.syncLocal()
				}
				this.updateUserItem({
					key: 'userPageType',
					val: userPageType == 2 ? 1 : 2
				})
			},
			onChange(e) {
				let {
					x,
					y
				} = e.detail
				this.$nextTick(() => {
					this.offsetL = x
					this.offsetT = y
				})
			},
			// 自动同步位置
			async syncLocal() {
				// #ifdef H5
				if (this.$jweixin.isWechat()) {
					// this.$util.showLoading()
					await this.$jweixin.wxReady2();
					let {
						latitude: lat = 0,
						longitude: lng = 0
					} = await this.$jweixin.getWxLocation()
					if (!lat) {
						this.$util.hideAll()
						this.$util.showToast({
							title: `请授权定位当前地址`
						})
						return
					}
					if (lat && lng) {
						let key = `${lat},${lng}`
						let data = await this.$api.base.getMapInfo({
							location: key
						})
						let {
							status,
							result
						} = JSON.parse(data)
						if (status == 0) {
							this.$util.hideAll()
							let {
								address
							} = result
							await this.coachUpdate(lat,lng,address);
						}
					}
				}
				// #endif
				// #ifndef H5
				// this.$util.showLoading()
				let {
					lat = '',
						lng = '',
						address = ''
				} = await this.$util.getBmapLocation()
				if (!lat) {
					this.$util.hideAll()
					this.$util.showToast({
						title: `请授权定位当前地址`
					})
					return
				}
				await this.coachUpdate(lat,lng,address);
				// #endif
			},
			// 求助
			async toHelp() {
				// #ifdef H5
				if (this.$jweixin.isWechat()) {
					this.$util.showLoading()
					await this.$jweixin.wxReady2();
					let {
						latitude: lat = 0,
						longitude: lng = 0
					} = await this.$jweixin.getWxLocation()
					if (!lat) {
						this.$util.hideAll()
						this.$util.showToast({
							title: `请授权定位当前地址`
						})
						return
					}
					if (lat && lng) {
						let key = `${lat},${lng}`
						let data = await this.$api.base.getMapInfo({
							location: key
						})
						let {
							status,
							result
						} = JSON.parse(data)
						if (status == 0) {
							this.$util.hideAll()
							let {
								address
							} = result
							this.toPolice({
								lat,
								lng,
								address
							})
						}
					}
				}
				// #endif
				// #ifndef H5
				this.$util.showLoading()
				let {
					lat = '',
						lng = '',
						address = ''
				} = await this.$util.getBmapLocation()
				if (!lat) {
					this.$util.hideAll()
					this.$util.showToast({
						title: `请授权定位当前地址`
					})
					return
				}
				this.toPolice({
					lat,
					lng,
					address
				})
				// #endif
			},
			async toPolice(param) {
				await this.$api.technician.police(param)
				this.$util.hideAll()
				this.$util.showToast({
					title: `求救成功`
				})
			}
		}
	}
</script>

<style lang="scss">
	.pages-mine {
		.mine-bg {
			width: 100%;
			height: 318rpx;
			/* #ifdef H5 */
			z-index: 0;
			/* #endif */
			/* #ifndef H5 */
			z-index: -1;
			/* #endif */
		}

		.mine-master-bg {
			width: 100%;
			height: 514rpx;
			z-index: -1;
		}

		.avatar_view {
			width: 120rpx;
			height: 120rpx;

			.avatar {
				width: 120rpx;
				height: 120rpx;
				overflow: hidden;

				open-data {
					width: 120rpx;
					height: 120rpx;
				}
			}

			.text {
				width: 110rpx;
				position: absolute;
				bottom: -5rpx;
				left: 5rpx;
				height: 36rpx;
				line-height: 36rpx;
				background: #FFFFFF;
				border-radius: 18rpx;
				font-size: 24rpx;
				text-align: center;
			}
		}


		.member-tag {
			min-width: 168rpx;
			height: 42rpx;
			background: rgba(255, 255, 255, 0.5);

			.iconfont {
				font-size: 28rpx;
			}
		}

		.iconbianjiziliao {
			font-size: 36rpx;
		}

		.icon-xitong {
			font-size: 40rpx;
		}

		// 定位/时间/求救
		.addr-time-help-list {
			width: 100%;
			padding: 40rpx 0;

			.flex-center {
				width: 33.33%;

				.iconfont {
					font-size: 60rpx;
					margin-bottom: 10rpx;
				}
			}

		}

		// 技-师信息
		.coach-info {
			.avatar {
				width: 140rpx;
				height: 140rpx;
			}

			.coach-name {
				font-size: 34rpx;
				color: #142C57
			}

			.coach-text {
				color: #5A677E
			}

			.icon-right {
				font-size: 22rpx
			}

			.tag-item {
				min-width: 92rpx;
				height: 36rpx;
				padding: 0 10rpx;
				font-size: 24rpx;
				border-radius: 6rpx;
				transform: rotateZ(360deg);
			}

			.map-addr-info {
				.map-addr {
					width: 102rpx;
					height: 46rpx;
					padding-right: 6rpx;

					.iconfont {
						margin-right: 2rpx;
						font-size: 26rpx;
					}
				}

				.map-addr.abs {
					top: 0;
					left: 0;
					opacity: 0.1;
				}

				.text {
					color: #5A677E;
				}

				.location-change {
					.iconfont {
						font-size: 70rpx;
					}
				}

			}
		}

		// 收入
		.mine-count-list {
			.cancel-auth {
				width: 110rpx;
				height: 100rpx;
				font-size: 100rpx;
				top: -230rpx;
				right: 55rpx;

				.text-bold {
					height: 26rpx;
					transform: rotate(-32deg);
				}
			}

			.item-child {
				width: 50%;
				padding: 28rpx;

				.text {
					color: #5A677E;
				}

				.cash-btn {
					width: 108rpx;
					height: 46rpx;
					transform: rotateZ(360deg);
				}
			}

		}


		.dot-unread-number {
			top: 0;
			right: 0;
			width: 24rpx;
			height: 24rpx;
			line-height: 24rpx;
			text-align: center;
			color: #fff;
			font-size: 18rpx;
			border-radius: 24rpx;
			background-color: #F1381F;
		}

		// 卡券/关注/收藏
		.share-collect-list {
			.share-item {
				width: 50%;
				height: 105rpx;
			}
		}

		// 充值/收藏/卡券	
		.item-btn {
			width: 150rpx;
			height: 52rpx;
			border-radius: 100rpx;
		}

		.share-list {
			.coupon-img {
				width: 97rpx;
				height: 87rpx;
			}

			.item-icon {
				width: 74rpx;
				height: 80rpx;

				.iconfont {
					font-size: 62rpx;
				}

				.item-icon {
					top: 0;
					left: 0;
					opacity: 0.1;
				}
			}
		}

		.store-btn {
			width: 320rpx;
			height: 60rpx
		}

		.vip-img {
			width: 100%;
			height: 186rpx;
			position: absolute;
			top: 0px;
			left: 0px;
			z-index: 0;
		}

		.vip {
			width: 44rpx;
			height: 44rpx;
		}

		.vip-base {
			height: 100%;
			line-height: 100%;
			color: #856534;
		}

		.vip-fx {
			width: 110rpx;
			height: 44rpx;
			position: absolute;
			top: -44rpx;
			left: 50%;
			margin-left: -54rpx;

		}

		// 分享-卡券
		.share-atv-img {
			width: 716rpx;
			height: 190rpx;
			margin: 0 auto;
		}

		// 我的订单/其他
		.mine-menu-list {
			margin: 20rpx 30rpx 0 30rpx;

			.menu-title {
				height: 90rpx;

				.iconfont {
					font-size: 24rpx;
				}
			}

			.item-child {
				width: 25%;
				margin: 10rpx 0;

				.iconfont {
					font-size: 52rpx;
				}

				.item-img {
					width: 88rpx;
					height: 88rpx;

					.iconfont {
						font-size: 44rpx;
					}

					.item-img {
						top: 0;
						left: 0;
						opacity: 0.1;
					}
				}

				.fdd-sign {
					width: 76rpx;
					height: 30rpx;
					background: #E82F21;
					font-size: 20rpx;
					transform: scale(0.9);
					top: -10rpx;
					right: 0;
					border-radius: 20rpx 20rpx 20rpx 0;
				}
			}
		}

		.column-img {
			width: 74rpx;
			height: 80rpx;
		}

		.mine-img {
			width: 68rpx;
			height: 68rpx;
			margin: auto;
		}

		// 工具
		.mine-tool-list {
			margin: 20rpx 30rpx 0 30rpx;
			box-shadow: 0px 3px 6px 0px rgba(227, 227, 227, 0.47);

			.list-item {
				.left-icon {
					width: 42rpx;
					font-size: 42rpx;
				}

				.icon-right {
					font-size: 28rpx;
				}

				.icon-switch {
					font-size: 70rpx;
					line-height: 48rpx;
					color: #ddd;
				}
			}

			.list-item.b-1px-t:before {
				left: 60rpx;
			}
		}

	}
</style>