<template>
	<div style="background-color: #f6f6f6;height: 100vh;padding-bottom: 65px; overflow: hidden;">
		<view style="padding:5px 10px;">
			<u-search placeholder="搜索载体名称" :focus="false" :show-action="false" :clearabled="true" radius="40" v-model="searchKey"
			 @search="searchHandler" @custom="searchHandler" bg-color="#FFF" ></u-search>
		</view>
		<view style="display: flex; align-items: center;">
			<view style="flex:1;overflow: hidden;">
				<u-tabs bg-color="#f6f6f6" :is-scroll="true" name="Name" :list="typeList" :active-color="mainColor"
					:current="active" @change="changeHandler" :show-bar="true" :activeFontSize="34" :bold="true" height="100"
					duration="0" font-size="28"></u-tabs>
			</view>
			<div style="width: 64rpx;height: 48rpx;display: table-cell; vertical-align: middle;text-align: right;">
				<u-icon name="filter-o" color="#111" size="42"></u-icon>
			</div>
		</view>
		<u-empty v-if="dataList.length == 0" text="暂无数据" mode="list" class="noBox"></u-empty>
		<view style="height: calc(100% - 101px);" v-if="dataList.length > 0">
			<scroll-view :scroll-y="true" :enable-back-to-top="true" :enable-flex="true" @scrolltolower="lower"
				style="height: 100%; padding-bottom: 0px;">
				<view v-for="(item,index) in dataList" :key="index">
					<div class="good_study_one" @click="openGood(item.ID,typeList[item.ProjectType].Name)" :style="{
						borderRadius:'15px'
					}">
						<view class="img-box">
							<view class="img-show">
								<image style="
							  width: 100%;
							  height:100%;
							  border-radius: 10rpx 10rpx 0 0;
							" mode='aspectFill'
									:src="item.BannerList[0]"/>
							</view>
						</view>
						<div class="good-info">
							<div class="good-name">
								<div class="span-name">{{item.CarrierName}}</div>
								<div class="span-type">{{typeList[item.ProjectType].Name}}</div>
							</div>
							<div class="good-price-info">
								<u-icon name="location" color="#999" size="24"></u-icon>
								<span class="price" style="margin-left: 5px;">{{item.Address}}</span>
							</div>
						</div>
					</div>
				</view>
				<u-loadmore :status="status" :load-text="loadText" :font-size="24" :margin-top="20" :margin-bottom="20"
					bg-color="#F6F6F6" />
			</scroll-view>
		</view>
		<!-- 加载中 -->
		<view class="loading" v-if="loading">
			<u-loading mode="flower" size="48"></u-loading>
			<Text style="color: #f6f6f6; margin-top: 10rpx;">加载中...</Text>
		</view>
		<tabbars></tabbars>
	</div>
</template>

<script>
	import tabbars from '@/components/tabbar/index';
	export default {
		components:{
			tabbars
		},
		data() {
			return {
				mainColor: '',
				active: 0,
				searchKey:"",
				typeList: [{
					Id: 0,
					Name: '全部'
				}, {
					Id: 1,
					Name: '百货'
				}, {
					Id: 2,
					Name: 'Shopping Mall'
				}, {
					Id: 3,
					Name: '集中式街区'
				}, {
					Id: 4,
					Name: '其他'
				}],
				dataList:[],
				msg:{
					 pageIndex:1,
					 pageSize:10,
					 MetroName:"",
					 CarrierName:"",
					 MetroNum:"",
					 Developers:"",
					 StartOpenTime:"",
					 EndOpenTime:"",
					 ProjectType:1,
					 OrderBy:0
				},
				loading: false,
				pageCount:0,
				status: "loadmore",
				loadText: {
					loadmore: "轻轻上拉，加载更多",
					loading: "努力加载中",
					nomore: "没有更多了",
				},
			};
		},
		onLoad(options) {
			if(options && options.id){
				this.msg.ProjectType = options.id
			}
			
			this.getTypeList()
		},
		created() {
			this.mainColor = this.$uiConfig.mainColor;
			
			
		},
		mounted() {
			uni.setNavigationBarTitle({
				title: '载体列表',
			});
		},
		methods: {
			// 获取载体列表
			getTypeList(){
				let parms = {
					url: "/api/AppletTrade/GetProjectTypeEnumList",
				}
				this.request2(parms, (res) => {
					if (res.resultCode == 1) {
						// this.pageCount = res.data.pageCount
						this.typeList = res.data
						if(this.msg.ProjectType ==1){
							
						
						}else{//指定跳入分类
							this.typeList.map((x,i)=>{
								if(x.Id== this.msg.ProjectType){
									this.active = i;
								}
							})
						}
					}
				})
				this.getCarrierPageList()
			},
			// 获取载体分页列表
			getCarrierPageList(){
				let parms = {
					url: "/api/AppletTrade/GetCarrierPageList",
					data:this.msg
				}
				this.request2(parms, (res) => {
					this.loading = false;
					if (res.resultCode == 1) {
						this.dataList = this.dataList.concat(res.data.pageData);
						this.pageCount = res.data.pageCount
						if (this.pageCount == 1) {
							this.status = "nomore";
						}
					}
				})
			},
			changeHandler(i) {
				this.active = i;
				this.msg.ProjectType = this.typeList[i].Id;
				this.msg.pageIndex = 1;
				this.dataList= [];
				this.getCarrierPageList()
			},
			openGood(id,type) {
				uni.navigateTo({
					url: '/pages/kotra/carrier/detail?id=' + id+"&&type="+type,
				});
			},
			searchHandler(val){
				this.msg.CarrierName=val
				this.msg.pageIndex = 1;
				this.dataList= [];
				this.getCarrierPageList()
				
			},
			//触底事件
			lower(e) {
				if (this.msg.pageIndex < this.pageCount) {
					this.msg.pageIndex++;
					this.status = "loading";
					this.getCarrierPageList();
				} else {
					this.status = "nomore";
				}
			},
		}
	};
</script>

<style>
	.good_study_one {
		margin: 12px;
		position: relative;
		border: 1rpx solid transparent;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.good_study_one .tips {
		width: 64rpx;
		height: 64rpx;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 4;
	}

	.good_study_one .guding {
		position: relative;
	}

	/* .good_study_one .guding .img-box {
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
	} */
	.good_study_one .img-box {
		width: 100%;
		height: 0;
		padding-top: 49%;
		position: relative;
		overflow: hidden;
	}

	.good_study_one .img-box .img-show {
		position: absolute;
		left: 0;
		top: 0;
		bottom: 0;
		right: 0;
		width: 100%;
		height: 100%;
		overflow: hidden;
	}

	.good_study_one .good-info {
		padding: 12px;
		background-color: #fff;
	}

	.good_study_one .good-info .good-name {
		display: flex;
		align-items: center;
	}
	.good_study_one .good-info .good-name .span-name{
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		font-size: 28rpx;
		font-weight: bold;
		color: #111;
		padding-bottom: 5px;
		flex: 1;
	}
	.good_study_one .good-info .good-name .span-type{
		font-weight: 500;
		color: #999999;
		font-size: 24rpx;
		margin-left: 10px;
	}
	.good_study_one .good-info .good-price-info {
		display: flex;
	}

	.good_study_one .good-info .good-price-info .price {
		color: #999999;
		font-size: 24rpx;
		flex: 1;
	}

	.good_study_one .good-info .good-price-info .buy {
		width: 24px;
		text-align: right;
	}
</style>
