<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 class="" v-if="info.fieldName != 'address'">
			<view class="g_mb_8 g_pl_12">{{ info.label }}</view>
			<view class="g_bg_f g_radius_8 g_p_6" style="width: calc(100% - 60rpx); margin: 0 auto">
				<!-- #ifdef APP-PLUS || H5 || MP-TOUTIAO || MP-KUAISHOU -->
				<u-input type="text" :clearable="false" :password-icon="false" :customStyle="{ fontSize: '17px' }" :placeholder="info.placeholder" input-align="left" class="g_text_r g_w_all" placeholder-style="color:#999999;font-size:17px;line-height:1" v-model="info.value" style="width: calc(100vw - (106px)); flex: none; font-size: 17px" />
				<!-- #endif -->
				<!-- #ifdef MP-WEIXIN -->
				<u-input type="text" :clearable="false" v-if="info.fieldName != 'desp'" :customStyle="{ fontSize: '17px' }" :password-icon="false" :placeholder="info.placeholder" input-align="left" class="g_text_r g_w_all" placeholder-style="color:#999999;font-size:17px;line-height:1" v-model="info.value" />
				<u-input type="textarea" :clearable="false" v-else :customStyle="{ fontSize: '17px' }" :password-icon="false" :placeholder="info.placeholder" input-align="left" class="g_text_r g_w_all" placeholder-style="color:#999999;font-size:17px;line-height:1" v-model="info.value" />
				<!-- #endif -->
			</view>
		</view>
		<!-- <rh-form-slot
			:list="[
				{
					icon: '',
					label: info.label,
					result: '',
					path: '',
					tip: 'user-name',
					type: 'slot',
					pColumn: 12,
				},
			]"
			v-if="info.fieldName != 'address'"
		>
			<slot> </slot>
		</rh-form-slot> -->
		<rh-form-slot
			v-else
			:list="[
				{
					icon: '',
					label: '企业地址',
					result: '',
					addressDetail: { latitude: info.value.lat, longitude: info.value.lng },
					value: info.value.address,
					path: '',
					tip: 'slot-choose-address',
					placeholder: '请选择企业地址',
					type: 'slot',
					fontSize: '16px',
					pColumn: 17,
					pRow: 12,
					require: false,
					suffix: 'icon-dizhi1',
				},
			]"
			@chooseAddress="chooseAddress"
		></rh-form-slot>
		<div class="g_c_9 g_fs_14 g_pl_16 g_mt_4" v-if="info.fieldName == 'fullName'">企业简称与发单号名称直接关联，请谨慎修改</div>
		<view class="g_mt_90 g_flex_row_center">
			<rh-button primaryColor='#00b666' btnText="提交" type="primary" @clickBtn="submitForm" />
		</view>
	</view>
</template>

<script>
export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	components: {},
	data() {
		return {
			info: {},
		};
	},
	onLoad(options) {
		console.log("options", options);
		this.info = options;
		if (this.info.fieldName != "address") {
			this.info.value = options.value;
		} else {
			this.info.value = JSON.parse(options.value);
		}
		this.info.placeholder = `请输入${options.label}`;

		uni.setNavigationBarTitle({
			title: `修改${options.label}`,
		});
	},
	methods: {
		submitForm() {
			let that = this;
			if (that.info.value == "") {
				uni.showToast({
					title: `请输入${that.info.label}`,
					icon: "none",
				});
				return false;
			}
			if (this.info.fieldName == "address") {
				this.submitAddress();
			} else {
				this.submitWithoutAddress();
			}
		},
		submitWithoutAddress() {
			let that = this;
			that.G.Put(
				"/yishoudan/agency/updateField",
				{
					fieldName: that.info.fieldName,
					fieldValue: that.info.value,
				},
				() => {
					uni.showToast({
						title: "修改成功",
						icon: "success",
					});
					that.G.checkToken();

					setTimeout(() => {
						uni.$emit("changeCompanyDesp", "测试");
						uni.navigateBack();
					}, 1500);
				}
			);
		},
		submitAddress() {
			let that = this;
			that.G.Put(
				this.api.user_changeTobeSupplierAddress,
				{
					address: that.info.value.address,
					lng: that.info.value.lng,
					lat: that.info.value.lat,
				},
				() => {
					uni.showToast({
						title: "修改成功",
						icon: "success",
					});
					that.G.checkToken();

					setTimeout(() => {
						uni.$emit("getBossAddress");
						uni.navigateBack();
					}, 1500);
				}
			);
		},
		chooseAddress(e) {
			console.log("eeeeeee", e);
			this.info.value.address = e.address;
			this.info.value.lat = e.lat;
			this.info.value.lng = e.lng;
		},
	},
};
</script>

<style></style>
