<template>
	<view class="my-info-page">
		<!-- 导航区域 -->
		<view class="icon-title-navBar-box">
			<view @click="handleBack" class="nav-bar-icon"></view>
			<text class="nav-bar-title">家政信息</text>
		</view>
		<!-- 社会信用代码 -->
		<view class="form-label-input">
			<view class="phone-form-label">社会信用代码</view>
			<input v-model="data.xinyongdaima"  placeholder="请输入社会信用代码" />
			<icon></icon>
		</view>
		<!-- 服务监督热线 -->
		<view class="form-label-input">
			<view class="phone-form-label">服务监督热线</view>
			<input v-model="data.jiandurexian"  placeholder="请输入服务监督热线" />
			<icon></icon>
		</view>
		<button type="default" class="phone-green-btn info-btn" @click="handleUpdate">修改资料</button>
	</view>
</template>

<script setup>
	import * as myApi from "@/api/my.js";
	import {ref,reactive} from "vue"
	import {onLoad} from "@dcloudio/uni-app"


	const data = reactive({
		xinyongdaima: '',
		jiandurexian: '',
		userId: null
	})

	onLoad((options) => {
		initPage();
	})

	function handleUpdate() {
		let arr = [];
		
		const opt = {
			xinyongdaima: data.xinyongdaima,
			// userId: data.userId,
			jiandurexian: data.jiandurexian,
		}
		myApi.getDaimaUpdate(opt).then(res => {
			if (res.data) {
				uni.showToast({
					title: '更新成功'
				})
				handleBack();
			}
		})

	}

	function handleBack() {
		const pages = getCurrentPages();
		if (pages.length>1) {
			uni.navigateBack()
		} else {
		
			history.back();
		}
	}

	function initPage() {
		myApi.getDaimaInfo().then(res => {
			const {xinyongdaima,jiandurexian,userId} = res.data;
			data.xinyongdaima = res.data.xinyongdaima; 
			data.jiandurexian = res.data.jiandurexian;
			// data.userId = res.data.userId;
		})
	}
</script>

<style>

</style>