<template>
	<view class="p-person-change g_w_all g_h_all g_bg_f_5 g_kuaishou">
		<view class="g_h_10"></view>

		<view v-if="info.title == '设置用户名'">
			<g-panel-form-slot
				:list="[
					{
						icon: '',
						label: '用户名',
						result: '',
						path: '',
						tip: 'user-name',
						type: 'slot',
						pColumn: 12,
					},
				]"
			>
				<slot> 
					<!-- #ifdef APP-PLUS || H5 || MP-TOUTIAO || MP-KUAISHOU -->
					<u-input type="text"
					 :clearable="false" 
					 :password-icon="false"
					 placeholder="请输入用户名" input-align="right" 
					 class="g_text_r g_w_all" 
					 placeholder-style="color:#999999;font-size:32rpx;line-height:1" 
					 v-model="info.value"
					 style="width: calc(100vw - 106px);flex: none;"
					/>
					<!-- #endif -->
					<!-- #ifdef MP-WEIXIN -->
					<u-input type="text"
					 :clearable="false" 
					 :password-icon="false"
					 placeholder="请输入用户名" input-align="right" 
					 class="g_text_r g_w_all" 
					 placeholder-style="color:#999999;font-size:32rpx;line-height:1" 
					 v-model="info.value"
					/>
					<!-- #endif -->
				</slot>
			</g-panel-form-slot>
			<view class="g_flex_row_center" style="margin-top:90px">
				<g-button btnText="提交" type="primary" @clickBtn="submitForm" />
			</view>
		</view>
		<view v-if="info.type == 'order'">
			<g-panel-form-slot
				:list="[
					{
						icon: '',
						label: info.remark,
						result: '',
						path: '',
						tip: 'user-name',
						type: 'slot',
						pColumn: 12,
					},
				]"
			>
				<slot>
					<u-input type="text" :clearable="false" :password-icon="false" :placeholder="info.place" input-align="right" class="g_text_r g_w_all" placeholder-style="color:#999999;font-size:32rpx;line-height:1" v-model="info.value" />
				</slot>
			</g-panel-form-slot>
			<view class="g_mt_90 g_flex_row_center">
				<g-button btnText="提交" type="primary" @clickBtn="submitOrderForm" />
			</view>
		</view>
		<view v-if="info.title == '设置手机号'">
			<g-panel-form-item
				:list="[
					{
						icon: '',
						label: '手机号',
						result: info.value,
						path: '',
						tip: 'user-tel',
						type: 'slot',
					},
				]"
			/>
			<view class="g_fs_14 g_c_9 g_flex_row_center g_mt_10">暂不支持修改</view>
		</view>
	</view>
</template>

<script>
export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	data() {
		return {
			info: {},
		};
	},
	onLoad(options) {
		console.log("options", options);
		this.info = options;
		uni.setNavigationBarTitle({
			title: options.title,
		});
	},
	methods: {
		submitForm() {
			let that = this;
			if (that.info.value == "") {
				uni.showToast({
					title: "请输入用户名",
					icon: "none",
				});
				return false;
			}
			that.G.Post(
				that.api.user_changeName,
				{
					userName: that.info.value,
					formdata: true,
				},
				() => {
					uni.showToast({
						title: "修改成功",
						icon: "success",
					});
					that.G.checkToken();

					// uni.setStorageSync('apply-username', that.info.value)
					setTimeout(() => {
						uni.navigateBack();
					}, 1500);
				}
			);
		},
		submitOrderForm(info) {
			let that = this;
			console.log(that.info.value);
			if (!this.info.value.trim()) {
				uni.showToast({
					title: "名称不能为空",
					icon: "none",
				});
				return false;
			}
			if (that.info.title == "修改账号名称") {
				if (that.info.value.length > 10) {
					uni.showToast({
						title: "账号名称最多10个字",
						icon: "none",
					});
					return;
				}
				uni.$emit("changeAccountName", { info: this.info.value });
				uni.navigateBack();
			} else if (that.info.title == "修改企业全称") {
				uni.$emit("changeStoreName", { info: this.info.value });
				uni.navigateBack();
			}
		},
	},
};
</script>

<style></style>
