<template>
	<view class="">
		<uni-popup ref="popup" type="bottom" background-color="#fff">
			<view class="popbox">
				<view class="listwarp">
					<view class="censear">
						<image :src="BASE_IMG_URL+'ss.png'" class="searimg" ></image>
						<input type="text" placeholder="请输入关键词搜索" @input="queryData" class="lself" placeholder-style="color:#999">
					</view>
					<scroll-view scroll-y class="listscroll">
						<view class="liwarp" v-for="(item,index) in list" :key="index" @click="selectItem(item)">
							<view class="warpleft">
								<view class="name">{{item.name}}</view>
							</view>
							<label class="radio"><radio value="r1" style="transform: scale(0.7);" color="#008EFF" :checked="sureObj.id == item.id" /></label>
						</view>
						<view class="noData" v-if="list.length == 0">暂无数据</view>
					</scroll-view>
				</view>
				<view class="btnlist">
					<view class="btn secbtn" @click="close">取消</view>
					<view class="btn firbtn" @click="sure">确定</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import { BASE_IMG_URL } from '@/util/api.js'
	import { netProductClass } from '@/api/kehu.js'
	
	export default{
		data() {
			return{
				BASE_IMG_URL:BASE_IMG_URL,
				list:[],
				name:'',  //搜索关键字
				sureObj:{}
			}
		},
		methods:{
			open() {
				this.$refs.popup.open()
				//获取分类
				this.getList()
			},
			getList() {
				let params = {
					name:this.name
				}
				netProductClass(params).then(res=>{
					this.list = res.data
				})
			},
			queryData(e){
				this.name = e.detail.value
				this.getList()
			},
			close() {
				this.$refs.popup.close()
			},
			selectItem(item) {
				if(item.id == this.sureObj.id){
					this.sureObj = {}
				}else{
					this.sureObj = item
				}
			},
			sure() {
				this.$emit('sure',this.sureObj)
				this.close()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.popbox{
		background:#fff;
		padding:20rpx 24rpx;
		width:750rpx;
		.listwarp{
			width:702rpx;
			.censear{
				display: flex;
				justify-content: flex-start;
				align-items: center;
				padding:0 24rpx;
				border-radius: 34rpx;
				background:#f5f5f5;
				width:690rpx;
				height:68rpx;
				margin:0 auto 24rpx;
				.searimg{
					padding-right: 15rpx;
					width:35rpx;
					height:35rpx;
				}
				.lself{
					font-size:26rpx;
					width:640rpx;
				}
			}
			.listscroll{
				width:100%;
				height:600rpx;
				background:#f5f5f5;
				.liwarp{
					width:640rpx;
					padding:20rpx 30rpx;
					margin:20rpx auto;
					background:#fff;
					border-radius: 10rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					.warpleft{
						flex: 1;
						.name{
							font-size:24rpx;
							color:#333;
						}
						.number{
							font-size:24rpx;
							color:#999;
							margin:15rpx 0;
						}
						.guishu{
							font-size:24rpx;
							color:#666;
						}
					}
				}
				.noData{
					font-size:26rpx;
					color:#666;
					text-align: center;
					padding-top:100rpx;
				}
			}
		}
		.btnlist{
			width:750rpx;
			display: flex;
			justify-content: space-around;
			padding:30rpx 0;
			.btn{
				width:200rpx;
				height:60rpx;
				border-radius: 30rpx;
				font-size:24rpx;
				color:#fff;
				text-align: center;
				line-height: 60rpx;
			}
			.firbtn{
				background:$uni-text-color;
			}
			.secbtn{
				background:#ff7800;
			}
		}
	}
</style>