This commit is contained in:
zmj 2024-06-22 20:26:36 +08:00
parent 0a8c7b0504
commit a75f9284f8
2 changed files with 828 additions and 812 deletions

View File

@ -1,5 +1,5 @@
<style lang="scss" scoped> <style lang="scss" scoped>
.share-btn { .share-btn {
display: flex; display: flex;
align-items: center; align-items: center;
position: fixed; position: fixed;
@ -15,7 +15,7 @@
color: #030303; color: #030303;
} }
} }
} }
</style> </style>
<template> <template>
<view class="content"> <view class="content">
@ -103,7 +103,8 @@
<view class="classify"> <view class="classify">
<scroll-view style="height: 90rpx;" scroll-x @scrolltolower="getgoodClassList(leftActive)"> <scroll-view style="height: 90rpx;" scroll-x @scrolltolower="getgoodClassList(leftActive)">
<view class="classify-list"> <view class="classify-list">
<view class="classify-list-item u-line-1" :class="{ 'item-active': rightActive === item.id }" <view class="classify-list-item u-line-1"
:class="{ 'item-active': rightActive === item.id }"
v-for="(item, index) in goodClassThree" :key="index" @click="changeThree(item, index)"> v-for="(item, index) in goodClassThree" :key="index" @click="changeThree(item, index)">
{{ item.name }} {{ item.name }}
</view> </view>
@ -114,7 +115,8 @@
<up-icon name="arrow-down"></up-icon> <up-icon name="arrow-down"></up-icon>
</view> </view>
<view class="order-by"> <view class="order-by">
<view class="item" :class="{ 'order-active': where.order == '' }" @click="changeOrder('')">综合</view> <view class="item" :class="{ 'order-active': where.order == '' }" @click="changeOrder('')">综合
</view>
<view class="item" :class="{ 'order-active': where.order == 'desc' || where.order == 'asc' }" <view class="item" :class="{ 'order-active': where.order == 'desc' || where.order == 'asc' }"
@click="changeOrder(where.order == 'asc' ? 'desc' : 'asc')">价格</view> @click="changeOrder(where.order == 'asc' ? 'desc' : 'asc')">价格</view>
<view class="item" :class="{ 'order-active': where.order == 'sales' }" <view class="item" :class="{ 'order-active': where.order == 'sales' }"
@ -128,16 +130,18 @@
<view class="classify-list"> <view class="classify-list">
<view class="classify-list-item u-line-1" <view class="classify-list-item u-line-1"
:class="{ 'item-active': rightActive === item.id }" :class="{ 'item-active': rightActive === item.id }"
v-for="(item, index) in goodClassThree" :key="index" @click="changeThree(item, index)"> v-for="(item, index) in goodClassThree" :key="index"
@click="changeThree(item, index)">
{{ item.name }} {{ item.name }}
</view> </view>
</view> </view>
</scroll-view> </scroll-view>
</view> </view>
</viewPopup> </viewPopup>
<scroll-view class="list" id='drag_area' style="overscroll-behavior: none;" @scroll="hideHeadView" scroll-y <scroll-view class="list" id='drag_area' style="overscroll-behavior: none;" @scroll="hideHeadView"
@scrolltolower="loadMoreGood"> scroll-y @scrolltolower="loadMoreGood">
<view class="shop-item" v-for="(item, index) in goodList" :key="item.id" @click="openGoodPopup(item)"> <view class="shop-item" v-for="(item, index) in goodList" :key="item.id"
@click="openGoodPopup(item)">
<view class="shop-img" <view class="shop-img"
:style="{ backgroundImage: `url(${item.image}?x-oss-process=image/format,webp)` }"> :style="{ backgroundImage: `url(${item.image}?x-oss-process=image/format,webp)` }">
</view> </view>
@ -158,7 +162,13 @@
<text class='price' style="font-size: 24rpx;">/{{ item.unit_name }}</text> <text class='price' style="font-size: 24rpx;">/{{ item.unit_name }}</text>
</view> </view>
<view class="price-btn"> <view class="price-btn">
<view class="price" style="font-size: 24rpx;">{{ item.price }}/{{ item.unit_name }}</view> <view class="price" style="font-size: 24rpx;"
v-if='userStore?.userInfo?.user_ship == 1'>
{{ item.price }}/{{ item.unit_name }}
</view>
<view class="price" v-else>
{{ item.price }}/{{ item.unit_name }}
</view>
<view class="btn"> <view class="btn">
<u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon> <u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon>
</view> </view>
@ -173,7 +183,12 @@
<view class="price-info"> <view class="price-info">
<view class="row"> <view class="row">
<view>合计</view> <view>合计</view>
<view class="price">¥<text style="font-size: 36rpx;">{{ cartInfo.total_price }}</text></view> <view class="price" v-if='cartInfo.pay_price<=0||userStore?.userInfo?.user_ship !=4'>¥<text
style="font-size: 36rpx;">{{ cartInfo.total_price }}</text></view>
<view class="price" v-else>¥<text style="font-size: 30rpx;">{{ cartInfo.total_price }}</text></view>
<view class="price" v-if="cartInfo.pay_price>0 &&userStore?.userInfo?.user_ship == 4"><text
style="font-size: 36rpx;">优惠后
{{ cartInfo.pay_price }}</text></view>
</view> </view>
<!-- <view class="row"> <!-- <view class="row">
<view style="color: #777;">原价 ¥50.00</view> <view style="color: #777;">原价 ¥50.00</view>
@ -195,48 +210,48 @@
</template> </template>
<script setup> <script setup>
import { import {
onLoad, onLoad,
onShow, onShow,
onShareAppMessage, onShareAppMessage,
} from "@dcloudio/uni-app" } from "@dcloudio/uni-app"
import { import {
reactive, reactive,
ref, ref,
onMounted, onMounted,
} from "vue" } from "vue"
import { import {
goodListApi, goodListApi,
goodClassListApi goodClassListApi
} from "@/api/good.js" } from "@/api/good.js"
import { import {
cartCreateApi, cartCreateApi,
cartChangeApi, cartChangeApi,
cartListApi cartListApi
} from "@/api/cart.js"; } from "@/api/cart.js";
import { import {
productLogApi, productLogApi,
userInfoApi, userInfoApi,
getStoreInfo getStoreInfo
} from "@/api/user.js"; } from "@/api/user.js";
import viewPopup from "@/components/viewPopup.vue" import viewPopup from "@/components/viewPopup.vue"
import goodPopup from "@/components/goodPopup.vue" import goodPopup from "@/components/goodPopup.vue"
import useCartStore from "@/store/cart.js" import useCartStore from "@/store/cart.js"
import { import {
getCurrentInstance getCurrentInstance
} from 'vue'; } from 'vue';
import { import {
shopDetailApi shopDetailApi
} from "@/api/multipleShop.js"; } from "@/api/multipleShop.js";
import useUserStore from "@/store/user"; import useUserStore from "@/store/user";
const userStore = useUserStore(); const userStore = useUserStore();
const STORE_INFO = reactive({ const STORE_INFO = reactive({
id: 4, id: 23,
store_name: "农(特)产品直营店" store_name: "农(特)产品直营店"
}) })
const getStoreInfoFn = () => { const getStoreInfoFn = () => {
if (uni.getStorageSync('STORE_INFO').length) { if (uni.getStorageSync('STORE_INFO').length) {
let data = JSON.parse(uni.getStorageSync('STORE_INFO')) let data = JSON.parse(uni.getStorageSync('STORE_INFO'))
for (let key in data) { for (let key in data) {
@ -250,12 +265,12 @@ const getStoreInfoFn = () => {
STORE_INFO[key] = data[key] STORE_INFO[key] = data[key]
} }
}) })
} }
getStoreInfoFn() getStoreInfoFn()
// //
onShareAppMessage(() => { onShareAppMessage(() => {
let shareStr = '?id=' + STORE_INFO.id; let shareStr = '?id=' + STORE_INFO.id;
if (userStore.userInfo.user_ship == 1) { if (userStore.userInfo.user_ship == 1) {
shareStr = shareStr + '&spread_uid=' + userStore.userInfo.id + '&real_name=' + (userStore.userInfo shareStr = shareStr + '&spread_uid=' + userStore.userInfo.id + '&real_name=' + (userStore.userInfo
@ -273,26 +288,26 @@ onShareAppMessage(() => {
} }
}; };
return shareInfo; return shareInfo;
}) })
/*商品列表滚动隐藏头部导航 */ /*商品列表滚动隐藏头部导航 */
const targetHeight = ref(0) const targetHeight = ref(0)
let scoHeight = 0 let scoHeight = 0
const isScroll = ref(false) const isScroll = ref(false)
let lastScollTop = 0 let lastScollTop = 0
const hideHeadView = (e) => { const hideHeadView = (e) => {
if (e.detail.scrollTop < 100) return if (e.detail.scrollTop < 100) return
if (e.detail.scrollTop <= 0 || e.detail.scrollTop > targetHeight.value) if (e.detail.scrollTop <= 0 || e.detail.scrollTop > targetHeight.value)
return return
isScroll.value = e.detail.scrollTop > lastScollTop isScroll.value = e.detail.scrollTop > lastScollTop
lastScollTop = e.detail.scrollTop lastScollTop = e.detail.scrollTop
} }
/*商品列表滚动隐藏头部导航结束 */ /*商品列表滚动隐藏头部导航结束 */
const cartStore = useCartStore(); const cartStore = useCartStore();
const show = ref(0); const show = ref(0);
const topActive = ref(0); const topActive = ref(0);
const changeOne = async (item, index) => { const changeOne = async (item, index) => {
topActive.value = item.id; topActive.value = item.id;
show.value = 0; show.value = 0;
goodClassTow.value = item?.children || []; goodClassTow.value = item?.children || [];
@ -301,10 +316,10 @@ const changeOne = async (item, index) => {
rightActive.value = goodClassThree.value[0]?.id || ''; rightActive.value = goodClassThree.value[0]?.id || '';
getGoodList(); getGoodList();
if (!item.isLoading && item.id) getgoodClassList(topActive.value, 2); // , , if (!item.isLoading && item.id) getgoodClassList(topActive.value, 2); // , ,
} }
const leftActive = ref(0); const leftActive = ref(0);
const changeTwo = (item, index) => { const changeTwo = (item, index) => {
isScroll.value = false; isScroll.value = false;
getWXDom(instance) getWXDom(instance)
leftActive.value = item.id; leftActive.value = item.id;
@ -313,16 +328,16 @@ const changeTwo = (item, index) => {
rightActive.value = goodClassThree.value[0]?.id || ''; rightActive.value = goodClassThree.value[0]?.id || '';
getGoodList(); getGoodList();
if (!item.isLoading && item.id) getgoodClassList(leftActive.value, 3); // , , if (!item.isLoading && item.id) getgoodClassList(leftActive.value, 3); // , ,
} }
const rightActive = ref(0); const rightActive = ref(0);
const changeThree = (item, index) => { const changeThree = (item, index) => {
rightActive.value = item.id; rightActive.value = item.id;
show.value = 0; show.value = 0;
getGoodList(); getGoodList();
} }
const addCart = (product_id, cart_num) => { // const addCart = (product_id, cart_num) => { //
cartCreateApi({ cartCreateApi({
cart_num: cart_num, cart_num: cart_num,
is_new: 0, // 01 is_new: 0, // 01
@ -334,33 +349,33 @@ const addCart = (product_id, cart_num) => { //加入购物车
}).catch(err => { }).catch(err => {
uni.$u.toast(err.msg || '添加失败') uni.$u.toast(err.msg || '添加失败')
}) })
} }
const keyword = ref(''); const keyword = ref('');
const searchKeyword = () => { const searchKeyword = () => {
where.value.name = keyword.value; where.value.name = keyword.value;
where.value.store_name = keyword.value; where.value.store_name = keyword.value;
getGoodList(); getGoodList();
} }
const changeOrder = (order) => { const changeOrder = (order) => {
where.value.order = order; where.value.order = order;
getGoodList(); getGoodList();
} }
const where = ref({ const where = ref({
page_no: 1, page_no: 1,
page_size: 15, page_size: 15,
name: '', name: '',
order: '', order: '',
store_name: '', store_name: '',
store_id: STORE_INFO.id store_id: STORE_INFO.id
}) })
const loading = ref(true); const loading = ref(true);
const goodList = ref([]); const goodList = ref([]);
const getGoodList = (loadmore = false) => { const getGoodList = (loadmore = false) => {
loading.value = true; loading.value = true;
let class_id = rightActive.value || leftActive.value || topActive.value || ''; let class_id = rightActive.value || leftActive.value || topActive.value || '';
let class_all = ''; let class_all = '';
@ -385,20 +400,20 @@ const getGoodList = (loadmore = false) => {
// STORE_INFO.value.detailed_address = res.data.store.detailed_address; // STORE_INFO.value.detailed_address = res.data.store.detailed_address;
// } // }
}) })
} }
// //
const loadMoreGood = () => { const loadMoreGood = () => {
getWXDom(instance) getWXDom(instance)
getGoodList(true); getGoodList(true);
} }
const goodClassList = ref([]); // const goodClassList = ref([]); //
const goodClassTow = ref([]); // const goodClassTow = ref([]); //
const goodClassThree = ref([]); // const goodClassThree = ref([]); //
const classMap = new Map(); const classMap = new Map();
const getgoodClassList = (pid = 0, three = 1) => { const getgoodClassList = (pid = 0, three = 1) => {
let page_no = classMap.get(pid) || 1; let page_no = classMap.get(pid) || 1;
goodClassListApi({ goodClassListApi({
pid: pid, pid: pid,
@ -477,9 +492,9 @@ const getgoodClassList = (pid = 0, three = 1) => {
page_no++; page_no++;
classMap.set(pid, page_no); classMap.set(pid, page_no);
}) })
} }
const navTo = (url) => { const navTo = (url) => {
if (!userStore.token || !userStore.userInfo.mobile) return uni.showModal({ if (!userStore.token || !userStore.userInfo.mobile) return uni.showModal({
content: '您需要先登录才可使用该功能, 是否前去登录', content: '您需要先登录才可使用该功能, 是否前去登录',
success: (e) => { success: (e) => {
@ -498,13 +513,13 @@ const navTo = (url) => {
uni.navigateTo({ uni.navigateTo({
url: url url: url
}) })
} }
// //
const showGoodPopup = ref(false); const showGoodPopup = ref(false);
const goodRef = ref(null); const goodRef = ref(null);
const goodData = ref({}); const goodData = ref({});
const openGoodPopup = (item) => { // / const openGoodPopup = (item) => { // /
goodData.value = item; goodData.value = item;
goodRef.value.setData(item); goodRef.value.setData(item);
showGoodPopup.value = true; showGoodPopup.value = true;
@ -515,8 +530,8 @@ const openGoodPopup = (item) => { // 打开数量/重量弹窗
cate_id: item.cate_id, cate_id: item.cate_id,
store_id: STORE_INFO.id store_id: STORE_INFO.id
}); });
}; };
const changeGood = (data) => { // const changeGood = (data) => { //
showGoodPopup.value = false; showGoodPopup.value = false;
if (!userStore.token) return uni.showModal({ if (!userStore.token) return uni.showModal({
content: '您需要先登录才可使用该功能, 是否前去登录', content: '您需要先登录才可使用该功能, 是否前去登录',
@ -535,56 +550,58 @@ const changeGood = (data) => { // 确定选择商品重量
}); });
addCart(data.product_id, data.cart_num); addCart(data.product_id, data.cart_num);
} }
// //
const settleAccounts = () => { const settleAccounts = () => {
uni.navigateTo({ uni.navigateTo({
url: '/pagesOrder/settle/settle' url: '/pagesOrder/settle/settle'
}) })
} }
// //
const cartInfo = ref({ const cartInfo = ref({
total_price: '0.00', total_price: '0.00',
pay_price: 0,
count: 0 count: 0
}) })
const getCartList = (res) => { const getCartList = (res) => {
cartListApi({ cartListApi({
page_no: 1, page_no: 1,
page_size: 100, page_size: 100,
}).then(res => { }).then(res => {
cartInfo.value = { cartInfo.value = {
total_price: res.data?.extend?.total_price || '0.00', total_price: res.data?.extend?.total_price || '0.00',
pay_price: res.data?.extend?.pay_price || '0.00',
count: res.data?.count || 0 count: res.data?.count || 0
} }
cartStore.setCartList(res.data?.lists.map(item => item.id)) cartStore.setCartList(res.data?.lists.map(item => item.id))
}) })
} }
// //
const btns = ref({ const btns = ref({
height: 0, height: 0,
top: 0, top: 0,
bottom: 0, bottom: 0,
left: 0 left: 0
}); });
// //
const shareInfo = ref({ const shareInfo = ref({
uid: '', uid: '',
real_name: '', real_name: '',
store_id: '' store_id: ''
}); });
const getShareInfo = () => { const getShareInfo = () => {
if (uni.getStorageSync('SHARE_INFO')) { if (uni.getStorageSync('SHARE_INFO')) {
shareInfo.value = (uni.getStorageSync('SHARE_INFO')) shareInfo.value = (uni.getStorageSync('SHARE_INFO'))
} }
} }
getShareInfo() getShareInfo()
onLoad(async (opt) => { onLoad(async (opt) => {
where.value.store_id = opt.id || STORE_INFO.id; where.value.store_id = opt.id || STORE_INFO.id;
// id // id
if (opt.id) { if (opt.id) {
@ -606,9 +623,9 @@ onLoad(async (opt) => {
// //
btns.value = uni.getMenuButtonBoundingClientRect(); btns.value = uni.getMenuButtonBoundingClientRect();
// #endif // #endif
}) })
onShow(() => { onShow(() => {
// //
if (userStore.token && userStore.userInfo.mobile) { if (userStore.token && userStore.userInfo.mobile) {
userInfoApi().then(res => { userInfoApi().then(res => {
@ -623,11 +640,11 @@ onShow(() => {
} }
}); });
} }
}); });
let instance; // let instance; //
const getWXDom = () => { const getWXDom = () => {
let query = uni.createSelectorQuery().in(instance).select("#drag_area"); let query = uni.createSelectorQuery().in(instance).select("#drag_area");
query.fields({ query.fields({
size: true, size: true,
@ -638,22 +655,22 @@ const getWXDom = () => {
targetHeight.value = data.scrollHeight - data.height targetHeight.value = data.scrollHeight - data.height
} }
).exec(); ).exec();
} }
onMounted(() => { onMounted(() => {
instance = getCurrentInstance(); // instance = getCurrentInstance(); //
setTimeout(() => { setTimeout(() => {
getWXDom(instance) getWXDom(instance)
}, 500) }, 500)
}) })
</script> </script>
<style lang="scss"> <style lang="scss">
.content { .content {
background-color: #fff; background-color: #fff;
} }
.navbar { .navbar {
padding: 0 20rpx; padding: 0 20rpx;
display: flex; display: flex;
align-items: center; align-items: center;
@ -686,9 +703,9 @@ onMounted(() => {
} }
} }
} }
.head-view { .head-view {
background-color: #fff; background-color: #fff;
height: 180rpx; height: 180rpx;
width: 750rpx; width: 750rpx;
@ -738,9 +755,9 @@ onMounted(() => {
} }
} }
} }
} }
.r-btn { .r-btn {
position: absolute; position: absolute;
right: 0; right: 0;
top: 0; top: 0;
@ -753,9 +770,9 @@ onMounted(() => {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
box-shadow: -10rpx 0 60rpx 1rpx rgba(0, 0, 0, 0.3); box-shadow: -10rpx 0 60rpx 1rpx rgba(0, 0, 0, 0.3);
} }
.cateOne { .cateOne {
background-color: #fff; background-color: #fff;
.head-title { .head-title {
@ -838,9 +855,9 @@ onMounted(() => {
background-color: rgba(#20b128, 0.1); background-color: rgba(#20b128, 0.1);
} }
} }
} }
.scroll-box { .scroll-box {
// background-color: red; // background-color: red;
display: flex; display: flex;
@ -1010,9 +1027,9 @@ onMounted(() => {
} }
} }
} }
} }
.fiexd-btn-box { .fiexd-btn-box {
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
height: 140rpx; height: 140rpx;
height: calc(constant(safe-area-inset-bottom) + 140rpx); height: calc(constant(safe-area-inset-bottom) + 140rpx);
@ -1065,16 +1082,16 @@ onMounted(() => {
font-size: 18rpx; font-size: 18rpx;
} }
} }
} }
.headScoll { .headScoll {
position: relative; position: relative;
overflow: hidden; overflow: hidden;
transition: 400ms; transition: 400ms;
} }
.store-info { .store-info {
margin: 0 0 20rpx 20rpx; margin: 0 0 20rpx 20rpx;
margin-top: 20rpx; margin-top: 20rpx;
} }
</style> </style>

View File

@ -9,8 +9,7 @@
@click="callPhone(shopInfo.phone)"> @click="callPhone(shopInfo.phone)">
<view class="top" style="align-items: flex-start;"> <view class="top" style="align-items: flex-start;">
<view style="color: #333;display: flex;align-items: center;flex-shrink: 0;"> <view style="color: #333;display: flex;align-items: center;flex-shrink: 0;">
<up-icon name="map"></up-icon> <text style="margin: 0 10rpx;color:#20B128">推荐自提点</text>
<text style="margin: 0 10rpx;">自提点</text>
</view> </view>
<view v-if="shopInfo.id"> <view v-if="shopInfo.id">
<view style="color: #333;"> <view style="color: #333;">