<template>
	<view>
		<view class="search"><u-search placeholder="公司名称" v-model="param.companyName" :animation="true" @search="getData()" @clear="clear()"></u-search></view>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
				<text>{{ item.companyName }}</text>
				<text class="icon">&#xe62b;</text>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			param: {}
		};
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/company/list',
				data: this.param,
				success: (res) => {
					this.list = res.data.data;
				}
			});
		},
		detail(item) {
			uni.showModal({
				title: '提示',
				content: '确定关联该企业?',
				success: (res) => {
					if (res.confirm) {
						this.http.request({
							url: '/app/relate/add',
							data: { companyId: item.id,way:'手动关联' },
							method: 'POST',
							success: (res) => {
								uni.showModal({
									title: '提示',
									content: '关联成功',
									showCancel: false,
									success: (res) => {
										uni.$emit('company');
										uni.navigateBack();
									}
								});
							}
						});
					}
				}
			});
		},
		clear() {
			this.list = [];
		}
	}
};
</script>

<style lang="scss">
.search {
	padding: 12px 20px 12px 20px;
	background-color: white;
}
.list {
	.item {
		padding: 17px;
		background-color: white;
		margin-top: 10px;
		.icon {
			float: right;
		}
	}
}
</style>