<!-- 单位查询列表 -->
<template>
	<view class="as-layout-horizontal as-gravity-center top">
		<view class="search-box as-layout-horizontal">
			<image :src="`${$imgUrl}service/icon-search.png`" class="icon"></image>
			<input class="search" placeholder="请输入单位名称" v-model="state.searchInput" @input="inputHandle" />
		</view>
		<view class="search-btn" @click="doSearch">搜索</view>
	</view>

	<!-- 列表 -->
	<view class="list" v-if="state.list.length >0">
		<view class="item" v-for="(item,index) in state.list" :key="index">
			<view class="head">
				<view class="name">
					<text class="title">申请时间 {{item.createTime}}</text>
				</view>
				<view class="status" :class="item.userApplyStatus === 1 ? 'text-orange' : 'text-green'">
					{{item.userApplyStatus === 1 ? '审核中' : '审核通过'}}
				</view>
			</view>
			<view class="detail">
				<view class="order-text">
					<text class="type">单位名称：</text>
					<text class="value">{{item.deptName}}</text>
				</view>
			</view>
			<view class="btns" v-if="item.status !== 1">
				<view class="btn btn-primary as-gravity-center"
					@click="$util.navTo('/subpackage/personal-center/car-submit-record?deptId='+item.deptID)">车辆提交记录
				</view>
			</view>
		</view>
	</view>
	<view class="blank" v-if="state.list.length==0 && state.keyupStatus">
		<view class="as-layout-horizontal as-gravity-center content">没有找到您查询的<text
				class="text-error">{{state.searchInput}}</text>信息</view>
	</view>
</template>

<script setup lang="ts">
	import {
		reactive
	} from "vue";
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		msg,
		navTo
	} from '@/utils/utils';
	import {
		request
	} from "@/utils/network/request.js";
	import {
		gongWuCheDanWeiChaXun
	} from "@/utils/network/api.js";
	import {
		stringToJson
	} from "@/utils/network/encryption";

	onLoad((option) => {
		state.searchInput = option.deptShortName ? option.deptShortName : "";
		console.log(option);
		if (state.searchInput != "") {
			doSearch()
		}

	})

	const state = reactive({
		//搜索关键字
		searchInput: '',
		keyupStatus: false,
		//申请列表 status:1-审核中  2-审核通过
		list: []
	})


	/* 输入 */
	const inputHandle = (event : any) => {
		// console.log(event);
		state.searchInput = event.target.value;
		state.keyupStatus = false;
	}

	/* 搜索 */
	const doSearch = () => {
		if (!state.searchInput) {
			msg("请输入搜索关键字");
			return
		}
		const options = {
			type: 2,
			data: {
				companyName: state.searchInput,
			},
			method: "POST",
			showLoading: true,
		};
		request(gongWuCheDanWeiChaXun, options).then((res) => {
			const result = stringToJson(res.bizContent)
			if (result.companys.length > 0) {
				state.list = result.companys
			} else {
				state.list = [];
				state.keyupStatus = true;
			}
		})
	}
</script>

<style>
	page {
		background-color: #EEF7F7;
	}
</style>
<style lang="scss" scoped>
	.top {
		padding: 30rpx 30rpx 0px;
	}

	.search-box {
		margin-right: 20rpx;
		height: 82rpx;
		border-radius: 40rpx;
		background: #ffffff;
		display: flex;
		justify-content: center;
		align-items: center;
		border: 1px solid #dcdcdc;
		box-sizing: border-box;
	}

	.search-box .icon {
		width: 38rpx;
		height: 38rpx;
		margin: 0 28rpx;
	}

	.search-box .search {
		flex: 1;
		height: 100%;
		font-size: 28rpx;
		color: #333333;
	}

	.search-btn {
		color: white;
		background-color: #00B38B;
		width: 140rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 32rpx;
		border-radius: 40rpx;
		text-align: center;
	}

	.add-btn {
		padding: 30rpx 40rpx;
		position: fixed;
		bottom: 0;
		width: 100%;
		background-color: #EEF7F7;
		box-sizing: border-box;
	}

	.list {
		padding: 30rpx 30rpx 140rpx;
		display: flex;
		flex-direction: column;
	}

	.list .item {
		background: #ffffff;
		box-shadow: 0rpx 2rpx 6rpx 0rpx rgba(223, 223, 223, 0.8);
		border-radius: 20rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		margin-bottom: 30rpx;
	}

	.list .item .head {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx 28rpx;
		border-bottom: 1px solid #dcdcdc;
	}

	.list .item .head .icon {
		width: 48rpx;
		height: 48rpx;
	}

	.list .item .head .name {
		display: flex;
		align-items: center;
	}

	.list .text-green {
		font-size: 26rpx;
		color: #00b38b;
	}

	.list .text-orange {
		font-size: 26rpx;
		color: #ff8000;
	}

	.list .title {
		font-size: 30rpx;
		color: #333;
	}

	.list .detail {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 32rpx;
	}

	.list .detail .type {
		font-size: 26rpx;
		color: #999;
	}

	.list .detail .value {
		font-size: 26rpx;
		color: #333;
	}

	.list .finished .detail .value {
		color: #999;
	}

	.list .detail .odd {
		margin: 20rpx 0;
	}

	.list .cny {
		font-size: 26rpx;
		color: #333;
	}

	.list .finished .cny {
		color: #999;
	}

	.list .amount {
		font-size: 40rpx;
		font-weight: bold;
	}

	.list .finished .amount {
		color: #999;
	}

	.list .btns {
		display: flex;
		align-items: center;
		justify-content: flex-end;
		border-top: 1px solid #dcdcdc;
		margin: 0 30rpx;
		padding: 20rpx 0;
	}

	.list .btn {
		height: 60rpx;
		// line-height: 60rpx;
		border-radius: 30rpx;
		padding: 0 24rpx;
		font-size: 26rpx;
		box-sizing: border-box;
		margin-right: 20rpx;
	}

	.list .btns .btn:last-child {
		margin: 0;
	}

	.list .btn-primary {
		border: 1px solid #00b38b;
		color: #00b38b;
	}

	.list .btn-normal {
		border: 1px solid #dcdcdc;
		color: #333;
	}

	.blank .content {
		font-size: 32rpx;
		padding-top: 50rpx;
	}

	.blank .content .text-error {
		font-weight: bold;
		font-size: 30rpx;
	}
</style>