<template>
	<view class="container">
		<navBar title="GIGESI 吉格斯" :back="false" color="black" background="#FDEED5" />
		<view class="content">
			<view class="top">
				<view class="userInfo">
					<view class="left">
						<navigator url="/pages/my/userInfo/index">
							<button class="avatarBox">
								<image class="avatar"
									:src="userInfo?userInfo.head:picUrl+'/static/other/defaultAvatar.png'"></image>
							</button>
						</navigator>
						<text class="btn" v-if="!token" @click="login">请点击登录</text>
						<text class="btn" v-if="token&&role=='cydg'">XXX电工</text>
						<text class="btn" v-if="token&&role=='hy'">XXX会员</text>

						<view class="lMember" v-if="token&&role=='lhy'">
							<text class="btn1">XXXL会员</text>
							<view class="botDes">
								查看商品会员价，72小时后自动恢复
								为售价。会员价格还剩 00:05:59
							</view>
						</view>
						<view class="lMember" v-if="token&&role=='dg'">
							<text class="btn1">陈冰冰CBb</text>
							<view class="botDes">
								17820937628
							</view>
						</view>

						<view class="lMember" v-if="token&&role=='svip'">
							<text class="btn1">XXXS-VIP</text>
							<view class="botDes">
								17820937628
							</view>
						</view>
						<view class="lMember" v-if="token&&role=='yk'">
							<text class="btn1">{{userInfo.nickname}}</text>
							<view class="botDes">
								{{userInfo.phone}}
							</view>
						</view>

						<text class="btn" v-if="token&&role=='sjkf'">XXX设计客服</text>
						<text class="btn" v-if="token&&role=='shkf'">XXX售后客服</text>
						<text class="btn" v-if="token&&role=='yw'">XXX业务</text>

						<text class="btn" v-if="token&&role=='superAdmin'">XXX超级管理员</text>


					</view>
					<navigator :url="'/pages/my/set/index?role=' + role">
						<image :src="picUrl+'/static/my/set2.png'" mode=""
							style="width: 37rpx;height: 41rpx;margin-right: 22rpx;">
						</image>
					</navigator>
				</view>

				<view class="invite" @click="show=true"
					v-if="role=='sjkf'||role=='shkf'||role=='yw'||role=='superAdmin'||role=='yk'||role==''">
					<view class="left">
						<image :src="picUrl+'/static/my/vip.png'" mode="" style="width: 27rpx;height: 30rpx;">
						</image>
						<text>邀约VIP</text>
					</view>

					<view class="right">
						<text class="price">VIP享专属价格</text>
						<image :src="picUrl+'/static/my/yellowR.png'" mode=""
							style="width: 12rpx;height: 20rpx;margin-left: 8rpx;"></image>
					</view>
					<image :src="picUrl+'/static/my/diwen.png'" mode=""
						style="width: 136rpx;height: 80rpx;position: absolute;z-index: 0;right: 0;right: 32rpx;border-radius: 0rpx 24rpx 8rpx 0rpx;">
					</image>
				</view>
			</view>

			<view class="serList">
				<navigator :url="item.url" v-for="(item,index) in serList">
					<view class="item">
						<view class="left">
							<image :src="item.icon" mode="" style="height: 31rpx;width: 35rpx;"></image>
							<text>{{item.name}}</text>
						</view>
						<view class="right">
							<text class="num" v-if="item.phone">{{item.phone}}</text>
							<image src="/static/my/arr_r.png" mode="" style="height: 24rpx;width: 14rpx;"></image>
						</view>
					</view>
				</navigator>
			</view>
		</view>

		<u-action-sheet :actions="list" :title="title" :show="show" cancelText="取消" @close="show=false"
			@select="handleSel"></u-action-sheet>
	</view>
</template>

<script>
	import uploadUrl from '@/common/config.js'
	import {
		wxAuthLoginReq,
		getUserInfoReq,
		updateUserInfoReq,
	} from '@/api/test/index.js'
	export default {
		// components: {
		// 	navBar
		// },
		data() {
			return {
				picUrl: this.$picUrl,

				token: uni.getStorageSync('token'),
				role: uni.getStorageSync('role'),
				// token: null,
				// role: null,
				// role: 'cydg',
				// role: 'dg',

				// role: 'hy',
				// role: 'lhy',
				// role: 'sjkf',
				// role: 'shkf',
				// role: 'yw',
				// role: 'svip',
				// role: 'superAdmin',

				serList: [{
						icon: this.$picUrl + '/static/my/set.png',
						name: '设置',
						url: '/pages/my/set/index?role=' + this.role
					},
					{
						icon: this.$picUrl + '/static/my/sh.png',
						name: '售后',
						url: '/pages/my/sellAfter/index'
					},
					{
						icon: this.$picUrl + '/static/my/tg.png',
						name: '团购商品',
						url: '/pages/my/actGoods/index'
					},
					{
						icon: this.$picUrl + '/static/my/sc.png',
						name: '收藏',
						url: '/pages/my/collect/index'
					},
					{
						icon: this.$picUrl + '/static/my/qt.png',
						name: '其他信息',
						url: '/pages/my/otherInfo/index'
					}
				],

				showPrivacy: true,

				avatarUrl: '',
				nickName: '',
				PhoneCode: '',
				imgUrl: '',
				isPhone: false,

				user_img: '', //微信头像
				user_name: '',

				show: false,
				list: [{
						name: '邀约VIP'
					},
					{
						name: '邀约L会员'
					},
					{
						name: '邀约会员'
					},
					{
						name: '邀约电工'
					},
					{
						name: '邀约活动用户'
					}
				],
				userInfo: null
			}
		},
		async onLoad() {
			if (uni.getStorageSync('token')) {
				let res = await getUserInfoReq()
				if (res.code == 0) {
					this.userInfo = res.data
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				}
			}


			wx.onNeedPrivacyAuthorization((resolve, eventInfo) => {
				console.log('触发本次事件的接口是：' + eventInfo.referrer)
				// 需要用户同意隐私授权时
				// 弹出开发者自定义的隐私授权弹窗
				this.showPrivacy = true

				this.resolvePrivacyAuthorization = resolve
			})

			if (this.role == 'cydg') {
				this.serList = [{
						icon: this.picUrl + '/static/my/set.png',
						name: '设置',
						url: '/pages/my/set/index?role=' + this.role
					},
					{
						icon: this.picUrl + '/static/my/sc.png',
						name: '收藏',
						url: '/pages/my/collect/index'
					},
					{
						icon: this.picUrl + '/static/my/qt.png',
						name: '小程序使用指南',
						url: '/pages/my/useLead/index'
					},
					{
						icon: this.picUrl + '/static/my/yjlx.png',
						name: '一键联系',
						phone: '12983098478'
					},
				]
			} else if (this.role == 'hy') {
				this.serList = [{
						icon: this.picUrl + '/static/my/sh.png',
						name: '售后',
						url: '/pages/my/sellAfter/index'
					}, {
						icon: this.picUrl + '/static/my/sc.png',
						name: '收藏',
						url: '/pages/my/collect/index'
					}, {
						icon: this.picUrl + '/static/my/qt.png',
						name: '小程序使用指南',
						url: '/pages/my/useLead/index'
					},
					{
						icon: this.picUrl + '/static/my/yjlx.png',
						name: '一键联系',
						phone: '12983098478'
					},
				]
			} else if (this.role == 'lhy') {
				this.serList = [{
					icon: this.picUrl + '/static/my/sh.png',
					name: '售后',
					url: '/pages/my/sellAfterCon/index'
				}, {
					icon: this.picUrl + '/static/my/sc.png',
					name: '收藏',
					url: '/pages/my/collect/index'
				}, {
					icon: this.picUrl + '/static/my/qt.png',
					name: '小程序使用指南',
					url: '/pages/my/useLead/index'
				}, ]
			} else if (this.role == 'sjkf' || this.role == 'yw') {
				if (this.role == 'sjkf') {
					this.serList = [{
						icon: this.picUrl + '/static/my/set.png',
						name: '设置',
						url: '/pages/my/set/index?role=' + this.role
					}, {
						icon: this.picUrl + '/static/my/sh.png',
						name: '售后',
						url: '/pages/my/sellAfter/index'
					}, {
						icon: this.picUrl + '/static/my/sc.png',
						name: '收藏',
						url: '/pages/my/collect/index'
					}, {
						icon: this.picUrl + '/static/my/qt.png',
						name: '小程序使用指南',
						url: '/pages/my/useLead/index'
					}, ]
				} else {
					this.serList = [{
						icon: this.picUrl + '/static/my/set.png',
						name: '设置',
						url: '/pages/my/set/index?role=' + this.role
					}, {
						icon: this.picUrl + '/static/my/sh.png',
						name: '售后',
						url: '/pages/my/sellAfter/index'
					}, {
						icon: this.picUrl + '/static/my/tg.png',
						name: '团购商品',
						url: '/pages/my/actGoods/index'
					}, {
						icon: this.picUrl + '/static/my/sc.png',
						name: '收藏',
						url: '/pages/my/collect/index'
					}, {
						icon: this.picUrl + '/static/my/qt.png',
						name: '小程序使用指南',
						url: '/pages/my/useLead/index'
					}, ]
				}

				this.list = [{
						name: '邀约VIP'
					},
					{
						name: '邀约L会员'
					},
					{
						name: '邀约活动用户'
					}
				]
			} else if (this.role == 'shkf') {
				this.serList = [{
					icon: this.picUrl + '/static/my/set.png',
					name: '设置',
					url: '/pages/my/set/index?role=' + this.role
				}, {
					icon: this.picUrl + '/static/my/sh.png',
					name: '售后',
					url: '/pages/my/sellAfter/index'
				}, {
					icon: this.picUrl + '/static/my/tg.png',
					name: '团购商品',
					url: '/pages/my/actGoods/index'
				}, {
					icon: this.picUrl + '/static/my/sc.png',
					name: '收藏',
					url: '/pages/my/collect/index'
				}, {
					icon: this.picUrl + '/static/my/qt.png',
					name: '小程序使用指南',
					url: '/pages/my/useLead/index'
				}, ]

				this.list = [{
						name: '邀约VIP'
					},
					{
						name: '邀约L会员'
					},
					{
						name: '邀约会员'
					},
					{
						name: '邀约活动用户'
					}
				]
			} else if (this.role == 'dg') {
				this.serList = [{
					icon: this.picUrl + '/static/my/set.png',
					name: '设置',
					url: '/pages/my/set/index?role=' + this.role
				}, {
					icon: this.picUrl + '/static/my/sc.png',
					name: '收藏',
					url: '/pages/my/collect/index'
				}, {
					icon: this.picUrl + '/static/my/yjlx.png',
					name: '一键联系',
					phone: '12983098478'
				}, {
					icon: this.picUrl + '/static/my/jiang.png',
					name: '兑奖信息',
					url: '/pages/my/chapinShip/index'
				}, {
					icon: this.picUrl + '/static/my/qt.png',
					name: '小程序使用指南',
					url: '/pages/my/useLead/index'
				}, ]
			} else if (this.role == 'svip') {
				this.serList = [{
					icon: this.picUrl + '/static/my/set.png',
					name: '设置',
					url: '/pages/my/set/index?role=' + this.role
				}, {
					icon: this.picUrl + '/static/my/sc.png',
					name: '收藏',
					url: '/pages/my/collect/index'
				}, {
					icon: this.picUrl + '/static/my/yjlx.png',
					name: '一键联系',
					phone: '12983098478'
				}, {
					icon: this.picUrl + '/static/my/qt.png',
					name: '小程序使用指南',
					url: '/pages/my/useLead/index'
				}, ]
			} else if (this.role == 'yk') {
				this.serList = [{
						icon: this.$picUrl + '/static/my/set.png',
						name: '设置',
						url: '/pages/my/set/index?role=' + this.role
					},
					{
						icon: this.$picUrl + '/static/my/sh.png',
						name: '售后',
						url: '/pages/my/sellAfter/index'
					},
					{
						icon: this.picUrl + '/static/my/tg.png',
						name: '活动商城',
						url: '/pages/my/actGoods/index'
					}, {
						icon: this.picUrl + '/static/my/sc.png',
						name: '收藏',
						url: '/pages/my/collect/index'
					}, {
						icon: this.picUrl + '/static/my/qt.png',
						name: '小程序使用指南',
						url: '/pages/my/useLead/index'
					},
					{
						icon: this.$picUrl + '/static/my/qt.png',
						name: '其他信息',
						url: '/pages/my/otherInfo/index'
					}
				]
			} else if (this.role == 'superAdmin') {
				this.serList = [{
					icon: this.picUrl + '/static/my/set.png',
					name: '设置',
					url: '/pages/my/set/index?role=' + this.role
				}, {
					icon: this.picUrl + '/static/my/sh.png',
					name: '售后',
					url: '/pages/my/sellAfter/index'
				}, {
					icon: this.picUrl + '/static/my/tg.png',
					name: '团购商品',
					url: '/pages/my/actGoods/index'
				}, {
					icon: this.picUrl + '/static/my/sc.png',
					name: '收藏',
					url: '/pages/my/collect/index'
				}, {
					icon: this.picUrl + '/static/my/qt.png',
					name: '其他信息',
					url: '/pages/my/otherInfo/index'
				}, ]
			} else {

			}

			// wx.getUserProfile({
			// 	success: console.log,
			// 	fail: console.error
			// })
		},
		computed: {},
		methods: {

			login() {
				let _this = this
				uni.login({
					provider: 'weixin',
					success: async (res) => {
						if (res.errMsg == 'login:ok') {
							let res1 = await wxAuthLoginReq({
								code: res.code
							})
							if (res1.code == 0) {
								uni.setStorageSync('token', res1.data.token)
								uni.setStorageSync('role', 'yk')
								uni.setStorageSync('userInfo', res1.data.user_info)
								_this.$toast('登录成功')
								setTimeout(() => {
									uni.reLaunch({
										url: '/pages/my'
									})
								}, 1500)
							} else {
								uni.showToast({
									title: res1.message,
									icon: 'none'
								})
							}
						}
					}
				});
			},

			handleSel(e) {
				console.log('sheet选择参数：', e);
				let type = -1
				if (e.name == '邀约VIP') {
					type = 'vip'
				} else if (e.name == '邀约L会员') {
					type = 'ls'
				} else if (e.name == '邀约会员') {
					type = 'hy'
				} else if (e.name == '邀约活动用户') {
					type = 'yh'
				} else if (e.name == '邀约电工') {
					type = 'dg'
				}
				uni.navigateTo({
					url: '/pages/my/inviteDetail/index?type=' + type
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./my.scss";
</style>