improve code

This commit is contained in:
paulGao
2022-03-31 09:26:24 +08:00
parent 48668fd2d4
commit 1e8279c849
12 changed files with 154 additions and 543 deletions

View File

@@ -1,15 +1,19 @@
<template>
<div class="wrapper">
<!-- 卡片组件 -->
<card _Title="我的足迹" :_Size="16" ></card>
<card _Title="我的足迹" :_Size="16"></card>
<Button class="del-btn" @click="clearAll" type="primary">删除全部</Button>
<!-- 订单列表 -->
<empty v-if="list.length === 0" />
<ul class="track-list" v-else>
<li v-for="(item, index) in list" :key="index" @click="goodsDetail(item.id, item.goodsId)">
<img :src="item.thumbnail" :alt="item.thumbnail" width="200" height="200">
<p class="ellipsis">{{item.goodsName}}</p>
<p>{{item.price | unitPrice('¥')}}</p>
<li
v-for="(item, index) in list"
:key="index"
@click="goodsDetail(item.id, item.goodsId)"
>
<img :src="item.thumbnail" :alt="item.thumbnail" width="200" height="200" />
<p class="ellipsis">{{ item.goodsName }}</p>
<p>{{ item.price | unitPrice("¥") }}</p>
<span class="del-icon" @click.stop="clearById(item.goodsId)">
<Icon type="md-trash" />
</span>
@@ -17,96 +21,104 @@
</ul>
<!-- 分页 -->
<div class="page-size">
<Page :total="total" @on-change="changePageNum"
<Page
:total="total"
@on-change="changePageNum"
@on-page-size-change="changePageSize"
:page-size="params.pageSize"
show-sizer>
show-sizer
>
</Page>
</div>
</div>
</template>
<script>
import { tracksList, clearTracks, clearTracksById } from '@/api/member';
import { tracksList, clearTracks, clearTracksById } from "@/api/member";
export default {
name: 'MyTrack',
data () {
name: "MyTrack",
data() {
return {
list: [], // 我的足迹,商品列表
spinShow: false, // 控制loading是否加载
params: {
pageNumber: 1,
pageSize: 30,
order: 'desc',
sort: 'createTime'
order: "desc",
sort: "updateTime",
},
total: 0
total: 0,
};
},
mounted () {
mounted() {
this.getList();
},
methods: {
goodsDetail (skuId, goodsId) {
goodsDetail(skuId, goodsId) {
// 跳转商品详情
let routeUrl = this.$router.resolve({
path: '/goodsDetail',
query: { skuId, goodsId }
path: "/goodsDetail",
query: { skuId, goodsId },
});
window.open(routeUrl.href, '_blank');
window.open(routeUrl.href, "_blank");
},
// 跳转店铺首页
shopPage (id) {
shopPage(id) {
let routeUrl = this.$router.resolve({
path: '/Merchant',
query: { id: id }
path: "/Merchant",
query: { id: id },
});
window.open(routeUrl.href, '_blank');
window.open(routeUrl.href, "_blank");
},
clearAll () { // 清除全部足迹
clearAll() {
// 清除全部足迹
this.$Modal.confirm({
title: '删除',
content: '<p>确定要删除全部足迹吗?</p>',
title: "删除",
content: "<p>确定要删除全部足迹吗?</p>",
onOk: () => {
clearTracks().then(res => {
clearTracks().then((res) => {
if (res.success) {
this.$Message.success('删除成功')
this.getList()
this.$Message.success("删除成功");
this.getList();
}
})
});
},
onCancel: () => { }
onCancel: () => {},
});
},
clearById (id) { // 清除全部足迹
clearTracksById(id).then(res => {
clearById(id) {
// 清除全部足迹
clearTracksById(id).then((res) => {
if (res.success) {
this.$Message.success('删除成功')
this.getList()
this.$Message.success("删除成功");
this.getList();
}
})
});
},
changePageNum (val) { // 修改页码
changePageNum(val) {
// 修改页码
this.params.pageNumber = val;
this.getList()
this.getList();
},
changePageSize (val) { // 修改页数
changePageSize(val) {
// 修改页数
this.params.pageNumber = 1;
this.params.pageSize = val;
this.getList()
this.getList();
},
getList () { // 获取足迹列表
getList() {
// 获取足迹列表
this.spinShow = true;
tracksList(this.params).then(res => {
this.spinShow = false
tracksList(this.params).then((res) => {
this.spinShow = false;
if (res.success && res.result) {
this.list = res.result;
} else {
this.list = []
this.list = [];
}
});
}
}
},
},
};
</script>
<style scoped lang="scss">
@@ -120,34 +132,34 @@ export default {
.track-list {
display: flex;
flex-wrap: wrap;
li{
li {
width: 200px;
overflow: hidden;
margin-left: 15px;
margin-bottom: 10px;
border: 1px solid #eee;
position: relative;
&:hover{
&:hover {
cursor: pointer;
box-shadow:1px 1px 3px #999;
.del-icon{
box-shadow: 1px 1px 3px #999;
.del-icon {
display: block;
}
}
p{
p {
padding: 0 5px;
margin: 3px 0;
}
p:nth-child(2) {
color: #999;
}
p:nth-child(3){
p:nth-child(3) {
color: $theme_color;
}
.del-icon {
display: none;
font-size: 30px;
background-color:rgba(0,0,0,.3);
background-color: rgba(0, 0, 0, 0.3);
position: absolute;
width: 40px;
height: 40px;