<template>
	<!-- 详情 -->
	<u-popup  v-model="showPop" mode="bottom" border-radius="14" closeable height="75%">
		<view class="son-wrap">
			<view class="title">
				明细
			</view>
	
			<view class="middle">
				<view class="merchantlist" v-for="(item,index) in merchantList" :key="index">
					<view class="merchant-title">
						{{item.merchantName}}
					</view>
					<view class="productlist" v-for="(items,a) in item.productlist" :key='a'>
						<text>
							{{items.name}}
						</text>
						<text style="font-weight: bold;">
							¥{{items.sellingPrice}}
						</text>
					</view>
				</view>
			</view>
	
			<view class="bottom">
				<view class="bottom-left">
					合计：¥ 
					<text style="font-size: 36rpx;font-weight: bold;">{{priceTotal}}</text> 
				</view>
				<view class="bottom-right">
					<text class="btn" @click="goFillorder()">
						去预订
					</text>
				</view>
			</view>
		</view>
	</u-popup>
</template>

<script>
export default {
  props: ['chooseProduct'],
  data() {
    return {
      showPop: false, //控制弹窗显示隐藏
      priceTotal:0,//总价
      merchantList:[],//商家列表
    }
  },
  watch: {
    //选中产品的数量变化
    chooseProduct: { 
      handler(newValue, oldValue){
        this.priceTotal=0
        this.chooseProduct.forEach((item)=>{
          this.priceTotal+=item.sellingPrice
        })
        this.priceTotal=parseFloat(this.priceTotal.toFixed(2))
        this.merchantList=[]
        this.chooseProduct.forEach(item=>{
				  if(!this.merchantList.find(item2=>item2.merchantId==item.merchantId)){
				    this.merchantList.push({
				      merchantName:item.merchantName,
				      merchantId:item.merchantId,
				      productlist:[]
				    })
				  }
        })
        //一级数组转化成二级数组
        this.merchantList.forEach(item=>{
				  this.chooseProduct.forEach(item2=>{
				    if(item.merchantId==item2.merchantId){
				      item.productlist.push(item2)
				    }
				  })
        })
      },
      deep:true,
      immediate: false
    },
  },
  methods: {
    //---跳转填写订单页面
    goFillorder(){
      this.$parent.goFillorder()
    }
  }
}
</script>

<style scoped="scoped" lang="scss">
.son-wrap{
	position: relative;
}	
.title{
	text-align: center;
	font-size: 32rpx;
	font-weight: bold;
	text-align: center;
	padding: 30rpx 0;
	position:fixed;
	top: 0;
	width: 100%;
	background: #fff;
	z-index: 1;	
}
.middle {
	padding: 100rpx 24rpx;
}
.merchantlist{
	border-bottom:2rpx solid #ececec;
	padding-bottom: 40rpx;
	margin-top: 24rpx;
}
.merchant-title{
	font-size: 36rpx;
	font-weight: bold;
	color: #191919;
}
.productlist{
	display: flex;
	justify-content: space-between;
	font-size: 32rpx;
	margin-top: 20rpx;
}
.bottom {
	display: flex;
	justify-content: space-between;
	padding: 0 24rpx;
	height: 100rpx;
	align-items: center;
	position: fixed;
	bottom: 0;
	width: 100%;
	z-index: 9;
	background: #FFFFFF;
	box-sizing: border-box;
}
.bottom-left{
	color:$red;
}
.btn{
	padding: 16rpx 48rpx;
	border-radius: 20rpx;
	font-size: 32rpx;
}
</style>
