<template>
	<view class="brandSearch">
		<view style="width: 100%;padding: 5px 15px;">
			<u-search shape="round" :clearabled="true" @change="search" v-model="keyword" @custom="search"></u-search>
			<view v-if='BrandClassList.length>0'>
				<scroll-view scroll-y="true" style="height: calc(100vh - 50px);">
					<view v-for="(x,y) in BrandClassList" class="box" @click="huoquId(x)">
						<view style="display: flex;align-items: flex-end;white-space: nowrap;text-overflow: ellipsis;overflow: hidden">
							<span style='font-size: 14px;font-family: PingFang SC;font-weight: bold;color: #1F1F1F;'>{{type ==1?x.BrandName:x.CarrierName}}</span>
							<span style='font-size: 12px;color: #1F1F1F;' v-if='type==1'>({{x.FullBrandName}})</span>
						</view>
					</view>
				</scroll-view>
			</view>
			<u-empty v-if="BrandClassList.length==0" text="暂无数据" mode="list"></u-empty>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				keyword:'',
				BrandClassList:[],
				allBrandClassList:[],
				type:1,//1位品牌 2位载体
			}
		},
		onLoad(options) {
			if(options && options.type){
				this.type = options.type
			}
			this.getList()
		},
		created() {
			
		},
		methods:{
			getList(){
				let url = "/api/AppletTrade/GetCenterBrandList"
				let obj = {BrandName:''}
				if(this.type==2){
					url = "/api/AppletTrade/GetCenterCarrierList";
					obj = {CarrierName:''}
				}
				
				this.request2({
						url: url,
						data: obj,
					},
					(res) => {
						if (res.resultCode == 1) {
							this.BrandClassList =  res.data
							this.allBrandClassList = JSON.parse(JSON.stringify(res.data)) 
						}
					}
				);
			},
			search(){
				let val = this.keyword
				 if (val === '') {
				  this.BrandClassList = JSON.parse(JSON.stringify(this.allBrandClassList))
				} else {
				  const needle = val.toLowerCase()
				  if(this.type==1){
					  this.BrandClassList = this.allBrandClassList.filter(v => v.BrandName.toLowerCase().indexOf(needle) > -1 || v.FullBrandName.toLowerCase().indexOf(needle) > -1)
				  }else{
					  this.BrandClassList = this.allBrandClassList.filter(v => v.CarrierName.toLowerCase().indexOf(needle) > -1 )
					  
				  }
				}
				
			},
			huoquId(x){
				let pages = getCurrentPages(); // 当前页面
				let beforePage = pages[pages.length - 2]; // 前一个页面
				let that = this
				setTimeout(()=>{
					 uni.navigateBack({
						 success: function() {
							 beforePage.$vm.Children(x.ID,that.type); // 执行前一个页面的方法
						 }
					 });
				},100)
			}
		}
	}
</script>

<style>
	.brandSearch{
		width: 100%;
		height: 100vh;
		background: #F6F6F6;
	}
	.brandSearch .box{
		width: 100%;
		height: 53px;
		display: flex;
		align-items: center;
		border-bottom: 1px solid #DADCE6;
		
	}
</style>
