<template>
	<view class="p-person-info g_w_all g_h_all g_bg_f_5 g_kuaishou">
		<view class="g_pt_16">
			<g-panel-form-item :list="list" @clickItem="handleClickItem" />
		</view>
	</view>
</template>

<script>
export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	data() {
		return {
			userinfo: {},
			list: [],
			cdnBaseImg: this.G.store().cdnBaseImg,
			localBaseImg: this.G.store().localBaseImg,
		};
	},
	onLoad() {
		let that = this;
		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);
			that.$forceUpdate();
		});
	},
	onShow() {
		let that = this;
		that.init();
	},
	methods: {
		init() {
			let that = this;
			that.userinfo = {
				imgSrc: uni.getStorageSync("apply-avatar") || that.localBaseImg + "default.svg",
				userName: uni.getStorageSync("apply-userinfo").userName,
				tel: uni.getStorageSync("apply-tel"),
				desp: that.userinfo.desp || "请简单介绍",
			};
			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",
				},
				// {
				// 	icon: "",
				// 	label: "个人简介",
				// 	result: "",
				// 	value: that.userinfo.desp,
				// 	path: "/root/person/inputAccountInfo?from=person&val=" + that.userinfo.desp,
				// 	tip: "desp",
				// 	placeholder: "请简单介绍",
				// 	type: "",
				// 	result: that.userinfo.desp,
				// 	fontSize: "16px",
				// 	fontColor: that.userinfo.desp == "请简单介绍" ? "g_c_9" : "g_c_3",
				// 	pColumn: 18,
				// },
			];
			if (uni.getStorageSync("apply-supplierAccount") == 1) {
				// 有
				that.list = defaultList.concat([
					{
						icon: "",
						label: "二维码名片",
						result: "",
						path: "/root/bind/search?active=1",
						tip: "code",
					},
				]);
			} else {
				// 无
				that.list = defaultList;
			}
		},
		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,
			});
		},
	},
};
</script>

<style></style>
