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
<!--
 * @Author: 张嘉彬
 * @Date: 2021-10-12 16:11:21
 * @Description:活动专区页面
-->
<template>
  <div class="index_page">
    <nav-bar :shadow="false" :autoBack="false" leftIcon="arrow-left" title="活动专区"
             @clickLeft="clickLeft">
    </nav-bar>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <h2 v-if="refreshStatusCode === '3'" class="no-active-style">专区暂无展示活动</h2>
      <div v-if="refreshStatusCode === '2'">
        <div class="status_bar" :style="{
            height: $setVw(43),
            background: diyInfo[0].titleColor || '#f8f8f8',
          }" v-if="diyInfo.length">
          <div class="top_view" :style="{
              height: $setVw(statusHeight),
              width: '100%',
              background: diyInfo[0].titleColor || '#f7f7f7',
            }" />
        </div>
        <component v-for="item in diyInfo" :key="item.id" class="component-box" :ref="item.type"
                   :is="currentView(item.type)" :infoData="item"></component>
        <div v-if="diyInfo[0] && diyInfo[0].bgImg && diyInfo[0].bgImg.length">
          <img :src="item.url | ossProcess" alt="" v-for="item in diyInfo[0].bgImg" :key="item.id"
               class="bg_img" />
        </div>
      </div>
    </van-pull-refresh>
  </div>
</template>
 
<script type="javascript">
import { getDiyInfo } from '@/api/oauth/index'
import NewHeader from '@/components/header/index.vue'
import imgGoods from './components/imgGoods.vue'
import { closeLoading, showLoading } from '@/utils/loading.js'
import NewImage from '@/components/image/index.vue'
 
export default {
  components: {
    NewHeader,
    imgGoods,
    NewImage
  },
 
  data () {
    return {
      isLoading: false,
      diyInfo: [],
      statusHeight: 0,
      ws: null,
      token: '',
      showHeader: '',
      isIos: false,
      refreshStatusCode: '1'// 标记刷新状态
    }
  },
 
  created () {
    // Browser environment sniffing
    var inBrowser = typeof window !== 'undefined'
    // Weex 是使用流行的 Web 开发体验来开发高性能原生应用的框架
    var inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform
    // 两个不等号的含义有值取值,没值就是false 类似于  var  a = 'b' || false
    var weexPlatform = inWeex && WXEnvironment.platform.toLowerCase()
    // 浏览器的用户代理报头:window.navigator.userAgent
    var UA = inBrowser && window.navigator.userAgent.toLowerCase()
    var isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios')
    if (isIOS) {
      this.isIos = isIOS
    }
    if (window.plus) {
      this.ws = window.plus.webview.currentWebview()
      this.setRefresh(true)
      this.statusHeight = window.plus.navigator.getStatusbarHeight()
    }
    this.refreshStatusCode = '1'
    this.getDiy({ status: 2, diyType: '2' })
  },
  methods: {
    // navigateBack 返回 navigateClose关闭
    clickLeft () {
      if (window.wlyxls) {
        window.wlyxls.navigateBack('')
      } else if (window.webkit) {
        window.webkit.messageHandlers.iosBrowserPop.postMessage('')
      } else {
        this.$router.go(-1)
      }
    },
    plusReady () {
      this.ws = window.plus.webview.currentWebview()
      this.setRefresh(true)
      this.judgeReq()
      this.statusHeight = window.plus.navigator.getStatusbarHeight()
    },
    setRefresh () {
      this.ws.setPullToRefresh(
        {
          style: 'circle',
          support: true,
          height: '50px',
          range: '50px',
          offset: '50px'
        },
        this.onRefresh
      )
    },
    judgeReq () {
      if (window.plus) {
        const url = this.ws.getURL()
        if (url.indexOf('?') > -1) {
          const id = url.split('?')[1].split('=')[1]
          this.getDiy({ id: id })
        } else {
          this.getDiy({ status: 2, diyType: '2' })
        }
      } else {
        this.getDiy({ status: 2, diyType: '2' })
      }
    },
    onRefresh () {
      this.diyInfo = []
      this.refreshStatusCode = '1'
      this.judgeReq()
    },
    async getDiy (params) {
      const _this = this
      try {
        _this.diyInfo = []
        showLoading(0)
        const res = await getDiyInfo(params)
        this.isLoading = false
        closeLoading(0)
        if (_this.ws) _this.ws.endPullToRefresh()
        if (res.data && res.data.length) {
          _this.diyInfo = JSON.parse(res.data[0].styleInfo)
          _this.diyInfo.map((v) => {
            // if (v.w) {
            //   v.w += 20
            // }
            // if (v.x) {
            //   v.x -= 10
            // }
            if (v.w) v.width = _this.$setVw(v.w)
            if (v.x) v.codeX = _this.$setVw(v.x)
            if (v.y) v.codeY = _this.$setVw(v.y)
            // 是否展示商品轮播  goods-list高度215 标题高度35  限时购没有标题
            if (v.h) v.height = _this.$setVw(v.isDisplayProd === '1' ? v.h - 215 - (v.type === '4' ? 0 : 35) : v.h)
            if (v.borderRadius) v.borderRadiu = _this.$setVw(v.borderRadius)
            if (v.strokeSize) v.borderSize = _this.$setVw(v.strokeSize)
          })
        } else {
          _this.diyInfo = []
        }
        this.setDisplayStatus()
        console.log(_this.diyInfo)
      } catch (error) {
        closeLoading(0)
        this.setDisplayStatus()
        if (this.ws) this.ws.endPullToRefresh()
      }
    },
    // 处理页面展示状态---避免刷新页面数据还未加载的情况下展示[专区暂无展示活动]
    setDisplayStatus () {
      this.refreshStatusCode = this.diyInfo && this.diyInfo.length ? '2' : '3'
    },
    currentView (type) {
      // 活动类型{1:满减2:满赠3:盲盒抽奖4:限时抢购5:优惠券,6:拼团活动}
      const typeObj = {
        basicSet: 'NewHeader',
        1: 'imgGoods',
        2: 'imgGoods',
        3: 'imgGoods',
        4: 'imgGoods',
        5: 'imgGoods',
        6: 'imgGoods',
        proDetails: 'NewImage'
      }
      console.log(typeObj[type])
      return typeObj[type]
    }
  }
}
</script>
 
<style scoped>
* {
  -webkit-touch-callout: none;
}
.bg_img {
  width: 100%;
  height: auto;
  display: block;
  -webkit-touch-callout: none;
}
.top_view {
  height: var(--status-bar-height);
  width: 100%;
  position: fixed;
  background-color: #e0c18f;
  top: 0;
  z-index: 999;
}
.no-active-style {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  font-size: 50px;
  color: rgb(163, 170, 175);
}
</style>