<template>
	<view class="page-wrap">
		<view class="item-row" v-for="(item, index) in enterpriseList" :key="index">
			<view class="wrap">
				<view class="name">{{ item.customerName }}</view>
				<view class="text">信用代码：{{ item.customerUsci || '--' }}</view>
				<view class="text">企业认证：{{ item.status }}</view>
				<view class="text">团队成员：{{ item.staffSize ? filterDict(item.staffSize, companySizeList) : '--' }}</view>
			</view>
			<button class="btn" @click="handleOpenInfo(item.customerId)">企业资料</button>
			<button class="btn">删除</button>
		</view>
		<button class="add-btn" @click="handleOpenAddEnterprise">+ 添加企业</button>
	</view>
</template>

<script>
import systemService from '@/api/system.js';
import enterpriseService from '@/api/enterprise.js';
import { filterDict } from '@/utils/util.js';
export default {
	data() {
		return {
			enterpriseList: [],
			companySizeList: []
		};
	},
	onLoad() {
		this.getSizeConfig();
		this.getEnterpriseList();
		uni.$on('onUpdateEnterprise', () => {
			this.getEnterpriseList();
		});
	},
	onPullDownRefresh(){
		this.getEnterpriseList()
	},
	methods: {
		// 获取企业列表
		async getEnterpriseList() {
			const { rows } = await enterpriseService.getEnterpriseList();
			this.enterpriseList = rows;
			uni.stopPullDownRefresh();
		},
		// 获取企业人员规模配置
		async getSizeConfig() {
			const { rows: companySizeList } = await systemService.getDict('biz_company_size');
			this.companySizeList = companySizeList;
		},
		handleOpenInfo(id) {
			uni.navigateTo({
				url: 'info?id=' + id
			});
		},
		handleOpenAddEnterprise() {
			uni.navigateTo({
				url: 'info'
			});
		},
		filterDict
	}
};
</script>

<style lang="scss" scoped>
.page-wrap {
	padding: 13.74rpx 0;
}
.item-row {
	background: #fff;
	margin-bottom: 13.74rpx;
	height: 178.57rpx;
	padding: 0 27.47rpx;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	.wrap {
		flex: 1;
	}
	.name {
		font-size: 32.97rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		margin-bottom: 6.87rpx;
	}
	.text {
		font-size: 27.47rpx;
		color: #999;
	}
	.btn {
		background: none;
		border: none;
		font-size: 27.47rpx;
		color: #f97631;
		white-space: nowrap;
		padding: 0;
		margin-left: 13.74rpx;
	}
}
.add-btn {
	margin-top: 27.47rpx;
	font-size: 27.47rpx;
	color: #00bcd2;
	height: 82.42rpx;
	line-height: 82.42rpx;
	display: block;
	text-align: left;
	padding: 0 0 0 54.95rpx;
	background: #fff;
	border: none;
	border-radius: 13.74rpx;
}
</style>
