Browse Source

2022-12-15

cmy 3 years ago
parent
commit
0a0e7548fc
1 changed files with 32 additions and 19 deletions
  1. 32 19
      app/admin/view/store/placeorder/index.php

+ 32 - 19
app/admin/view/store/placeorder/index.php

@@ -438,10 +438,11 @@
 								return
 							}
 							that.lodingAddCart = true;
-							await that.isShopNum().catch(() => {
+							await that.isShopNum().then(() => {
+								that.lodingAddCart = false;
+							}).catch(() => {
 								that.lodingAddCart = false;
 							})
-							that.lodingAddCart = false;
 							// 处理设置允许获得焦点
 							that.$nextTick(function() {
 								that.$refs.code.focus();
@@ -485,7 +486,6 @@
 											//添加到购物车
 											that.addCart(data, num).then(() => {
 												console.log('购物车加入成功');
-
 												resolve()
 											}).catch((err) => {
 												console.log('购物车加入失败');
@@ -529,12 +529,16 @@
 										if (ind > -1) {
 											that.shopList[ind].num = (+that.shopList[ind].num + (
 												+num)).toFixed(3);
-
+											resolve(true)
 										} else {
 											//初始化商品
 											that.initShopData(product, cartId, (+num).toFixed(3))
+												.then((data) => {
+													resolve(true)
+												}).catch((err) => {
+													reject(err);
+												})
 										}
-										resolve(true)
 									} else {
 										layer.msg(data.msg, {
 											icon: 5
@@ -551,20 +555,26 @@
 						//初始化购物车商品
 						initShopData(product, cartId, num) {
 							const that = this;
-							that.shopList = ([{
-								name: product.store_name, //商品
-								num: num, //购物车中的数量
-								id: product.product_id, //当前商品id
-								cartId: cartId, //保存购物车id
-								typeName: product.suk, //商品规格名称
-								unique: product.unique, //商品规格id
-								image: product.image, //商品主图
-								price: product.price, //商品价格
-								is_consumer: product.is_consumer //商品类型
-							}]).concat(that.shopList);
-							// console.log(this, '初始化后this对象')
-							//初始化该商品为1
-							that.changeCartShop(cartId, num)
+							return new Promise((resolve, rejact) => {
+								that.shopList = ([{
+									name: product.store_name, //商品
+									num: num, //购物车中的数量
+									id: product.product_id, //当前商品id
+									cartId: cartId, //保存购物车id
+									typeName: product.suk, //商品规格名称
+									unique: product.unique, //商品规格id
+									image: product.image, //商品主图
+									price: product.price, //商品价格
+									is_consumer: product.is_consumer //商品类型
+								}]).concat(that.shopList);
+								// console.log(this, '初始化后this对象')
+								//初始化该商品为1
+								that.changeCartShop(cartId, num).then((data) => {
+									resolve(data);
+								}).catch((err) => {
+									rejact(err);
+								})
+							})
 						},
 						//修改购物车物品数量
 						changeCartShop(cartId, num) {
@@ -578,6 +588,9 @@
 									console.log(ok)
 									ok(res)
 								}).catch(function(err) {
+									layer.msg('购物车加入失败请刷新页面', {
+										icon: 5
+									})
 									erro(err)
 									console.log(err);
 								})