sx_basement.js
10.9 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
define(['jquery', 'bootstrap', 'frontend', 'form', 'template', 'swiper', 'layer', 'layui'], function ($, undefined, Frontend,
Form, Template, Swiper, Layer, layui) {
var Controller = {
index: function () {
require(['upload'], function (Upload) {
// console.log(true)
var first_swiper = new Swiper('#first_swiper', {
loop: true, // 循环模式选项
// 如果需要分页器
autoplay: true,
pagination: {
el: '.swiper-pagination',
}
})
Upload.api.upload($('#btn-upload'));
$(".defaultOption").click(function(){
$(this).parents(".myCollapse").find(".options").toggleClass("optionShow")
})
$(".options .option").click(function(){
$(this).parents(".myCollapse").find(".defaultOption text").text($(this).text())
$(".options").removeClass("optionShow")
})
$(".add").click(function () {
var len = $(".list").length + 1
$(".joiner").append(getPeopleItem(len))
})
function getPeopleItem(index) {
return `<div class="list">
<div>
<text>姓名</text>
<input type="text" />
<text>学号</text>
<input type="text" />
</div>
</div>`
}
});
function getBeforeDate(n){//n为你要传入的参数,当前为0,前一天为-1,后一天为1
var date = new Date() ;
var year,month,day ;
date.setDate(date.getDate()+n);
year = date.getFullYear();
month = date.getMonth()+1;
day = date.getDate() ;
s = year + '-' + ( month < 10 ? ( '0' + month ) : month ) + '-' + ( day < 10 ? ( '0' + day ) : day) ;
return s ;
}
layui.use('element', function () {
var $ = layui.jquery
, element = layui.element;
});
layui.use('laydate', function(){
var laydate = layui.laydate;
laydate.render({
elem: '#apply_date',
type: 'date',
min:0,
max:getBeforeDate(7)
});
});
layui.use('laydate', function(){
var laydate = layui.laydate;
laydate.render({
elem: '#station_date',
type: 'date',
min:0,
max:getBeforeDate(7)
});
});
layui.use('laydate', function(){
var laydate = layui.laydate;
laydate.render({
elem: '#test10'
,type: 'datetime'
,range: true
});
});
$(".showdetial").click(function () {
$(this).parents(".outter").addClass("detial")
$(this).parents(".outter").siblings().removeClass("detial")
})
$(".change").click(function(){
$(this).parents(".inner").addClass("detial")
$(this).parents(".inner").siblings().removeClass("detial")
})
$(".back").click(function(){
$(this).parents(".inner").addClass("detial")
$(this).parents(".inner").siblings().removeClass("detial")
});
/**
* 房间预约
*/
$(document).on('click','#build_type li:not(:first-child)',function(){
$(this).children('a').addClass("conditions_select");
$(this).siblings('li').children('a').removeClass("conditions_select");
var $bulidId = $(this).children('a').attr("data-id");
if($bulidId != '0') {
Fast.api.ajax({
url:'building/getFloorList',
data:{building_id:$bulidId}
},function (ret) {
if(ret) {
clear_floor();
var str = '';
$.each(ret,function(i,v) {
str +='<li><a title="'+v.floor_name+'" href="javascript:;" data-id="'+v.id+'">'+v.floor_name+'</a></li>';
});
$("#floor").append(str);
}
return false;
});
}else{
clear_floor();
}
get_room();
});
//工位
$(document).on('change',".station_type",function () {
var val = $(".station_type").find("option:selected").val();
if(val == 2) {
$("#company").show();
}else {
$("#company").hide();
}
});
$("#company").hide();
$(document).on('click','#stations li:first-child, #stations li:not(:first-child),#stations li:not(:first-child),#stations li:not(:first-child)',function(){
// $(this).children('a').children('div').children('div').addClass("conditions_select");
// $(this).siblings('li').children('a').removeClass("conditions_select");
var appoint_count = $(this).children('a').data('appoint_count');
var station_name = $(this).children('a').data('station_name');
if (appoint_count > 0){
layer.msg('此工位不可约');
return false;
}
$(this).children('a').children('div').children('div').addClass("station_check_select");
$(this).siblings('li').children('a').children('div').children('div').removeClass("station_check_select");
// $('.station_block').removeClass('hidden');
$('.station_name').text(station_name);
});
//房间选择 不需要请求 房间接口
$(document).on('click','#room li:not(:first-child)',function(){
$(this).children('a').addClass("conditions_select");
$(this).siblings('li').children('a').removeClass("conditions_select");
});
$(document).on('click','#floor li:not(:first-child),#room_type li:not(:first-child) ,#build_type li:not(:first-child)',function(){
$(this).children('a').addClass("conditions_select");
$(this).siblings('li').children('a').removeClass("conditions_select");
get_room();
});
//清除所有楼层
function clear_floor() {
var floor_lis = $("#floor li");
$.each(floor_lis,function(i,v) {
if(i > 1) {
$(this).remove();
}
});
}
//清除房间
function clear_room() {
var room_lis = $("#room li");
$.each(room_lis,function(i,v) {
if(i > 1) {
$(this).remove();
}
});
}
//查看检索条件 搜索可用房间
function get_room() {
var roomType = $("#room_type .conditions_select").attr("data-id"),
buildId = $("#build_type .conditions_select").attr("data-id"),
floorId = $("#floor .conditions_select").attr("data-id");
Fast.api.ajax({
url:'building/getRoomList',
data:{room_type:roomType,building_id:buildId,floor_id:floorId}
},function (ret) {
if(ret) {
clear_room();
var str = '';
$.each(ret,function(i,v) {
str +='<li><a title="'+v.room_name+'" href="javascript:;" data-id="'+v.id+'">'+v.room_name+'</a></li>';
});
$("#room").append(str);
}
return false;
});
}
//工位分配提交
$(document).on('click',"#commit_station",function(){
var conditions_select = $("#stations .station_check_select").attr("data-id"),
station_date = $("input[name='station_date']").val(),
station_start_time = $(".station_start_time option:selected").val(),
station_end_time = $(".station_end_time option:selected").val(),
station_user_count = $("input[name='station_user_count']").val(),
station_desc = $("#station_desc").val(),
enter_id = $(".enter_id option:selected").val(),
apply_type = $(".station_type option:selected").val();
if(!conditions_select) {
layer.msg('请选择工位');
return false;
}
if(station_date == '') {
layer.msg('请选择预约日期');
return false;
}
if(station_start_time == '') {
layer.msg('请选择预约开始时间');
return false;
}
if(station_end_time == '') {
layer.msg('请选择预约结束时间');
return false;
}
if(station_user_count == '') {
layer.msg('参与人数不能为空');
return false;
}
if(apply_type == 2 && enter_id == '') {
layer.msg('公司不能为空');
return false;
}
// setTimeout(function () {
// layer.msg('提交成功');
// }, 1000);
Fast.api.ajax({
url:'sx_basement/stationApply',
data:{
station_id:conditions_select,
station_date:station_date,
station_start_time:station_start_time,
station_end_time:station_end_time,
station_user_count:station_user_count,
station_desc:station_desc,
station_type:apply_type,
enter_id:enter_id
}
},function (i,ret) {
if(ret.code == 1) {
setTimeout(function () {
location.href = ret.url ? ret.url : "/";
}, 1000);
}else{
return false;
}
});
});
//选择时间切换工位数据
// $(document).on('change','.station_date,.station_start_time,.station_end_time',function () {
// console.log('time',$(this).val());
// var station_date = $("input[name='station_date']").val(),
// station_start_time = $(".station_start_time option:selected").val(),
// station_end_time = $(".station_end_time option:selected").val();
//
// if(station_date != '' && station_start_time != '' && station_end_time != '') {
// Fast.api.ajax({
// url:'sx_basement/station',
// data:{
// station_date:station_date,
// station_start_time:station_start_time,
// station_end_time:station_end_time,
// }
// },function (i,ret) {
// if(ret.code == 1) {
// console.log('ret',ret);
// }else{
// return false;
// }
// });
// }
// });
$(document).on('click',"#commit_build",function(){
var room_id = $("#room .conditions_select").attr("data-id"),
apply_date = $("input[name='apply_date']").val(),
use_count = $("input[name='use_count']").val(),
start_time = $(".start_time option:selected").val(),
end_time = $(".end_time option:selected").val(),
apply_desc = $("#apply_desc").val();
apply_type = $(".apply_type option:selected").val();
if(room_id == '0') {
layer.msg('请选择房间');
return false;
}
if(apply_date =='') {
layer.msg('请选择预约日期');
return false;
}
if(start_time == '') {
layer.msg('请选择预约开始时间');
return false;
}
if(end_time == '') {
layer.msg('请选择预约结束时间');
return false;
}
if(use_count == '') {
layer.msg('使用人数不能为空');
return false;
}
Fast.api.ajax({
url:'building/roomApply',
data:{room_id:room_id,apply_date:apply_date,start_time:start_time,end_time:end_time,apply_desc:apply_desc,apply_type:apply_type,use_count:use_count}
},function (i,ret) {
if(ret.code == 1) {
setTimeout(function () {
location.href = ret.url ? ret.url : "/";
}, 1000);
}else{
return false;
}
});
});
},
}
return Controller;
});