<template>
	<view>
		<u-navbar back-text="查找工会"></u-navbar>
		<view class="search">
			<u-search placeholder="输入关键字查询工会" v-model="keyword" :action-style="actionStyle" @custom="searchQrg" @search="searchQrg"></u-search>
		</view>
		<view class="searchList" v-if="orgResult.length > 0">		
			<list>
				<cell v-for="(item, index) in orgResult" :key="item.id">
					<view class="searchList-item"  @click="getRegister(item)">
						<text>{{item.name}}</text>
					</view>
				</cell>
			</list>		
			<u-divider color="#B6BDC3" style="margin-top:20px;">已经到底了</u-divider>
		</view>
		<view class="jpDefault" v-else>
			<u-image width="179px" height="126px" src="/static/img/default1.png"></u-image>
			<p>没有匹配的搜索结果</p>
		</view>
	</view>
</template>

<script>
	import * as loginApi from '@/apis/login.js'

	export default {
		data() {
			return {
				keyword: '',
				pageIndex: 1,
				pageSize: 100,
				orgResult: [],
				actionStyle: {
					background: '#FF5E5E',
					color: '#ffffff',
					padding: '5px 0',
					width: '60px',
					borderRadius: '15px',
				},
			}
		},
		methods: {
			getRegister(item) {
				this.carhelp.set("searchOrgItem",item)
				uni.navigateBack({
					url: 'pagesA/pages/login/register'
				})
			},
			getList() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				loginApi.orgList({
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
					orgName: this.keyword
				}).then((response) => {
					var jsonData = response.data.data;
					console.log(jsonData);
					this.orgResult = jsonData;
					uni.hideLoading()
				})
				.catch((error) => {
					uni.showToast({
						title: error
					})
				})
			},
			searchQrg() {			
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				loginApi.orgList({
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
					orgName: this.keyword
				}).then((response) => {
					var jsonData = response.data.data;
					this.orgResult = jsonData;
					uni.hideLoading();			
				})
				.catch((error) => {
					uni.showToast({
						title: error
					})
				})
			},
			onReady() {
				this.getList();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.search {
		padding: 10px 15px;
	}

	.searchList {
		padding: 0 15px;

		.searchList-item {
			border-bottom: 1px solid #E5E7EA;
			padding: 15px 0;
		}
	}
	
	.jpDefault{
		padding-top:150px;
		display: flex;
		flex-direction: column;
		align-items: center;
		p{
			color: #A69F9F;
			font-size: 16px;
			margin-top: 12px;
		}
	}
</style>
