double.js
8.6 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
define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {
var Controller = {
index: function () {
// js文件加载后,设置区域可触发交互事件
$('.project_index').attr('style', '');
initDateTimeRange();
// 复选框的中文名你
var checkboxNameMap = {
is_open: '项目',
can_apply_double: '项目双选',
can_apply_approval: '项目申报',
can_apply_mid: '中期项目检查',
can_apply_conclusion: '项目结题'
}
// 展开/收起项目设置面板
$('.project_set_body').on('click', '.trigger', function () {
$(this).parents('.item').find('.bottom').toggleClass('show')
})
// 关闭/开启项目阶段
$('.project_index').on('change', 'input[type="checkbox"]', function (e) {
var _me = this,
isChecked = this.checked;
var checkboxName = checkboxNameMap[this.name] || '';
var stateText = isChecked ? '开启' : '关闭'
var tip = '是否' + stateText + checkboxName + '?';
if (isChecked) {
if ('is_open' !== this.name) {
tip += '<br><b class="text-danger">注: 开启后,与该阶段相关的设置将无法更改</b>'
} else {
tip += '<br><b class="text-danger">注: 开启后,该容器相关的设置将无法更改</b>'
}
}
confirm(tip, function () {
var data = {};
data['row[' + _me.name + ']'] = Number(isChecked)
$.ajax({
url: '/school/double/editContainer',
method: 'POST',
data: data,
success: function (res) {
if (1 === res.code) {
$(_me).parent().find('.switchA').text(stateText);
$(_me).parents('.item').toggleClass('open');
_me.value = isChecked ? 1 : 0;
Toastr.success(stateText + '成功');
} else {
_me.checked = !isChecked
Toastr.error(res.msg)
}
}
})
}, function () {
_me.checked = !isChecked
})
})
/**
* 初始化日期时间选择器
* @param {function} changeCallback 日期改变后的回调
*/
function initDateTimeRange(changeCallback) {
//绑定日期时间元素事件
if ($(".datetimerange").size() > 0) {
require(['bootstrap-daterangepicker'], function () {
var ranges = {};
// ranges[__('Today')] = [Moment().startOf('day'), Moment().endOf('day')];
// ranges[__('Yesterday')] = [Moment().subtract(1, 'days').startOf('day'), Moment().subtract(1, 'days').endOf('day')];
ranges[__('Last 7 Days')] = [Moment().subtract(6, 'days').startOf('day'), Moment().endOf('day')];
ranges[__('Last 30 Days')] = [Moment().subtract(29, 'days').startOf('day'), Moment().endOf('day')];
//ranges[__('This Month')] = [Moment().startOf('month'), Moment().endOf('month')];
// ranges[__('Last Month')] = [Moment().subtract(1, 'month').startOf('month'), Moment().subtract(1, 'month').endOf('month')];
var options = {
timePicker: false,
autoUpdateInput: false,
timePickerSeconds: true,
timePicker24Hour: true,
autoApply: true,
locale: {
format: 'YYYY-MM-DD',
customRangeLabel: __("Custom Range"),
applyLabel: __("Apply"),
cancelLabel: __("Clear"),
},
ranges: ranges,
opens:'right'
}
editUpdate("begindate",options,0);
editUpdate("doublebdate",options,1);
editUpdate("midbdate",options,2);
options.opens= 'left';
editUpdate("finishbdate",options,3);
// var origincallback = function (start, end) {
// var _me = this;
// confirm('是否修改项目双选时间?', function () {
// var options = {
// element: _me.element,
// start: start.format(_me.locale.format),
// end: end.format(_me.locale.format)
// };
// changeCallback && changeCallback(options)
//
// })
// };
// $(".datetimerange").each(function () {
// var callback = typeof $(this).data('callback') == 'function' ? $(this).data('callback') : origincallback;
// $(this).on('apply.daterangepicker', function (ev, picker) {
// callback.call(picker, picker.startDate, picker.endDate);
// });
// $(this).on('cancel.daterangepicker', function (ev, picker) {
// $(this).val('').trigger('blur');
// });
// $(this).daterangepicker($.extend(true, options, $(this).data()));
// });
});
}
}
var editUpdate = function(id,options,type){
$('#'+id).daterangepicker(options, function(start, end, label) {
var type_num = parseInt(type);
var data = {};
switch(type){
case 0:
data = {project_starttime: start.format('YYYY-MM-DD'),project_endtime: end.format('YYYY-MM-DD')};
break;
case 1:
data = {project_double_starttime: start.format('YYYY-MM-DD'),project_double_endtime: end.format('YYYY-MM-DD')};
break;
case 2:
data = {midterm_review_starttime: start.format('YYYY-MM-DD'),midterm_review_endtime: end.format('YYYY-MM-DD')};
break;
case 3:
data = {conclusion_starttime: start.format('YYYY-MM-DD'),conclusion_endtime: end.format('YYYY-MM-DD')};
break;
}
$.ajax({
url: '/school/double/editDoubleDateTime',
type: 'post',
data: data,
dataType:'json',
success: function (res) {
if (1 === res.code) {
$(options.element).val(options.start + " - " + options.end);
$(options.element).trigger('blur');
$('#'+id).val(start.format('YYYY-MM-DD')+' - '+end.format('YYYY-MM-DD'));
Toastr.success('修改成功')
} else {
Toastr.error(res.msg)
}
}
});
});
}
}
}
/**
* 询问弹窗
* @param {string} tip 询问文字
* @param {function} yes 确认回调
* @param {function} cancel 取消回调
*/
function confirm(tip, yes, cancel) {
layer.confirm(tip, {
btn: ['确定', '取消'] //按钮
}, function (index) {
yes && yes()
layer.close(index)
}, function () {
cancel && cancel();
});
}
return Controller
})