【vue3.0】24.0 某东到家( 廿四)——订单列表开发
DOM完善
修改src\views\orderList\OrderList.vue
<template>
<!-- 主体内容容器 -->
<div class="wrapper">
<!-- 主体商铺展示内容 -->
<div class="title">我的订单</div>
<div class="orders">
<div class="order">
<div class="order__title">
某什么码1
<span class="order__status">已取消</span>
</div>
<div class="order__content">
某什么码1
<span class="order__content__imgs">
<img class="order__content__img" src="" alt="" />
<img class="order__content__img" src="" alt="" />
<img class="order__content__img" src="" alt="" />
<img class="order__content__img" src="" alt="" />
</span>
</div>
<div class="order__info">
<div class="order__info__price">¥588</div>
<div class="order__info__count">共3件</div>
</div>
</div>
</div>
</div>
<!-- 底部主菜单容器 -->
<Docker :current-index="2" />
<router-view />
</template>
<script>
import Docker from '@/components/Docker/Docker'
export default {
name: 'OrderList',
components: { Docker }
}
</script>
<style lang="scss" scoped>
.wrapper {
overflow-y: auto;
position: absolute;
left: 0;
top: 0;
bottom: 0.5rem;
right: 0;
background-color: #eee;
}
.title {
line-height: 0.44rem;
background: #fff;
font-size: 0.16rem;
color: #333;
text-align: center;
}
</style>
进一步完善
<style lang="scss" scoped>
......
.orders {
}
.order {
padding: 0.16rem;
background: #fff;
margin: 0.16rem 0.18rem;
}
</style>
继续优化
<template>
<!-- 主体内容容器 -->
<div class="wrapper">
<!-- 主体商铺展示内容 -->
<div class="title">我的订单</div>
<div class="orders">
<div class="order">
<div class="order__title">
某什么码1
<span class="order__status">已取消</span>
</div>
<div class="order__content">
<span class="order__content__imgs">
<img class="order__content__img" src="/i18n/9_16/img/crab.png" alt="" />
<img class="order__content__img" src="/i18n/9_16/img/crab.png" alt="" />
<img class="order__content__img" src="/i18n/9_16/img/crab.png" alt="" />
<img class="order__content__img" src="/i18n/9_16/img/crab.png" alt="" />
</span>
<div class="order__content__info">
<div class="order__content__info__price">¥588</div>
<div class="order__content__info__count">共3件</div>
</div>
</div>
</div>
</div>
</div>
<!-- 底部主菜单容器 -->
<Docker :current-index="2" />
<router-view />
</template>
<script>
import Docker from '@/components/Docker/Docker'
export default {
name: 'OrderList',
components: { Docker }
}
</script>
<style lang="scss" scoped>
.wrapper {
overflow-y: auto;
position: absolute;
left: 0;
top: 0;
bottom: 0.5rem;
right: 0;
background-color: #f8f8f8;
}
.title {
line-height: 0.44rem;
background: #fff;
font-size: 0.16rem;
color: #333;
text-align: center;
}
.orders {
}
.order {
padding: 0.16rem;
background: #fff;
margin: 0.16rem 0.18rem;
line-height: 0.22rem;
&__title {
margin-bottom: 0.16rem;
font-size: 0.16rem;
color: #333;
}
&__status {
float: right;
font-size: 0.14rem;
color: #999;
}
&__content {
display: flex;
&__imgs {
flex: 1;
}
&__img {
width: 0.4rem;
height: 0.4rem;
margin-right: 0.12rem;
}
&__info {
width: 0.7rem;
}
}
}
</style>
继续优化
<template>
<!-- 主体内容容器 -->
<div class="wrapper">
<!-- 主体商铺展示内容 -->
<div class="title">我的订单</div>
<div class="orders">
<div class="order">
<div class="order__title">
某什么码1
<span class="order__status">已取消</span>
</div>
<div class="order__content">
<span class="order__content__imgs">
<img class="order__content__img" src="/i18n/9_16/img/crab.png" alt="" />
<img class="order__content__img" src="/i18n/9_16/img/crab.png" alt="" />
<img class="order__content__img" src="/i18n/9_16/img/crab.png" alt="" />
<img class="order__content__img" src="/i18n/9_16/img/crab.png" alt="" />
</span>
<div class="order__content__info">
<div class="order__content__info__price">¥588</div>
<div class="order__content__info__count">共3件</div>
</div>
</div>
</div>
</div>
</div>
<!-- 底部主菜单容器 -->
<Docker :current-index="2" />
<router-view />
</template>
<script>
import Docker from '@/components/Docker/Docker'
export default {
name: 'OrderList',
components: { Docker }
}
</script>
<style lang="scss" scoped>
@import '@/style/viriables.scss';
.wrapper {
overflow-y: auto;
position: absolute;
left: 0;
top: 0;
bottom: 0.5rem;
right: 0;
background-color: #f8f8f8;
}
.title {
line-height: 0.44rem;
background: $bg-color;
font-size: 0.16rem;
color: $content-font-color;
text-align: center;
}
.orders {
}
.order {
padding: 0.16rem;
background: $bg-color;
margin: 0.16rem 0.18rem;
line-height: 0.22rem;
&__title {
margin-bottom: 0.16rem;
font-size: 0.16rem;
color: $content-font-color;
}
&__status {
float: right;
font-size: 0.14rem;
color: $light-font-color;
}
&__content {
display: flex;
&__imgs {
flex: 1;
}
&__img {
width: 0.4rem;
height: 0.4rem;
margin-right: 0.12rem;
}
&__info {
width: 0.7rem;
&__price {
line-height: 0.2rem;
margin-bottom: 0.4rem;
font-size: 0.14rem;
color: $height-light-font-color;
text-align: right;
}
&__count {
line-height: 0.14rem;
font-size: 0.12rem;
color: $content-font-color;
text-align: right;
}
}
}
}
</style>
新建get接口/api/order
数据如下:
{
"code": 200,
"data": [
{
"address": {
"city": "北京",
"department": "xx小区",
"houseNumber": "门牌号",
"name": "张三",
"phone": "18012341234"
},
"shopId": "1",
"shopName": "某什么码1",
"isCanceled": false,
"products": [
{
"orderSales": 5,
"product": {
"name": "番茄250g/份",
"imgUrl": "/i18n/9_16/img/tomato.png",
"sales": 10,
"price": 33.6
}
},
{
"orderSales": 10,
"product": {
"name": "樱桃250g/份",
"imgUrl": "/i18n/9_16/img/cherry.png",
"sales": 10,
"price": 79.6
}
},
{
"orderSales": 8,
"product": {
"name": "帝王蟹250g/份",
"imgUrl": "/i18n/9_16/img/crab.png",
"sales": 10,
"price": 159.6
}
},
{
"orderSales": 4,
"product": {
"name": "橙子250g/份",
"imgUrl": "/i18n/9_16/img/orange.png",
"sales": 10,
"price": 92.6
}
}
]
}
],
"desc": "成功"
}
页面完善:
<template>
<!-- 主体内容容器 -->
<div class="wrapper">
<!-- 主体商铺展示内容 -->
<div class="title">我的订单</div>
<div class="orders">
<div class="order" v-for="(item, index) in list" :key="index">
<div class="order__title">
{{ item.shopName }}
<span class="order__status">{{ item.isCanceled ? '已取消' : '已下单' }}</span>
</div>
<div class="order__content">
<span class="order__content__imgs">
<template v-for="(itemImg, indexImg) in item.products" :key="indexImg">
<img
class="order__content__img"
:src="itemImg.product.imgUrl"
alt="图片"
v-if="indexImg <= 3"
/>
</template>
</span>
<div class="order__content__info">
<div class="order__content__info__price">¥{{ item.totalPrice }}</div>
<div class="order__content__info__count">共{{ item.totalNumber }}件</div>
</div>
</div>
</div>
</div>
</div>
<!-- 底部主菜单容器 -->
<Docker :current-index="2" />
<Toast v-if="show" :message="message" />
<router-view />
</template>
<script>
import { reactive, toRefs } from 'vue'
import { get } from '@/utils/request.js'
import Toast, { useToastEffect } from '@/components/Toast/Toast'
const useOrderListEffect = toastMsg => {
const data = reactive({ list: [] })
const getNearbyList = async () => {
// 可以写成: const resultData = await get(`/api/shop/${route.params.id}`)
const resultData = await get('/api/order/')
if (resultData?.code === 200 && resultData?.data?.length) {
console.log('data :' + JSON.stringify(data))
const tempData = resultData.data || []
tempData.forEach(item => {
const products = item.products
let totalPrice = 0 //商品总价
let totalNumber = 0
products.forEach(item2 => {
totalNumber += Number(item2?.orderSale || 0)
totalPrice += Number(item2?.product.price || 0) * Number(item2?.orderSales || 0)
})
item.totalPrice = totalPrice.toFixed(2)
item.totalNumber = totalNumber
})
data.list = tempData
} else {
toastMsg('没有数据!')
}
}
getNearbyList()
const { list } = toRefs(data)
return { getNearbyList, list }
}
import Docker from '@/components/Docker/Docker'
export default {
name: 'OrderList',
components: { Docker, Toast },
setup() {
const { show, message, toastMsg } = useToastEffect()
const { list } = useOrderListEffect(toastMsg)
return { show, message, list }
}
}
</script>
<style lang="scss" scoped>
@import '@/style/viriables.scss';
.wrapper {
overflow-y: auto;
position: absolute;
left: 0;
top: 0;
bottom: 0.5rem;
right: 0;
background-color: #f8f8f8;
}
.title {
line-height: 0.44rem;
background: $bg-color;
font-size: 0.16rem;
color: $content-font-color;
text-align: center;
}
.orders {
}
.order {
padding: 0.16rem;
background: $bg-color;
margin: 0.16rem 0.18rem;
line-height: 0.22rem;
&__title {
margin-bottom: 0.16rem;
font-size: 0.16rem;
color: $content-font-color;
}
&__status {
float: right;
font-size: 0.14rem;
color: $light-font-color;
}
&__content {
display: flex;
&__imgs {
flex: 1;
}
&__img {
width: 0.4rem;
height: 0.4rem;
margin-right: 0.12rem;
}
&__info {
width: 0.7rem;
&__price {
line-height: 0.2rem;
margin-bottom: 0.04rem;
font-size: 0.14rem;
color: $height-light-font-color;
text-align: right;
}
&__count {
line-height: 0.14rem;
font-size: 0.12rem;
color: $content-font-color;
text-align: right;
}
}
}
}
</style>
发表评论 (审核通过后显示评论):