Calendar_wev8.js
18.7 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
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
define(['mUtil', "Component", "_calendar"],function(mUtil, Component, CalendarLib) {
var Calendar = function(options) {
var _calendar = {}, calendarInstance, currentDateObj = new Date(), container = null;
Component.super(this, options);
this.type = "Calendar";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
var vm = this.viewModel = {
basic : {
showLunar : true, //显示阴历
showNew : true, //显示新建
showBack : true, //显示返回
expand : true
},
action : {
type : "", //点击日期动作类型
target : {
id: "",
sourceType: "" //
}, //列表插件
dataFilter : {
field : "", //字段设置
field2 : "", //字段设置,
fieldType : "",
field2Type : "",
isEquals : true //默认为等于
},
dataInit : "currentMonth",
dataReload : true
},
remark : null,
callback : {},
standalone : true,
reloadCallback : function(){}
};
this.reload = function (date,pageId,callback) {
if (mUtil.isFunction(callback)){
vm.reloadCallback = callback;
}
var regex = /^[0-9]{4}[-/][0-9]{2}[-/][0-9]{2}(\s[0-2][0-9]:[0-5][0-9]:[0-5][0-9])?$/;
var noSpaceDate = regex.test(date) ? date : mUtil.getCurrDate();
currentDateObj = new Date(noSpaceDate);
calendarInstance.reload(noSpaceDate,container,pageId);
var preiodDate = this.getStartAndEndDate(currentDateObj);
_calendar.drawingDate(preiodDate[0],preiodDate[1]);
}
this.mounted = function(){
var that = this,
$comp = that.$el.children(".wev-comp-"+that.type),
dataShowWay = vm.action.type,
listChoose = _calendar.getListChooseId(),
actionListSourceType = vm.action.target.sourceType,
dataInitScope = vm.action.dataInit,
currentYear = currentDateObj.getFullYear(),
currentMonth = currentDateObj.getMonth()+1 > 9 ? currentDateObj.getMonth()+1 : "0"+(currentDateObj.getMonth()+1),
currentDate = currentDateObj.getDate(),
startDate = "",
endDate = "";
container = $comp;
calendarInstance = new CalendarLib($comp, !vm.basic.expand);
calendarInstance.init();
//英文状态下也不显示农历
if(!vm.basic.showLunar || mUtil.getUserLanguage() == 8){
calendarInstance.showLunar();
}
//显示新建
if(vm.basic.showNew){
calendarInstance.showAddData();
}
//显示返回
if(vm.basic.showBack){
calendarInstance.showBack();
}
var periodDate = this.getStartAndEndDate(currentDateObj);
startDate = periodDate[0];
endDate = periodDate[1];
var callbackFn = function(){
_calendar.resetListHeight(false);
};
var startFieldSet = "", endFieldSet = "", fieldType = "", field2Type = "", dataFilter = vm.action.dataFilter;
if(dataFilter){
startFieldSet = dataFilter.field;
endFieldSet = dataFilter.field2;
fieldType = dataFilter.fieldType;
field2Type = dataFilter.field2Type;
}
//初始化列表
var mName = vm.standalone ? "refreshList" : "triggerLazyLoad";
if(dataShowWay == "refreshList"
|| (dataShowWay == "refreshNList" && (actionListSourceType == "cube" || actionListSourceType == "sql"))
|| dataShowWay == "refreshTimelinr"
|| (dataShowWay == "refreshNTimeline" && (actionListSourceType == 'cube' || actionListSourceType == 'sql'))
){ //列表或时间轴
var columns = [];
if (startDate && endDate){
if (startFieldSet && !endFieldSet){
//只存在开始字段
if (vm.action.dataFilter.isEquals){
columns.push({ "name": startFieldSet, "value": startDate, "opt": "greaterThanEqualTo", "fieldType": fieldType});
columns.push({ "name": startFieldSet, "value": endDate, "opt": "lessThanEqualTo", "fieldType": fieldType});
} else {
columns.push({ "name": startFieldSet, "value": startDate, "opt": "greaterThanEqualTo", "fieldType": fieldType});
}
} else if (endFieldSet && !startFieldSet){
//只存在结束字段
columns.push({ "name": endFieldSet, "value": endDate, "opt": "lessThanEqualTo", "fieldType": field2Type});
} else if (endFieldSet && startFieldSet){
//两个都存在
columns.push({ "name": startFieldSet, "value": startDate, "opt": "greaterThanEqualTo", "fieldType": fieldType});
columns.push({ "name": endFieldSet, "value": endDate, "opt": "lessThanEqualTo", "fieldType": field2Type});
} else {
//两个都不存在,默认加载全部数据
}
}
_calendar.getSqlwhere(columns, function(result){
var params = {};
if (columns.length){
params = { "sqlwhere": result };
}
Mobile_NS[mName](listChoose, params, callbackFn);
});
}else if(dataShowWay == "refreshUrlList" || dataShowWay == "refreshNList" || dataShowWay == 'refreshNTimeline'){ //url列表 或 NList 或 NTimeline
var params = {};
var pValue = startDate;
if(startDate != endDate){
pValue += "," + endDate;
}
params[startFieldSet] = pValue;
Mobile_NS[mName](listChoose, params, callbackFn);
}
if(dataInitScope == "all"){ //初始化范围为全部
startDate = currentYear + "-" + currentMonth + "-01";
currentDateObj.setDate(0);
endDate = currentYear + "-" + currentMonth + "-" + currentDateObj.getDate();
}
if(!vm.basic.expand){
$("._m_cdar_upDownCalendar", $comp).bind("click",function(){
var $this = $(this);
if(!$this.hasClass("_m_cdar_upDownCalendarSwitch")){
_calendar.drawingDate(startDate, endDate); //渲染日期
}
});
}
_calendar.drawingDate(startDate, endDate); //渲染日期
};
this.getStartAndEndDate = function(dateObj){
var currentYear = dateObj.getFullYear(),
dataInitScope = vm.action.dataInit,
currentMonth = dateObj.getMonth()+1 > 9 ? dateObj.getMonth()+1 : "0"+(dateObj.getMonth()+1),
currentDate = dateObj.getDate(),
startDate = "",
endDate = "";
if(dataInitScope == "currentDay"){ //当天
startDate = currentYear + "-" + currentMonth + "-" + (currentDate > 9 ? currentDate : "0"+currentDate);
endDate = startDate;
}else if(dataInitScope == "currentWeek"){ //本周
currentDateObj.setDate(currentDate - currentDateObj.getDay());
currentMonth = currentDateObj.getMonth()+1 > 9 ? currentDateObj.getMonth()+1 : "0"+(currentDateObj.getMonth()+1);
currentDate = currentDateObj.getDate() > 9 ? currentDateObj.getDate() : "0"+currentDateObj.getDate();
startDate = currentDateObj.getFullYear() + "-" + currentMonth+ "-" +currentDate;
currentDateObj.setDate(currentDateObj.getDate() + 6);
currentMonth = currentDateObj.getMonth()+1 > 9 ? currentDateObj.getMonth()+1 : "0"+(currentDateObj.getMonth()+1);
currentDate = currentDateObj.getDate() > 9 ? currentDateObj.getDate() : "0"+currentDateObj.getDate();
endDate = currentDateObj.getFullYear() + "-" + currentMonth+ "-" +currentDate;
}else if(dataInitScope == "currentMonth"){ //本月
startDate = currentYear + "-" + currentMonth + "-01";
endDate = currentYear + "-" + currentMonth + "-" + new Date(currentYear,currentDateObj.getMonth()+1,0).getDate();
}
return [startDate,endDate];
}
this.monthChange = function(dateV1, dateV2){
if(!dateV1 && !dateV2) return _calendar.resetListHeight(true);
_calendar.drawingDate(dateV1, dateV2); //渲染日期
_calendar.resetListHeight(true);
if(!vm.action.dataReload) return;
var that = this;
var listChoose = _calendar.getListChooseId();
var dataShowWay = vm.action.type;
var actionListSourceType = vm.action.target.sourceType;
var dataReload = vm.action.dataReload;
var startFieldSet = "", endFieldSet = "", fieldType = "", field2Type = "";
if(vm.action.dataFilter){
startFieldSet = vm.action.dataFilter.field;
endFieldSet = vm.action.dataFilter.field2;
fieldType = vm.action.dataFilter.fieldType;
field2Type = vm.action.dataFilter.field2Type;
}
if(dataShowWay == "refreshList"
|| (dataShowWay == "refreshNList" && (actionListSourceType == "cube" || actionListSourceType == "sql"))
|| dataShowWay == "refreshTimelinr"
|| (dataShowWay == 'refreshNTimeline' && (actionListSourceType == 'cube' || actionListSourceType == 'sql'))
){ //列表
var columns = [];
if (dateV1 && dateV2){
if (startFieldSet && !endFieldSet){
//只存在开始字段
if (vm.action.dataFilter.isEquals){
columns.push({ "name": startFieldSet, "value": dateV1, "opt": "greaterThanEqualTo", "fieldType": fieldType});
columns.push({ "name": startFieldSet, "value": dateV2, "opt": "lessThanEqualTo", "fieldType": fieldType});
} else {
columns.push({ "name": startFieldSet, "value": dateV1, "opt": "greaterThanEqualTo", "fieldType": fieldType});
}
} else if (endFieldSet && !startFieldSet){
//只存在结束字段
columns.push({ "name": endFieldSet, "value": dateV2, "opt": "lessThanEqualTo", "fieldType": field2Type});
} else if (endFieldSet && startFieldSet){
//两个都存在
columns.push({ "name": startFieldSet, "value": dateV1, "opt": "greaterThanEqualTo", "fieldType": fieldType});
columns.push({ "name": endFieldSet, "value": dateV2, "opt": "lessThanEqualTo", "fieldType": field2Type});
} else {
//两个都不存在,默认加载全部数据
}
}
if(columns.length){
_calendar.getSqlwhere(columns, function(result){
var params = "sqlwhere=" + result;
Mobile_NS.refreshList(listChoose, params);
});
}
} else {
var filterVal = dateV1 + "," + dateV2;
if (dataShowWay == "refreshUrlList" || dataShowWay == "refreshNList" || dataShowWay == 'refreshNTimeline'){ //url列表 或 NList
Mobile_NS.refreshList(listChoose, startFieldSet + "=" + filterVal);
} else if (dataShowWay == "custom" && vm.script){ //自定义脚本
var $cal_date_script = "var $cal_date = \""+filterVal+"\";";
mUtil.eval($cal_date_script + vm.script, that.pageid);
}
}
if(vm.callback && mUtil.isFunction(vm.callback.swipe)){
vm.callback.swipe.call(this, startDate, endDate);
}
};
this.dayChange = function(dateV1, dateV2){
if(dateV1 && dateV2 && dateV1 != dateV2) return;
var that = this;
var listChoose = _calendar.getListChooseId();
var dataShowWay = vm.action.type;
var actionListSourceType = vm.action.target.sourceType;
var dataReload = vm.action.dataReload;
var startFieldSet = "", endFieldSet = "", fieldType = "", field2Type = "";
if(vm.action.dataFilter){
startFieldSet = vm.action.dataFilter.field;
endFieldSet = vm.action.dataFilter.field2;
fieldType = vm.action.dataFilter.fieldType;
field2Type = vm.action.dataFilter.field2Type;
}
var reloadCallback = vm.reloadCallback || function(){};
if(dataShowWay == "refreshList"
|| (dataShowWay == "refreshNList" && (actionListSourceType == "cube" || actionListSourceType == "sql"))
|| dataShowWay == "refreshTimelinr"
|| (dataShowWay == 'refreshNTimeline' && (actionListSourceType == 'cube' || actionListSourceType == 'sql'))
){ //列表
var columns = [];
if (dateV1 && dateV2){
if (startFieldSet && !endFieldSet){
//只存在开始字段
if (vm.action.dataFilter.isEquals){
columns.push({ "name": startFieldSet, "value": dateV1, "opt": "greaterThanEqualTo", "fieldType": fieldType});
columns.push({ "name": startFieldSet, "value": dateV2, "opt": "lessThanEqualTo", "fieldType": fieldType});
} else {
columns.push({ "name": startFieldSet, "value": dateV1, "opt": "lessThanEqualTo", "fieldType": fieldType});
}
} else if (endFieldSet && !startFieldSet){
//只存在结束字段
columns.push({ "name": endFieldSet, "value": dateV2, "opt": "greaterThanEqualTo", "fieldType": field2Type});
} else if (endFieldSet && startFieldSet){
//两个都存在
columns.push({ "name": startFieldSet, "value": dateV1, "opt": "lessThanEqualTo", "fieldType": fieldType});
columns.push({ "name": endFieldSet, "value": dateV2, "opt": "greaterThanEqualTo", "fieldType": field2Type});
} else {
//两个都不存在,默认加载全部数据
}
}
if(columns.length){
_calendar.getSqlwhere(columns, function(result){
var params = "sqlwhere=" + result;
Mobile_NS.refreshList(listChoose, params,reloadCallback);
});
}
} else if (dataShowWay == "refreshUrlList" || dataShowWay == "refreshNList" || dataShowWay == 'refreshNTimeline'){ //url列表 或 NList 或 NTimeline
Mobile_NS.refreshList(listChoose, startFieldSet + "=" + dateV1,reloadCallback);
} else if (dataShowWay == "custom" && vm.script){ //自定义脚本
var $cal_date_script = "var $cal_date = \""+dateV1+"\";";
mUtil.eval($cal_date_script + vm.script, that.pageid);
reloadCallback();
} else {
reloadCallback();
}
if(vm.callback && mUtil.isFunction(vm.callback.click)) {
vm.callback.click.call(this, dateV1, dateV2);
}
//确保刷新日历的回调函数只执行一次
vm.reloadCallback = function(){};
};
_calendar.getSqlwhere = function(params, callback){
var url = mUtil.jionActionUrl("com.api.mobilemode.web.mobile.service.MobileCommonAction", "action=getCalendarCondition&columns="+encodeURIComponent(JSON.stringify(params)));
mUtil.getJSON(url, function(result){
callback && callback(result.data);
});
};
this.addData = function(dateVal){
var that = this;
var parseWayChoose = vm.parseWayChoose;
if(vm.standalone){
if(vm.callback && mUtil.isFunction(vm.callback.add)){
vm.callback.add.call(this, dateVal);
}
return;
}
if (parseWayChoose == 1) { //自动解析
var layoutUrl = vm.layoutUrl,
param = (layoutUrl.param || "").replace(/\${calendarDateVal}/g, dateVal);
if(vm.autoParseUrl) return $u(vm.autoParseUrl + param);
var actionUrl = mUtil.getActionUrl("service.FormComponent", { action: "getLayoutUrl" });
var requestParams = {
modelid: layoutUrl.modeid,
appid: layoutUrl.appid,
uitype: 0
};
var beginstamp = (new Date()).valueOf();
var hideLoader = function(cb) {
var endstamp = (new Date()).valueOf();
if ((endstamp - beginstamp) >= 500) {
Mobile_NS.hideLoader();
return cb.call();
}
setTimeout(function () {
Mobile_NS.hideLoader();
cb.call();
}, 500)
};
Mobile_NS.showLoader();
mUtil.getJSON(actionUrl, requestParams, function (result) {
hideLoader(function () {
vm.autoParseUrl = result.data;
$u(vm.autoParseUrl + param);
});
}, function (result) {
hideLoader(function () {
Mobile_NS.msg(result);
});
});
} else if (parseWayChoose == 2 && vm.clickScript) { //输入脚本
var $cal_date_script = "var $cal_date = \"" + dateVal + "\";";
mUtil.eval($cal_date_script + vm.clickScript, that.pageid);
}
};
//日期标记
_calendar.drawingDate = function(startDate, endDate){
var actionUrl;
if(vm.standalone){
actionUrl = vm.remark;
}else{
if(vm.remark === true){
actionUrl = mUtil.getActionUrl(this.type, { action: "getDatas", "mec_id": vm.id }, this.pageid);
}
}
if(!actionUrl) return;
if(mUtil.isArray(actionUrl)) return _calendar.buildDrawingDate(actionUrl);
mUtil.getJSON(actionUrl, {startDate : startDate, endDate : endDate}, function(result){
_calendar.buildDrawingDate(result.data);
});
};
_calendar.toogleMarkPoint = function(date,color){
var $visible = $(".swiper-slide-visible", this.$el);
var $td = $visible.find("td[data-id='" + mUtil.dateToStr(new Date(date),"yyyy-MM-dd") + "']");
var $pointWrap = $td.find('._m_cdar_mark_wrap');
if(!$pointWrap.size()){
$pointWrap = $("<div class='_m_cdar_mark_wrap'></div>");
$td.append($pointWrap);
}
var $point = $("<span class='_m_cdar_mark'></span>").css('background-color',color).data('color',color);
var $selectHasCol = $pointWrap.find('._m_cdar_mark[data-color="' + color + '"]');
var $selectNoCol = $pointWrap.find('._m_cdar_mark');
$selectHasCol.remove();
if (!color) {
$selectNoCol.remove();
}
$pointWrap.append($point);
};
_calendar.clearMarkPoint = function(dataObj){
$.isArray(dataObj) && dataObj.forEach(function(d) {
var date = d;
if(mUtil.isObject(d)){
var dvs = Object.values(d);
date = d['date']||dvs[0];
}
var $visible = $(".swiper-slide-visible", this.$el);
var $td = $visible.find("td[data-id='" + date + "']");
var $pointWrap = $td.find('._m_cdar_mark_wrap');
if($pointWrap.size()){
$pointWrap.empty();
}
});
};
_calendar.buildDrawingDate = function(dataObj){
var dataObj = mUtil.isString(dataObj) ? $.parseJSON(dataObj) : dataObj;
_calendar.clearMarkPoint(dataObj);
$.isArray(dataObj) && dataObj.forEach(function(d) {
var date = d,color = '';
if(mUtil.isObject(d)){
var dvs = Object.values(d);
date = d['date']||dvs[0];
color =d['color']||dvs[1];
}
_calendar.toogleMarkPoint(date,color);
});
};
_calendar.resetListHeight = function(monthChange){
if(!monthChange) return _calendar.setListHeight();
setTimeout(_calendar.setListHeight.bind(_calendar), 100);
};
_calendar.setListHeight = function(){
var actionTarget = _calendar.getListChooseId();
var instance = actionTarget && Component.getInstance(actionTarget);
if(!instance) return;
var $page = this.$container,
$target = instance.$el.find(".wev-comp-" + instance.type);
var offsetTop = $target.offset().top,
height = $page.height() - offsetTop;
if(height <= 50) return;
$target.height(height).css({ "overflow-x": "hidden", "overflow-y": "auto", "-webkit-overflow-scrolling": "touch" });
};
_calendar.getListChooseId = function(){
var target = vm.action.target;
return mUtil.isObject(target) ? target.id : target;
};
_calendar.toogleMarkPoint = _calendar.toogleMarkPoint.bind(this);
_calendar.clearMarkPoint = _calendar.clearMarkPoint.bind(this);
_calendar.drawingDate = _calendar.drawingDate.bind(this);
_calendar.buildDrawingDate = _calendar.buildDrawingDate.bind(this);
_calendar.resetListHeight = _calendar.resetListHeight.bind(this);
_calendar.setListHeight = _calendar.setListHeight.bind(this);
};
return Component.init(Calendar);
});