Ui
yfx
2026-03-13 ce71ac1ec3c725d10af689dd5716ba7ad4109958
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
<template>
    <view>
        <view class="banner">
            <image class="backLeft" src="/static/imgs/blackleft.png"  @click="$util.goBack"></image>
            <swiper class="swiper" circular @change="durationChange" :indicator-dots="indicatorDots" :indicator-color="indicatorColor" :autoplay="autoplay" :indicator-active-color="indicatorActiveColor" :interval="interval" :duration="duration">
                <swiper-item v-for="(item, index) in goodsData.banner" :key="index">
                    <image lazy-load :src="item" ></image>
                </swiper-item>
            </swiper>
            <view class="bannerIndex">{{bannerIndex}}/{{goodsData.bannerCount}}</view>
        </view>
        <view class="gTitle">
            <view class="">{{goodsData.title}}</view>
            <view class="">
                <text>¥</text>
                <text>{{goodsData.price}}</text>
                <text>积分:{{goodsData.points}}</text>
            </view>
            <view class="collect" @tap="collectGoods">
                <image :src="goodsData.collect == 1 ? '/static/imgs/colls.png' : '/static/imgs/coll.png'" ></image>
            </view>
        </view>
        <view class="gInfo-title">商品详情</view>
        <view class="gInfo" v-html="goodsData.info"></view>
        <view class="gBtn">
            <view class="gBtn-view" @tap="$util.goSwitch('/pages/index/index')">
                <view class="">
                    <image src="/static/imgs/home.png" ></image>
                    <view>首页</view>
                </view>
            </view>
            <view class="gBtn-view" @tap="goKefu">
                <view class="">
                    <image src="/static/imgs/message.png" ></image>
                    <view>客服</view>
                </view>
            </view>
            <view class="gBtn-view" @tap="addCarts">
                <view class="">
                    <image src="/static/imgs/carts.png" ></image>
                    <view>购物车</view>
                </view>
            </view>
            <view class="gBtn-buy" @click="goBuy">
                <text>立即购买</text>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                indicatorDots: true,
                indicatorColor: '#e3b400',
                indicatorActiveColor: '#ffffff',
                autoplay: true,
                interval: 3000,
                duration: 500,
                goodsId: 0,
                goodsData: {},
                bannerIndex: 1,
                userInfo: uni.getStorageSync('user-info') ? JSON.parse(uni.getStorageSync('user-info')) : null,
                Config: uni.getStorageSync('Config') ? JSON.parse(uni.getStorageSync('Config')) : null,
            }
        },
        onLoad(op){
            this.getConfig()
            this.goodsId = op.id ? op.id : 0
            if(this.goodsId > 0) {
                this.getGoodsInfo()
            }
        },
        methods: {
            goKefu() {
                if(this.Config && this.Config.kefu_open == 1) {
                    this.wechatWork()
                } else {
                    this.$util.checkLogin('/pages/customer/customer')
                }
            },
            getConfig () {
                let t = this
                t.$util.post('Index/getConfig').then(res => {
                    t.Config = res.data
                })
            },
            wechatWork () {
                let t = this
                if(t.Config){
                    if(t.Config.put_open == 1){
                        uni.showModal({
                            title: '联系客服',
                            content: '请联系客服电话:' + t.Config.kefu_phone,
                            showCancel: false,
                            success: function (res) {
                                if (res.confirm) {
                                }
                            }
                        });
                    } else {
                        uni.share({
                            provider: "weixin",
                            openCustomerServiceChat: true,
                            customerUrl: t.Config.work_url, //企业微信地址
                            corpid: t.Config.work_id, //企业id
                            success: (res) => {
                                console.log("success:" + JSON.stringify(res))
                            },
                            fail: (err) => {
                                console.log("fail:" + JSON.stringify(err))  
                            }
                        })
                    }
                }    
            },
            durationChange (e) {
                this.bannerIndex = e.detail.current + 1
            },
            getGoodsInfo () {
                this.$util.post('Goods/getGoodsInfo', {goodsId: this.goodsId}).then(res => {
                    this.goodsData = res.data
                    this.goodsData.info = res.data.info.replace(/\<img/gi, '<img style="max-width:100%;height:auto;margin-bottom: -4px"')
                })
            },
            collectGoods () {
                let burl = '/pages/ginfo/ginfo?id=' + this.goodsData.id
                if(!this.$util.checkGoPages('/pages/login/login', burl, 0)) {
                    return
                }
                this.$util.post('Collect/addCollect', {goodsid: this.goodsData.id}).then(res => {
                    if(res.code == 1) {
                        this.goodsData.collect = 1
                        uni.showToast({
                            title: res.msg || '收藏成功',
                            icon: 'success'
                        })
                    } else if(res.code == 2) {
                        this.goodsData.collect = 0
                        uni.showToast({
                            title: res.msg || '取消成功',
                            icon: 'success'
                        })
                    } else {
                        uni.showToast({
                            title: res.msg || '收藏失败',
                            icon: 'error'
                        })
                    }
                })
            },
            goBuy () {
                let t = this
                let burl = '/pages/ginfo/ginfo?id=' + this.goodsData.id
                if(!this.$util.checkLogin('', burl)) {
                    return
                }
                t.$util.post('Carts/addCarts', {goodsId: this.goodsData.id}).then(res => {
                    if(res.code == 1) {
                        uni.navigateTo({
                            url: '/pages/pays/pays?cartsIds=' + res.data.cartsId
                        })
                    } else {
                        uni.showToast({
                            title: res.msg || '操作失败',
                            icon: '',
                        })
                    }
                })
            },
            addCarts () {
                let t = this
                let burl = '/pages/ginfo/ginfo?id=' + this.goodsData.id
                if(!this.$util.checkGoPages('/pages/login/login', burl, 0)) {
                    return
                }
                this.$util.post('Carts/addCarts', {goodsId: this.goodsData.id}).then(res => {
                    if(res.code == 1) {
                        uni.showModal({
                            title: '温馨提示',
                            content: '添加购物车成功,是否去结算?',
                            success: function (res) {
                                if (res.confirm) {
                                    t.$util.goSwitch('/pages/carts/carts')
                                }
                            }
                        })
                    } else {
                        uni.showToast({
                            title: res.msg || '添加购物车失败',
                            icon: 'error'
                        })
                    }
                })
            }
        }
    }
</script>
 
<style>
    @import url(/static/css/ginfo.css);
</style>