<template>
	<view class="p-root-merchantManagement-relationUs g_bg_f_5 g_pt_10 g_pb_120" style="min-height: 100vh">
		<!-- 图片区 -->
		<view class="g_flex_row_center">
			<span class="g_position_abso g_c_6" style="left: 40px; top: 20px">预览:</span>
			<view class="g_bg_f g_mt_36 g_mb_24 g_p_10 g_flex_column_center flex_center g_radius_8" style="width: calc(100vw - 80px)">
				<view class="g_pt_18 g_fw_600 g_pb_24 g_fs_18">联系我们</view>
				<view class="g_pb_4 g_fs_14 g_c_6">联系人: {{ submitInfo.contactUserName || "-" }}</view>
				<view class="g_pb_10 g_fs_14 g_c_6">联系电话: {{ submitInfo.contactTel || "-" }}</view>
				<image class="g_w_184 g_h_184" :src="submitInfo.contactWechatQrcode || 'https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/pugongying/wr.png'" mode="aspectFit|aspectFill|widthFix" lazy-load="false" binderror="" bindload="" show-menu-by-longpress> </image>
				<view class="g_mt_8 g_fs_14 g_pb_24 g_fw_600">长按识别二维码</view>
			</view>
		</view>
		<view class="g_h_10"></view>
		<!-- 表单区 -->
		<g-panel-form-slot
			:list="[
				{
					icon: '',
					label: '联系人',
					result: '',
					value: submitInfo.contactUserName,
					path: '',
					tip: 'slot-name',
					placeholder: '输入姓名',
					type: 'slot',
					pColumn: 8,
				},
				{
					icon: '',
					label: '联系电话',
					result: '',
					path: '',
					value: submitInfo.contactTel,
					tip: 'slot-mobile',
					placeholder: '请输入手机号',
					type: 'slot',
					pColumn: 8,
				},
				{
					icon: '',
					label: '二维码',
					result: '',
					path: '',
					tip: 'update-QRCode',
					img: submitInfo.contactWechatQrcode || 'https://bocai-cms.oss-cn-beijing.aliyuncs.com/web-resource/pugongying/wr.png',
					type: 'slot',
					pColumn: 12,
				},
			]"
			@changeName="changeName"
			@updateFile="uploadPhoto"
			@changeMobile="changeMobile"
		/>
		<!-- 提交区 -->
		<!--  -->
		<view v-if="!idauth">
			<view class="g_flex_row_center g_mt_32 m-submit">
				<rh-button  btnText="确定" 
									:loading='isSubmitLoading' 
									:type="isChange ? 'primary' : 'disabled'"
									@clickBtn="subNameInfo" />
			</view>
		</view>
	</view>
</template>

<script>
export default {
	onShareAppMessage() {
		return this.G.shareFun();
	},
	onLoad(options) {
		let appInfo = uni.getStorageSync("miniApp-info");
		this.sqlObj = uni.getStorageSync("miniApp-info");
		this.submitInfo = appInfo;
	},
	data() {
		return {
			isChange:false,
			isSubmitLoading:false,
			sqlObj:{},
			submitInfo: {
				contactUserName: "",
				contactTel: "",
				contactWechatQrcode: "",
			},
		};
	},
	methods: {
		changeName(e) {
			if(this.sqlObj.contactUserName == e){
				this.isChange = false;
			}else{
				this.isChange = true;
			}
			this.submitInfo.contactUserName = e;
		},
		uploadPhoto(e) {
			if(this.sqlObj.contactWechatQrcode == e){
				this.isChange = false;
			}else{
				this.isChange = true;
			}
			this.submitInfo.contactWechatQrcode = e;
		},
		changeMobile(e) {
			if(this.sqlObj.contactTel == e){
				this.isChange = false;
			}else{
				this.isChange = true;
			}
			this.submitInfo.contactTel = e;
		},
		subNameInfo() {
			let that = this;
			let params = {
				recordId: this.submitInfo.id,
				fullName: this.submitInfo.fullName,
				agencyName: this.submitInfo.agencyName,
				desp: this.submitInfo.desp,
				contactUserName: this.submitInfo.contactUserName,
				contactTel: this.submitInfo.contactTel,
				contactWechatQrcode: this.submitInfo.contactWechatQrcode,
				address: this.submitInfo.address,
				lat: this.submitInfo.lat,
				lng: this.submitInfo.lng,
				slogan: this.submitInfo.slogan,
			};
			if(!that.isChange){
				return false;
			}
			that.isSubmitLoading = true;
			that.G.Post(that.api.user_changeTobeSupplierInfo, params, (res) => {
				that.isSubmitLoading = false;
				that.isChange = false;
				console.log(res);
				uni.showToast({
					title: "修改成功",
					icon: "none",
				});
				that.G.getAgencyInfo();
			},()=>{
				that.isSubmitLoading = false;
			});
		},
	},
};
</script>

<style lang="less">
.p-root-person-idform {
	.m-submit {
		.bocai_btn_type_infro {
			background: #ccc !important;
			color: #fff !important;
			font-weight: 600 !important;
			font-size: 18px !important;
		}
	}
	.cardText {
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		text-align: center;
	}
}
</style>
