feat(custom): build

This commit is contained in:
2023-11-28 17:59:45 +08:00
parent 22868fdf2c
commit d5c4651665
39 changed files with 5779 additions and 10624 deletions

View File

@@ -7,7 +7,7 @@
pagination-color="red"
auto-play="3000"
>
<nut-swiper-item v-for="(itm, idx) in (swiperList as any)" :key="idx">
<nut-swiper-item v-for="(itm, idx) in swiperList" :key="idx">
<img
style="width: 100%; height: 100%"
:src="itm"
@@ -45,9 +45,6 @@
</view>
</view>
<!-- 商品列表 -->
<!-- <view class="good">
<view class="item"></view>
</view> -->
<view class="good-class" v-if="class_list.length > 0">
<nut-tabs
v-model="value"
@@ -56,43 +53,39 @@
title-gutter="5"
animated-time="0"
name="tabName"
@click="clickTab"
>
<nut-tab-pane
v-for="(item, index) in class_list as any[]"
v-for="(itm, index) in good_list"
:key="index"
:title="item.name"
:title="itm.name"
:pane-key="index"
>
<view v-if="good_list.length > 0">
<view
class="list"
v-for="(item, index) in good_list as any[]"
:key="index"
>
<view class="item">
<img :src="item.cover" />
<view v-if="itm.Goods.length > 0">
<view class="list" v-for="(item, index) in itm.Goods" :key="index">
<view class="item" @click.stop="toGoodDetails(item.gid, 1)">
<image :src="item.cover" lazy-load />
<view class="right">
<view class="name">{{ item.name }}</view>
<view class="stock"> 库存剩余:{{ item.stock }} </view>
<view class="stock">剩余:{{ item.stock }}</view>
<view class="bom">
<view class="price">
<text style="font-size: 15px">{{ item.number }} </text>
{{ mer_info.bType === 1 ? "元" : "积分" }}
<view>
<view class="price">
<text style="font-size: 15px">{{ item.number }}</text>
</view>
<view class="price">
<text style="font-size: 15px"
>{{ item.exchange }}积分</text
>
</view>
</view>
<nut-button
size="mini"
v-if="mer_info.bType === 1"
type="primary"
@click.stop="toGoodDetails(item.gid as number, 1)"
>去购买
</nut-button>
<nut-button
size="mini"
v-else
type="primary"
@click.stop="toGoodDetails(item.gid as number, 2)"
>去兑换
@click.stop="add_cart(item)"
>
<template #icon>
<Cart2 />
</template>
</nut-button>
</view>
</view>
@@ -100,19 +93,24 @@
</view>
</view>
<nut-empty v-else description="该分类暂无商品"></nut-empty>
<view style="height: 180rpx"></view>
</nut-tab-pane>
</nut-tabs>
</view>
<nut-empty v-else description="该商家暂无商品"></nut-empty>
<!-- 购物车 -->
<cart ref="cartRef" :mer-info="mer_info" @update-cart="updateCartNum" />
</view>
</template>
<script setup lang="ts">
import Taro from "@tarojs/taro";
import { Find, Locationg3 } from "@nutui/icons-vue-taro";
import { ref } from "vue";
import { Ref, ref } from "vue";
import { calculateDistance } from "@/utils";
import { getGoodList, getMerCategory } from "@/api/goods";
import Cart from "@/components/Cart.vue";
import { Cart2 } from "@nutui/icons-vue-taro";
const swiperList = ref([]);
@@ -125,7 +123,7 @@ const userLocalNum = ref({
t: 0,
});
Taro.useLoad(() => {
Taro.useLoad(async () => {
Taro.getLocation({
type: "wgs84",
success: (res) => {
@@ -138,7 +136,8 @@ Taro.useLoad(() => {
title: mer_info.value.name,
});
swiperList.value = mer_info.value.img.split(",");
get_class_list();
await get_class_list();
await cartRef.value.get_cart_list();
});
const clickPhone = () => {
@@ -171,11 +170,38 @@ const get_class_list = async () => {
await get_good_list(class_list.value[0].ID as number);
};
const clickTab = (val: any) => {
get_good_list(class_list.value[val.paneKey].ID as number);
};
// const clickTab = (val: any) => {
// get_good_list(class_list.value[val.paneKey].ID as number);
// };
const good_list = ref([]);
interface goodList {
ID: number;
name: string;
bid: string;
Goods: GoodsType[];
}
interface GoodsType {
gid: string;
cover: string;
name: string;
number: number;
stock: number;
cartNum: number;
exchange: number;
}
interface CartItems {
bid: string;
gid: string;
number: number;
price: number;
cover: string;
name: string;
exchange: number;
}
const good_list = ref<goodList[]>([]);
const get_good_list = async (id: number) => {
Taro.showLoading({
title: "加载中",
@@ -183,8 +209,7 @@ const get_good_list = async (id: number) => {
});
const res = await getGoodList({
bid: mer_info.value.bid,
BType: mer_info.value.bType,
class_id: id,
goods_class_id: id,
status: 1,
state: 1,
});
@@ -192,14 +217,47 @@ const get_good_list = async (id: number) => {
Taro.hideLoading();
};
const toGoodDetails = (id: number, type: number) => {
const toGoodDetails = (id: string, type: number) => {
Taro.navigateTo({
url: `/pages/goods/goods_detail/index?gid=${id}&type=${type}`,
});
};
const cartRef = ref(null) as Ref;
const add_cart = (item: GoodsType) => {
const num = item.cartNum ? Number(item.cartNum) + 1 : 1;
cartRef.value.add_cart(item, num);
};
const updateCartNum = (cartItems: CartItems[]) => {
if (cartItems.length > 0) {
good_list.value.forEach((category: goodList) => {
category.Goods.forEach((good: GoodsType) => {
cartItems.forEach((cartItem: CartItems) => {
if (good.gid === cartItem.gid) {
good.cartNum = cartItem.number;
}
});
});
});
} else {
good_list.value.forEach((category: goodList) => {
category.Goods.forEach((good: GoodsType) => {
Reflect.deleteProperty(good, "cartNum");
});
});
}
};
</script>
<style lang="scss">
page {
// IOS安全区域
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
.nut-swiper {
height: 350px;
}
@@ -250,9 +308,9 @@ const toGoodDetails = (id: number, type: number) => {
display: flex;
margin-bottom: 10px;
img {
width: 140px;
height: 150px;
image {
width: 180px;
height: 180px;
border-radius: 10px;
}