peng
3 天以前 2fd269af9df3653b058deee57bcd7a9f39ff28e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<template>
  <div class="wrapper">
    <!-- 卡片组件 -->
    <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>
        <span class="del-icon" @click.stop="clearById(item.goodsId)">
          <Icon type="md-trash" />
        </span>
      </li>
    </ul>
    <!-- 分页 -->
    <div class="page-size">
      <Page
        :total="total"
        @on-change="changePageNum"
        @on-page-size-change="changePageSize"
        :page-size="params.pageSize"
        show-sizer
      >
      </Page>
    </div>
  </div>
</template>
 
<script>
import { tracksList, clearTracks, clearTracksById } from "@/api/member";
export default {
  name: "MyTrack",
  data() {
    return {
      list: [], // 我的足迹,商品列表
      spinShow: false, // 控制loading是否加载
      params: {
        pageNumber: 1,
        pageSize: 30,
        order: "desc",
        sort: "updateTime",
      },
      total: 0,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    goodsDetail(skuId, goodsId) {
      // 跳转商品详情
      let routeUrl = this.$router.resolve({
        path: "/goodsDetail",
        query: { skuId, goodsId },
      });
      window.open(routeUrl.href, "_blank");
    },
    // 跳转店铺首页
    shopPage(id) {
      let routeUrl = this.$router.resolve({
        path: "/Merchant",
        query: { id: id },
      });
      window.open(routeUrl.href, "_blank");
    },
    clearAll() {
      // 清除全部足迹
      this.$Modal.confirm({
        title: "删除",
        content: "<p>确定要删除全部足迹吗?</p>",
        onOk: () => {
          clearTracks().then((res) => {
            if (res.success) {
              this.$Message.success("删除成功");
              this.getList();
            }
          });
        },
        onCancel: () => {},
      });
    },
    clearById(id) {
      // 清除全部足迹
      clearTracksById(id).then((res) => {
        if (res.success) {
          this.$Message.success("删除成功");
          this.getList();
        }
      });
    },
    changePageNum(val) {
      // 修改页码
      this.params.pageNumber = val;
      this.getList();
    },
    changePageSize(val) {
      // 修改页数
      this.params.pageNumber = 1;
      this.params.pageSize = val;
      this.getList();
    },
    getList() {
      // 获取足迹列表
      this.spinShow = true;
      tracksList(this.params).then((res) => {
        this.spinShow = false;
        if (res.success && res.result.records.length) {
          this.list = res.result.records.filter(item =>{
            return item != null
          });
          this.total = res.result.total
        } else {
          this.list = [];
        }
      });
    },
  },
};
</script>
<style scoped lang="scss">
.wrapper {
  margin-bottom: 40px;
}
.del-btn {
  margin: 0 0 10px 15px;
}
 
.track-list {
  display: flex;
  flex-wrap: wrap;
  li {
    width: 200px;
    overflow: hidden;
    margin-left: 15px;
    margin-bottom: 10px;
    border: 1px solid #eee;
    position: relative;
    &:hover {
      cursor: pointer;
      box-shadow: 1px 1px 3px #999;
      .del-icon {
        display: block;
      }
    }
    p {
      padding: 0 5px;
      margin: 3px 0;
    }
    p:nth-child(2) {
      color: #999;
    }
    p:nth-child(3) {
      color: $theme_color;
    }
    .del-icon {
      display: none;
      font-size: 30px;
      background-color: rgba(0, 0, 0, 0.3);
      position: absolute;
      width: 40px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      right: 0;
      top: 0;
      cursor: pointer;
    }
  }
}
.page-size {
  margin: 15px 0px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
</style>