question-list.page.js
3.62 KB
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
'use strict';
require('scss/3party/question-list.page.scss');
let $ = require('yoho-jquery'),
yoho = require('js/yoho-app');
const DETAIL_URI = location.protocol + '//m.yohobuy.com/3party/questionnaire';
require('../common');
let qs = window.queryString;
function getQuestionStatus(reqData, cb) {
if (qs.uid) {
reqData.uid = qs.uid;
}
$.ajax({
type: 'POST',
url: '/3party/questionnaire/check',
data: reqData
}).then(function(data) {
if (cb && typeof cb === 'function') {
return cb(data);
}
});
}
function jumpQuestionDetail(data) {
let href;
if (qs && qs.uid && yoho.isApp) {
href = DETAIL_URI + '/' + data.id + '?uid=' + qs.uid;
} else {
href = DETAIL_URI + '/' + data.id;
}
if (yoho && yoho.isApp) {
let link = yoho.parseUrl(href);
yoho.goH5(href, JSON.stringify({
action: 'go.h5',
params: {
islogin: 'N',
type: 14,
updateflag: Date.now() + '',
url: link.path,
param: link.query
}
}));
} else {
window.location.href = href;
}
}
let tipDialog = {
$base: $('#tip-dialog'),
init: function() {
let that = this;
this.$content = $('.dg-content', this.$base);
this.$sureBtns = $('.sure-btns', this.$base);
this.$shareBtns = $('.share-btns', this.$base);
this.$base.on('click', '.close-btn', function() {
that.hide();
});
this.$base.on('click', '.share-btn', function() {
if (that.share && typeof that.share === 'function') {
that.share();
} else {
that.hide();
}
});
},
show: function(info) {
this.share = false;
if (typeof info === 'object') {
this.$content.html(info.content);
this.$sureBtns.addClass('hide');
this.$shareBtns.removeClass('hide');
} else if (typeof info === 'string') {
this.$content.html('<p>' + info + '</p>');
this.$sureBtns.removeClass('hide');
this.$shareBtns.addClass('hide');
} else {
return;
}
this.$base.removeClass('hide');
},
hide: function() {
this.$base.addClass('hide');
}
};
tipDialog.init();
let $list = $('#qs-list');
let canShare = $list.hasClass('can-share');
$list.on('click', 'li', function() {
let data = $(this).data();
if (!data.id) {
return;
}
getQuestionStatus({uid: qs.uid, id: data.id}, function(resData) {
if (resData.code === 200) {
jumpQuestionDetail(data);
} else if (resData.code === 206) {
if (canShare && yoho && yoho.isApp) {
yoho.invokeMethod('go.showShareAlert', {
title: data.title,
link: DETAIL_URI + '/' + data.id,
desc: data.desc,
imgUrl: data.img
});
} else {
tipDialog.show('调查问卷已成功提交,<br>感谢您的帮助!');
}
} else if (resData.message) {
if (yoho && yoho.isApp) {
yoho.goH5(DETAIL_URI + '/0');
} else {
window.location.href = DETAIL_URI + '/0';
}
}
});
});
if ($list.children().length === 1) {
let data = $list.children().first().data();
getQuestionStatus({uid: qs.uid, id: data.id}, function(resData) {
if (resData.code === 200) {
jumpQuestionDetail(data);
}
});
}