-
Notifications
You must be signed in to change notification settings - Fork 161
/
index.js
413 lines (386 loc) · 11.1 KB
/
index.js
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
// 按钮点击事件
$(function() {
var Datepicker = function(div, y, m, d) {
var _this = this;
this.info_ul = div.find('.order-info-div .oid-ul');
this.PArr = []; // 预约信息数组
this.yuyue_td = null; // 临时保存数据操作行
this.y = y;
this.m = m;
this.d = d;
this.om = m;
this.div = div;
this.div.width(800);
// var months = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月',
// '十月', '十一月', '十二月'];
// 检查当月天数
function checkLength(y, m) {
var len = 31;
var day31 = [ 1, 3, 5, 7, 8, 10, 12 ];
var str31 = day31.join(",");
var regExp = eval("/" + (m + 1) + ",|," + (m + 1) + ",|," + (m + 1)
+ "/g");
// 判断每个月有多少天
if (str31.search(regExp) == -1) {
len = 30;
}
if (m == 1) {
if (y % 4 == 0) {
if (y % 100 == 0 && y % 400 != 0) {
len = 28;
} else
len = 29;
} else
len = 28;
}
return len;
}
// 创建table数据
this.createTableNum = function() {
var table = $('<table></table>');
table.addClass('date-table');
var info_tr = $('<tr class="info-title-tr">'
+ '<td colspan="5"><span class="year-span"></span>年<span class="month-span"></span>月预定信息</td>'
+ '<td style="text-align: right;" colspan="1"><a class="lastM" href="#">上月</a></td>'
+ '<td style="text-align: right;" colspan="1"><a class="nextM" href="#">下月</a></td></tr>');
var week_tr = $('<tr class="week-tr">' + '<td>星期日</td>'
+ '<td>星期一</td>' + '<td>星期二</td>' + '<td>星期三</td>'
+ '<td>星期四</td>' + '<td>星期五</td>' + '<td>星期六</td></tr>');
var plus_tr = $('<tr class="date-plus-tr"><td colspan="7">'
+ '<label for="shang">8:00-11:00:</label>'
+ '<input class="s" type="checkbox" id="Checkbox2" checked="" />'
+ '<label for="zhong">13:00-15:00:</label>'
+ '<input class="z" type="checkbox" id="Checkbox3" checked="" />'
+ '<label for="xia">15:00-18:00:</label>'
+ '<input class="x" type="checkbox" id="Checkbox4" checked="" />'
+ '<!--<span class="yibeiyuyue-span">已被预约</span>-->'
+ '<a href="#" class="confirm-anchor">确定</a></td></tr>');
table.append(info_tr);
table.append(week_tr);
table.append(plus_tr);
this.div.prepend(table);
for (var i = 0; i < 6; i++) {
var tr = $('<tr class="date-tr"></tr>');
for (var j = 0; j < 7; j++) {
var td = $('<td></td>');
tr.append(td);
}
table.append(tr);
}
this.table = table;
this.td = this.table.find(
'tr:not(.date-plus-tr):not(.info-title-tr):not(.week-tr)')
.children('td');
// table头部信息
var mSpan = this.table.find('.month-span');
var ySpan = this.table.find('.year-span');
ySpan.text(this.y);
mSpan.text(this.m);
// 点击下月按钮事件
this.table.find('.nextM').click(function() {
if (_this.m == 12) {
_this.m = 1;
_this.y = _this.y + 1;
} else
_this.m++;
mSpan.text(_this.m);
ySpan.text(_this.y);
_this.initial();
});
// 点击上月按钮事件
this.table.find('.lastM').click(function() {
if (_this.m == 1) {
_this.m = 12;
_this.y = _this.y - 1;
} else
_this.m--;
mSpan.text(_this.m);
ySpan.text(_this.y);
_this.initial();
});
}
// 清空table
this.initialTable = function() {
this.div.find('table').remove();
this.createTableNum();
}
// 添加日期
this.dateScale = function(y, m, d) {
var date = new Date();
date.setFullYear(y, m - 1, _this.d);
var y = date.getFullYear();
var m = date.getMonth();
var fdate = new Date();
fdate.setFullYear(y, m, 1);
var fd = fdate.getDay();
var dayLength = checkLength(y, m);
for (var i = 0; i < dayLength; i++) {
this.td.eq(i + fd).attr('id',
'd-' + y + '-' + (m + 1) + '-' + (i + 1));
this.td.eq(i + fd).html('<span>' + (i + 1) + '</span>');
if (i == _this.d - 1 && _this.d != null && m == (_this.om - 1)) {
this.td.eq(i + fd).append('<span class="today">今天</span>');
}
}
}
// 开始执行
this.initial();
};
// 运行控件
Datepicker.prototype.initial = function() {
this.initialTable();
this.dateScale(this.y, this.m, this.d);
var i = this.PArr.length;
while (i--)
this.setKeyuyue(this.PArr[i].date, this.PArr[i].p);
}
// 指定可预约日期
Datepicker.prototype.setKeyuyue = function(date, p) {
var _this = this;
var _id = 'd-' + date;
var _td = $('#' + _id);
if (!_td.size())
return false;
p.s = p.s == 'true' ? true : p.s;
p.z = p.z == 'true' ? true : p.z;
p.x = p.x == 'true' ? true : p.x;
if (p.s == false && p.z == false && p.x == false) {
_td.addClass('yuyueyiman-td');
_td.append('<div class="yuyueyiman-div">预约已满</div>');
return false;
} else {
_td.addClass('keyuyue-td');
_td.append('<div class="keyuyue-div">可预约</div>');
}
_td
.on(
'click',
function() {
if (_this.yuyue_td != null) {
$('.clone').remove();
if (_this.yuyue_td.attr('id') == _id) {
_this.yuyue_td = null;
return false;
}
}
var cloneTr = $('.date-plus-tr').clone();
cloneTr.addClass('clone');
if (p.s) {
cloneTr.find('.s')
.prop('checked', ''/* p.s */);
} else {
cloneTr
.find('.s')
.replaceWith(
'<span class="yibeiyuyue-span">已被预约</span>');
}
if (p.z) {
cloneTr.find('.z')
.prop('checked', ''/* p.z */);
} else {
cloneTr
.find('.z')
.replaceWith(
'<span class="yibeiyuyue-span">已被预约</span>');
}
if (p.x) {
cloneTr.find('.x')
.prop('checked', ''/* p.x */);
} else {
cloneTr
.find('.x')
.replaceWith(
'<span class="yibeiyuyue-span">已被预约</span>');
}
_td.parent('tr').after(cloneTr);
cloneTr.show();
// 临时值保存为当前td;
_this.yuyue_td = _td;
// 添加弹出行的确定按钮事件
cloneTr.find('.confirm-anchor').on(
'click',
function() {
/*
* 添加按钮事件
*
*/
var s = cloneTr.find('.s');
var z = cloneTr.find('.z');
var x = cloneTr.find('.x');
var date = _td.attr('id')
.substring(2)
.split('-');
var returnValue = date[0]
+ ', ' + date[1] + ', '
+ date[2] + ', '
+ s.prop('checked')
+ ', '
+ z.prop('checked')
+ ', '
+ x.prop('checked');
// alert(returnValue);
var userEmail = $("#userEmail");
if (userEmail.val() == "") {
alert("很抱歉,预约挂号需要您登录!");
return false;
}
var userIdenf = $("#userIdenf");
if (userIdenf.val() == "") {
alert("很抱歉,请完善您的个人信息!");
return false;
}
if (!s.prop('checked')
&& !z.prop('checked')
&& !x.prop('checked')) {
alert("请选择预约日期");
return false;
}
if (s.prop('checked')
|| z.prop('checked')
|| x.prop('checked')) {
var str = '';
if (s.prop('checked')
&& z
.prop('checked')
&& x
.prop('checked')) {
alert("只能选择一个时间段");
return false;
}
if (s.prop('checked')
&& z
.prop('checked')) {
alert("只能选择一个时间段");
return false;
}
if (s.prop('checked')
&& x
.prop('checked')) {
alert("只能选择一个时间段");
return false;
}
if (z.prop('checked')
&& x
.prop('checked')) {
alert("只能选择一个时间段");
return false;
}
if (s.prop('checked')) {
str = '8:00-11:00';
}
if (z.prop('checked')) {
str += '13:00-15:00';
}
if (x.prop('checked')) {
str += '15:00-18:00';
}
if (str.substring(
str.length - 1,
str.length) == ',') {
str = str.substring(0,
str.length - 1);
}
// alert(date.join('-')+','
// +str);
$("#orderInfoValue")
.attr(
"value",
date
.join('-')
+ ','
+ str);// 填充内容
$("#orderInfo").submit();
/*
* _this.info_ul.append(date +
* str); //
* intoTempArr.push(new //
* specialDate(date.join('-'), //
* {s: str[0], z: str[1], x: //
* str[2]}));
*
*
* var dp = new
* Datepicker($('.a'), 2015,
* 5, 16); dp.PArr.push(new
* specialDate('2015-5-17', {
* 's': false, 'z': false,
* 'x': false }));
* dp.initial();
*/
}
_this.yuyue_td = null;
cloneTr.remove();
$(this).unbind();
});
return false;
});
}
// 预约信息类
var specialDate = function(date, p) {
var d = date.split('-');
this.y = d[0];
this.m = d[1];
this.d = d[2];
this.date = date;
this.p = p;
}
var intoTempArr = [];
var myDate = new Date();
var today = addDate(myDate, 0);
var year = today.substring(0, 4);
var month = today.substring(5, 6);
var day = today.substring(7, 8);
var dp = new Datepicker($('.a'), year, month, day);
dp.PArr.push(new specialDate(addDate(myDate, 1), {
's' : false,
'z' : false,
'x' : false
}));
dp.PArr.push(new specialDate(addDate(myDate, 2), {
's' : false,
'z' : true,
'x' : false
}));
dp.PArr.push(new specialDate(addDate(myDate, 3), {
's' : false,
'z' : false,
'x' : false
}));
dp.PArr.push(new specialDate(addDate(myDate, 4), {
's' : false,
'z' : true,
'x' : true
}));
dp.PArr.push(new specialDate(addDate(myDate, 5), {
's' : false,
'z' : true,
'x' : false
}));
dp.PArr.push(new specialDate(addDate(myDate, 6), {
's' : true,
'z' : true,
'x' : true
}));
dp.PArr.push(new specialDate(addDate(myDate, 7), {
's' : false,
'z' : false,
'x' : false
}));
dp.PArr.push(new specialDate(addDate(myDate, 8), {
's' : false,
'z' : true,
'x' : true
}));
dp.PArr.push(new specialDate(addDate(myDate, 9), {
's' : true,
'z' : true,
'x' : false
}));
dp.initial();
});
function addDate(date, days) {
var d = new Date(date);
d.setDate(d.getDate() + days);
var m = d.getMonth() + 1;
return d.getFullYear() + '-' + m + '-' + d.getDate();
}