<template>
	<view class="phone-xycx-page">
		<view class="icon-title-navBar-box">
			<view @click="goUpPage" class="nav-bar-icon"></view>
			<text class="nav-bar-title">信用查询</text>
		</view>
		<view class="phone-xycx-body">
			<view class="xycx-search-box">
				<view class="xycx-text">姓名：{{data.userInfo ? data.userInfo.realName: ''}} </view>
				<view class="xycx-text">身份证号：{{data.userInfo ? data.userInfo.idcard: ''}} </view>
				<view class="xycx-line"></view>
				<button @click="handleUpdate" type="default" class="phone-green-btn">查询</button>
			</view>
			<template v-if="data.userInfo">
				<view class="search-result-box">
					<view class="result-title-box">
						<view class="title-icon">1</view>
						<view>失信人查询</view>
					</view>
					<view class="xycx-line"></view>
					<view class="result-text" v-if="!data.userInfo.createTime">未查询</view>
					<view class="result-text" v-else>查询时间：{{data.userInfo.createTime}}</view>
					<view class="result-content">
						失信人：是指被执行人具有履行能力而不履行生效法律文书确定的义务，俗称“老赖”。
					</view>
					<view v-if="data.userInfo.createTime">
						<icon class="yztg-icon" v-if="!data.userInfo.shixing"></icon>
						<icon class="yzsb-icon" v-if="data.userInfo.shixing"></icon>
					</view>
				</view>

				<view class="search-result-box">
					<view class="result-title-box">
						<view class="title-icon">2</view>
						<view>限制高消费</view>
					</view>
					<view class="xycx-line"></view>
					<view class="result-text" v-if="!data.userInfo.createTime">未查询</view>
					<view class="result-text" v-else>查询时间：{{data.userInfo.createTime}}</view>
					<view class="result-content">
						限制高消费令：是指国家针对拒不执行法院生效法律文书的“老赖”，采取“限制高消费”的措施。
					</view>
					<view v-if="data.userInfo.createTime">
						<icon class="yztg-icon" v-if="!data.userInfo.xiangao"></icon>
						<icon class="yzsb-icon" v-if="data.userInfo.xiangao"></icon>
					</view>
				</view>

				<view class="search-result-box">
					<view class="result-title-box">
						<view class="title-icon">3</view>
						<view>法院被执行人查询</view>
					</view>
					<view class="xycx-line"></view>
					<view class="result-text" v-if="!data.userInfo.createTime">未查询</view>
					<view class="result-text" v-else>查询时间：{{data.userInfo.createTime}}</view>
					<view class="result-content">
						法院被执行人：是指在法定的上诉期满后，或终审判决做出后，未履行法院判决或仲裁裁决，并进入执行程序的当事人。
					</view>
					<view v-if="data.userInfo.createTime">
						<icon class="yztg-icon" v-if="!data.userInfo.zhixing"></icon>
						<icon class="yzsb-icon" v-if="data.userInfo.zhixing"></icon>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

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

	const data = reactive({
		userId: null,
		userInfo: null,
		loading: false,
	})

	onLoad((options) => {
		data.userId = options.userId;

		getUserInfo();
	})

	function getUserInfo() {
		jzApi.jiazhengXinyongInfo({
			userId: data.userId
		}).then(res => {
			data.userInfo = res.data;
		})
	}

	function handleUpdate() {
		if (data.loading) {
			uni.showToast({
				title: '查询中，请稍等'
			})
			return;
		}
		data.loading = true;
		jzApi.jiazhengXinyongUpdate({
			userId: data.userId
		}).then(res => {
			if (res.data) {
				uni.showToast({
					title: '查询成功'
				})
				getUserInfo()
			}
		}).finally(() => {
			data.loading = false;
		})
	}

	function goUpPage() {
		uni.navigateBack()
	}
</script>

<style>

</style>