PageSourceSearch

https://www.med66.com/OtherItem/js/2021precisionMarketing/redEnvelopes.js?v=20220117

js med66.com collected 2026-10-02 04:00:49 UTC 19,845 bytes, 369 lines download raw bytes

1(function (win) {
2    var drawView = {
3        _body : $('body'),
4        _redConf_flag: true,
5        _red_serverTime : null,
6        _redConfLoginstatus : null,
7        _redConfUserinfo : null,
8        _redVoucherStatus : null,
9        _redVoucherIds : null,
10        init: function () {
11            this.serverTime();
12            this.initdata();
13            this.addEven();
14        },
15        initdata: function () {
16            var that = this;
17            //展示优惠券
18            that.checkLogin(function (){
19                if(!$("#tkRedSource").val()||$(".redPopSuspend").length>0){}else {
20                    that.showCoupon($("#tkRedSource").val());
21                }
22                if(!$("#flRedSource").val()){}else {
23                    that.showCoupon($("#flRedSource").val());
24                }
25            });
26        },
27        addEven: function () {
28            var that = this;
29            //点击红包关闭
30            $('body').on("click",".redMain .pm-redBox .pm-close,.redMain .pm-redBox-mask",function (){
31                $(".pm-redBox").fadeOut();
32                $(".pm-redBox-mask").fadeOut();
33                $(".redMain .ylqCoupon .list").remove();
34            });
35            //点击右侧浮动按钮打开红包
36            $('body').on("click",".rightFloatNav-redEnvelopes",function (){
37                that.serverTime();
38                that.receiveCoupon($("#flRedSource").val(),that._redVoucherStatus,that._redVoucherIds);
39            });
40            //点击底部浮动按钮打开红包
41            $('body').on("click",".settlement-mod .redBtn",function (){
42                that.serverTime();
43                that.receiveCoupon($("#flRedSource").val(),that._redVoucherStatus,that._redVoucherIds);
44            });
45            //点击红包按钮打开红包
46            $('body').on("click",".pm-redBox.wlq .pm-bot .wlqBtn",function (){
47                that.serverTime();
48                $(".redMain .pm-redBox.wlq").fadeOut();
49                that.receiveCoupon($("#tkRedSource").val(),that._redVoucherStatus,that._redVoucherIds);
50            });
51        },
52        //优惠券倒计时
53        redCountDown : function(eleId, nowtime, dstart, dend, j){
54            var that = this;
55            var NowTime = Number(nowtime) || new Date().getTime();
56            var neweleId;
57            if(j == undefined || j == null){
58                neweleId = eleId;
59            }else {
60                neweleId = eleId+j;
61            }
62            var element = document.getElementById(neweleId);
63            if (element) {
64                var dateValue = element.getAttribute('data-countDown').replace(new RegExp(/-/gm) ,"/");
65                var EndTime = new Date(dateValue).getTime();
66                var t = EndTime - NowTime;
67                NowTime = NowTime+1000;
68                var date = {}
69                if (t > 0) {
70                    date.d = Math.floor(t / 1000 / 60 / 60 / 24),
71                        date.h = Math.floor(t / 1000 / 60 / 60),
72                        date.m = Math.floor(t / 1000 / 60 % 60),
73                        date.s = Math.floor(t / 1000 % 60)
74                    for (var i in date) date[i] < 10 ? date[i] < 10 && (date[i] = "0" + date[i]) : '';
75                    dstart && dstart(date,j);
76                    setTimeout(function () {
77                        that.redCountDown(eleId, NowTime, dstart, dend, j);
78                    }, 1000);
79                } else {
80                    dend && dend(date,j);
81                };
82            }
83        },
84        //服务器时间
85        serverTime : function () {
86            var that = this;
87            $.ajax({
88                type: "POST",
89                url: "//member.med66.com/homeapi/live/getServiceTime",
90                async: false,
91                success: function (res) {
92                    that._red_serverTime = res;
93                }
94            });
95        },
96        //读取cookie
97        getCookie : function (name) {
98            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
99            if (arr = document.cookie.match(reg)) {
100                return unescape(arr[2]);
101            } else {
102                return null;
103            }
104        },
105        //设置cookie
106        //setCookie(cookieName,value,time,path)  //time: 10h=10小时 10m=10分 10=10天
107        setCookie : function (cookieName, value, time, path) {
108            var expiresDate = new Date(),
109                insertCoo = "",
110                domainPath = '.med66.com';
111            var timeVal = !time ? '0' : time
112            if (timeVal.indexOf('h') > -1) {
113                expiresDate.setTime(expiresDate.getTime() + (parseInt(timeVal) * 3600 * 1000));
114            } else if (timeVal.indexOf('m') > -1) {
115                expiresDate.setTime(expiresDate.getTime() + (parseInt(timeVal) * 60 * 1000));
116            } else {
117                expiresDate.setTime(expiresDate.getTime() + (parseInt(timeVal) * 24 * 3600 * 1000));
118            }
119            if (value != null && typeof (value) != "null" && typeof (value) != "null,") {
120                insertCoo = escape(value);
121            }
122            if (path) {
123                domainPath = path
124            }
125            var cookieStr = cookieName + "=" + insertCoo + "; expires=" + expiresDate.toGMTString() + "; path=/; domain=" + domainPath;
126            if (cookieStr != "") {
127                document.cookie = cookieStr;
128            }
129        },
130        //显示:that.setLoad()  关闭:that.setLoad(true);
131        setLoad : function (type) {
132            if (type) {
133                $('#loadMod').remove();
134            } else {
135                $('body').append('<div id="loadMod" style="width:118px;height:43px;line-height:24px;padding-top:75px;background:url(//www.med66.com/images/common2020/loadNew.gif) no-repeat center 15px #fff;text-align:center;color:#999;-webkit-box-shadow:0 0 12px rgba(0,0,0,.2);-moz-box-shadow:0 0 12px rgba(0,0,0,.2);box-shadow:0 0 12px rgba(0,0,0,.2);-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;border:1px solid #e5e5e5;position:fixed;left:50%;top:50%;margin:-60px 0 0 -60px;z-index:900;">Loading</div>')
136            }
137        },
138        //提示
139        alertTip : function (msg, time) {
140            if ($('.alertPop').length > 0) {
141                $('.alertPop').remove()
142            };
143            $('body').append('<div class="alertPop" style="position:fixed;left:50%;top:50%;line-height:50px;font-size:16px;padding:0 20px;background:#000;opacity:.8;filter:alpha(opacity=80);color:#fff;-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:5px;z-index:9999;">' + msg + '</div>');
144            var alertPop = $('.alertPop');
145            alertPop.css({
146                'margin-top': -alertPop.outerHeight(true) / 2,
147                'margin-left': -alertPop.outerWidth(true) / 2
148            });
149            setTimeout(function () {
150                alertPop.fadeOut(200, function () {
151                    alertPop.remove()
152                });
153            }, time || 4000);
154        },
155        //ajax
156        ajax : function (param) {
157            var that = this;
158            if (param.load) {
159                that.setLoad()
160            }
161            return $.ajax({
162                type: param.type || 'GET',
163                url: param.url,
164                data: param.data || {},
165                dataType: 'jsonp',
166                jsonp: "jsonpCallback",
167                jsonpCallback: param.jsonpCallback || "jsonpCallback" + (new Date().getTime())
168            });
169        },
170        //验证登录
171        checkLogin : function (succ) {
172            var that = this;
173            var ucToken = that.getCookie("client_ucToken")
174            if (ucToken != "" && ucToken != null) {
175                that.ajax({
176                    "type": "GET",
177                    "url": "//member.med66.com/ucenter/loginRegister/checkUserLoginStatus/" + ucToken
178                }).then(function (json) {
179                    if (json.success) {
180                        if (json.result.loginFlag) {
181                            //已登录
182                            that._redConfLoginstatus = true;
183                            that._redConfUserinfo = json;
184                            succ && succ(json);
185                        } else {
186                            //未登录
187                        }
188                    }
189                })
190            } else {
191                //未登录
192            }
193        },
194        //判断登录
195        islogin : function (param) {
196            var that = this;
197            if (that._redConfLoginstatus&&that._redConfUserinfo&&that.getCookie('username')) {
198                param && param();
199            } else {
200                loginRegister(1);
201            }
202        },
203        //**************************************接口部分**************************************//
204        //展示优惠券弹框和右侧浮动
205        showCoupon : function (source) {
206            var that = this;
207            postAesData({
208                data : {
209                    "params" : {
210                        "time":new Date().getTime(),
211                        "uuid":that.getCookie("bdp_uuid") || "",
212                        "uid":that.getCookie('cdeluid') || "",
213                        "source":source    //201:PC首页精准营销弹窗,202:PC栏目页精准营销弹窗,203:PC栏目选课中心列表页精准营销弹窗, 204:PC资讯详情页精准营销弹窗,205:PC右侧公用多功能栏精准营销悬浮悬浮,206:购物车页底部精准营销悬浮
214                    },
215                    "domain" : "med66",
216                    "resourcePath" : "+/precision/promptProbability",
217                    "af":"1",                //类型:String  必有字段  备注:无
218                    "ap":"pc"                //类型:String  必有字段  备注:无
219                },
220                // ajax成功回调
221                success : function (data) {
222                    var result = data.result;
223                    if(source == 201 || source == 202 || source == 203 || source == 204){
224                        //弹出红包弹框
225                        if(result.type == 1){
226                            if(that.getCookie("redEnvelopes") != result.voucherIds){
227                                $(".pm-redBox.wlq .pm-top .wlqPrice .min").text(result.minDiscount);
228                                $(".pm-redBox.wlq .pm-top .wlqPrice .max").text(result.maxDiscount);
229                                $(".pm-redBox.wlq").css("margin-top",-($(".pm-redBox").height()/2));
230                                $(".pm-redBox.wlq").fadeIn();
231                                $(".pm-redBox-mask").fadeIn();
232                                that._redVoucherIds = result.voucherIds;
233                                that._redVoucherStatus = result.voucherStatus;
234                                that.setCookie("redEnvelopes",result.voucherIds,"2h");
235
236                                //诸葛埋点
237                                var zhugeObj;
238                                if($(".topNav .nav-courseEdu h1").text() != ""){
239                                    zhugeObj = $(".topNav .nav-courseEdu h1").text();
240                                }else if($(".nav h1").text() != ""){
241                                    zhugeObj = $(".nav h1").text();
242                                }
243                                zhuge.track('PC-进入-精准营销',{
244                                    '辅导名称': zhugeObj,
245                                    '所在页面名称': $("title").text(),
246                                    '所在页面URL': window.location.href
247                                });
248                            }
249                        }
250                        if(source == 203){
251                            $(".pm-redBox.ylq .pm-bot .ylqBtn").addClass("close").attr({"href":"javascript:void(0)","target":"_self"});
252                            $('body').on("click",".pm-redBox.ylq .pm-bot .ylqBtn.close",function (){
253                                $(".pm-redBox").fadeOut();
254                                $(".pm-redBox-mask").fadeOut();
255                                $(".redMain .ylqCoupon .list").remove();
256                            });
257                        }
258                    }else if(source == 205){
259                        //展示右侧浮动红包按钮
260                        if(result.floatType == 1){
261                            if($(".rightFloatNav").length>0){
262                                //首页、栏目页、列表页、新闻页右侧浮动
263                                var redBtnHtml = '<a href="javascript:void(0)" target="_self" class="rightFloatNav-redEnvelopes"><img src="'+result.floatImg+'"></a>';
264                                $(".rightFloatNav").append(redBtnHtml);
265                            }else if($(".rignav").length>0){
266                                //选课列表页右侧浮动
267                                var redBtnHtml = '<a href="javascript:void(0)" target="_self" class="rightFloatNav-redEnvelopes"><img src="'+result.floatImg+'"></a>';
268                                $(".rignav").append(redBtnHtml);
269                            }
270                            that._redVoucherIds = result.voucherIds;
271                            that._redVoucherStatus = result.voucherStatus;
272                        }
273                    }else if(source == 206){
274                        //展示购物车底部浮动红包按钮
275                        if($(".settlement-mod").length>0){
276                            var redBtnHtml;
277                            if(result.voucherStatus == 0){
278                                redBtnHtml = '<a href="javascript:void(0)" class="redBtn fl"><p class="redBtn-ltxt">专属优惠不是每个人都有<br><b>可优惠<strong>'+result.minDiscount+'~'+result.maxDiscount+'</strong>元</b></p><span class="redBtn-rbtn">领取优惠</span></a>';
279                            }else if(result.voucherStatus == 1){
280                                redBtnHtml = '<a href="javascript:void(0)" class="redBtn fl" id="redBtnTime" data-countDown="'+result.couponTime+'"><p class="redBtn-ltxt">专属优惠不是每个人都有<br><b class="fs12"><em class="th"></em>小时后失效:<em class="tt"></em></b></p><span class="redBtn-rbtn">查看优惠券</span></a>';
281                            }
282                            $(".settlement-mod").append(redBtnHtml);
283                            that.redCountDown("redBtnTime",that._red_serverTime,function (obj) {
284                                $("#redBtnTime").find(".th").text(obj.h >= 10 ? obj.h : obj.h.replace("0",""));
285                                $("#redBtnTime").find(".tt").text(obj.h+":"+obj.m+":"+obj.s);
286                            })
287                            that._redVoucherIds = result.voucherIds;
288                            that._redVoucherStatus = result.voucherStatus;
289                        }
290                    }
291                },
292                // ajax失败回调
293                error : function (xhr) {
294                    console.log(xhr);
295                }
296            });
297        },
298        //领取红包优惠券
299        receiveCoupon : function (source,voucherStatus,voucherIds) {
300            var that = this;
301            if (!that._redConf_flag) return false;    //确认是否拦截ajax
302            that._redConf_flag = false;
303            that.setLoad();
304            postAesData({
305                data : {
306                    "params" : {
307                        "time":new Date().getTime(),
308                        "uuid":that.getCookie("bdp_uuid") || "",
309                        "uid":that.getCookie('cdeluid') || "",
310                        "source":source,    //201:PC首页精准营销弹窗,202:PC栏目页精准营销弹窗,203:PC栏目选课中心列表页精准营销弹窗, 204:PC资讯详情页精准营销弹窗,205:PC右侧公用多功能栏精准营销悬浮悬浮,206:购物车页底部精准营销悬浮
311                        "voucherStatus":voucherStatus,    //1已领未使用0未领取
312                        "voucherIds":voucherIds
313                    },
314                    "domain" : "med66",
315                    "resourcePath" : "+/precision/getLotteryResults",
316                    "af":"1",                //类型:String  必有字段  备注:无
317                    "ap":"pc"                //类型:String  必有字段  备注:无
318                },
319                // ajax成功回调
320                success : function (data) {
321                    that.setLoad(true);
322                    var result = data.result;
323                    if(result.type == 1){
324                        var couponList = result.couponInfoList;
325                        var couponListObj = '';
326                        for (var i = 0; i < couponList.length; i++){
327                            var voucherTypeName;
328                            if(couponList[i].voucherType == 1){
329                                voucherTypeName = "元";
330                            }else if(couponList[i].voucherType == 2){
331                                voucherTypeName = "折";
332                            }
333                            couponListObj += '<div class="list" data-voucherId="'+couponList[i].voucherId+'"><div class="list-price"><b>'+couponList[i].voucherDiscount+'</b>'+voucherTypeName+'</div><div class="list-right"><div class="list-right-top">优惠券</div><div class="list-right-cen" id="couponTime'+[i]+'" data-countDown="'+couponList[i].couponTime+'"><em class="th"></em>小时后失效:<em class="tt"></em></div><div class="list-right-bot">'+couponList[i].useDesc+'</div></div><i class="fdIcon"></i></div>';
334                        }
335                        $(".pm-redBox .ylqCoupon").html(couponListObj);
336                        //优惠券倒计时
337                        for (var j = 0; j < couponList.length; j++){
338                            that.redCountDown("couponTime",that._red_serverTime,function (obj,j) {
339                                $("#couponTime"+j).find(".th").text(obj.h >= 10 ? obj.h : obj.h.replace("0",""));
340                                $("#couponTime"+j).find(".tt").text(obj.h+":"+obj.m+":"+obj.s);
341                            },function (obj,j) {
342                                $("#couponTime"+j).hide().parents(".list").addClass("no");
343                            },j)
344                        }
345                        $(".pm-redBox.ylq .pm-top .ylqTit b").text(result.couponNum);
346                        $(".pm-redBox.ylq").css("margin-top",-($(".pm-redBox").height()/2));
347                        $(".pm-redBox.ylq").fadeIn();
348                        $(".pm-redBox-mask").fadeIn();
349                    }else{
350                        $(".rightFloatNav .rightFloatNav-redEnvelopes").remove();
351                        $(".rignav .rightFloatNav-redEnvelopes").remove();
352                        $(".settlement-mod .redBtn").remove();
353                        that.alertTip("您的优惠券已使用或已过期");
354                    }
355                },
356                // ajax失败回调
357                error : function (xhr) {
358                    console.log(xhr);
359                    that.setLoad(true);
360                }
361            });
362            setTimeout(function (){
363                that._redConf_flag = true;
364            },1000)
365        }
366    }
367    drawView.init();
368    win.drawView = drawView;
369})(window)

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.