<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='业务单位' bgColor='transparent'></cus-header>
		<image class="topbg" :src="imgBase+'storage/home_bg.png'" mode="widthFix"></image>
		<div class="search">
			<u--input
				placeholder="请输入单位名称"
				border="none"
				prefixIcon="search"
				prefixIconStyle="font-size: 24px;color: #86909C"
				v-model="params.merchantName"
			></u--input>
			<div class="btn" @tap="search">搜索</div>
		</div>
		<template v-if="list.length">
			<div class="list">
				<div class="item" v-for="item in list" :key="item.id">
					<div class="name">{{item.merchantName}}</div>
					<div class="info">
						<div class="iitem">
							<div class="pre">
								<div class="title">企业类型</div>
								<div class="nr">{{merchantTypeCfg[item.merchantType]||''}}</div>
							</div>
							<div class="pre">
								<div class="title">企业编号</div>
								<div class="nr">{{item.merchantCode||''}}</div>
							</div>
						</div>
						<div class="iitem">
							<div class="pre">
								<div class="title">联系人</div>
								<div class="nr">{{item.contactPerson||''}}</div>
							</div>
							<div class="pre">
								<div class="title">职称级别</div>
								<div class="nr">{{item.merchantLevel||''}}</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</template>
		<template v-else>
			<page-empty :height="'calc(100vh - 100px)'"></page-empty>
		</template>
	</view>
</template>

<script>
	import pageEmpty from '@/components/pageEmpty/index.vue'
	export default {
		components:{ pageEmpty },
		data(){
			return {
				params:{
					page:1,
					limit:10,
					merchantName:''
				},
				merchantTypeCfg:{},
				list:[],
				isOver:false
			}
		},
		onLoad() {
			this.getMerchantType();
			this.getList();
		},
		onReachBottom() {
			if(this.isOver) return;
			this.getList();
		},
		methods:{
			async getMerchantType(){
				let res = await this.$api.get('/sys/dict/data/getListByType/merchant_type');
				if(res.data.code===0){
					res.data.data.forEach(d=>{
						this.merchantTypeCfg[+d.dictValue] = d.dictLabel;
					})
				}else this.$showToast(res.data.msg)
			},
			getList(){
				this.$api.get('/wms/merchant/page',this.params).then(res=>{
					if(res.data.code===0){
						if(this.list.length<res.data.data.total){
							this.params.page++;
							this.list = [...this.list,...res.data.data.list];
						}else this.isOver = true
					}else this.$showModal(res.data.msg)
				});
			},
			search(){
				this.params.page = 1;
				this.isOver = false;
				this.list = [];
				this.getList();
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		padding: 0 24rpx 20rpx;
		background: #F4F8FB;
		box-sizing: border-box;
		
		.topbg{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 0;
		}
		
		.search{
			width: 100%;
			height: 84rpx;
			padding: 6rpx 6rpx 6rpx 30rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			border-radius: 40rpx;
			border: 1rpx solid #198CFF;
			position: relative;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.btn{
				width: 118rpx;
				height: 68rpx;
				background: #198CFF;
				border-radius: 40rpx;
				border: 1rpx solid #198CFF;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #FFFFFF;
				line-height: 68rpx;
				text-align: center;
				letter-spacing: 2rpx;
			}
		}
		
		.list{
			width: 100%;
			position: relative;
			.item{
				width: 100%;
				padding: 36rpx 24rpx;
				box-sizing: border-box;
				margin-top: 20rpx;
				background: #FFFFFF;
				box-shadow: inset 0rpx -1rpx 0rpx 0rpx #ECECEC;
				border-radius: 16rpx;
				.name{
					font-family: PingFang-SC, PingFang-SC;
					font-weight: bold;
					font-size: 30rpx;
					color: #1D2129;
					line-height: 30rpx;
					text-align: left;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
				.info{
					.iitem{
						width: 100%;
						display: flex;
						.pre{
							width: 50%;
							margin-top: 28rpx;
							display: flex;
							align-items: center;
							.title{
								width: 116rpx;
								font-family: PingFangSC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: #86909C;
								line-height: 24rpx;
								text-align: left;
							}
							.nr{
								width: calc(100% - 116rpx);
								font-family: PingFang-SC, PingFang-SC;
								font-weight: bold;
								font-size: 28rpx;
								color: #4E5969;
								line-height: 30rpx;
								text-align: left;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}
						}
					}
				}
			}
		}
	}
</style>