zxl
昨天 b1c9a5d056e85fe8b0ee6e92f10e6e2c5495b356
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<template>
  <div style="background:#fff;">
    <BaseHeader></BaseHeader>
    <Search style="border-bottom:2px solid red;"></Search>
    <!-- <drawer></drawer> -->
    <div class="base-width cate-container">
      <Breadcrumb>
        <BreadcrumbItem to="/">首页</BreadcrumbItem>
        <BreadcrumbItem>{{goodsMsg.pointsGoodsCategoryName}}</BreadcrumbItem>
      </Breadcrumb>
    </div>
    <!-- 商品信息展示 -->
    <div class="item-detail-show">
      <!-- 详情左侧展示数据、图片,收藏、举报 -->
      <div class="item-detail-left">
        <!-- 大图、放大镜 -->
        <div class="item-detail-big-img">
          <pic-zoom v-if="goodsSku.thumbnail" :url="goodsSku.thumbnail" :scale="2"></pic-zoom>
        </div>
        <div class="item-detail-img-row">
          <div class="item-detail-img-small">
            <img :src="goodsSku.thumbnail" />
          </div>
        </div>
      </div>
      <!-- 右侧商品信息、活动信息、操作展示 -->
      <div class="item-detail-right">
        <div class="item-detail-title">
          <p>{{ goodsSku.goodsName }}</p>
        </div>
        <div class="sell-point">
          {{goodsSku.sellingPoint}}
        </div>
        <!-- 商品详细 -->
        <div class="item-detail-price-row">
          <div class="item-price-left">
            <!-- 商品原价 -->
            <div class="item-price-row">
              <p>
                <span class="item-price-title">积 &nbsp;&nbsp;&nbsp;&nbsp;分</span>
                <span class="item-price">{{goodsMsg.points}}</span>
              </p>
            </div>
          </div>
        </div>
        <div class="add-buy-car-box">
          <div class="item-select">
            <div class="item-select-title">
              <p>数量</p>
            </div>
            <div class="item-select-row">
              <InputNumber :min="1" :disabled="goodsSku.quantity === 0" v-model="count"></InputNumber>
              <span class="inventory"> 库存{{goodsSku.quantity}}</span>
            </div>
          </div>
          <div class="item-select" v-if="goodsSku.goodsType !== 'VIRTUAL_GOODS' && goodsSku.weight !== 0">
            <div class="item-select-title">
              <p>重量</p>
            </div>
            <div class="item-select-row">
              <span class="inventory"> {{goodsSku.weight}}kg</span>
            </div>
          </div>
          <div class="add-buy-car">
            <Button type="error" :loading="loading" :disabled="goodsSku.quantity === 0" @click="pointBuy">积分购买</Button>
          </div>
        </div>
      </div>
    </div>
    <!-- 商品详情 -->
    <div class="base-width item-intro" ref="itemIntroGoods">
      <div>商品介绍</div>
      <div v-html="goodsSku.intro" class="mt_10 ml_10" v-if="goodsSku.intro"></div>
      <div v-else style="margin:20px;">暂无商品介绍</div>
    </div>
    <Spin size="large" fix v-if="isLoading"></Spin>
    <BaseFooter></BaseFooter>
  </div>
</template>
 
<script>
import Search from '@/components/Search';
import PicZoom from 'vue-piczoom';
import { addCartGoods } from '@/api/cart.js';
import { pointGoodsDetail } from '@/api/promotion';
export default {
  name: 'PointGoodsDetail',
  beforeRouteEnter (to, from, next) {
    window.scrollTo(0, 0);
    next();
  },
  created () {
    this.getGoodsDetail();
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  data () {
    return {
      goodsMsg: {}, // 商品信息
      goodsSku: {}, // 商品sku
      isLoading: false, // 加载状态
      categoryBar: [], // 分类
      onceFlag: true, // 只调用一次
      count: 1, // 购买商品数量
      loading: false // 提交加载状态
    };
  },
  methods: {
    // 获取积分商品详情
    getGoodsDetail () {
      this.isLoading = true;
      pointGoodsDetail(this.$route.query.id).then((res) => {
        this.isLoading = false;
        if (res.success) {
          this.goodsMsg = res.result;
          this.goodsSku = res.result.goodsSku
        } else {
          this.$Message.error(res.message)
          this.$router.push('/')
        }
      }).catch(() => {
        this.$router.push('/')
      });
    },
    pointBuy () {
      const params = {
        num: this.count,
        skuId: this.goodsMsg.skuId,
        cartType: 'POINTS'
      };
      this.loading = true;
      addCartGoods(params).then(res => {
        this.loading = false;
        if (res.success) {
          this.$router.push({path: '/pay', query: {way: params.cartType}});
        } else {
          this.$Message.warning(res.message);
        }
      }).catch(() => {
        this.loading = false;
      });
    },
    handleScroll () { // 监听页面滚动
      if (this.onceFlag) {
        this.$nextTick(() => {
          this.changeHeight()
        });
        this.onceFlag = false
      }
    },
    changeHeight () { // 设置商品详情高度
      let goodsDetailCon = document.querySelector('.item-intro')
      let heightCss = window.getComputedStyle(goodsDetailCon).height;
      heightCss = parseInt(heightCss.substr(0, heightCss.length - 2)) + 89;
      this.$refs.itemIntroGoods.style.height = heightCss + 'px';
    }
  },
  components: {
    Search, PicZoom
  }
};
</script>
<style scoped lang="scss">
.base-width{
  width: 1200px;
  margin: 0 auto;
  position: relative;
}
.cate-container{
  background-color: #eee;
  height: 30px;
  line-height: 30px;
  padding-left: 10px;
  margin-top: 10px;
}
// 商品图片,价格等
.item-detail-show {
  width: 1200px;
  margin: 0 auto;
  padding: 30px;
  display: flex;
  flex-direction: row;
}
.item-detail-left {
  width: 350px;
  margin-right: 30px;
}
 
.item-detail-big-img {
  width: 350px;
  height: 350px;
  box-shadow: 0px 0px 8px $border_color;
  cursor: pointer;
  img {
    width: 100%;
  }
}
 
.item-detail-img-row {
  margin-top: 15px;
  display: flex;
}
 
.item-detail-img-small {
  width: 68px;
  height: 68px;
  box-shadow: 0px 0px 8px #ccc;
  cursor: pointer;
  margin-left: 5px;
  img {
    height: 100%;
    width: 100%;
  }
}
/*商品选购详情*/
.item-detail-right {
  flex: 1;
  display: flex;
  flex-direction: column;
}
 
.item-detail-title p {
  @include content_color($light_content_color);
  font-weight: bold;
  font-size: 20px;
  padding: 8px 0;
}
 
.item-detail-express {
  font-size: 14px;
  padding: 2px 3px;
  border-radius: 3px;
  background-color: $theme_color;
  color: #fff;
}
 
/*商品标签*/
.item-detail-tag {
  padding: 8px 0;
  font-size: 12px;
  color: $theme_color;
}
 
/*价格详情等*/
.item-detail-price-row {
  padding: 10px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  background: url("../../assets/images/goodsDetail/price-bg.png");
}
 
.item-price-left {
  display: flex;
  flex-direction: column;
}
 
.item-price-title {
  color: #999999;
  font-size: 14px;
  margin-right: 15px;
}
 
.item-price-row {
  margin: 5px 0px;
}
 
.item-price {
  color: $theme_color;
  font-size: 20px;
  cursor: pointer;
}
.item-price-old {
  color: gray;
  text-decoration: line-through;
  font-size: 14px;
  margin-left: 5px;
}
.add-buy-car-box {
  width: 100%;
  margin-top: 15px;
  border-top: 1px dotted $border_color;
}
 
.add-buy-car {
  margin-top: 15px;
  >*{
    margin: 0 4px;
  }
}
.item-select {
  display: flex;
  flex-direction: row;
  margin-top: 15px;
}
 
.item-select-title {
  @include content_color($light_content_color);
  font-size: 14px;
  margin-right: 15px;
  width: 60px;
}
 
.item-select-column {
  display: flex;
  flex-wrap: wrap;
  flex: 1;
}
 
.item-select-row {
  margin-bottom: 8px;
}
 
.item-select-box {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 5px;
  margin-right: 8px;
  @include background_color($light_background_color);
  border: 0.5px solid $border_color;
  cursor: pointer;
  @include content_color($light_content_color);
}
 
.item-select-box:hover {
  border: 0.5px solid $theme_color;
}
 
.item-select-box-active {
  border: 0.5px solid $theme_color;
}
 
.item-select-intro p {
  margin: 0px;
  padding: 5px;
}
.sell-point {
  font-size: 12px;
  color: red;
  margin-bottom: 5px;
}
// 商品详情
.item-intro {
  margin-top: 10px;
  >div:nth-child(1) {
    height: 40px;
    line-height: 40px;
    background-color: #eee;
    padding-left: 20px;
  }
}
</style>