USER-20230908AJ\Administrator 2 лет назад
Родитель
Сommit
e989ac466a
1 измененных файлов с 123 добавлено и 109 удалено
  1. 123 109
      pages-takeout/shop-mod/menu.vue

+ 123 - 109
pages-takeout/shop-mod/menu.vue

@@ -55,21 +55,21 @@
 					</view>
 				</view>
 				<view class="goods-info flex-justify-space mb-32 box-border-box plr-32">
-					<image src="@/static/img/my/bg.png" mode="scaleToFill"></image>
+					<image v-if="popData.goodsItem.goods_image" :src="popData.goodsItem.goods_image" mode="scaleToFill"></image>
 					<view class="flex-1">
-						<view style="width: 446rpx;" class="fw-600 fs-34 text-overflow-ellipsis-one">[畅销款]奥尔1良烤肉牛油拌饭
+						<view style="width: 446rpx;" class="fw-600 fs-34 text-overflow-ellipsis-one">{{popData.goodsItem.goods_name}}
 						</view>
-						<view class="fw-400 fc-9 fs-24">月销196</view>
+						<view class="fw-400 fc-9 fs-24">月销{{popData.goodsItem.sales}}</view>
 					</view>
 				</view>
 
 				<view class="scroll-view-css box-border-box plr-32">
-					<view class="" v-for="(item,i) in popData.specList" :key="i">
-						<view class="fs-32 fw-500 fc-0 mb-32">{{item.specName}}</view>
+					<view class="" v-for="(item,i) in popData.spec_attr" :key="i">
+						<view class="fs-32 fw-500 fc-0 mb-32">{{item.group_name}}</view>
 						<view class="flex-wrap-wrap">
-							<view class="spec-item text-align-center fs-28" :class="info.isSelect?'s-item':'n-item'"
-								v-for="(info,k) in item.list" :key="k" @click="select(i,k,item,info)">
-								{{info.name}}
+							<view class="spec-item text-align-center fs-28" :class="popData.spec_ids.indexOf(info.item_id)>=0?'s-item':'n-item'"
+								v-for="(info,k) in item.spec_items" :key="k" @click="selectSpec(info,i)">
+								{{info.spec_value}}
 							</view>
 						</view>
 
@@ -81,20 +81,20 @@
 						<view class="pop-buttom-left">
 							<view class="">
 								<span class="fw-600 fs-32 fc-ED301D">¥</span>
-								<span class="fw-600 fs-48 fc-ED301D">19.26</span>
+								<span class="fw-600 fs-48 fc-ED301D">{{popData.price}}</span>
 							</view>
 							<view class="">
 								<span class="fw-400 fs-24 fc-9">已选规格:</span>
-								<span class="fw-400 fs-24">不辣</span>
+								<span class="fw-400 fs-24">{{popData.spec_name.join(';')}}</span>
 							</view>
 						</view>
 						<view class="display-flex align-items-center">
-							<view class="right-only-right-red fw-500 text-align-center fs-36 fc-f">-</view>
-							<view class="right-only-right-2 text-align-center fs-28 fw-400">1</view>
-							<view class="right-only-right-add fw-500 text-align-center fs-36 fc-f">+</view>
+							<view class="right-only-right-red fw-500 text-align-center fs-36 fc-f" @click.stop="setSpecNum(1)">-</view>
+							<view class="right-only-right-2 text-align-center fs-28 fw-400">{{popData.num}}</view>
+							<view class="right-only-right-add fw-500 text-align-center fs-36 fc-f" @click.stop="setSpecNum(2)">+</view>
 						</view>
 					</view>
-					<view class="pop-buttom-2  text-align-center fs-32 fw-600 fc-f">选好了</view>
+					<view class="pop-buttom-2  text-align-center fs-32 fw-600 fc-f" @click="addred(4)">选好了</view>
 				</view>
 			</view>
 		</uni-popup>
@@ -103,7 +103,7 @@
 
 <script>
 	import tools from "@/service/tools";
-  import {shopCategory, shopGoods} from "@/api/shop";
+  import {shopCategory, shopGoods, shopGoodsSpec} from "@/api/shop";
   import {getShopIngList, setShopIngAdd, setShopIngDel, setShopIngNumber} from "@/api/shopping";
 	export default {
 		name: 'menu-box',
@@ -135,73 +135,18 @@
         operate_id: '',
 
 				popData: {
-					spec_name: '',
-					spec_ids: '',
-					spec_list: [],
-					specList: [{
-							specName: '口味',
-							specType: 1,
-							list: [{
-								name: '辣1',
-								id: 1,
-								isSelect: false
-							}, {
-								name: '辣2',
-								id: 2,
-								isSelect: false
-							}, {
-								name: '辣3',
-								id: 3,
-								isSelect: false
-							}, {
-								name: '辣4',
-								id: 4,
-								isSelect: false
-							}, ]
-						},
-						{
-							specName: '大小',
-							specType: 2,
-							list: [{
-								name: '大1',
-								id: 5,
-								isSelect: false
-							}, {
-								name: '大2',
-								id: 6,
-								isSelect: false
-							}, {
-								name: '大3',
-								id: 7,
-								isSelect: false
-							}, {
-								name: '大4',
-								id: 8,
-								isSelect: false
-							}, ]
-						},
-						{
-							specName: '加料',
-							specType: 3,
-							list: [{
-								name: '加1',
-								id: 9,
-								isSelect: false
-							}, {
-								name: '加2',
-								id: 10,
-								isSelect: false
-							}, {
-								name: '加3',
-								id: 11,
-								isSelect: false
-							}, {
-								name: '加4',
-								id: 12,
-								isSelect: false
-							}, ]
-						},
-					]
+					goodsItem: {},
+          price: '0.00',
+          line_price: '',
+          num: 0,
+					goods_id: '',
+          spec_key: '',
+          goods_spec_id: '',
+					spec_name: [],
+					spec_ids: [],
+          spec_list: [],
+          spec_attr: [],
+
 				},
 			}
 		},
@@ -217,6 +162,76 @@
 
 		},
 		methods: {
+      setSpecNum(type){
+        console.log(this.popData.goods_spec_id)
+        if(this.isAjax){
+          return
+        }
+        this.isAjax=true
+        if (type === 1) {
+          // 减
+          if(this.popData.num>0){
+            --this.popData.num;
+          }else {
+            this.isAjax=false
+            return
+          }
+        } else {
+          // 加
+          ++this.popData.num;
+        }
+        let cartKey=this.cartData.goods_list.findIndex(row=>this.popData.goods_spec_id===row.goods_spec_id)
+        console.log(cartKey)
+        console.log(type===2 && cartKey<0)
+        if(type===2 && cartKey<0){
+          this.popData.num++
+          this.setShopIngAdd(this.popData.goods_id,this.popData.goodsItem.category_id,this.popData.goods_spec_id)
+        }else {
+          this.setShopIngNumber(this.popData.goods_id,this.popData.goodsItem.category_id,type,this.popData.goods_spec_id)
+        }
+      },
+      getShopGoodsSpec(item){
+        shopGoodsSpec({
+          'goods_id':item.goods_id
+        }).then(res=>{
+          this.popData.goodsItem=item
+          if(this.popData.goods_id!==item.goods_id){
+            this.popData.goods_id=item.goods_id
+            this.popData.spec_name=[]
+            this.popData.price='0.00'
+            this.popData.line_price=''
+            this.popData.spec_key=''
+            this.popData.num=0
+            this.popData.spec_ids=[]
+          }
+          this.popData.spec_list=res.data.spec_list
+          this.popData.spec_attr=res.data.spec_attr
+          this.$refs.popupGG.open();
+          this.setGoodsSpecPrice()
+          this.isAjax=false
+        }).catch(()=>{
+          tools.error('规格信息异常')
+          this.isAjax=false
+        })
+      },
+      setGoodsSpecPrice(){
+        if(this.popData.spec_ids.length>0){
+          let spec_ids=JSON.parse(JSON.stringify(this.popData.spec_ids))
+          spec_ids.sort((a, b) => a - b);
+          let spec_key=spec_ids.join('_')
+          this.popData.spec_key=spec_key
+          console.log(this.popData.spec_list[spec_key])
+          if(this.popData.spec_list[spec_key]!==undefined){
+            this.popData.price=this.popData.spec_list[spec_key].seckill_money>0?this.popData.spec_list[spec_key].seckill_money:this.popData.spec_list[spec_key].price
+            this.popData.line_price=this.popData.spec_list[spec_key].line_price
+            this.popData.goods_spec_id=this.popData.spec_list[spec_key].goods_spec_id+''
+            let cartKey=this.cartData.goods_list.findIndex(row=>this.popData.goods_spec_id===row.goods_spec_id)
+            if(cartKey>=0){
+              this.popData.num=this.cartData.goods_list[cartKey].goods_number
+            }
+          }
+        }
+      },
       setShopIngList(cartData){
         this.cartData=cartData
         this.setGoodsNum()
@@ -314,18 +329,16 @@
 					// this.setSub(item);
 				} else if (type === 3) {
 					// 选规格
-					this.$refs.popupGG.open();
+          this.getShopGoodsSpec(item)
 				} else {
 					this.$refs.popupGG.close();
+          this.isAjax=false
 				}
 			},
+
+
 			setSub(item,type) {
-        console.log(item)
-        console.log(this.cartData.goods_list)
         let cartKey=this.cartData.goods_list.findIndex(row=>row.goods_id===item.goods_id)
-        console.log(cartKey)
-        console.log(type, cartKey)
-        console.log(type===2 && cartKey<0)
         if(type===2 && cartKey<0){
           this.setShopIngAdd(item.goods_id,item.category_id,'')
         }else {
@@ -368,27 +381,28 @@
       },
 
 			// -------弹窗选择规格-----------
-			select(i, k, item, info) {
-				if (!info.isSelect) {
-					item.list.forEach((v) => {
-						v.isSelect = false;
-					})
-					info.isSelect = true;
-
-					item.list.forEach(v => {
-						this.popData.spec_list.forEach((n, i) => {
-							if (v.id == n) {
-								this.popData.spec_list.splice(i, 1)
-							}
-						})
-					})
-					this.popData.spec_list.push(info.id);
-				} else {
-					info.isSelect = false;
-					let index = this.popData.spec_list.indexOf(info.id)
-					this.popData.spec_list.splice(index, 1)
-				}
-				this.spec_ids = this.popData.spec_list.join('_')
+			selectSpec( info,groupKey) {
+          let  specKey=this.popData.spec_ids.indexOf(info.item_id)
+        if(specKey>=0){
+          this.popData.spec_ids.splice(specKey,1)
+          this.popData.spec_name.splice(specKey,1)
+        }else {
+          this.popData.spec_ids.push(info.item_id)
+          this.popData.spec_name.push(info.spec_value)
+          for (const attrKey in this.popData.spec_attr[groupKey].spec_items) {
+            if(this.popData.spec_attr[groupKey].spec_items[attrKey].item_id!==info.item_id){
+              let  oldKey=this.popData.spec_ids.indexOf(this.popData.spec_attr[groupKey].spec_items[attrKey].item_id)
+              if(oldKey>=0){
+                this.popData.spec_ids.splice(oldKey,1)
+                this.popData.spec_name.splice(oldKey,1)
+              }
+            }
+
+          }
+
+        }
+				// this.spec_ids = this.popData.spec_list.join('_')
+        this.setGoodsSpecPrice()
 
 			},
 		},