xiuli.gao 6 years ago
parent
commit
e1e3cebe77

+ 47 - 0
fund_h5/choose_city02.html

@@ -0,0 +1,47 @@
1
+<!DOCTYPE html>
2
+<html lang="en">
3
+
4
+<head>
5
+    <meta charset="UTF-8">
6
+    <title>选择城市</title>
7
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
8
+    <link rel="stylesheet" href="./css/reset.css">
9
+    <link rel="stylesheet" href="./css/choose_city.css">
10
+    <script src="./js/jquery.min.js"></script>
11
+    <script src="./js/common.js"></script>
12
+</head>
13
+
14
+<body style='display: none;'>
15
+    <nav>
16
+        <i id='back'></i>
17
+        <p>选择城市</p>
18
+    </nav>
19
+    <div class="current-city-wrapper" id="top">
20
+        <p>当前定位城市</p>
21
+        <div class="current-city">
22
+            <span data-code='00111000'>北京</span>
23
+            <i></i>
24
+        </div>
25
+    </div>
26
+    <div class="city-list-wrapper">
27
+        <div class="city-list-content">
28
+            <div id="hot" class="city-list-hot-wrapper">
29
+                <!-- 热门城市 -->
30
+                <p>热门城市</p>
31
+                <ul class="city-list-hot"></ul>
32
+            </div>
33
+            <div class="city-list">
34
+                <!-- 城市列表 -->
35
+            </div>
36
+        </div>
37
+    </div>
38
+    <div class="alert-info" style="display: none;">
39
+        <!-- tip提示,3s后消失 -->
40
+        <p></p>
41
+    </div>
42
+    <script src="./js/auto_size.js"></script>
43
+    <script src="./js/city_picker2.js"></script>
44
+    <script src="./js/choose_city2.js"></script>
45
+</body>
46
+
47
+</html>

+ 1 - 1
fund_h5/css/choose_city.css

@@ -92,7 +92,7 @@ nav p {
92 92
 .city-list-hot {
93 93
     margin-top: 0.12rem;
94 94
     width: 100%;
95
-    height: 0.94rem;
95
+    /*height: 0.94rem;*/
96 96
     background-color: #fff;
97 97
 }
98 98
 

+ 1 - 5
fund_h5/js/choose_city.js

@@ -11,11 +11,7 @@ if (qs.name) {
11 11
 }
12 12
 
13 13
 $('#back').click(function() {
14
-    if (document.referrer.includes('fund_h5_api.html')) {
15
-        window.location.href = document.referrer;
16
-    } else {
17
-        redirectToFailedReturnUrl('', 'failed', 1020, '退出公积金查询页');
18
-    }
14
+   window.history.go(-1)
19 15
 });
20 16
 
21 17
 $('.current-city').click(function() {

+ 81 - 0
fund_h5/js/choose_city2.js

@@ -0,0 +1,81 @@
1
+var qs = parseQueryString(window.location.href);
2
+// var hostUrl = '../..';
3
+var hostUrl = 'http://api.security.726p.com/v1';
4
+var returnUrl = qs.returnUrl;
5
+var token = qs.token;
6
+
7
+checkToken();
8
+
9
+if (qs.name) {
10
+    $('.current-city span').text(qs.name).attr('data-code', qs.code);
11
+}
12
+
13
+$('#back').click(function() {
14
+   window.history.go(-1)
15
+});
16
+
17
+$('.current-city').click(function() {
18
+	var data = {
19
+		name: $(".current-city span").html(),
20
+		code: $(".current-city span").attr('data-code')
21
+	}
22
+//	data = JSON.stringify(data);
23
+    CityLocationMessageHandler(data)
24
+    window.history.go(-1)
25
+})
26
+
27
+function redirectToFailedReturnUrl(tid, result, failCode, reason) {
28
+    var linkString = returnUrl.includes('?') ? '&' : '?';
29
+    returnUrl += linkString + "result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason;
30
+    window.location.href = returnUrl;
31
+}
32
+
33
+function showMsg(msg) {
34
+    var msgBox = $('.alert-info');
35
+    msgBox.children('p').text(msg);
36
+    msgBox.show();
37
+    setTimeout(function() {
38
+        msgBox.hide();
39
+    }, 30000);
40
+}
41
+
42
+function checkToken() {
43
+    var getTokenInfo = $.ajax({
44
+        type: 'GET',
45
+        url: hostUrl + '/token?token=' + token + "&time=" + Math.round(Date.now() / 1000),
46
+        timeout: 30000,
47
+        contentType: 'application/json;charset=utf-8'
48
+    });
49
+
50
+    getTokenInfo.done(function(data) {
51
+        if (data.returnUrl && !returnUrl) {
52
+            returnUrl = data.returnUrl;
53
+        }
54
+
55
+        if (data.tid && data.region && data.loginLabel && data.inputData) {
56
+//          window.location.href = './fund_h5_api.html?token=' + token + "&time=" + Math.round(Date.now() / 1000);
57
+            return;
58
+        }
59
+        $('body').show();
60
+        getCityListAndRender();
61
+    });
62
+
63
+    getTokenInfo.fail(function(err) {
64
+        $('body').show();
65
+        showMsg('token校验失败:' + JSON.stringify(err.responseJSON.error));
66
+    });
67
+}
68
+
69
+function getCityListAndRender() {
70
+    $.ajax({
71
+        type: "GET",
72
+        url: hostUrl + '/city_list?type=fund&sort=true&token=' + token + '&time=' + Math.round(Date.now() / 1000),
73
+        contentType: 'application/json;charset=utf-8',
74
+        success: function(data) {
75
+            return $(".city-list").CityPicker(data);
76
+        },
77
+        error: function(err) {
78
+            return showMsg('获取城市列表失败:' + JSON.stringify(err.responseJSON.error));
79
+        }
80
+    });
81
+}

+ 154 - 0
fund_h5/js/city_picker2.js

@@ -0,0 +1,154 @@
1
+(function($, win, doc) {
2
+    var CityPicker = function(ele, cities) {
3
+        this.ele = $(ele);
4
+        this.cities = cities || [];
5
+        this.hotCities = cities.hot || [];
6
+        this.city = null;
7
+        this.code = null;
8
+        this.init();
9
+    };
10
+
11
+    var p = CityPicker.prototype;
12
+
13
+    p.init = function() {
14
+        this.renderHotCityList();
15
+        this.renderCityList();
16
+        this.initCityListEvent();
17
+        this.renderCityNav();
18
+        this.initCityNavEvent();
19
+    };
20
+
21
+    p.renderCityList = function() {
22
+        var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split("");
23
+        var cities = this.cities;
24
+        var cityListStr = "";
25
+        for (var letter of letters) {
26
+            var val = cities[letter];
27
+            if (val && val.length > 0) {
28
+                var dt = "<dt id='" + letter + "'>" + letter + "</dt>";
29
+                var dd = "";
30
+                for (var city of val) {
31
+                    dd += "<dd data-letter='" + letter + "'' data-code='" + city.regionCode + "'>" + city.region + "</dd>";
32
+                }
33
+                cityListStr += "<dl>" + dt + dd + "</dl>";
34
+            }
35
+        }
36
+        $(".city-list").append(cityListStr);
37
+    };
38
+
39
+    p.renderHotCityList = function() {
40
+        var hotCitiesStr = '';
41
+        for (var city of this.hotCities) {
42
+            hotCitiesStr += "<li data-code='" + city.regionCode + "'>" + city.region + "</li>"
43
+        }
44
+        $('.city-list-hot').html(hotCitiesStr);
45
+    };
46
+
47
+    p.initCityListEvent = function() {
48
+        var that = this;
49
+        $(".city-list-wrapper").on("click", function(e) {
50
+            var target = e.target;
51
+            if ($(target).is("dd") || $(target).is("li")) {
52
+                that.city = $(target).text().trim();
53
+                that.code = $(target).attr('data-code');
54
+                var letter = $(target).data("letter");
55
+                $('.current-city span').text(that.city);
56
+                
57
+                var data = {
58
+					name: that.city,
59
+					code: that.code
60
+				}
61
+			    CityLocationMessageHandler(data)
62
+			    window.history.go(-1)
63
+//              if (document.referrer.indexOf('&name=') === -1) {
64
+//                  window.location.href = './fund_h5_api.html?token=' + token + '&name=' + that.city + '&code=' + that.code;
65
+//              } else {
66
+//                  window.location.href = document.referrer.replace(/&name=[^&]+&code=[^&]+/, '&name=' + that.city + '&code=' + that.code);
67
+//              }
68
+            }
69
+        });
70
+    };
71
+
72
+    p.renderCityNav = function() {
73
+        // var str = "热" + Object.keys(this.cities).toString().replace(/,/g, '');
74
+        var str = '热ABCDEFGHIJKLMNOPQRSTUVWXYZ';
75
+        var arr = str.split("");
76
+        var a = "<a href='#top' class='to-top'></a>";
77
+        arr.forEach(function(item, i) {
78
+            if (item === '热') {
79
+                a += '<a href="#hot">' + item + '</a>';
80
+            } else {
81
+                a += '<a href="#' + item + '">' + item + '</a>';
82
+            }
83
+        });
84
+        var div = '<div class="navbar">' + a + '</div>';
85
+        $(".city-list-wrapper").append(div);
86
+    };
87
+
88
+    p.initCityNavEvent = function() {
89
+        var that = this;
90
+        var navBar = $(".navbar");
91
+        var width = navBar.find("a").width();
92
+        var height = navBar.find("a").height();
93
+        navBar.on("touchstart", function(e) {
94
+            $(this).addClass("active");
95
+            that.createLetterPrompt($(e.target).html());
96
+        });
97
+        navBar.on("touchmove", function(e) {
98
+            e.preventDefault();
99
+            var touch = e.originalEvent.touches[0];
100
+            var pos = { "x": touch.pageX, "y": touch.pageY };
101
+            var x = pos.x,
102
+                y = pos.y;
103
+            $(this).find("a").each(function(i, item) {
104
+                var offset = $(item).offset();
105
+                var left = offset.left,
106
+                    top = offset.top;
107
+                if (x > left && x < (left + width) && y > top && y < (top + height)) {
108
+                    that.changeLetter($(item).html());
109
+                    var targetEle = $($(item).attr('href'));
110
+                    if (targetEle.length > 0) {
111
+                        targetEle[0].scrollIntoView();
112
+                        window.scrollBy(0, -56);
113
+                    }
114
+                    return e.preventDefault();
115
+                }
116
+            });
117
+        });
118
+
119
+        navBar.on("touchend", function(e) {
120
+            $(this).removeClass("active");
121
+            $(".prompt").hide();
122
+        });
123
+
124
+        navBar.click(function(e) {
125
+            var currentEle = $(e.target);
126
+            that.changeLetter(currentEle.html());
127
+            var targetEle = $(currentEle.attr('href'));
128
+            if (targetEle.length > 0) {
129
+                targetEle[0].scrollIntoView();
130
+                window.scrollBy(0, -56);
131
+            }
132
+            return e.preventDefault();
133
+        });
134
+    };
135
+
136
+    p.createLetterPrompt = function(letter) {
137
+        var prompt = $(".prompt");
138
+        if (prompt[0]) {
139
+            prompt.show();
140
+        } else {
141
+            var span = "<span class='prompt'>" + letter + "</span>";
142
+            $(".city-list").append(span);
143
+        }
144
+    };
145
+
146
+    p.changeLetter = function(letter) {
147
+        var prompt = $(".prompt");
148
+        prompt.html(letter);
149
+    };
150
+
151
+    $.fn.CityPicker = function(cities) {
152
+        return new CityPicker(this, cities);
153
+    }
154
+}(window.jQuery, window, document));

+ 2 - 1
fund_h5/js/fund_h5_api.js

@@ -169,7 +169,8 @@ function initEvent() {
169 169
     });
170 170
     // 导航栏左上角退出H5的点击事件
171 171
     $('#back').click(function() {
172
-        redirectToFailedReturnUrl(tid, 'failed', 1020, '退出公积金查询页');
172
+//      redirectToFailedReturnUrl(tid, 'failed', 1020, '退出公积金查询页');
173
+		window.history.go(-1)
173 174
     })
174 175
 }
175 176