移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
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
<template>
    <!-- 页面主体 -->
    <view>
        <!--提示框组件-->
        <u-toast ref="uToast" />
        <!--无网络组件-->
        <u-no-network></u-no-network>
        <!--头部组件-->
        <u-navbar leftIcon="search" :title="appTitle" safeAreaInsetTop fixed placeholder @leftClick="goSearch"></u-navbar>
        <!--首页模块化组合组件-->
        <coreshop-page :coreshopdata="pageData"></coreshop-page>
        <!--版权组件-->
        <coreshop-copyright v-if="copy"></coreshop-copyright>
        <!--客服组件-->
        <!-- #ifdef APP-PLUS-NVUE || APP-PLUS -->
        <view class="floatingButton" @click="showChat()">
            <u-icon name="server-man" color="#e54d42" size="45"></u-icon>
        </view>
        <!-- #endif -->
        <!-- #ifdef MP-WEIXIN -->
        <button class="floatingButton" hover-class="none" open-type="contact" bindcontact="showChat" :session-from="kefupara">
            <u-icon name="server-man" color="#e54d42" size="45"></u-icon>
        </button>
        <!-- #endif -->
        <!--返回顶部组件-->
        <u-back-top :scroll-top="scrollTop" :duration="500"></u-back-top>
        <!--弹出框-->
        <coreshop-modal-img :show="modalShow" :src="indexPopupWindowImageUrl" @imgTap="imgTap" @closeTap="closeTap" />
        <!-- 登录提示 -->
        <coreshop-login-modal></coreshop-login-modal>
    </view>
</template>
<script>
    import { mapState } from 'vuex';
    export default {
        data() {
            return {
                currentIndex: 0,
                opacity: 0,
                scrollTop: 0,
                pageData: [],
                pageCode: 'mobile_home', //页面布局编码
                kefupara: '', //客服传递资料
                copy: false,
                shareUrl: this.$globalConstVars.shareUrl,
                isScorll: false,
                homeTitle: '',
                modalShow: false,
            };
        },
        updated() {
            this.copy = true;
        },
        computed: {
            ...mapState({
                hasLogin: state => state.hasLogin,
                userInfo: state => state.userInfo,
            }),
            hasLogin: {
                get() {
                    return this.$store.state.hasLogin;
                },
                set(val) {
                    this.$store.commit('hasLogin', val);
                }
            },
            userInfo: {
                get() {
                    return this.$store.state.userInfo;
                },
                set(val) {
                    this.$store.commit('userInfo', val);
                }
            },
            appTitle() {
                this.homeTitle = this.$store.state.config.shopName;
                return this.homeTitle || '';
            },
            // 获取店铺联系人手机号
            shopMobile() {
                return this.$store.state.config.shopMobile || 0;
            },
            modalShowData() {
                this.modalShow = this.$store.state.config.showIndexPopupWindow == 1;
                return this.$store.state.config.showIndexPopupWindow == 1;
            },
            indexPopupWindowHrefUrl() {
                return this.$store.state.config.indexPopupWindowHrefUrl;
            },
            indexPopupWindowImageUrl() {
                return this.$store.state.config.indexPopupWindowImageUrl;
            }
        },
        onLoad(e) {
            this.initData();
        },
        methods: {
            imgTap() {
                this.modalShow = false;
                var val = this.indexPopupWindowHrefUrl;
                if (this.indexPopupWindowHrefUrl.indexOf('http') != -1) {
                    // #ifdef APP-PLUS || APP-PLUS-NVUE || MP
                    this.$u.route('/pages/webview/webview', { src: val });
                    // #endif
                } else {
                    // #ifdef APP-PLUS || APP-PLUS-NVUE || MP
                    if (val == '/pages/index/default/default' || val == '/pages/category/index/index' || val == '/pages/index/cart/cart' || val == '/pages/index/member/member') {
                        this.$u.route({ type: 'switchTab', url: val });
                        return;
                    } else if (val.indexOf('/pages/coupon/coupon?id=') > -1) {
                        var id = val.replace('/pages/coupon/coupon?id=', "");
                        this.receiveCoupon(id)
                    } else {
                        this.$u.route(val);
                        return;
                    }
                    // #endif
                }
            },
            closeTap() {
                this.modalShow = false;
            },
            // 首页初始化获取数据
            initData() {
                uni.showLoading({
                    title: '加载中'
                });
                //获取首页配置
                this.$u.api.getPageConfig({ code: this.pageCode }).then(res => {
                    if (res.status == true) {
                        this.pageData = res.data.items;
                    }
                    setTimeout(function () {
                        uni.hideLoading();
                    }, 1000);
                });
 
                var _this = this;
                if (this.$db.get('userToken')) {
                    this.$u.api.userInfo().then(res => {
                        if (res.status) {
                            _this.userInfo = res.data;
                            _this.hasLogin = true;
                            // #ifdef MP-WEIXIN
                            //微信小程序打开客服时,传递用户信息
                            var kefupara = {};
                            kefupara.nickName = res.data.nickName;
                            kefupara.tel = res.data.mobile;
                            _this.kefupara = JSON.stringify(kefupara);
                            //console.log(_this.kefupara);
                            // #endif
                        }
                    });
                }
                this.getShareUrl();
            },
            //在线客服
            showChat() {
                // #ifdef APP-PLUS || APP-PLUS-NVUE
                this.$u.route('/pages/member/customerService/index');
                // #endif
            },
            //获取分享URL
            getShareUrl() {
                let data = {
                    client: this.$globalConstVars.shareClient.wxMiNiProgram,
                    url: this.$globalConstVars.shareUrl,
                    type: this.$globalConstVars.shareModel.url,
                    page: this.$globalConstVars.shareType.index,
                };
                let userToken = this.$db.get('userToken');
                if (userToken && userToken != '') {
                    data.token = userToken
                }
                this.$u.api.share(data).then(res => {
                    this.shareUrl = res.data
                });
            }
        },
        onPullDownRefresh() {
            this.initData();
            uni.stopPullDownRefresh();
        },
        watch: {
            hasLogin() {
                if (this.hasLogin == true && this.shareUrl.indexOf('-0-') != -1) {
                    this.getShareUrl();
                }
            }
        },
        //分享
        onShareAppMessage(res) {
            return {
                title: this.$store.state.config.shareTitle,
                imageUrl: this.$store.state.config.shareImage,
                path: this.shareUrl
            }
        },
        onShareTimeline(res) {
            return {
                title: this.$store.state.config.shareTitle,
                imageUrl: this.$store.state.config.shareImage,
                path: this.shareUrl
            }
        },
        onPageScroll: function (e) {
            this.isScorll = e.scrollTop > 100 ? true : false;
            this.scrollTop = e.scrollTop;
            if (e.scrollTop <= 100) {
                this.opacity = e.scrollTop / 100;
            } else if (this.scrollTop > 100) {
                this.opacity = 1;
            }
        },
    };
</script>
 
<style lang="scss">
</style>