<template>
	<view id="page">
		<!-- 顶部 -->
		<view class="top">
			<NavBar ref="nav" navTitle=" " :showIcon="false" :start-change-height="page.startHeight"
				:end-change-height="page.endHeight">
			</NavBar>
		</view>
		<!-- 功能区 -->
		<view class="func-area">
			<view class="center">
				<!-- 左侧菜单区 -->
				<view class="menu-area">
<!-- 					<text style="font-weight: 600;font-family: sans-serif;
					color: #333;
					font-size: 15px;
					padding-top: 15px;
					padding-bottom: 15px;
					margin-top: -20px;
					text-align: center;">菜窖分类</text> -->

<!-- 					<scroll-view scroll-y="true" style="height: 100%; width: 100%;border-bottom-left-radius: 25px;"
						:scroll-top="scrollLeftTop" bindscrolltoupper="upper" bindscrolltolower="lower"
						:show-scrollbar="false" :enhanced="true" bindscroll="scroll">
						<view
							style="width: 100%;height: 100%;; display: flex;flex-direction: column; background: #F7F7F7;border-bottom-left-radius: 25px;">
							<view v-for="(item,index) in data" @click="labelClick(index,item)"
								style="display: flex;flex-direction: column;justify-content: center; margin-bottom: 15px; position: relative;">

								<text class="label" :class="{ label2: selectIndex==index }">{{item.name}}</text>

								<view v-if="item.count>0" style="border-radius: 50%;text-align: center;background: #f00;color: #fff;font-size: 8px;
								position: absolute;
								  top: 8px;
								  right: 3px;
								  padding: 2px 5px;
								  width: auto;">{{item.count}}</view>
							</view>

						</view>
					</scroll-view> -->
					<!-- 左侧菜单列表 -->
					<scroll-view scroll-y="true" style="height: 100%; width: 100%;border-bottom-left-radius: 25px;"
						:scroll-top="scrollLeftTop" bindscrolltoupper="upper" bindscrolltolower="lower"
						:show-scrollbar="false" :enhanced="true" bindscroll="scroll">
						<view class="menu">
							<view v-for="(item,index) in data" @click="labelClick(index,item)"	class="method">
								<text class="label" :class="{'label-selected':selectIndex==index}">{{item.name}}</text>
								<view v-if="item.count>0" class="goods-count">{{item.count}}</view>
							</view>
						</view>
					</scroll-view>

				</view>
				
				<view style="width: 78%;background-color: #fff;overflow-y: auto;">
					<scroll-view scroll-y="true" style="height: 100%;  width: 100%;" bindscrolltoupper="upper"
						bindscrolltolower="lower" bindscroll="scroll" :show-scrollbar="false"
						:scroll-top="scrollRightTop" :enhanced="true">

						<view style="width: 100%; display: flex;flex-direction: column;">
							<view v-for="(item,index) in goods" @click="itemClick(item.goodsSid)"
								style="display: flex;flex-direction: column;justify-content: center;width: 100%; margin-top: 15px; ">

								<view style="display: flex;flex-direction: row;align-items: center;width: 100%;  ">

									<image :src="item.iconUrl" style="width: 90px;height: 90px; border-radius: 10px; "
										mode="aspectFill"></image>

									<view
										style="display: flex;flex-direction: column;flex: 1;  padding-bottom: 15px; margin-left: 10px;"
										:style="{'border-bottom':(index == goods.length-1 ? 'none' : '1px #EFEFEF solid')}">

										<text style="font-size: 13px;color: #000;">{{item.name}}</text>

										<text
											style="font-size: 10px;color: #999;margin-top: 5px;">{{item.remark}}</text>

										<view
											style="display: flex;flex-direction: row;align-items: center;margin-top: 8px;">
											<text
												style="border: 1px #EE752F solid; border-radius: 5px;	padding: 0px 8px;
											font-size: 10px;color: #EE752F;  margin-right: 10px; ">{{item.weight}}{{item.specificationUnit}}/{{item.unitName}}</text>

											<text
												style="border: 1px #EE752F solid; background: #FF9900; color: #fff; font-size: 10px;border-radius: 5px;	padding: 0px 8px;"
												v-if="item.type=='0'">百姓菜!</text>
											<text
												style="border: 1px #3AA15F solid; background: #40C772; color: #fff; font-size: 10px;border-radius: 5px;	padding: 0px 8px;"
												v-if="item.type=='1'">精品菜!</text>
											<text
												style="border: 1px #1D60C7 solid; background: #2489F7; color: #fff; font-size: 10px;border-radius: 5px;	padding: 0px 8px;"
												v-if="item.type=='2'">企业菜!</text>

										</view>

										<view style="display: flex;flex-direction: row;align-items: center;justify-content: space-between; margin-top: 15px;
										margin-right: 15px;">


											<view style="display: flex;flex-direction: row;align-items: center;">
												<text style="font-size: 12px;color: #666;">存量：</text>
												<text
													style="font-size: 14px;color: #FF5006;">{{item.goodsNumber}}{{item.unitName}}</text>
											</view>



											<view style="display: flex;flex-direction: row;align-items: center;">

												<image src="../../static/jian_icon.png" mode="aspectFill"
													style="width: 20px;height: 20px;" @click.stop="jian(item)"></image>

												<text
													style="font-size: 14px;margin-left: 8px;margin-right: 8px;">{{item.count}}</text>
												<image src="../../static/jia_icon.png" mode="aspectFill"
													style="width: 20px;height: 20px;" @click.stop="jia(item)"></image>

											</view>

										</view>

									</view>

								</view>

							</view>

							<view v-if="notData"
								style="display: flex;flex-direction: column;justify-content: center;align-items: center;">

								<image src="https://supervise.yxtsoft.com/lpk/image/buchongcaijiao.png"
								mode="aspectFit" style="width: 50vw;height: 50vw;"></image>
								<view style="display: flex;flex-direction: row;align-items: center;margin-top: 15px;">
									<text style="font-size: 14px; color: #666;margin-right: 5px;">您的菜窖为空,请</text>
									<text
										style="background: #FF9900; border-radius: 8px; padding: 3px 8px; color: #fff;"
										@click="gotoShopp()">补充菜窖</text>
								</view>
							</view>

						</view>
					</scroll-view>

				</view>

			</view>

			<view style="display: flex;flex-direction: column;border-top: 1px solid #F8F8F8; border-bottom-left-radius: 25px;border-bottom-right-radius: 25px;
			padding-top: 5px; flex-shrink: 0; ">

				<view
					style="display: flex;flex-direction: row; justify-content: center;align-items: center;padding-bottom: 10px;margin-top: 5px;">

					<text style="background: #FF9900; color: #fff;font-size: 13px; padding: 8px 15px;
					border: 1px #FF5006 solid; border-top-left-radius: 25px; border-bottom-left-radius: 25px;">转赠亲友</text>

					<view style="border: 1px #FF5006 solid;margin-left: 5px;margin-right: 5px;padding: 5px 10px;
					display: flex;flex-direction: row;align-items: center;" @click="gotoCart()">
						<image src="../../static/shoppCart_icon.png" mode="aspectFill"
							style="height: 20px;width: 25px;"></image>
						<text style="font-size: 12px;color: #666;margin-left: 10px; ">共选</text>
						<text style="font-size: 15px;color: #FF5006;margin-left: 10px; ">{{page.count}}</text>
						<text style="font-size: 12px;color: #666;margin-left: 10px; ">份蔬菜</text>
					</view>
					<text style="background: #FF9900; color: #fff;font-size: 13px; padding: 8px 15px;
					border: 1px #FF5006 solid; border-top-right-radius: 25px; border-bottom-right-radius: 25px;"
						@click="reservation()">预约提菜</text>

				</view>

			</view>



			<!-- 弹窗蒙版 -->
			<view class="model" catchtouchmove='preventTouchMove' v-if='showModal' @click.stop="colseDialog()"></view>
			<view class="modalDlg" catchtouchmove='preventTouchMove' v-if='showModal'>

				<scroll-view scroll-y="true" style="min-height: calc(100% - 50px);; padding-top: 10px;"
					bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll">

					<view style="display: flex;flex-direction: column; margin: 20px;padding-top: 10px;">

						<view
							style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;">

							<text
								style="font-size: 16px; color: #333; font-weight: 600; font-family: sans-serif;">提菜点信息</text>

							<view style="display: flex;flex-direction: row;align-items: center;">
								<text v-if="pickingUp.name==''"
									style="font-size: 14px;color: #666;margin-right: 10px;">{{pickingUp.type}}</text>
								<text v-if="pickingUp.name!=''"
									style="font-size: 16px;color: #333;margin-right: 10px;">{{pickingUp.name}}</text>
								<image src="../../static/right_icon.png" mode="aspectFill"
									style="width: 20px;height: 20px;"></image>
							</view>

						</view>

						<view v-if="pickingUp.name!=''" style="display: flex;flex-direction: column;">

							<view style="display: flex;flex-direction: row;align-items: center;margin-top: 15px;">
								<image src="https://supervise.yxtsoft.com/lpk/image/date.png"
									style="width:20px;height: 20px;"></image>
								<text
									style="margin-left: 5px;flex: 1;color: #666;font-size: 14px;">营业时间:{{pickingUp.date}}</text>

							</view>

							<view style="display: flex;flex-direction: row;align-items: center;margin-top: 15px;">
								<image src="https://supervise.yxtsoft.com/lpk/image/location.png"
									style="width: 20px;height: 20px;"></image>
								<text
									style="margin-left: 5px;flex: 1; color: #666;font-size: 14px;">{{pickingUp.address}}</text>

							</view>

						</view>


						<view
							style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;margin-top: 20px;">

							<text
								style="font-size: 16px; color: #333; font-weight: 600; font-family: sans-serif;">提菜人信息</text>

							<view style="display: flex;flex-direction: row;align-items: center;">
								<text v-if="userInfo.name==''"
									style="font-size: 14px;color: #666;margin-right: 10px;">{{userInfo.type}}</text>
								<text v-if="userInfo.name!=''"
									style="font-size: 16px;color: #333;margin-right: 10px;">{{userInfo.name}}</text>
								<text v-if="userInfo.phone!=''"
									style="font-size: 14px;color: #666;margin-right: 10px;">{{userInfo.phone}}</text>
								<image src="../../static/right_icon.png" mode="aspectFill"
									style="width: 20px;height: 20px;"></image>
							</view>

						</view>


						<view style="display: flex;flex-direction: column;margin-top: 20px;">

							<text
								style="font-size: 16px; color: #333; font-weight: 600; font-family: sans-serif;">所提蔬菜列表</text>

							<view style="width: 100%; display: flex;flex-direction: column;">
								<view v-for="(item,index) in pickingUpGoods" @click="itemClick(item.goodsSid)"
									style="display: flex;flex-direction: column;justify-content: center;width: 100%; margin-top: 15px; ">

									<view style="display: flex;flex-direction: row;align-items: center;width: 100%;  ">

										<image :src="item.iconUrl"
											style="width: 90px;height: 90px; border-radius: 10px; " mode="aspectFill">
										</image>

										<view
											style="display: flex;flex-direction: column;flex: 1;  padding-bottom: 15px; margin-left: 10px;"
											:style="{'border-bottom':(index == pickingUpGoods.length-1 ? 'none' : '1px #EFEFEF solid')}">

											<text style="font-size: 13px;color: #000;">{{item.name}}</text>

											<text
												style="font-size: 10px;color: #999;margin-top: 5px;">{{item.remark}}</text>

											<view
												style="display: flex;flex-direction: row;align-items: center;margin-top: 8px;">
												<text
													style="border: 1px #EE752F solid; border-radius: 5px;	padding: 0px 8px;
												font-size: 10px;color: #EE752F;  margin-right: 10px; ">{{item.weight}}{{item.specificationUnit}}/{{item.unitName}}</text>

												<text
													style="border: 1px #EE752F solid; background: #FF9900; color: #fff; font-size: 10px;border-radius: 5px;	padding: 0px 8px;"
													v-if="item.type=='0'">百姓菜!</text>
												<text
													style="border: 1px #3AA15F solid; background: #40C772; color: #fff; font-size: 10px;border-radius: 5px;	padding: 0px 8px;"
													v-if="item.type=='1'">精品菜!</text>
												<text
													style="border: 1px #1D60C7 solid; background: #2489F7; color: #fff; font-size: 10px;border-radius: 5px;	padding: 0px 8px;"
													v-if="item.type=='2'">企业菜!</text>

											</view>

											<view style="display: flex;flex-direction: row;align-items: center;justify-content: space-between; margin-top: 15px;
											margin-right: 15px;">


												<view style="display: flex;flex-direction: row;align-items: center;">
													<text style="font-size: 12px;color: #FF5006;">剩余：</text>
													<text
														style="font-size: 14px;color: #FF5006;">{{item.goodsNumber}}{{item.unitName}}</text>
												</view>



												<view style="display: flex;flex-direction: row;align-items: center;">

													<image src="../../static/jian_icon.png" mode="aspectFill"
														style="width: 20px;height: 20px;" @click.stop="jian(item)">
													</image>

													<text
														style="font-size: 14px;margin-left: 8px;margin-right: 8px;">{{item.count}}</text>
													<image src="../../static/jia_icon.png" mode="aspectFill"
														style="width: 20px;height: 20px;" @click.stop="jia(item)">
													</image>

												</view>

											</view>

										</view>

									</view>

								</view>

							</view>

						</view>

						<view style="height: 150px;"></view>

						<text style="background: #FF9900;color: #fff; margin-left: 20px; margin-right: 20px;border-radius: 20px;
						padding-top: 10px;padding-bottom: 10px;text-align: center;">确认提菜</text>

						<view style="height: 80px;"></view>

					</view>

				</scroll-view>
			</view>


		</view>

	</view>

</template>

<script>
	export default {
		data() {
			return {
				notData: false,
				showModal: false,
				scrollHeight: "",
				scrollLeftTop: "0",
				scrollRightTop: "0",
				brandType: "0",
				styleObject: {
					// 'position': 'fixed',
					// 'top':'80vw',
					'margin-top': '62vw',
					'border-top-left-radius': '25px',
					'border-top-right-radius': '25px',
					'border-bottom-left-radius': '25px',
					'border-bottom-right-radius': '25px',
					'background': '#fff',
					'padding-top': '10px',
					'margin-bottom': "60px"

				},
				page: {
					count: "0",
					startHeight: 0,
					endHeight: 0
				},
				data: [],
				goods: [],
				selectIndex: 0,
				pickingUp: {
					type: "去完善",
					name: "",
					date: "",
					address: ""
				},
				userInfo: {
					type: "去完善",
					name: "",
					phone: ""
				},
				pickingUpGoods: [

				]

			}
		},
		onShow() {
			if (typeof this.$mp.page.getTabBar === 'function' && this.$mp.page.getTabBar()) {
				this.$mp.page.getTabBar().setData({
					selected: 1
				})

			}
			
				this.request()
				this.page.count=0
		},
		onHide() {
			this.colseDialog()
		},

		onLoad() {

			let info = uni.getSystemInfoSync();

			this.page.startHeight = info.windowWidth * 0.6
			this.page.endHeight = info.windowWidth * 0.8

		

		},
		methods: {
			labelClick(index, item) {
				this.selectIndex = index
				this.brandType = item.sid
				this.pickingUpGoods = []
				this.page.count = 0
				this.getgoods()

			},
			request() {
				let _this = this
				var params = {
					customerSid: getApp().globalData.sid
				}

				_this.$api.vegeCellarTypeList(params).then((resp) => {
					_this.data = resp
					_this.selectIndex = 0
					_this.getgoods()
					_this.scrollLeftTop = _this.scrollLeftTop == 0 ? -1 : 0
					_this.scrollRightTop = _this.scrollRightTop == 0 ? -1 : 0
				}).catch(e => {})
			},
			getgoods() {
				let _this = this

				var params = {
					customerSid: getApp().globalData.sid,
					affiliation: this.brandType
				}

				_this.$api.vegeCellarList(params).then((resp) => {
					_this.goods = resp

					_this.notData = resp.length == 0
				}).catch(e => {})
			},
			jian(item) {
				if (Number(item.count) > 0) {
					item.count = Number(item.count) - 1
					this.addGoods(item)
				}
				this.getcount()
			},
			jia(item) {
				item.count = Number(item.count) + 1
				this.getcount()
				this.addGoods(item)
			},

			getcount() {

				let num = 0;
				for (var i = 0; i < this.goods.length; i++) {
					num += Number(this.goods[i].count);
				}

				this.page.count = num
			},

			addGoods(goods) {

				var item = this.pickingUpGoods.find(item => item.goodsSid == goods.goodsSid)

				if (item) {

					if (goods.count == 0) {
						var index = this.pickingUpGoods.findIndex(item => item.goodsSid == goods.goodsSid)
						this.pickingUpGoods.splice(index, 1)
					} else {
						item.count = goods.count
					}

				} else {
					this.pickingUpGoods.push(goods)

				}

			},

			itemClick(goodsSid) {
				uni.navigateTo({
					url: '/pages/good/goodsDetail?sid=' + goodsSid
				})
			},

			gotoShopp() {
				uni.switchTab({
					url: '/pages/home/cloudCard2',
				})
			},
			reservation() {
				if (this.pickingUpGoods.length > 0){
					
					uni.navigateTo({
						url: '/pages/good/reservation?pickingUpGoods='+JSON.stringify(this.pickingUpGoods)+"&affiliation="+this.brandType,
					})
					
					// this.showModal = true
				}else{
					this.shortToast('请先选择商品')
				}
					
			},
			colseDialog() {
				this.showModal = false
			}
		}
	}
</script>

<style>
	
	#page{
		display: flex;
		flex-direction: column;
		height: 100vh;
		background: -webkit-linear-gradient(left,#FEA65F,#FB9440);
	}
	/* 顶部 */
	.top {
		width: 100vw;
		/* height: 126.66vw; */
		height: 50vw;
		/* 加载背景图 */
		background-image: url(https://supervise.yxtsoft.com/lpk/image/clound_bj1.png);
		/* background-image: url(../../static/clound_bj1.png); */
		/* 让背景图基于容器大小伸缩 */
		background-size: 100% 100%;
	}
	/* 功能区 */
    .func-area{
		background: #fff; 
		height: calc(100vh - 45px - 50vw);
		width: 100%; 
		border-radius: 15px;
		display: flex;
		flex-direction: column; 
		box-sizing: border-box;
		margin-top: -15px;
		box-sizing: border-box;
	}
	/* 功能区-菜单区 */
	.func-area .menu-area{
        width: 22%;
		display: flex;
		flex-direction: column;
		overflow-y: auto;
		padding-top: 10px;
    }
	
	/* 功能区-菜单区-菜单 */
	.func-area .menu-area .menu{
		width: 100%;
		display: flex;
		flex-direction: column; 
	}
	
	/* 功能区-菜单区-菜单-显示方法 */
	.func-area .menu-area .menu .method{
		display: flex;
		flex-direction: column;
		justify-content: center;
	}
	
	/* 功能区-菜单区-菜单-标签 */
	.func-area .menu-area .menu .label{
		color: #191919;
		font-size: 12px;
		margin-top: 10px;
		margin-bottom: 10px;
		text-align: center;
		padding-top: 7px;
		padding-bottom: 7px;
		margin-left: 5px;
	}
	/* 功能区-菜单区-菜单-标签选中 */
	.func-area .menu-area .menu .label-selected{
		background: #FFF;
		color: #FFF;
		background-color: #FF9900;
		font-size: 12px;
		margin-top: 10px;
		margin-bottom: 10px;
		padding-top: 7px;
		padding-bottom: 7px;
		text-align: center;
		font-weight: bold;
		border-radius: 20px;
		margin-left: 5px;
	}
	/* 功能区-菜单区-菜单-商品数量 */
	.func-area .menu-area .menu .goods-count{
	    border-radius: 50%;
		text-align: center;
		background: #f00;
		color: #fff;
		font-size: 8px;
	    position: absolute;
	    top: 8px;
	    right: 3px;
	    padding: 2px 5px;
	    width: auto;
	}
/* 	.label {
		background: #fff;
		color: #FF9900;
		font-size: 13px;
		padding-top: 15px;
		padding-bottom: 15px;
		text-align: center;
	}
	.label2 {
	
		background: #FF9900;
		color: #fff;
		font-size: 13px;
		padding-top: 15px;
		padding-bottom: 15px;
		text-align: center;
	} */

	.center {
		display: flex;
		flex-direction: row;
		flex: 1;
		background-color: #f7f7f7;
		border-radius: 15px;
		overflow: hidden;
		min-width: 0;
	}

	/* 弹窗样式 */
	.model {
		position: absolute;
		width: 100%;
		height: 100%;
		background: #000;
		z-index: 999;
		opacity: 0.5;
		top: 0;
		left: 0;
		bottom: 65;
	}

	.modalDlg {
		/* 设置超出滚动 */
		overflow: auto;
		width: 100%;
		position: fixed;
		top: 50vw;
		left: 0;
		right: 0;
		z-index: 9999;
		opacity:1;
		background-color: #fff;
		border-top-right-radius: 20px;
		border-top-left-radius: 20px;
		display: flex;
		flex-direction: column;


	}
</style>