<template>
	<view class="addGoodsStyle" :style="{'height':contentHeight}">
		<view style="width: 100%;height: 100%;">
			<view style="padding: 5px 10px;background: #FFFFFF;">
				<u-search
				  action-text="搜索"
				  :focus="true"
				  :clearabled="true"
				  :show-action="true"
				  radius="40"
				  v-model="searchKey"
				  @search="searchHandler"
				  @custom="searchHandler"
				  
				></u-search>
			</view>
			
			<u-empty v-if="g.length==0" text="暂无数据" mode="data"></u-empty>
			<template v-if="g.length > 0">
				<view  
				  style="
						height: calc(100vh - 50px);
						width: calc(100vw);
						overflow: hidden;
						padding: 10px 0;
				  ">
					<scroll-view
						:scroll-y="true"
						:enable-back-to-top="true"
						:enable-flex="true"
						@scrolltolower="lower"
						:style="{ height: '100%' }">
						<view style="display: flex;flex-direction: column;align-items: center;">
							<view v-for="(item, index) in g" :key="index" class="listbox">
								<view class="box_c" >
									<image :src="item.CoverImage" style="width: 65px;height: 65px;border-radius: 6px;"></image>	
									<view style="width: calc(100vw - 30px - 65px - 15px);display: flex;flex-direction: column;margin-left: 15px;">
										<view class="box_c_name">{{item.Name}}</view>
										<view style="width:100%;height: 20px;display: flex;align-items: center;justify-content: flex-end;margin-top: 10px;">
											<view class="allEdit" @click="addGoods(item)">
												添加
											</view>
										</view>
									</view>
								</view>
								<view class="SupplierListstyle">
									<view class="Sitem" v-for="(x, index2) in item.SpecificationList" :key="index2" v-if='item.showdetail == true || index2==0' @click=" isdetail(index,index2) ">
										<view class="Sitem_gg" >
											<text v-for="(j, index3) in x.AttrList" :key="index3">{{j.attr_group_name}}:{{j.attr_name}}{{x.attr_list.length==index3+1?'':','}}</text>
										</view>
										<u-icon name="arrow" v-if='item.showdetail==false && index2==0 &&  item.SpecificationList.length>1' ></u-icon>
										<u-icon name="arrow-down" v-if='item.showdetail==true && index2==0&&  item.SpecificationList.length>1'></u-icon>
									</view>
								</view>
							</view>
						</view>
							<u-loadmore
							  :status="status"
							  :load-text="loadText"
							  :font-size="24"
							  :margin-top="20"
							  :margin-bottom="20"
							  bg-color="#f3f4f6"
							/>
					</scroll-view>
					
				</view>
			</template>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: "添加商品",
				contentHeight:0,
				mainColor:'',
				secondary:'',
				g:[],
			
				msg:{
					pageIndex: 1,
					pageSize:10,
					Id:0,
					GoodsName:'',
				},
				page_count:1,
				status: "loadmore",
				loadText: {
				  loadmore: "轻轻上拉，加载更多",
				  loading: "努力加载中",
				  nomore: "没有更多了",
				},
			}
		},
	
		created(){
			
			 this.contentHeight = this.$utils.calcContentHeight(-40)+'px';
			 this.mainColor = this.$uiConfig.mainColor;
			 this.secondary = this.$uiConfig.secondary;
			 this.init()
		},
		mounted() {
			let currentPages = getCurrentPages();
			 let u = "/" + currentPages[currentPages.length-1].route;
			 let pages = wx.getStorageSync("basedata")
			   ? wx.getStorageSync("basedata").bar_title
			   : [];
			 pages.forEach((x) => {
			   if (x.value == u) {
			     this.pageTitle = x.new_name ? x.new_name : x.name;
			   }
			 });
			 uni.setNavigationBarTitle({
			   title: this.pageTitle,
			 });
		},
		methods: {
			init(){
				
				uni.showLoading({
					title: '加载中'
				});
				this.request2(
				  {
				  	url: '/api/AppletSmallShops/GetSmallShopsChooseGoodsPageList',
				  	data: this.msg
				  },
							
				  (res) => {
					uni.hideLoading();
					let list = res.data.pageData;
					list.forEach((x)=>{
						x.showdetail = false
					})
					this.g = this.g.concat(list);
					this.page_count = res.data.pageCount;
					if (this.page_count == 1) {
					  this.status = "nomore";
					}
				  }
			);
			},
		
			isdetail(index){
				this.g[index].showdetail = !this.g[index].showdetail
			},	
			lower(e) {
			  if (this.msg.pageIndex < this.page_count) {
				this.msg.pageIndex++;
				this.status = "loading";
				this.init();
			  } else {
				this.status = "nomore";
			  }
			},
			searchHandler(val){
				this.msg.GoodsName = val;
				this.g= [];
				this.msg.pageIndex = 1;
				this.init()
			},
			addGoods(data){
				data.SpecificationList.forEach(x=>{
					x.UpPrice = 0;
					x.PriceType = 0;
				})
				let obj = encodeURIComponent(JSON.stringify(data))
				uni.navigateTo({
						url:'/pages/microShop/storeManagement/goodsEdit?data='+obj+'&type=2'
				});
			}
		}
	}
</script>

<style>
.addGoodsStyle{
	background: #f3f4f6;
	
}

	.addGoodsStyle .listbox{
		width: 100%;
		background: #fff;
		padding: 0 15px;
		margin-bottom: 15px;
		display: flex;
		flex-direction: column;
		align-items: center;
		
	}
	.addGoodsStyle .listbox .box_top{
		width: 100%;
		height: 45px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1px solid #f5f5f5;
	}
	.addGoodsStyle .listbox .box_center{
		width: 100%;
		height: 45px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		font-size: 13px;
	}
	.addGoodsStyle .center_l{
		display: flex;flex-direction: row;align-items: center;
	}
	.addGoodsStyle .listbox .box_ltext{
		width: 90px;
		margin-left: 5px;
	}
	.addGoodsStyle .listbox .l_name{
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}
	.addGoodsStyle .listbox .box_bottom{
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 15px 0 0;
		border-top: 1px solid #f5f5f5;
		font-size: 13px;
	}
	.box_bottom .b_r{
		width: calc(100vw - 30px - 50px - 20px);
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		
	}
	.addGoodsStyle .search{
		width: 100%;
		height: 50px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 0 15px;
		background: #FFFFFF;
	}
	.addGoodsStyle .listbox{
		width: 100%;
		margin-bottom: 10px;
		padding: 15px;
		background: #fff;
		display: flex;
		flex-direction: column;
		align-items: center
		
	}
	.addGoodsStyle .box_c{
		display: flex;
		flex-direction: row;
		width: 100%;
		overflow: hidden;
		margin-top: 15px;
	}
	.addGoodsStyle .box_c_name{
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		-webkit-box-orient: vertical;
		font-size: 13px;
		color: #111111;
	}
	.addGoodsStyle .SupplierListstyle{
		width: 100%;
		background: #F8F6F5;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 10px;
	}
	.addGoodsStyle .Sitem{
		width: 96%;
		display: flex;
		flex-direction: row;
		align-items: center;
		font-size: 11px;
		color: #888888;
		height: 35px;
		margin-left: 2%;
		
	}
	.addGoodsStyle .Sitem_gg{
		width: 90%;
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		line-clamp: 1;
		-webkit-box-orient: vertical;
	}
	
	.addGoodsStyle .allEdit{
		width: 60px;
		height: 20px;
		border-radius: 10px;
		background: #FF4048;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #FFFFFF;
		font-size: 12px;
	}
	
</style>
