diff --git a/.env b/.env new file mode 100644 index 0000000..5e88cc1 --- /dev/null +++ b/.env @@ -0,0 +1,39 @@ +#是否是TOC应用 +VITE_IS_TOC=true + +#是否是H5模式 +VITE_IS_H5=true + +#是否是微服务架构 +VITE_IS_MICRO=true + +# 后端请求前缀 +VITE_API_URL = /api + +# 前端加密密钥 +VITE_PWD_ENC_KEY='pigxpigxpigxpigx' + +# OAUTH2 APP模式客户端信息 +VITE_OAUTH2_APP_CLIENT='mini:mini' + +# --------------------------- 开发环境 api地址 ---------------------------------- +# VITE_APP_DEV_SERVICE = https://stgl.pj.gov.cn/api # 域名线上 +#VITE_APP_DEV_SERVICE = http://59.202.170.152:81/api # 信创线上 +VITE_APP_DEV_SERVICE = http://192.168.101.139:9999 # 邓-本地 +# VITE_APP_DEV_SERVICE = http://127.0.0.1:9999 # 邓-本地 +# VITE_APP_DEV_SERVICE = http://123.156.230.15:8089/api # 测试线上 + +# --------------------------- 开发环境 图片访问基础地址 --------------------------- +# VITE_IMAGE_DEV_PATH = https://stgl.pj.gov.cn/api # 域名线上 +#VITE_IMAGE_DEV_PATH = http://59.202.170.152:81/api # 信创线上 +VITE_IMAGE_DEV_PATH = http://192.168.101.139:9999 # 邓-本地 +# VITE_IMAGE_DEV_PATH = http://127.0.0.1:9999 +# VITE_IMAGE_DEV_PATH = http://123.156.230.15:8089/api # 测试线上 + +# --------------------------- 生产环境 api地址 ---------------------------------- +VITE_APP_PROD_SERVICE = https://stgl.pj.gov.cn/api # 域名线上 +#VITE_APP_PROD_SERVICE = http://59.202.170.152:81/api # 信创线上 +#VITE_APP_PROD_SERVICE = http://123.156.228.134:48080/app-api + +# --------------------------- 生产环境 图片访问基础地址 --------------------------- +VITE_APP_PROD_IMAGE = https://stgl.pj.gov.cn/api # 域名线上 diff --git a/src/App.vue b/src/App.vue index ac5b9d9..f314ac1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,11 +2,6 @@ import { isDevEnv, getLaunchParam } from "@/sheep/utils/app" import { getAppInfo } from "@@/utils/app" -// import { onLaunch, onShow, onHide } from "@dcloudio/uni-app" -// onLaunch(() => {}) -// onShow(() => {}) -// onHide(() => {}) - interface TabbarItem { pagePath: string text: string @@ -33,6 +28,14 @@ const tabbar: TabbarItem[] = [ launchParam: ["selfMerchant"], auth: ["user"], }, + { + pagePath: "pages/tabbar/onlineShop", + text: "在线商城", + iconPath: "/static/tabbar/online-shop.png", + selectedIconPath: "/static/tabbar/online-shop-select.png", + launchParam: ["onlineShop"], + auth: ["user"], + }, { pagePath: "pages/tabbar/coopMerchant", text: "合作商家", @@ -54,7 +57,7 @@ const tabbar: TabbarItem[] = [ text: "订单", iconPath: "/static/tabbar/order.png", selectedIconPath: "/static/tabbar/order-select.png", - launchParam: ["canteen", "selfMerchant", "coopMerchant"], + launchParam: ["canteen", "selfMerchant", "onlineShop", "coopMerchant"], auth: ["user"], }, { @@ -94,7 +97,7 @@ const tabbar: TabbarItem[] = [ text: "我的", iconPath: "/static/tabbar/my.png", selectedIconPath: "/static/tabbar/my-select.png", - launchParam: ["canteen", "selfMerchant", "coopMerchant"], + launchParam: ["canteen", "selfMerchant", "onlineShop", "coopMerchant"], auth: ["user", "merchant", "doorAdmin"], }, ] @@ -149,6 +152,9 @@ export default { case "selfMerchant": uni.switchTab({ url: "/pages/tabbar/selfMerchant" }) break + case "onlineShop": + uni.switchTab({ url: "/pages/tabbar/onlineShop" }) + break case "coopMerchant": uni.switchTab({ url: "/pages/tabbar/coopMerchant" }) break @@ -169,6 +175,7 @@ export default { return uni.switchTab({ url: "/pages/tabbar/individualOrder" }) case "user": if (launchParam === "selfMerchant") return uni.switchTab({ url: "/pages/tabbar/selfMerchant" }) + if (launchParam === "onlineShop") return uni.reLaunch({ url: "/pages/tabbar/onlineShop" }) if (launchParam === "coopMerchant") return uni.reLaunch({ url: "/pages/tabbar/coopMerchant" }) return case "doorAdmin": @@ -179,8 +186,6 @@ export default { } } }, - onShow() {}, - onHide() {}, methods: { async _initTabbar() { diff --git a/src/pages.json b/src/pages.json index df22365..eff3e15 100644 --- a/src/pages.json +++ b/src/pages.json @@ -23,6 +23,13 @@ "disableScroll": true } }, + { + "path": "pages/tabbar/onlineShop", + "style": { + "navigationBarTitleText": "在线商城", + "disableScroll": true + } + }, { "path": "pages/tabbar/coopMerchant", "style": { @@ -483,6 +490,12 @@ "iconPath": "", "selectedIconPath": "" }, + { + "pagePath": "pages/tabbar/onlineShop", + "text": "", + "iconPath": "", + "selectedIconPath": "" + }, { "pagePath": "pages/tabbar/coopMerchant", "text": "", @@ -521,7 +534,7 @@ }, { "pagePath": "pages/tabbar/message", - "text": "通知公告", + "text": "", "iconPath": "", "selectedIconPath": "" }, @@ -540,4 +553,4 @@ // } ] } -} +} \ No newline at end of file diff --git a/src/pages/canteen/detail.vue b/src/pages/canteen/detail.vue index 01b2f3f..496d130 100644 --- a/src/pages/canteen/detail.vue +++ b/src/pages/canteen/detail.vue @@ -156,7 +156,7 @@ const updateFoodCart = async () => { } // 打开购物车 -const doVisibleCart = async () => (state.showCartDialog = true) +const doVisibleCart = () => (state.showCartDialog = true) // 购买 打开预订时间段选择对话框 const doBuy = async () => { diff --git a/src/pages/shop/components/product-car.vue b/src/pages/shop/components/product-cart.vue similarity index 63% rename from src/pages/shop/components/product-car.vue rename to src/pages/shop/components/product-cart.vue index d75f2fb..998380c 100644 --- a/src/pages/shop/components/product-car.vue +++ b/src/pages/shop/components/product-cart.vue @@ -6,27 +6,28 @@ title="购物车" position="bottom" size="60%" + bgColor="#ECF4F9" @close="doClose" > @@ -38,28 +39,26 @@ import { filePath } from "@/sheep/utils/file" import ProductRow from "./product-row.vue" import ProductTotal from "./product-total.vue" -const emit = defineEmits(["update:modelValue", "doPay", "add", "remove"]) +const emit = defineEmits(["update:modelValue", "add", "remove", "submit"]) -export type Props = { - modelValue: any - carList: any - totPrice: number - totCount: number -} -const props = withDefaults(defineProps(), { - modelValue: false, - carList: [], - totPrice: 0, - totCount: 0, -}) +const props = withDefaults( + defineProps<{ + modelValue: any + cartList: any + totPrice: number + totCount: number + }>(), + { + modelValue: false, + cartList: [], + totPrice: 0, + totCount: 0, + }, +) -const doClose = () => { - emit("update:modelValue", false) -} +const doClose = () => emit("update:modelValue", false) -const doPay = () => { - emit("doPay") -} +const doPay = () => emit("submit") const getHeight = () => { const { bottom } = uni.getSystemInfoSync().safeAreaInsets! diff --git a/src/pages/shop/components/product-row.vue b/src/pages/shop/components/product-row.vue index 17866d2..4b0b92f 100644 --- a/src/pages/shop/components/product-row.vue +++ b/src/pages/shop/components/product-row.vue @@ -1,46 +1,45 @@ @@ -77,38 +68,37 @@ import { shopApi } from "@/sheep/api" import { filePath } from "@/sheep/utils/file" import { computed, reactive, watch } from "vue" +import { hooks } from "@@/index" -const emit = defineEmits(["update:modelValue", "onAddToCar"]) +const emit = defineEmits(["update:modelValue", "onSkuAddToCart"]) + +const props = withDefaults( + defineProps<{ + modelValue: boolean + productData: any + }>(), + { + modelValue: false, + productData: {}, + }, +) -export type Props = { - modelValue: boolean - productData: any - onAddToCar?: () => void -} -const props = withDefaults(defineProps(), { - modelValue: false, - productData: {}, -}) const state = reactive({ goodsCount: 1, - selectedSku: {}, + selectedSku: { + retailPrice: 0, + promotionPrice: 0, + packageNum: 0, + }, goodsDetail: {}, }) -// 售价 -const retailPrice = computed(() => - state.selectedSku.retailPrice ? Number(state.selectedSku.retailPrice) * Number(state.goodsCount) : 0, -) -// 优惠价 -const promotionPrice = computed(() => - state.selectedSku.promotionPrice ? Number(state.selectedSku.promotionPrice) * Number(state.goodsCount) : 0, -) watch( () => props.modelValue, async (newValue) => { if (newValue) { // 获取商品详情 - const { data } = await shopApi.getSupermarketSpuDetail({ id: props.productData.productId }) + const { data } = await shopApi.getSupermarketSpuDetail({ id: props.productData.id }) state.goodsDetail = data if (data.skuList.length > 0) { state.selectedSku = state.goodsDetail.skuList[0] @@ -117,122 +107,37 @@ watch( }, ) -// SKU 列表 -// const skuList = computed(() => { -// let skuPrices = props.goodsInfo.skus; -// for (let price of skuPrices) { -// price.value_id_array = price.properties.map((item) => item.valueId); -// } -// return skuPrices; -// }); - -// 当前所选属性下,获取所有有库存的 SKU 们 -// function getCanUseSkuList() { -// let newSkus = []; -// for (let sku of skuList.value) { -// if (sku.stock <= 0) { -// continue; -// } -// let isOk = true; -// state.currentPropertyArray.forEach((propertyId) => { -// // propertyId 不为空,并且,这个 条 sku 没有被选中,则排除 -// if (propertyId.toString() !== "" && sku.value_id_array.indexOf(propertyId) < 0) { -// isOk = false; -// } -// }); -// if (isOk) { -// newSkus.push(sku); -// } -// } -// return newSkus; -// } - -// 选择规格 -function onSelectSku(skuItem: any) { - // const index = state.currentPropertyArray.findIndex((item: any) => item.id === skuItem.id); - // if (index === -1) { +// 选择规格/取消选择规格 +const onSelectSku = (skuItem: any) => { if (state.selectedSku.id === skuItem.id) { state.selectedSku = {} - } else { - state.selectedSku = skuItem + return } - // } else { - // state.currentPropertyArray.splice(index, 1); - // } - - // 清空已选择 - // let isChecked = true; // 选中 or 取消选中 - // if (state.currentPropertyArray[propertyId] !== undefined && state.currentPropertyArray[propertyId] === valueId) { - // 点击已被选中的,删除并填充 '' - // isChecked = false; - // state.currentPropertyArray.splice(propertyId, 1, ""); - // } else { - // 选中 - // state.currentPropertyArray[propertyId] = valueId; - // } - // 选中的 property 大类 - // let choosePropertyId: any = []; - // state.currentPropertyArray.forEach((currentPropertyId: string) => { - // if (currentPropertyId !== "") { - // // currentPropertyId 为空是反选 填充的 - // choosePropertyId.push(currentPropertyId); - // } - // }); - // 当前所选 property 下,所有可以选择的 SKU 们 - // let newSkuList = getCanUseSkuList(); - // 判断所有 property 大类是否选择完成 - // if (choosePropertyId.length === skuData.length && newSkuList.length) { - // newSkuList[0].name = state.selectedSku.goods_num || 1; - // state.selectedSku = newSkuList[0]; - // } else { - // state.selectedSku = {}; - // } - // if (choosePropertyId.length === skuData.value.length) { - // state.selectedSku = state.currentPropertyArray; - // } - // 改变 property 禁用状态 - // changeDisabled(isChecked, propertyId, valueId); + state.selectedSku = skuItem } // 加数量 const handleNumAdd = () => { - if (state.goodsCount >= state.goodsDetail.stock) { - return - } + if (state.goodsCount >= state.goodsDetail.stock) return uni.showToast({ title: "库存不足", icon: "none" }) state.goodsCount += 1 } // 减数量 const handleNumRemove = () => { - if (state.goodsCount <= 1) { - return - } + if (state.goodsCount <= 1) return state.goodsCount -= 1 } -// 点击加入购物车 -const handleClickAddToCar = async () => { - // 检查规格选择 - if (!state.selectedSku.id) { - uni.showToast({ - title: "请选择规格", - icon: "none", - duration: 1000, - }) - return - } +// 点击sku加入到购物车 +const handleSkuAddToCar = async () => { + // 检查包装单位选择 + if (!state.selectedSku.id) return uni.showToast({ title: "请选择包装单位", icon: "none" }) + // 检查库存 try { uni.showLoading({ title: "加载中", mask: true }) - const { code }: any = await shopApi.checkSpuStock({ - spuId: state.goodsDetail.id, - incrCount: state.goodsCount, - }) + const { code }: any = await shopApi.checkSpuStock({ spuId: state.goodsDetail.id, incrCount: state.goodsCount }) if (code != 0) { - return uni.showToast({ - title: "库存不足", - icon: "none", - duration: 1000, - }) + return uni.showToast({ title: "库存不足", icon: "none" }) } } catch (e) { console.error(e) @@ -240,22 +145,20 @@ const handleClickAddToCar = async () => { uni.hideLoading() } // 检查库存 - if (state.goodsDetail.stock === 0) { - uni.showToast({ - title: "库存不足", - icon: "none", - duration: 1000, - }) - return - } - emit("onAddToCar", { ...state.goodsDetail, productCount: state.goodsCount, productId: state.selectedSku.id }) + if (state.goodsDetail.stock === 0) return uni.showToast({ title: "库存不足", icon: "none" }) + + emit("onSkuAddToCart", { ...state.goodsDetail, productCount: state.goodsCount, productId: state.selectedSku.id }) } const doClose = () => { emit("update:modelValue", false) state.goodsCount = 1 - state.selectedSku = {} + state.selectedSku = { + retailPrice: 0, + promotionPrice: 0, + packageNum: 0, + } state.goodsDetail = {} } diff --git a/src/pages/shop/components/product-total.vue b/src/pages/shop/components/product-total.vue index 76e4e26..41b66f2 100644 --- a/src/pages/shop/components/product-total.vue +++ b/src/pages/shop/components/product-total.vue @@ -1,37 +1,37 @@ diff --git a/src/pages/shop/components/select-sku.vue b/src/pages/shop/components/select-sku.vue deleted file mode 100644 index 3eeb8c3..0000000 --- a/src/pages/shop/components/select-sku.vue +++ /dev/null @@ -1,447 +0,0 @@ - - - - - diff --git a/src/pages/shop/detail.vue b/src/pages/shop/detail.vue index f9909e4..eaae7fb 100644 --- a/src/pages/shop/detail.vue +++ b/src/pages/shop/detail.vue @@ -66,15 +66,12 @@ :borderColor="['#89c0ff']" > {{ state.detail.discountsPrice }} - - - {{ v.name }} - + {{ v.name }} - - - - + + - - +