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

289
src/components/Cart.vue Normal file
View File

@@ -0,0 +1,289 @@
<script setup lang="ts">
import { ref } from "vue";
import Taro from "@tarojs/taro";
import { addCart, getCart, clearCart } from "@/api/cart";
import { Del2 } from "@nutui/icons-vue-taro";
import { createActiveOrder } from "@/api/goods";
import Pay from "@/components/Pay.vue";
interface CardList {
name: string;
cover: string;
bid: string;
gid: string;
number: string;
price: number;
exchange: number;
}
const show = ref(false);
const props = defineProps({
merInfo: {
required: true,
type: Object,
},
});
const emit = defineEmits(["updateCart"]);
const openModal = async () => {
await get_cart_list();
if (card_list.value.length === 0) return;
show.value = !show.value;
};
const add_cart = async (item: CardList, num: number = 1) => {
try {
const res = await addCart({
Bid: item.bid,
Gid: item.gid,
Number: Number(num),
});
Taro.showToast({
title: res.msg,
icon: "none",
});
await get_cart_list();
} catch (e) {
Taro.showToast({
title: e.msg,
icon: "none",
});
}
};
const onAdd = async (item: CardList) => {
await add_cart(item, Number(item.number) + 1);
};
const onReduce = async (item: CardList) => {
await add_cart(item, Number(item.number) - 1);
if (card_list.value.length === 0) show.value = false;
};
const card_list = ref<CardList[]>([]);
const cartInfo = ref({
count: 0,
price: 0,
exchange: 0,
});
const get_cart_list = async () => {
try {
const res = await getCart({
Bid: props.merInfo.bid,
});
card_list.value = res.data.data || [];
cartInfo.value = {
count: 0,
price: 0,
exchange: 0,
};
card_list.value.forEach((item: CardList) => {
cartInfo.value.count += Number(item.number);
cartInfo.value.price += Number(item.price);
cartInfo.value.exchange += Number(item.exchange);
});
emit("updateCart", res.data.data || []);
} catch (e) {
Taro.showToast({
title: e.msg,
icon: "none",
});
}
};
const clear_cart = async () => {
try {
await clearCart({
Bid: props.merInfo.bid,
});
await get_cart_list();
} catch (e) {
Taro.showToast({
title: e.msg,
icon: "none",
});
}
show.value = false;
};
const isShowPay = ref(false);
const orderData = ref<any>([]);
const closePay = (val: boolean) => {
isShowPay.value = val;
orderData.value = [];
Taro.redirectTo({
url: "/pages/users/order_list/index?type=0",
});
};
const create_order = async () => {
try {
const { data: res } = await createActiveOrder({
Bid: [props.merInfo.bid],
});
if (res.oid) {
orderData.value = res.oid;
isShowPay.value = true;
}
} catch (e) {
Taro.showToast({
title: e.msg,
icon: "none",
});
}
// await get_cart_list();
};
defineExpose({
add_cart,
get_cart_list,
});
</script>
<template>
<view>
<view class="cart" @click.stop="openModal">
<view class="container">
<view>购物车数量: {{ cartInfo.count }}</view>
<view v-if="cartInfo.count > 0">
<text>总金额: {{ cartInfo.price.toFixed(2) }}</text
>,
<text>总积分: {{ cartInfo.exchange.toFixed(2) }}</text>
</view>
</view>
<view v-if="cartInfo.count > 0" class="payBtn" @click.stop="create_order"
>立即结算</view
>
</view>
<!-- 购物车弹窗 -->
<nut-popup
:style="{ padding: '20rpx' }"
round
position="bottom"
z-index="1"
:catch-move="true"
:safe-area-inset-bottom="true"
v-model:visible="show"
>
<view class="list-header">
<view class="left" @click.stop="clear_cart">
<Del2 color="#666666" />
<text style="color: #666666">清空购物车</text>
</view>
</view>
<scroll-view :scroll-y="true" class="cart-list">
<view class="item" v-for="(item, index) in card_list" :key="index">
<view class="left">
<image :src="item.cover" />
<view class="center">
<view class="name">{{ item.name }}</view>
<view class="price">
<view>现金:{{ item.price }}</view>
<view>积分:{{ item.exchange }}</view>
</view>
</view>
</view>
<nut-input-number
v-model="item.number"
readonly
:min="-1"
@add="() => onAdd(item)"
@reduce="() => onReduce(item)"
/>
</view>
</scroll-view>
<view style="height: 140rpx"></view>
</nut-popup>
<!-- 支付 -->
<Pay
:is-show-pay="isShowPay"
v-model:jfInfo="orderData"
@closePay="closePay"
@successPay="closePay"
/>
</view>
</template>
<style lang="scss">
$h-border-radius: 50rpx;
.cart {
position: fixed;
bottom: 50rpx;
left: 50%;
transform: translateX(-50%);
z-index: 9999;
width: 95%;
background-color: red;
border-radius: $h-border-radius;
color: #fff;
height: 100rpx;
display: flex;
justify-content: space-between;
align-items: center;
.container {
margin-left: 30rpx;
}
.payBtn {
width: 180rpx;
height: 100rpx;
line-height: 100rpx;
text-align: center;
background-color: #000;
border-radius: 0 $h-border-radius $h-border-radius 0;
}
}
.list-header {
margin: 15rpx 0;
.left {
display: flex;
align-items: center;
}
}
.cart-list {
height: 290rpx;
.item {
display: flex;
align-items: flex-end;
margin-bottom: 10rpx;
justify-content: space-between;
.left {
display: flex;
image {
width: 130rpx;
height: 130rpx;
border-radius: 10rpx;
margin-right: 10rpx;
}
.center {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
.price {
color: red;
margin-top: 20rpx;
}
}
}
}
}
</style>

152
src/components/MerList.vue Normal file
View File

@@ -0,0 +1,152 @@
<template>
<view class="goodBox">
<view
class="good"
v-for="item in merdata"
:key="item.ID"
@click.stop="toMerDetails(item)"
>
<image :src="item.head_photo" />
<view class="good-text-box">
<text class="good-text">{{ item.name }}</text>
<text style="color: #999"
>距离我{{
calculateDistance(
userLocalNum.t,
userLocalNum.l,
Number(item.lat),
Number(item.lon)
)
}}
</text>
</view>
</view>
</view>
</template>
<script setup lang="ts">
import { ref } from "vue";
import Taro from "@tarojs/taro";
import { calculateDistance } from "@/utils";
import { bindParent } from "@/api/user";
import { getMerList } from "@/api/goods";
const props = defineProps({
classId: {
type: Number,
default: 0,
},
});
Taro.useDidShow(async () => {
await get_mer_list();
if (Taro.getStorageSync("token") && Taro.getStorageSync("bind_id")) {
try {
const res = await bindParent({
uid: Taro.getStorageSync("bind_id"),
});
Taro.showToast({
title: res.msg,
});
Taro.removeStorageSync("bind_id");
} catch (error) {
Taro.removeStorageSync("bind_id");
throw error;
}
}
});
interface MerData {
ID: number;
name: string;
head_photo: string;
lat: string;
lon: string;
}
const merdata = ref<MerData[]>([]);
const userLocalNum = ref({
l: 0,
t: 0,
});
const get_mer_list = async () => {
Taro.getLocation({
type: "wgs84",
success: (res) => {
userLocalNum.value.l = res.longitude;
userLocalNum.value.t = res.latitude;
},
});
const res = await getMerList({
PageNum: 1,
PageSize: 10,
class_id: props.classId,
});
merdata.value = res.data.data;
};
const toMerDetails = (item: any) => {
Taro.setStorageSync("mer_info", item);
Taro.navigateTo({
url: `/pages/mer/mer_detail/index`,
});
};
</script>
<style lang="scss">
.goodBox {
display: flex;
padding: 20px;
flex-wrap: wrap;
justify-content: space-between;
.good {
width: 340px;
background-color: #fff;
margin-bottom: 20px;
border-radius: 10px;
image {
width: 100%;
height: 250px;
border-top-right-radius: 10px;
border-top-left-radius: 10px;
}
.good-text-box {
padding: 10px;
.good-text {
flex-shrink: 0;
font-size: 28px;
color: #333;
font-weight: 400;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
word-break: break-word;
}
.good-price-box {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 10px;
.good-text-price {
font-size: 28px;
font-weight: bold;
color: #ff0000;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
}
}
}
}
}
</style>

View File

@@ -11,13 +11,14 @@
>
<view class="div">
<view style="text-align: center">支付方式</view>
<nut-cell-group>
<nut-cell-group
:style="{ margin: interval ? '40rpx 0 150rpx 0' : '40rpx 0' }"
>
<nut-cell
v-if="payType === 'wx'"
title="微信支付"
desc="使用微信快捷支付"
is-link
@click="goPay()"
@click="goPay(1)"
>
<template v-slot:icon>
<IconFont
@@ -27,11 +28,10 @@
</template>
</nut-cell>
<nut-cell
v-if="payType === 'jf'"
title="积分支付"
:desc="`剩余积分:${info.integral || 0}`"
is-link
@click="goPay()"
@click="goPay(2)"
>
<template v-slot:icon>
<IconFont
@@ -50,26 +50,28 @@ import { ref, watch } from "vue";
import { IconFont } from "@nutui/icons-vue-taro";
import Taro from "@tarojs/taro";
import { payOrder } from "@/api/order";
import { payJfOrder } from "@/api/goods";
import { getPersonalInfo } from "@/api/user";
const prop = defineProps({
interval: {
type: Boolean,
default: true,
},
isShowPay: {
required: true,
type: Boolean,
default: false,
},
payType: {
required: true,
type: String,
default: "wx",
},
jfInfo: {
type: Object,
default: () => {
return {};
},
},
OrderType: {
type: Number,
default: 1,
},
});
const emit = defineEmits(["closePay", "successPay"]);
@@ -96,61 +98,67 @@ const getInfo = async () => {
}
};
const goPay = async () => {
console.log(prop.jfInfo);
const goPay = async (type: number) => {
console.log(prop);
if (!prop.jfInfo)
return Taro.showToast({
title: "未获取到订单信息",
icon: "none",
});
if (prop.payType === "wx") {
try {
const { data } = await payOrder({
oid: prop.jfInfo.oid,
});
Taro.requestPayment({
timeStamp: data.data.timeStamp,
nonceStr: data.data.nonceStr,
package: data.data.package,
signType: data.data.signType,
paySign: data.data.paySign,
success: function () {
Taro.showToast({
title: "支付成功",
icon: "success",
duration: 2000,
});
Taro.navigateTo({
url: "/pages/hotGoods/hot_list/index",
});
},
fail: function () {
Taro.showToast({
title: "支付失败",
icon: "none",
duration: 2000,
});
},
});
emit("closePay", false);
} catch (e) {
try {
const { data } = await payOrder({
oid: prop.jfInfo,
OrderType: prop.OrderType,
PayType: type,
});
if (data.data) {
// 1微信支付 2积分支付
if (type === 1) {
Taro.requestPayment({
timeStamp: data.data.timeStamp,
nonceStr: data.data.nonceStr,
package: data.data.package,
signType: data.data.signType,
paySign: data.data.paySign,
success: function () {
Taro.showToast({
title: "支付成功",
icon: "success",
duration: 2000,
});
emit("successPay", false);
},
fail: function () {
Taro.showToast({
title: "支付失败",
icon: "none",
duration: 2000,
});
emit("closePay", false);
},
});
} else {
Taro.showToast({
title: "支付成功",
icon: "success",
duration: 2000,
});
emit("successPay", false);
}
} else {
Taro.showToast({
title: e.msg,
title: "未知异常",
icon: "none",
});
throw e;
emit("closePay", false);
}
} else {
const res = await payJfOrder(prop.jfInfo);
} catch (e) {
Taro.showToast({
title: res.msg,
icon: "success",
duration: 2000,
title: e.msg,
icon: "none",
});
Taro.navigateTo({
url: "/pages/users/order_list/index?type=0",
});
emit("closePay", false);
// emit("closePay", false);
throw e;
}
};
@@ -166,13 +174,13 @@ const closePay = () => {
<style lang="scss">
.nut-popup {
.nut-popup__container {
border-radius: 10px;
border-radius: 10rpx;
}
}
.div {
padding: 20px;
// text-align: center;
padding: 20rpx;
--nut-cell-box-shadow: none;
.nut-cell {
align-items: center;

View File

@@ -1,12 +1,12 @@
<script setup lang="ts">
import { ref } from "vue";
import Taro from "@tarojs/taro";
import { getSignRecord, userSign } from "@/api/user";
import { userSign } from "@/api/user";
const show = ref(false);
Taro.useLoad(async () => {
show.value = true;
if (Taro.getStorageSync("token")) show.value = true;
// const res = await getSignRecord()
// console.log(res)
});

View File

@@ -37,7 +37,6 @@ const closeAttr = () => {
const onChooseAvatar = (e) => {
const { avatarUrl } = e.detail;
console.log(avatarUrl);
Taro.uploadFile({
url: `${BASE_URL}/upload`,
filePath: avatarUrl,