diff --git a/pages/product/shopPage.vue b/pages/product/shopPage.vue index 6399ecb..34fd335 100644 --- a/pages/product/shopPage.vue +++ b/pages/product/shopPage.vue @@ -1,927 +1,933 @@ - - - - - +const themeStyle = computed(() => getThemeStyle(store.state.theme)) +const mainColor = computed(() => store.getters.mainColor) + +const pageData = ref<{ list: any[] }>({ list: [] }) +const enablePageData = ref(false) +const basePageData = ref(false) +const scrollTop = ref(0) +const current = ref(0) +const tabs = [ + { name: '全部商品' }, + { name: '分类查看' }, +] +const storeId = ref('') +const keyword = ref('') +const storeInfo = ref({}) +const isCollection = ref(false) +const goodsList = ref([]) +const couponList = ref([]) +const categoryList = ref([]) +const couponParams = reactive({ + pageNumber: 1, + pageSize: 50, + storeId: '', +}) +const goodsParams = reactive({ + pageNumber: 1, + pageSize: 10, + storeId: '', +}) + +const floorHasTopSearch = computed(() => { + const list = pageData.value && pageData.value.list + if (!list || !list.length) return false + return list.some((item, index) => item.type === 'search' && index !== 1) +}) + +watch(current, (val) => { + if (val == 0) { + goodsList.value = [] + getGoodsData() + } else { + getCategoryData() + } +}) + +function talk() { + talkIm(storeInfo.value.storeId) +} + +function back() { + const pages = getCurrentPages() + if (pages.length > 1) { + uni.navigateBack({ delta: 1 }) + } else { + uni.switchTab({ url: '/pages/tabbar/home/index' }) + } +} + +function isPageDataSuccess(payload: any) { + return payload?.success === true || payload?.code === 200 +} + +function shouldUseFloorPage(pageShow: unknown) { + return pageShow === '1' || pageShow === 1 || pageShow === true +} + +function initPageData() { + getFloorStoreData({ + pageType: 'STORE', + num: storeId.value, + }) + .then((res) => { + const payload = res?.data != null ? res.data : res + const result = payload?.result + const pageDataStr = result?.pageData + if (!isPageDataSuccess(payload) || !pageDataStr) { + fallbackToBasePage() + return + } + try { + const parsed = JSON.parse(pageDataStr) + pageData.value = + parsed && Array.isArray(parsed.list) ? parsed : { list: [] } + enablePageData.value = pageData.value.list.length > 0 + if (!enablePageData.value) { + fallbackToBasePage() + } + } catch (e) { + fallbackToBasePage() + } + }) + .catch(() => { + fallbackToBasePage() + }) +} + +function fallbackToBasePage() { + enablePageData.value = false + basePageData.value = true + pageData.value = { list: [] } + getGoodsData() + getCategoryData() +} + +function applyStoreId(id) { + storeId.value = id || '' + goodsParams.storeId = storeId.value + couponParams.storeId = storeId.value +} + +function parseStoreIdFromParams(params) { + const text = String(params || '').trim() + if (!text) return '' + if (text.indexOf('id=') === 0) return text.slice(3) + const match = /(?:^|&)id=([^&]+)/.exec(text) + return match ? decodeURIComponent(match[1]) : '' +} + +async function resolveStoreIdFromScene(scene) { + const raw = decodeURIComponent(String(scene || '')).trim() + if (!raw) return '' + const direct = parseStoreIdFromParams(raw) + if (direct) return direct + try { + const res = await getMpScene(raw) + return parseStoreIdFromParams(res?.data?.result) + } catch { + return '' + } +} + +function getStoreLicencePhoto() { + uni.navigateTo({ + url: `/pages/product/licencePhoto?id=${storeId.value}`, + }) +} + +function init() { + goodsList.value = [] + categoryList.value = [] + couponList.value = [] + goodsParams.pageNumber = 1 + if (isLogin('auth')) { + enableGoodsIsCollect() + } + getStoreData() +} + +function linkKefuDetail() { + // 客服 + // #ifdef MP-WEIXIN + + const params = { + // originalPrice: goodsDetail.original || goodsDetail.price, + uuid: storage.getUuid(), + token: storage.getAccessToken(), + sign: storeInfo.value.yzfSign, + mpSign: storeInfo.value.yzfMpSign, + } + uni.navigateTo({ + url: '/pages/mine/im/index', + }) + // uni.navigateTo({ + // url: + // "/pages/product/customerservice/index?params=" + + // encodeURIComponent(JSON.stringify(params)), + // }); + // // #endif + // // #ifndef MP-WEIXIN + // const sign = storeInfo.yzfSign; + // uni.navigateTo({ + // url: + // "/pages/tabbar/home/web-view?src=https://yzf.qq.com/xv/web/static/chat/index.html?sign=" + + // sign, + // }); + // #endif +} + +async function getCategoryData() { + const res = await getStoreCategory(storeId.value) + if (res.data.success) { + categoryList.value = res.data.result + } +} + +async function enableGoodsIsCollect() { + const res = await getStoreIsCollect('STORE', storeId.value) + if (res.data.success) { + isCollection.value = res.data.result + } +} + +function getCategoryGoodsList(val: any) { + uni.navigateTo({ + url: `/pages/product/shopPageGoods?title=${val.labelName}&id=${val.id}&storeId=${storeId.value}`, + }) +} + +function goToSearch() { + uni.navigateTo({ + url: `/pages/navigation/search/searchPage?storeId=${storeId.value}&keyword=${keyword.value}`, + }) +} + +async function getStoreData() { + const res = await getStoreBaseInfo(storeId.value) + if (res.data.success) { + storeInfo.value = res.data.result + getCouponsData() + if (shouldUseFloorPage(res.data.result.pageShow)) { + initPageData() + } else { + getGoodsData() + getCategoryData() + basePageData.value = true + } + } else { + uni.reLaunch({ + url: '/', + }) + } +} + +async function getGoodsData() { + const res = await getGoodsList(goodsParams) + if (res.data.success) { + goodsList.value.push(...res.data.result.records) + } +} + +async function getCouponsData() { + couponParams.storeId = storeId.value + const res = await getAllCoupons(couponParams) + if (res.data.success) { + couponList.value.push(...res.data.result.records) + } +} + +function whetherCollection() { + if (isCollection.value) { + deleteStoreCollection(storeId.value).then((res) => { + if (res.data.success) { + isCollection.value = false + uni.showToast({ + icon: 'none', + duration: 3000, + title: '取消关注成功!', + }) + } + }) + } else { + collectionStore(storeId.value).then((res) => { + if (res.data.success) { + isCollection.value = true + uni.showToast({ + icon: 'none', + duration: 3000, + title: '关注成功!', + }) + } + }) + } +} + +function getCoupon(item: any) { + if (!isLogin('auth')) { + uni.showToast({ + icon: 'none', + duration: 3000, + title: '请先登录!', + }) + + navigateToLogin('redirectTo') + return false + } + receiveCoupons(item.id).then((res) => { + if (res.data.success) { + uni.showToast({ + icon: 'none', + duration: 3000, + title: '领取成功!', + }) + } + }) +} + +onLoad((options: any) => { + applyStoreId(options?.id) + if (!storeId.value && options?.scene) { + resolveStoreIdFromScene(options.scene).then((id) => { + if (!storeId.value && id) { + applyStoreId(id) + init() + } + }) + } +}) + +onPageScroll((e) => { + scrollTop.value = e.scrollTop +}) + +onPullDownRefresh(() => { + init() +}) + +onReachBottom(() => { + goodsParams.pageNumber++ + getGoodsData() +}) + +onMounted(() => { + // #ifdef MP-WEIXIN + uni.showShareMenu({ + withShareTicket: true, + }) + // #endif + if (storeId.value) init() +}) + + + diff --git a/pages/tabbar/home/index.vue b/pages/tabbar/home/index.vue index f65cc75..4f6a9e2 100644 --- a/pages/tabbar/home/index.vue +++ b/pages/tabbar/home/index.vue @@ -43,6 +43,9 @@ + + + @@ -78,6 +81,9 @@ import goods from '@/pages/tabbar/home/template/tpl_goods.vue' import notice from '@/pages/tabbar/home/template/tpl_notice.vue' import promotions from '@/pages/tabbar/home/template/tpl_promotions_detail.vue' import fetchCoupon from '@/pages/tabbar/home/template/fetch_coupon.vue' +import blank from '@/pages/tabbar/home/template/tpl_blank.vue' +import lineLayout from '@/pages/tabbar/home/template/tpl_line.vue' +import richText from '@/pages/tabbar/home/template/tpl_rich_text.vue' import { getFloorData } from '@/api/home' const HOME_LAYOUT_PADDING_RPX = 16 diff --git a/pages/tabbar/home/template/tpl_blank.vue b/pages/tabbar/home/template/tpl_blank.vue new file mode 100644 index 0000000..2f2307e --- /dev/null +++ b/pages/tabbar/home/template/tpl_blank.vue @@ -0,0 +1,15 @@ + + + diff --git a/pages/tabbar/home/template/tpl_line.vue b/pages/tabbar/home/template/tpl_line.vue new file mode 100644 index 0000000..8cc3ca9 --- /dev/null +++ b/pages/tabbar/home/template/tpl_line.vue @@ -0,0 +1,21 @@ + + + diff --git a/pages/tabbar/home/template/tpl_rich_text.vue b/pages/tabbar/home/template/tpl_rich_text.vue new file mode 100644 index 0000000..fac519e --- /dev/null +++ b/pages/tabbar/home/template/tpl_rich_text.vue @@ -0,0 +1,26 @@ + + + diff --git a/pages/tabbar/special/special.vue b/pages/tabbar/special/special.vue index 96c19f9..495d0be 100644 --- a/pages/tabbar/special/special.vue +++ b/pages/tabbar/special/special.vue @@ -44,6 +44,9 @@ + + + @@ -71,6 +74,9 @@ import videoLayout from '@/pages/tabbar/home/template/tpl_video' import goods from '@/pages/tabbar/home/template/tpl_goods' import notice from '@/pages/tabbar/home/template/tpl_notice' import promotions from '@/pages/tabbar/home/template/tpl_promotions_detail' +import blank from '@/pages/tabbar/home/template/tpl_blank' +import lineLayout from '@/pages/tabbar/home/template/tpl_line' +import richText from '@/pages/tabbar/home/template/tpl_rich_text' import { toSpecial, getSpecial } from '@/api/home' import permision from '@/js_sdk/wa-permission/permission.js' import config from '@/config/config'