订单横向展示卡片
源码解析
显示订单事件和状态
显示订单商品信息
价格总计和拓展
大约 4 分钟
需要把创建人和编辑人的id替换成自己的id
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('a268e25b-b3b7-4fc2-880d-5b97e1acab0b', '2024-01-26 11:11:40.133277', '2024-01-26 11:11:40.133277', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 1, 'ALI_PAY', '支付宝', 1004, '支付方式', 'PAY_TYPE', 0);
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('1a687b7d-9b24-47b0-aa57-e361812dcdf0', '2024-01-26 11:10:49.521488', '2024-01-26 11:10:49.521488', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 0, 'WE_CHAT_PAY', '微信支付', 1004, '支付类型', 'PAY_TYPE', 0);
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('461a361d-073c-4574-aed1-c025e04a81a3', '2024-01-26 11:09:32.434369', '2024-01-26 11:13:54.428416', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 5, 'REFUNDING', '退款中', 1003, '商品订单状态', 'PRODUCT_ORDER_STATUS', 0);
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('2a8a7427-9fb6-4ecb-822c-8b22fd493a93', '2024-01-26 11:08:34.090534', '2024-01-26 11:08:37.984915', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 4, 'CLOSED', '已关闭', 1003, '商品订单状态', 'PRODUCT_ORDER_STATUS', 0);
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('a1a13655-7328-45c3-8cdd-dc0d41ef5792', '2024-01-26 11:06:10.939935', '2024-01-26 11:06:16.216645', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 3, 'TO_BE_EVALUATED', '待评价', 1003, '商品订单状态', 'PRODUCT_ORDER_STATUS', 0);
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('56e8d930-6953-4f6a-875c-34d5c26802a5', '2024-01-26 11:03:49.162351', '2024-01-26 11:04:00.418344', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 2, 'TO_BE_RECEIVED', '待收货', 1003, '商品订单状态', 'PRODUCT_ORDER_STATUS', 0);
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('fc930d38-0612-4217-91ab-809a5be03656', '2024-01-26 11:02:08.987958', '2024-01-26 11:02:22.277984', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 1, 'TO_BE_DELIVERED', '待发货', 1003, '商品订单状态 ', 'PRODUCT_ORDER_STATUS', 0);
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('5c820b53-6545-45fd-8442-22f7e486fc8e', '2024-01-26 10:56:45.364997', '2024-01-26 11:02:58.744868', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 0, 'TO_BE_PAID', '待付款', 1003, '商品订单状态', 'PRODUCT_ORDER_STATUS', 0);
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('1f01fa7b-f162-4376-870d-9207735f658d', '2024-01-16 09:33:09.151337', '2024-01-16 09:33:09.151337', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 2, 'BUTTON', '按钮', 1002, '菜单类型', 'MENU_TYPE', 2);
INSERT INTO mall.dict (id, created_time, edited_time, creator_id, editor_id, key_id, key_en_name, key_name, dict_id, dict_name, dict_en_name, order_num) VALUES ('416c90b4-42e8-4af1-a3f5-7e321c9c3437', '2024-01-16 09:32:28.555205', '2024-01-16 09:32:28.555205', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', '0f07d638-f1bc-4011-88d8-6dc650ab06a7', 1, 'DIRECTORY', '目录', 1002, '菜单类型', 'MENU_TYPE', 0);
该组件用于从地址列表中选择地址。通过弹出框显示地址列表,用户点击地址后,会更新选择的地址并发出选择事件。该组件还会在加载时从API获取用户地址列表,并设置第一个地址作为默认选择。
相关信息
-- auto-generated definition
create table address
(
id varchar(36) not null
primary key,
created_time datetime(6) not null,
edited_time datetime(6) not null,
creator_id varchar(36) not null,
editor_id varchar(36) not null,
latitude double not null,
longitude double not null,
address varchar(255) not null,
province varchar(255) not null,
city varchar(255) not null,
district varchar(255) not null,
phone_number varchar(255) not null,
real_name varchar(255) not null,
top tinyint(1) not null,
details varchar(255) not null
);
export default defineAppConfig({
pages: [
"pages/index/index",
"pages/user/index",
"pages/address/address-list",
"pages/address/address-save",
],
// 忽略...
plugins: {
chooseLocation: {
version: "1.0.10",
provider: "wx76a9a06e5b4e693e",
},
},
permission: {
"scope.userLocation": {
desc: "你的位置将用于确认收货地址",
},
},
requiredPrivateInfos: ["getLocation"],
});
<script setup lang="ts">
import { AddressDto } from "@/apis/__generated/model/dto";
defineProps<{ address: AddressDto["AddressRepository/SIMPLE_FETCHER"] }>();
</script>
<template>
<!-- 前面展示地址和收件人信息,后面提供操作按钮插槽 -->
<div class="address-row">
<div class="address-info">
<!-- 上面展示地址信息 -->
<div class="details">{{ address.address + " " + address.details }}</div>
<!-- 下面展示收件人信息 -->
<div class="connector">
<div class="real-name">{{ address.realName }}</div>
<div class="phone-number">{{ address.phoneNumber }}</div>
<!-- 是否是默认地址 -->
<div class="is-default" v-if="address.top">
<nut-tag type="primary" plain>默认</nut-tag>
</div>
</div>
</div>
<slot name="operation"></slot>
</div>
</template>
<style lang="scss">
.address-row {
padding: 30rpx;
background: white;
display: flex;
align-items: center;
.address-info {
width: 600rpx;
.details {
font-size: 30rpx;
font-weight: bold;
margin-bottom: 10rpx;
}
.connector {
font-size: 28rpx;
color: rgba(black, 0.3);
display: flex;
align-items: center;
.real-name {
margin-right: 30rpx;
}
.is-default {
margin-left: 20px;
}
}
}
}
</style>
全局存储购物车的数据
import { ProductDto } from "@/apis/__generated/model/dto";
import Taro from "@tarojs/taro";
import { defineStore } from "pinia";
import { computed, ref, watchEffect } from "vue";
type ProductSkuFetcherDto = ProductDto["ProductRepository/PRODUCT_SKU_FETCHER"];
export type CartItem = {
product: ProductSkuFetcherDto;
sku: ProductSkuFetcherDto["skuList"][0];
count: number;
checked: boolean;
};
export const useCartStore = defineStore("cart", () => {
// 购物车是否显示
const visible = ref(false);
// 从本地存储中获取购物车列表
const cartList = ref<CartItem[]>(
JSON.parse(Taro.getStorageSync("cart") || "[]"),
);
// cartList有变动就缓存到本地存储
watchEffect(() => {
Taro.setStorageSync("cart", JSON.stringify(cartList.value));
});
const checkedItems = computed(() =>
cartList.value.filter((item) => item.checked),
);
// 总价
const totalPrice = computed(() =>
checkedItems.value
// 计算每个商品的总价
.map((item) => item.count * item.sku.price)
// 求和
.reduce((prev, curr) => prev + curr, 0),
);
// 购物车添加商品
const pushItem = (cartItem: CartItem) => {
const index = cartList.value.findIndex(
(item) => item.sku.id === cartItem.sku.id,
);
if (index === -1) {
cartList.value.push(cartItem);
} else {
plusItem(index);
}
};
// 购物车减少商品数量
const plusItem = (index: number) => {
cartList.value[index].count++;
};
// 购物车减少商品数量
const minusItem = (index: number) => {
const item = cartList.value[index];
if (item.count === 1) {
// 少于1时移除购物车
cartList.value.splice(index, 1);
} else {
item.count--;
}
};
// 清空购物车
const clearCart = () => {
cartList.value = [];
};
// 全选或者反选
const toggleCart = () => {
// 如果已选的数量等于购物车数量反向否则全勋。
const value = checkedItems.value.length !== cartList.value.length;
cartList.value.forEach((item) => {
item.checked = value;
});
};
return {
visible,
checkedItems,
cartList,
totalPrice,
pushItem,
plusItem,
minusItem,
clearCart,
toggleCart,
};
});