diff --git a/package.json b/package.json
index d41bb0c..1d34db9 100644
--- a/package.json
+++ b/package.json
@@ -87,4 +87,4 @@
"vite": "5.2.8",
"vue-tsc": "^1.0.24"
}
-}
+}
\ No newline at end of file
diff --git a/src/pages/merchant/components/product-row.vue b/src/pages/merchant/components/product-row.vue
index dafd6ed..625d967 100644
--- a/src/pages/merchant/components/product-row.vue
+++ b/src/pages/merchant/components/product-row.vue
@@ -1,6 +1,6 @@
-
-
-
-
-
- {{ props.name }}
-
-
- ¥{{ hooks.useMoney(props.price) }}
-
-
- ¥{{ hooks.useMoney(props.marketPrice) }}
-
-
-
- x{{ props.count }}
-
-
- {{ hooks.useFormatNum("库存", "", props.stock) }}
-
- {{ hooks.useFormatNum("销量", "", props.salesCount) }}
-
-
-
-
-
- {{ props.modelValue }}
-
-
-
-
-
-
+
+
+
+
+ {{ props.name }}
+
+ ¥{{ hooks.useMoney(props.price) }}
+
+ ¥{{ hooks.useMoney(props.marketPrice) }}
+
+
+ x{{ props.count }}
+
+ {{ hooks.useFormatNum("库存", "", props.stock) }}
+
+ {{ hooks.useFormatNum("销量", "", props.salesCount) }}
+
+
+
+
+
+ {{ props.modelValue }}
+
+
+
+
+
+
\ No newline at end of file
+
diff --git a/src/pages/merchant/detail.vue b/src/pages/merchant/detail.vue
index 683cc88..906b282 100644
--- a/src/pages/merchant/detail.vue
+++ b/src/pages/merchant/detail.vue
@@ -50,7 +50,13 @@ const getShopCar = async () => {
const _pa = { merchantId: state.detailId, hardType: "CANTEEN" }
const { data } = await foodApi.getShopCar(_pa)
state.carList = data ?? []
- asyncCarCount(state.shopList)
+ if (isEmpty(state.carList)) {
+ state.shopList.forEach((v: any) => {
+ v.productCount = 0
+ })
+ } else {
+ asyncCarCount(state.shopList)
+ }
state.totPrice = state.carList.map((v) => Number(v.totalPrice)).reduce((pre, next) => pre + next, 0)
state.totCount = state.carList.map((v) => v.productCount).reduce((pre, next) => pre + next, 0)
}
@@ -110,22 +116,39 @@ const asyncCarCount = (shopList) => {
}
const doAdd = async (item: any) => {
- chentProductCount(item)
+ chentProductCount(item, "add")
}
const remove = async (item: any) => {
- chentProductCount(item)
+ chentProductCount(item, "remove")
}
-const chentProductCount = async (item: any) => {
- const target = state.carList.find((v) => v.productId == item.productId)
- const targetIndex = state.carList.findIndex((v) => v.productId == item.productId)
- if (target) {
- state.carList[targetIndex].productCount = item.productCount
- } else {
- state.carList.push({ ...item, productId: item.id })
+const chentProductCount = async (item: any, type: "add" | "remove") => {
+ try {
+ uni.showLoading({ title: "加载中", mask: true })
+ let count = item.productCount
+ if (type === "add") {
+ count += 1
+ const { code }: any = await foodApi.checkSpuStock({ spuId: item.productId, incrCount: count })
+ if (code != 0) throw new Error()
+ } else if (type === "remove") {
+ count -= 1
+ }
+ const target = state.carList.find((v) => v.productId == item.productId)
+ const targetIndex = state.carList.findIndex((v) => v.productId == item.productId)
+ if (target) {
+ state.carList[targetIndex].productCount = count
+ } else {
+ state.carList.push({ ...item, productId: item.id, productCount: count })
+ }
+ nextTick(async () => {
+ await updateShopCar()
+ })
+ } catch (e) {
+ console.error(e)
+ } finally {
+ uni.hideLoading()
}
- nextTick(() => updateShopCar())
}
const doClassify = (i: any) => {
diff --git a/src/pages/tabbar/my.vue b/src/pages/tabbar/my.vue
index 5f8f6b3..86c1b1d 100644
--- a/src/pages/tabbar/my.vue
+++ b/src/pages/tabbar/my.vue
@@ -1,171 +1,184 @@
-
-
-
-
-
-
- {{ state.userInfo?.sysUser?.name }}
-
-
- ID {{ state.userInfo?.sysUser?.userId }}
-
-
- 请先登录
-
-
-
+
+
+
+
+
+
+ {{ state.userInfo?.sysUser?.name }}
+
+
+ ID {{ state.userInfo?.sysUser?.userId }}
+
+
+ 请先登录
+
+
+
-
-
-
-
- {{ v.text }}
-
-
-
-
+
+
+
+
+ {{ v.text }}
+
+
+
+
-
-
- 退出登录
-
-
-
+
+
+ 退出登录
+
+
+
diff --git a/src/sheep/api/food.ts b/src/sheep/api/food.ts
index 7c5ba07..e29256f 100644
--- a/src/sheep/api/food.ts
+++ b/src/sheep/api/food.ts
@@ -1,53 +1,63 @@
-import request from "@/sheep/utils/request";
+import request from "@/sheep/utils/request"
export default {
- page: (data: any) =>
- request({
- url: `/canteen/canteenDailyMenu/app/page`,
- method: "POST",
- data,
- params:{
- pageNo: data.pageNo,
- pagesize: data.pagesize
- },
- custom: {
- showLoading: false,
- },
- }),
- classify: (params: any) =>
- request({
- url: `/canteen/canteenOnlineCategory/app/getAllSimple`,
- method: "GET",
- params,
- custom: {
- showLoading: false,
- },
- }),
- product: (params: any) =>
- request({
- url: `/canteen/canteenOnlineSpu/app/getCanteenSpuList`,
- method: "GET",
- params,
- custom: {
- showLoading: false,
- },
- }),
- getShopCar: (params: any) =>
- request({
- url: `/hard/hard-car/app/mch-detail`,
- method: "GET",
- params,
- custom: {
- showLoading: false,
- },
- }),
- updateShopCar: (data: any) =>
- request({
- url: `/hard/hard-car/app/save-or-upload`,
- method: "POST",
- data,
- custom: {
- showLoading: false,
- },
- }),
-};
+ page: (data: any) =>
+ request({
+ url: `/canteen/canteenDailyMenu/app/page`,
+ method: "POST",
+ data,
+ params: {
+ pageNo: data.pageNo,
+ pagesize: data.pagesize,
+ },
+ custom: {
+ showLoading: false,
+ },
+ }),
+ classify: (params: any) =>
+ request({
+ url: `/canteen/canteenOnlineCategory/app/getAllSimple`,
+ method: "GET",
+ params,
+ custom: {
+ showLoading: false,
+ },
+ }),
+ product: (params: any) =>
+ request({
+ url: `/canteen/canteenOnlineSpu/app/getCanteenSpuList`,
+ method: "GET",
+ params,
+ custom: {
+ showLoading: false,
+ },
+ }),
+ getShopCar: (params: any) =>
+ request({
+ url: `/hard/hard-car/app/mch-detail`,
+ method: "GET",
+ params,
+ custom: {
+ showLoading: false,
+ },
+ }),
+ updateShopCar: (data: any) =>
+ request({
+ url: `/hard/hard-car/app/save-or-upload`,
+ method: "POST",
+ data,
+ custom: {
+ showLoading: false,
+ },
+ }),
+ checkSpuStock: (params) => {
+ return request({
+ url: "/canteen/canteenOnlineSpu/app/checkSpuStock",
+ method: "GET",
+ params,
+ custom: {
+ showLoading: false,
+ },
+ })
+ },
+}
diff --git a/src/sheep/api/product.ts b/src/sheep/api/product.ts
index 0e17b45..e653608 100644
--- a/src/sheep/api/product.ts
+++ b/src/sheep/api/product.ts
@@ -1,11 +1,11 @@
-import request from "@/sheep/utils/request";
+import request from "@/sheep/utils/request"
export default {
- get: (params) => {
- return request({
- url: "/canteen/canteenOnlineSpu/app/getCanteenSpuDetails",
- method: "GET",
- params,
- });
- },
-};
+ get: (params) => {
+ return request({
+ url: "/canteen/canteenOnlineSpu/app/getCanteenSpuDetails",
+ method: "GET",
+ params,
+ })
+ },
+}
diff --git a/src/sheep/api/shop.ts b/src/sheep/api/shop.ts
index ce8be34..20f6be5 100644
--- a/src/sheep/api/shop.ts
+++ b/src/sheep/api/shop.ts
@@ -1,68 +1,41 @@
-import request from "@/sheep/utils/request";
+import request from "@/sheep/utils/request"
export default {
- getSupermarketSpuCategory: (params: any) =>
- request({
- url: `/supermarket/supermarketCategory/app/simpleAll`,
- method: "GET",
- params,
- custom: {
- showLoading: false,
- },
- }),
- getSupermarketSpuList: (data: any) =>
- request({
- url: `/supermarket/supermarketSpu/app/selectListAll`,
- method: "POST",
- data,
- custom: {
- showLoading: false,
- },
- }),
- getSupermarketSpuDetail: (params: any) =>
- request({
- url: `/supermarket/supermarketSpu/app/SpuDetails`,
- method: "GET",
- params,
- custom: {
- showLoading: false,
- },
- }),
-
- // del: (params: any) =>
- // request({
- // url: `/sys/user/face-delete`,
- // method: "DELETE",
- // params,
- // custom: {
- // showLoading: false,
- // },
- // }),
- // create: (data: any) =>
- // request({
- // url: `/sys/user/face-create`,
- // method: "POST",
- // data,
- // custom: {
- // showLoading: false,
- // },
- // }),
- // get: (params: any) =>
- // request({
- // url: `/sys/user/face-get`,
- // method: "GET",
- // params,
- // custom: {
- // showLoading: false,
- // },
- // }),
- // put: (data: any) =>
- // request({
- // url: `/sys/user/face-update`,
- // method: "PUT",
- // data,
- // custom: {
- // showLoading: false,
- // },
- // }),
-};
+ getSupermarketSpuCategory: (params: any) =>
+ request({
+ url: `/supermarket/supermarketCategory/app/simpleAll`,
+ method: "GET",
+ params,
+ custom: {
+ showLoading: false,
+ },
+ }),
+ getSupermarketSpuList: (data: any) =>
+ request({
+ url: `/supermarket/supermarketSpu/app/selectListAll`,
+ method: "POST",
+ data,
+ custom: {
+ showLoading: false,
+ },
+ }),
+ getSupermarketSpuDetail: (params: any) =>
+ request({
+ url: `/supermarket/supermarketSpu/app/SpuDetails`,
+ method: "GET",
+ params,
+ custom: {
+ showLoading: false,
+ },
+ }),
+ checkSpuStock: (params) => {
+ return request({
+ url: "/supermarket/supermarketSpu/app/checkSpuStock",
+ method: "GET",
+ params,
+ custom: {
+ showLoading: false,
+ },
+ })
+ },
+}