Forráskód Böngészése

购物车普通商品购买添加完成

USER-20230908AJ\Administrator 2 éve
szülő
commit
75899f15a7
5 módosított fájl, 184 hozzáadás és 69 törlés
  1. 2 1
      api/common.js
  2. 1 1
      api/order.js
  3. 85 38
      pages-takeout/shop-mod/menu.vue
  4. 87 27
      pages-takeout/shop.vue
  5. 9 2
      pages.json

+ 2 - 1
api/common.js

@@ -26,4 +26,5 @@ export const setRiderApply = (data) => request('/api/system/' + 'riderApply', 'p
 // 文字说明
 export const getCommonText = (data) => request(commonUrl + 'text', 'post', { ...data })
 // 获取实习岗位二维码
-export const commonPracticeCode = (data) => request(commonUrl + 'practice_code', 'post', { ...data })
+export const commonPracticeCode = (data) => request(commonUrl + 'practice_code', 'post', { ...data })
+export const getDeliveryMoney = (data) => request(commonUrl + 'delivery_money', 'post', { ...data },false)

+ 1 - 1
api/order.js

@@ -10,4 +10,4 @@ export const orderCancel = (data) => request(newsUrl + 'cancel', 'post', { ...da
 // 获取订单状态
 export const orderStatus = (data) => request(newsUrl + 'status', 'post', { ...data },false)
 // 支付订单
-export const orderPay = (data) => request(newsUrl + 'pay', 'post', { ...data },false)
+export const orderPay = (data) => request(newsUrl + 'pay', 'post', { ...data },false)

+ 85 - 38
pages-takeout/shop-mod/menu.vue

@@ -104,7 +104,7 @@
 <script>
 	import tools from "@/service/tools";
   import {shopCategory, shopGoods} from "@/api/shop";
-  import {getShopIngList} from "@/api/shopping";
+  import {getShopIngList, setShopIngAdd, setShopIngDel, setShopIngNumber} from "@/api/shopping";
 	export default {
 		name: 'menu-box',
     props:{
@@ -129,8 +129,9 @@
           must_category:0,
           is_place_order:0,
           err_msg:0,
-          goods_list:0,
+          goods_list:[],
         },
+        isAjax:false,
         operate_id: '',
 
 				popData: {
@@ -212,34 +213,40 @@
 		mounted() {
       this.operate_id = uni.getStorageSync('operate_id')
 			this.getShopGoods();
+			this.getShopIngList(true);
 
 		},
 		methods: {
-      getShopIngList(){
-        getShopIngList().then(res=>{
+      setShopIngList(cartData){
+        this.cartData=cartData
+        this.setGoodsNum()
+      },
+      getShopIngList(isStart){
+        getShopIngList({
+          'shop_id':this.shop_id,
+        }).then(res=>{
           if(res.code===1){
             this.cartData=res.data
+            this.$emit('setCartData',this.cartData)
+           if(isStart) this.setGoodsNum()
           }
         })
       },
-      // getShopCategory(){
-      //   if(this.shop_id<0 || !this.operate_id){
-      //     return;
-      //   }
-      //   shopCategory({'shop_id':this.shop_id,	operate_id: this.operate_id,}).then(res=>{
-      //     if(res.code===1){
-      //       for (const cKey in res.data) {
-      //         let item =res.data[cKey]
-      //         item.goodsList=[]
-      //         this.categoryData.push(item)
-      //         if(cKey===0){
-      //           this.selectType(item)
-      //         }
-      //       }
-      //       this.getShopGoods()
-      //     }
-      //   })
-      // },
+      setGoodsNum(){
+        this.cartData.goods_list.forEach(item=>{
+          this.categoryData.forEach(categoryItem=>{
+            if(categoryItem.type===item.category_id){
+              categoryItem.list.forEach(goodsItem=>{
+                console.log(item.goods_id,goodsItem.goods_id)
+                if(item.goods_id===goodsItem.goods_id){
+                  goodsItem.num=item.goods_number*1
+                }
+              })
+            }
+
+          })
+        })
+      },
       getShopGoods(){
           if(this.shop_id<0 || !this.operate_id){
             return;
@@ -282,23 +289,27 @@
 				}).exec();
 			},
 			addred(type, i, k, item) {
-        console.log(item,type)
+        if(this.isAjax){
+          return
+        }
+        this.isAjax=true
 				if (type === 1) {
 					// 减
           if(item.num>0){
             --item.num;
-            // this.menuList[i].list[k].num -= 1;
-            this.setSub(item);
+            this.setSub(item,type);
+          }else {
+            this.isAjax=false
           }
 
 				} else if (type === 2) {
 					// 加
-          console.log(item.is_infinite===1 || item.stock>item.num)
           if(item.is_infinite===1 || item.stock>item.num){
             ++item.num;
-            this.setSub(item);
+            this.setSub(item,type);
+          }else {
+            this.isAjax=false
           }
-          console.log(item.num)
 					// this.menuList[i].list[k].num += 1;
 					// this.setSub(item);
 				} else if (type === 3) {
@@ -308,17 +319,53 @@
 					this.$refs.popupGG.close();
 				}
 			},
-			setSub(item) {
-				// let num = 0;
-				// item.list.forEach((n) => {
-				// 	num += n.num
-				// })
-				// this.typeList.forEach((v) => {
-				// 	if (v.type == item.type) {
-				// 		v.num = num
-				// 	}
-				// })
+			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 {
+          this.setShopIngNumber(item.goods_id,item.category_id,type,'')
+        }
+
 			},
+      setShopIngAdd(goodsId,categoryId,goodsSpecId){
+        setShopIngAdd({
+          'type':1,
+          'goods_id':goodsId,
+          'shop_id':this.shop_id,
+          'category_id':categoryId,
+          'goods_spec_id':goodsSpecId,
+        }).then(res=>{
+          this.isAjax=false
+          this.getShopIngList()
+        }).catch(()=>{
+          this.isAjax=false
+        })
+      },
+      setShopIngNumber(goodsId,categoryId,operation,goodsSpecId){
+        setShopIngNumber({
+          'type':1,
+          'goods_id':goodsId,
+          'shop_id':this.shop_id,
+          'category_id':categoryId,
+          'goods_spec_id':goodsSpecId,
+          'operation':operation===2?1:2,
+        }).then(res=>{
+          this.isAjax=false
+          this.getShopIngList()
+        }).catch(()=>{
+          this.isAjax=false
+        })
+      },
+
+      setShopIngDel(){
+
+      },
 
 			// -------弹窗选择规格-----------
 			select(i, k, item, info) {

+ 87 - 27
pages-takeout/shop.vue

@@ -58,7 +58,7 @@
 
 
 		<view class="common-view-css bgc-f" style="overflow: hidden;">
-			<Menu style="height: 100%;" v-if="shopType === 1"  :shop_id="shop_id"></Menu>
+			<Menu style="height: 100%;" v-if="shopType === 1"  :shop_id="shop_id" @setCartData="setCartData" ref="goodsMenu"></Menu>
 			<Evaluate style="height: 100%;" :shopId='shop_id' :shopScore='shopsInfo.shop_score' v-else-if="shopType === 2"></Evaluate>
 			<ShopInfo style="height: 100%;" :shopId='shop_id' v-else-if="shopType === 3"></ShopInfo>
 		</view>
@@ -66,17 +66,17 @@
 		<view class="shop-buttom-money box-border-box" @click="openBuyCrad()">
 			<view class="shop-buttom-money-1 flex-justify-space align-items-center">
 				<image src="@/static/img/takeout/buy-icon.png" mode="scaleToFill"></image>
-				<view class="shop-buttom-num fs-24 fc-f text-align-center">3</view>
-				<view class="">
-					<view class="">
-						<span class="fw-600 fs-24 fc-f">¥</span>
-						<span class="fw-600 fs-44 fc-f">19.26</span>
-					</view>
-					<!-- <view class="fs-24 fc-ADADAD">免配送</view> -->
-					<view class="fs-24 fc-ff3939">配送费¥10</view>
-				</view>
-				<view class="fs-32 fw-600 fc-f mr-30">20元起送</view>
-				<!-- <view class="shop-buttom-money-2 text-align-center fc-f fs-32 fw-600">去结算</view> -->
+				<view class="shop-buttom-num fs-24 fc-f text-align-center">{{cartData.total_num}}</view>
+        <view class="" v-if="cartData.is_place_order===1">
+          <view class="">
+            <span class="fw-600 fs-24 fc-f">¥</span>
+            <span class="fw-600 fs-44 fc-f">{{cartData.total_price}}</span>
+          </view>
+          <view class="fs-24 fc-ADADAD" v-if="delivery_money<=0">免配送</view>
+          <view class="fs-24 fc-ff3939" v-else>配送费¥{{delivery_money}}</view>
+        </view>
+        <view class="fs-32 fw-600 fc-f mr-30" v-else>{{cartData.err_msg}}</view>
+				 <view class="shop-buttom-money-2 text-align-center fc-f fs-32 fw-600">去结算</view>
 			</view>
 		</view>
 
@@ -85,7 +85,7 @@
 				<view class="buy-card-top box-border-box plr-32 flex-justify-space align-items-center">
 					<view class="">
 						<span class="fs-32 fc-3 mr-12">已选商品</span>
-						<span class="fs-32 fc-9">(打包费<span class="fs-32 fc-FB3D03">8元</span>)</span>
+						<span class="fs-32 fc-9">(打包费<span class="fs-32 fc-FB3D03">{{cartData.pack_price}}元</span>)</span>
 					</view>
 					<view class="fs-28 fw-400 fc-9 align-items-center">
 						<view class="">
@@ -95,41 +95,42 @@
 					</view>
 				</view>
 				<view class="scroll-view-css box-border-box p-32">
-					<view class="buy-card-item display-flex" v-for="(item,i) in 5" :key="i">
-						<image src="@/static/img/my/bg.png" mode="scaleToFill"></image>
+					<view class="buy-card-item display-flex" v-for="(goods,i) in cartData.goods_list" :key="i">
+						<image :src="goods.goods_image" mode="scaleToFill"></image>
 						<view class="flex-1">
 							<view class="w-514 text-overflow-ellipsis-one fs-34 fw-600 mb-12">
-								[畅销款]奥尔1良烤肉牛油拌饭拌饭[畅销款]奥尔1良烤肉牛油拌饭拌饭</view>
-							<view class="w-514 text-overflow-ellipsis-one fs-24 fw-400 fc-9 mb-18">不辣,加辣</view>
+                {{goods.goods_name}}</view>
+							<view class="w-514 text-overflow-ellipsis-one fs-24 fw-400 fc-9 mb-18">{{goods.goods_attr}}</view>
 
 							<view class="flex-justify-space">
 								<view class="">
 									<span class="fs-24 fc-FB3D03 fw-400">¥</span>
-									<span class="fs-40 fc-FB3D03 fw-b">3.99</span>
+									<span class="fs-40 fc-FB3D03 fw-b">{{goods.price}}</span>
 								</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="setShopIngNumber(goods,2)">-</view>
+									<view class="right-only-right-2 text-align-center fs-28 fw-400">{{goods.goods_number}}</view>
+									<view class="right-only-right-add fw-500 text-align-center fs-36 fc-f" @click.stop="setShopIngNumber(goods,1)">+</view>
 								</view>
 							</view>
 						</view>
 					</view>
+          <en-blank v-if="cartData.goods_list.length<=0" message="快去选购商品吧!~"></en-blank>
 				</view>
 
 				<view class="shop-buttom-money box-border-box" @click="createOrder()">
 					<view class="shop-buttom-money-1 flex-justify-space align-items-center">
 						<image src="@/static/img/takeout/buy-icon.png" mode="scaleToFill"></image>
-						<view class="shop-buttom-num fs-24 fc-f text-align-center">3</view>
-						<view class="">
+						<view class="shop-buttom-num fs-24 fc-f text-align-center">{{cartData.total_num}}</view>
+						<view class="" v-if="cartData.is_place_order===1">
 							<view class="">
 								<span class="fw-600 fs-24 fc-f">¥</span>
-								<span class="fw-600 fs-44 fc-f">19.26</span>
+								<span class="fw-600 fs-44 fc-f">{{cartData.total_price}}</span>
 							</view>
-							<!-- <view class="fs-24 fc-ADADAD">免配送</view> -->
-							<view class="fs-24 fc-ff3939">配送费¥10</view>
+							 <view class="fs-24 fc-ADADAD" v-if="delivery_money<=0">免配送</view>
+							<view class="fs-24 fc-ff3939" v-else>配送费¥{{delivery_money}}</view>
 						</view>
-						<!-- <view class="fs-32 fw-600 fc-f mr-30">20元起送</view> -->
+						 <view class="fs-32 fw-600 fc-f mr-30" v-else>{{cartData.err_msg}}</view>
 						<view class="shop-buttom-money-2 text-align-center fs-32 fc-f fw-600" @click="toConfirmOrder()">
 							去结算</view>
 					</view>
@@ -197,6 +198,8 @@
 		shopInfo,
 		shopCoupon
 	} from "@/api/shop.js"
+  import {getDeliveryMoney} from "@/api/common";
+  import {getShopIngList, setShopIngNumber} from "@/api/shopping";
 	export default {
 		components: {
 			Menu,
@@ -225,6 +228,18 @@
 				couponData: [], // 可领优惠卷
 				goodsData: [], // 可领优惠卷
         categoryData: [], // 可领优惠卷
+        delivery_money: 0, // 可领优惠卷
+        cartData: {
+          total_price:0,
+          total_num:0,
+          total_goods_money:0,
+          pack_price:0,
+          must_category:0,
+          is_place_order:0,
+          err_msg:0,
+          goods_list:[],
+        },
+        isAjax:false
 			}
 		},
 		onLoad(e) {
@@ -239,6 +254,51 @@
 			this.shopCoupon()
 		},
 		methods: {
+      setShopIngNumber(item,type){
+        if(this.isAjax){
+          return
+        }
+        this.isAjax=true
+        setShopIngNumber({
+          'type':1,
+          'goods_id':item.goods_id,
+          'shop_id':this.shop_id,
+          'category_id':item.category_id,
+          'goods_spec_id':item.goods_spec_id,
+          'operation':type===1?1:2,
+        }).then(res=>{
+          this.isAjax=false
+          this.getShopIngList()
+        }).catch(()=>{
+          this.isAjax=false
+        })
+      },
+      getShopIngList(){
+        getShopIngList({
+          'shop_id':this.shop_id,
+        }).then(res=>{
+          if(res.code===1){
+            this.cartData=res.data
+            if(this.shopType===1){
+              this.$refs.goodsMenu.setShopIngList( this.cartData)
+            }
+          }
+        })
+      },
+      setCartData(cartData){
+        this.cartData=cartData
+        this.getDeliveryMoney()
+      },
+      getDeliveryMoney(){
+        getDeliveryMoney({
+          'school_id':this.operate_id,
+          'shop_id':this.shop_id,
+        }).then(res=>{
+          if(res.code===1){
+              this.delivery_money=res.data.delivery_money*1
+          }
+        })
+      },
 			receiveCode(item) {
 				receiveCoupon({grant_id: item.grant_id,coupon_id: item.coupon_id}).then((res) => {
 					if(res.code == 1) {

+ 9 - 2
pages.json

@@ -408,10 +408,17 @@
 	},
 	"condition": {
 		"current": 0,
-		"list": [{
+		"list": [
+			{
 			"name": "列表调试",
 			"path": "pages-position/Internship-position",
 			"query": ""
-		}]
+		},
+			{
+				"name": "店铺详情",
+				"path": "pages-takeout/shop",
+				"query": "shop_id=1"
+			}
+		]
 	}
 }