fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
<!--
 * @Author: 张嘉彬
 * @Date: 2021-10-12 15:10:21
 * @Description: 拼团活动详情
-->
<template>
  <div class="seckill-detail">
    <nav-bar :shadow="false" :autoBack="false" leftIcon="arrow-left" title="拼团活动"
             @clickRight="clickShare" @clickLeft="clickLeft" v-if="getQueryVariable('flag')">
      <div v-if='isShowList.flag' slot="right" class="right-icon"></div>
    </nav-bar>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh" style="min-height: 100vh;"
                      :class="goodsList.length?'seckill-box-grey':'seckill-box-red'">
      <div class="seckill-bg">
        <div class="bg-style" :style="{
            'padding-top': getQueryVariable('flag') ? '44px' : '0',
          }">
          <div class="seckill-header"
               :style="{ 'background-image': `url(${activityData.backgroundUrl})` }">
            <!-- <div class="banner-style"> -->
            <banner-module :list="bannerImgList"></banner-module>
            <!-- </div> -->
          </div>
        </div>
        <div class="seckill-con">
          <div class="seckill-con-c">
            <div class="seckill-list">
              <div class="seckill-list-bottom">
                <div v-if='goodsList.length' class="list-bg">
                  <div class="seckill-info" v-for="(item, index) in goodsList" :key="index"
                       @click="goClick(item)">
                    <div class="seckill-list-left">
                      <div class="seckill-list-img"
                           :style="{ 'background-image': `url(${item.prodImgUrl?($isMp4(item.prodImgUrl)?`${item.prodImgUrl}?x-oss-process=video/snapshot,t_1000,f_jpg,w_640,h_360`:item.prodImgUrl) : require('@/assets/images/find_logo.png')})` }">
                      </div>
                    </div>
                    <div class="seckill-list-right">
                      <div class="bt-style">
                        <div class="info-left">
                          <div class="title" :class="{'grey-box':!item.ensalequantity}">
                            <span class="title-d">{{ item.prodName }}</span>
                            <span class="title-info">{{ item.prodSpecs }}</span>
                          </div>
                          <div class="price-style" :class="{'grey-box':!item.ensalequantity}">
                            <div class="p-price">
                              <span class="price_tag">¥</span>
                              <span class="price_tag">{{
                                item.salePrice | fillerToFixed
                              }}</span>
                            </div>
                            <div class="actual-price">
                              <span class="price_tag">¥</span>
                              <span class="price_tag">{{
                                item.prodPrice | fillerToFixed
                              }}</span>
                            </div>
                          </div>
                          <div class="desc" v-if="item.maxbuyquantity && item.ensalequantity">
                            每人限购&nbsp;{{ item.maxbuyquantity }}&nbsp;件
                          </div>
                        </div>
                        <div v-if='isShowList.flag' class="info-right">
                          <span class="qg" v-if="item.ensalequantity">去拼团</span>
                          <div class="qg-xq" v-else>
                            <img src="../../assets/images/seckill/xq.jpg" />
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div v-else class="row-center coloum-center">
                  <div class="empty-row pdt" style="background: #fff">
                    <img src="../../assets/images/seckill/empy.png" class="empty-img" />
                    <div class="empty-text">{{activityMsg}}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="download-btn" @click="goApp()" v-if="!getQueryVariable('flag')">
        下载APP
      </div>
    </van-pull-refresh>
    <!-- 微信引导提示 -->
    <guide-open :openStatus.sync="openStatus"></guide-open>
  </div>
</template>
<script type="text/javascript">
import { searchCollageActivity } from '@/api/collageActivity/index'
import bannerModule from './modules/banner.vue'
import guideOpen from '@/components/pop-up/guideOpen.vue'
import { closeLoading, showLoading } from '@/utils/loading.js'
var baseUrl = process.env.VUE_APP_H5_URL
 
export default {
  components: {
    bannerModule,
    guideOpen
  },
  data () {
    return {
      isLoading: false,
      htmlHeight: {
        height: '0px'
      },
      bannerImgList: [],
      goodsList: [],
      activityData: {}, // 拼团活动数据
      openStatus: false,
      shareUrl: `${baseUrl}/collageActivity` // 分享链接
    }
  },
  filters: {
    // 保留两位小数
    fillerToFixed (val) {
      var num = '0.00'
      if (val) {
        num = Number(val).toFixed(2)
      }
      return num
    }
  },
  computed: {
    activityMsg () {
      return !this.isShowList.flag || this.isShowList.nowTime > this.isShowList.endTime ? '很抱歉,当前活动已结束' : ''
    },
    isShowList () {
      if (!this.activityData.startTime) return { flag: false }
      const nowTime = Date.now()
      //  兼容IOS日期格式
      const startTime = new Date(this.activityData.startTime.replace(/-/g, '/')).getTime()
      const endTime = new Date(this.activityData.endTime.replace(/-/g, '/')).getTime()
      return {
        flag: nowTime <= endTime && nowTime >= startTime,
        nowTime,
        startTime
      }
    }
  },
  created () {
    this.getActivityList()
  },
  mounted () {
    this.getHtmlHeight()
  },
  methods: {
    getHtmlHeight () {
      const htmlHeight = window.innerHeight + 'px'
      this.$set(this.htmlHeight, 'height', htmlHeight)
    },
    // 获取活动列表
    async getActivityList () {
      showLoading(0)
      const res = await searchCollageActivity({
        promotionId: this.getQueryVariable('promotionId')
      })
      this.bannerImgList = []
      this.activityData = {}
      this.goodsList = []
      this.isLoading = false
      closeLoading(0)
      if (res.code === '0') {
        const _data = res.data
        this.activityData = _data.promotionAgglomerate
        // 活动开始、结束时间
        this.activityData.startTime = _data.npPromotion.promotionStartTime
        this.activityData.endTime = _data.npPromotion.promotionEndTime
        this.activityData.promotionName = _data.npPromotion.promotionName
        this.bannerImgList = this.activityData.bannerUrl ? this.activityData.bannerUrl.split(',') : []
        this.goodsList = _data.npPromotionProd || []
      }
    },
    onRefresh () {
      this.getActivityList()
    },
    // 点击抢购
    goClick (data) {
      if (this.$route.query.isPreview) return
      // 已抢购完  不跳转
      if (!data.ensalequantity) {
        this.$toast('当前商品已售罄')
        return
      }
      const _extparams = JSON.parse(data.extparams)
      const promotionId = this.getQueryVariable('promotionId')
      if (JSON.stringify(_extparams) != '{}') {
        if (this.getQueryVariable('flag')) {
          const params = {
            activityType: '6',
            shopSpuId: _extparams.shopSpuId,
            shopSkuId: _extparams.shopSkuId,
            spuId: data.prodId,
            promotionId
          }
          if (this.$root.isIos) {
            window.webkit.messageHandlers.iosRouter.postMessage(
              `wlyxls://product_detail?activityType=${params.activityType}&promotionId=${promotionId}&shopSpuId=${_extparams.shopSpuId}&spuId=${data.prodId}&shopSkuId=${_extparams.shopSkuId}`
            )
          } else if (window.wlyxls) {
            window.wlyxls.toCommodityDetailPage(JSON.stringify(params))
          }
        } else {
          location.href = `${baseUrl}/goodsDetail?promotionId=${promotionId}&shopSpuId=${_extparams.shopSpuId}&spuId=${data.prodId}&shopSkuId=${_extparams.shopSkuId}`
        }
      }
    },
    // 下载app
    goApp () {
      let url
      var isWeixin = this.is_weixin()
      // 判断是否在微信内置浏览器打开
      if (isWeixin) {
        this.openStatus = true
      } else {
        if (this.$root.isIos) {
          url = this.$store.getters.iosUrl
        } else {
          url = this.$store.getters.androidUrl
        }
        location.href = url
      }
    },
    is_weixin () {
      var ua = window.navigator.userAgent.toLowerCase()
      if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        return true
      } else {
        return false
      }
    },
    // 打开分享面板
    clickShare () {
      if (this.$route.query.isPreview) return
      const _this = this
      const params = {
        // type: _name === "wx" ? 0 : 1, //0-好友 1-朋友圈
        title: `${this.activityData.promotionName}`,
        description: '五味相谐,人生对味!五粮液新零售APP邀您共品佳酿!',
        imgurl: `${baseUrl}/frame.png`,
        url: `${_this.shareUrl}?promotionId=${this.$route.query.promotionId}`
      }
      if (this.$root.isIos) {
        window.webkit.messageHandlers.iosShare.postMessage(JSON.stringify(params))
      } else if (window.wlyxls) {
        window.wlyxls.openShareWindow(JSON.stringify(params))
      }
    },
    // 获取url参数
    getQueryVariable (variable) {
      var query = window.location.search.substring(1)
      var vars = query.split('&')
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split('=')
        if (pair[0] == variable) {
          return pair[1]
        }
      }
      return false
    },
    // navigateBack 返回 navigateClose关闭
    clickLeft () {
      if (window.wlyxls) {
        window.wlyxls.navigateBack('')
      } else if (window.webkit) {
        window.webkit.messageHandlers.iosBrowserPop.postMessage('')
      } else {
        this.$router.go(-1)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import "@/views/activityList/index.scss";
.bg-style {
  height: 460px;
}
.banner-style {
  top: 80px;
  width: 82%;
}
.seckill-con {
  margin-top: 20px;
}
</style>