<template>
	<view class="p-person-info g_w_all g_h_all g_bg_f_5 g_kuaishou">
		<view class="g_bg_f sticky" :style="{ boxShadow: '0px 4px 4px 0px rgba(218, 218, 218, 0.5)' }">
			<g-tabs bg-color="transparent" from="index" :list="menuList" :is-scroll="false" :current="menuActive" bar-width="64" bar-height="6" @change="handleUpdateMenu" font-size="32" duration="0.05" height="76"></g-tabs>
		</view>
		<scroll-view class="" :scroll-y="true" style="height: calc(100vh - 38px)">
			<view class="g_h_10"> </view>
			<!-- 根据menuActive显示不同内容 -->
			<view v-if="menuActive === 0" class="g_flex_column_start">
				<!-- 个人资料内容 -->
				<view class="">
					<g-panel-form-item :list="list" @clickItem="handleClickItem" />
				</view>
				<!-- <view class="" hover-class="none" hover-stop-propagation="false">
					<g-panel-form-item
						:list="[
							{
								icon: '',
								label: '人海号',
								result: userinfo.bocaiId,
								type: 'slot',
								tip: 'copy',
							},
						]"
						@copyVal="onCopyVal"
					/>
				</view> -->
				<view class="g_pt_8">
					<g-panel-form-item :list="[{ icon_after: userinfo.realName ? 'yirenzheng g_c_main' : '', label: '实名认证', result: userinfo.realName ? '' : '去认证', path: '/root/person/idcardForm', type: userinfo.realName ? 'slot' : '' }]" @clickItem="goRealName" />
				</view>
			</view>
			<view v-else>
				<!-- 企业资料内容，直接引入组件 -->
				<OrderEdit v-if="reset" />
			</view>
		</scroll-view>
	</view>
</template>

<script>
import OrderEdit from "./orderEdit.vue";

export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	components: {
		OrderEdit,
	},
	data() {
		return {
			isRelease: uni.getAccountInfoSync().miniProgram.envVersion === 'release',
			themeColor: getApp().globalData.themeColor,
			isAdmin: uni.getStorageSync("apply-userinfo").admin,
			userinfo: {},
			list: [],
			cdnBaseImg: this.G.store().cdnBaseImg,
			localBaseImg: this.G.store().localBaseImg,
			svgBaseImg: this.G.store().svgBaseImg,
			menuList: [
				{
					name: "个人资料",
					tip: "0",
				},
				{
					name: "企业资料",
					tip: "1",
				},
			],
			menuActive: 0,
			reset: true,
		};
	},
	onLoad(options) {
		let that = this;
		if (options.active) {
			that.menuActive = parseInt(options.active);
		}
		uni.$on("changePersonDesp", function (data) {
			console.log(data.info);
			console.log("监听到事件来自 update ，携带参数 msg 为：" + data.info);
			that.userinfo.desp = data.info;
			let info = {
				fieldName: "desp",
				fieldValue: that.userinfo.desp,
			};
			setTimeout(() => {
				that.editField(info);
			}, 100);
		});
	},
	onShow() {
		let that = this;
		// this.reset = false;
		// console.log("this.reset", this.reset);
		// setTimeout(() => {
		// 	this.reset = true;
		// }, 10);
		console.log("this.reset", this.reset);
		that.init();
		// that.getBocaiId();
	},
	methods: {
		init() {
			let that = this;
			let userinfo = uni.getStorageSync("apply-userinfo");
			that.userinfo = {
				imgSrc: userinfo.user.imgSrc || that.svgBaseImg + "defaultAva.svg",
				userName: userinfo.userName,
				tel: userinfo.user.tel,
				desp: that.userinfo.desp || "请简单介绍",
				realName: userinfo.user.realName,
				id: userinfo.user.id,
			};
			console.log("userinfo", that.userinfo);
			let defaultList = [
				{
					icon: "",
					label: "头像",
					result: "",
					value: that.userinfo.imgSrc,
					path: "/root/person/avatar",
					tip: "avatar",
					pColumn: 22,
				},
				{
					icon: "",
					label: "用户名",
					result: that.userinfo.userName,
					path: "/root/person/change?title=设置用户名&remark=好的花名，让团队成员更好记住你&value=" + that.userinfo.userName,
					tip: "username",
				},
				{
					icon: "",
					label: "手机号",
					result: that.userinfo.tel,
					path: "/root/person/change?title=设置手机号&remark=&value=" + that.userinfo.tel,
					tip: "mobile",
				},
			];
			if (that.isRelease) {
				that.list = defaultList;
			}else{
				that.list = [
					{
						icon: "",
						label: "用户名",
						result: that.userinfo.userName,
						path: "/root/person/change?title=设置用户名&remark=好的花名，让团队成员更好记住你&value=" + that.userinfo.userName,
						tip: "username",
					},
					{
						icon: "",
						label: "手机号",
						result: that.userinfo.tel,
						path: "/root/person/change?title=设置手机号&remark=&value=" + that.userinfo.tel,
						tip: "mobile",
					},
				];
			}
		},
		getBocaiId() {
			let that = this;
			this.F.wyyxPost(this.api.wyyx_getConfig, { userId: that.userinfo.id }, (res) => {
				console.log("res", res);
				that.userinfo.bocaiId = res.accid;
			});
		},
		editField(info) {
			let that = this;
			console.log(info);
			that.G.Put(that.api.user_changeTobeSupplierField, info, (res) => {
				that.showSuccess();
			});
		},
		handleClickItem(e) {
			let that = this;
			uni.navigateTo({
				url: e.item.path,
			});
		},
		goRealName(e) {
			if (!this.userinfo.realName) {
				uni.navigateTo({
					url: e.item.path,
				});
			}
		},
		handleUpdateMenu(index) {
			this.menuActive = index;
		},
		onCopyVal(e) {
			uni.setClipboardData({
				data: e.item.result,
				success(res) {
					uni.showToast({
						title: "复制成功",
						icon: "success",
					});
				},
			});
		},
	},
};
</script>

<style></style>
