science_competition.js
9.4 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
define(['jquery', 'bootstrap', 'frontend', 'form', 'template', 'swiper', 'layer','layui','upload',], function($, undefined, Frontend, Form, Template, Swiper, Layer,layui,Upload) {
var Controller = {
index: function() {
var first_swiper = new Swiper ('#first_swiper', {
loop: true, // 循环模式选项
// 如果需要分页器
autoplay:true,
pagination: {
el: '.swiper-pagination',
}
});
},
detail:function () {
$("#apply").click(function(){
layer.open({
type: 1,
title:['请选择分类','font-size:1rem;'],
area:['50rem','28rem'],
scrollbar:false,
content: $('#modal2') //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
});
});
},
enter:function () {
var _Form = Form;
var vm = new Vue({
el:"#app",
data() {
return {
activeName: '0',
formSet:[],
formData:[],
loading:true,
collageAll:{},
match_type:Config.match_type,
cdn_url:Config.cdn_url,
id:Config.id || 0,
match_id:Config.match_id || '',
matchData:Config.matchData,
file_flg:false,
form:{},
match_type_id:Config.match_type || '',
user_id:Config.user_id || '',
rules:{},
formLength:1,
f_last:false,
f_first:false,
teachersFormVisible:false,
membersFormVisible:false,
tmp_teachers:{},
tmp_members:{},
//项目领域数据
territory:Config.territory || {},
};
},
computed: {
rulesList: function() {
var formset = this.formSet;
var formsetsVal = formset[this.activeName];
if(formsetsVal) {
var name = formsetsVal.stage_type;
var rules = this.rules;
if(name in rules) {
return rules[name];
}else{
return [];
}
}
}
},
mounted(){
var match_type_id = this.match_type_id ? this.match_type_id : this.getDefaultType();
this.match_type_id = parseInt(match_type_id);
this.getData();
},
methods: {
getDefaultType() {
var initTypeId = '';
$.each(this.matchData.types,function (i,it) {
if(initTypeId == '') {
initTypeId = it.id;
}
});
return initTypeId;
},
prev(key) {
//
//
key = key.toString();
var arr = Object.keys(this.formSet);
var index = arr.indexOf(key);
var $prev = arr[index - 1];
var start = arr[0];
if($prev == start) {
this.f_first = true;
}
this.activeName = $prev != 0 ? parseInt($prev) : '0';
this.f_last = false;
this.$nextTick(()=>{
this.$refs.form.clearValidate();
});
},
next(form,key) {
this.$refs[form].validate((valid) => {
if (valid) {
var k_index = parseInt(key);
var indexLength = this.formSet.length -1;
k_index++
if(k_index == indexLength) {
this.f_last = true;
}
this.activeName = k_index;
this.f_first = false;
this.$nextTick(()=>{
this.$refs.form.clearValidate();
});
}else {
layer.msg('信息不完整',{icon: 5});
return false;
}
});
},
getCollage(){
var _this = this;
Fast.api.ajax({
url:'science_competition/getCollage',
data:{user_id:_this.user_id}
},function (ret) {
_this.collageAll = ret;
return false;
});
},
changeType (val) {
_this = this;
this.match_type_id = val;
this.formSet = [];
setTimeout(function () {
_this.getData();
},50);
},
getData(){
var _this = this;
Fast.api.ajax({
url:'science_competition/getFormData',
data:{match_id:_this.match_id ,match_type_id:_this.match_type_id,id:_this.id}
},function (ret) {
//初始化
_this.formSet = ret.formSets;
_this.form = ret.detail;
_this.rules = ret.rules;
_this.formLength = Object.keys(_this.formSet).length;
console.log(_this.formSet)
console.log(_this.form)
_this.f_first = true;
$.each(_this.formSet,function (k,v) {
v.stage_title=v.stage_title+'>>';
var stage = Object(v.stage_type);
_this.formData.push(stage);
});
_this.loading = false;
_this.getCollage();
//上传绑定事件
_this.$nextTick(function () {
var _this = this;
$.each(this.formSet,function(i,val) {
$.each(val.form_data,function(k,v){
if(v.type == 'file') {
var uploadName = v.name;
var uploadKey = v.file_key;
$("#"+uploadName).data("upload-success", function (res) {
$("#"+uploadName).parent().siblings('.file_box').show();
_this.$set(_this.form[val.stage_type],uploadName,res.file.url);
_this.$set(_this.form[val.stage_type],uploadKey,res.file.name);
});
}
});
Form.api.bindevent($("#form"));
});
});
return false;
});
},
del_file(key,name,stage_type) {
var _this = this;
$("#"+name).parent().siblings('.file_box').hide();
_this.$set(_this.form[stage_type],name,'');
_this.$set(_this.form[stage_type],key,'');
},
getMembers(e){
var value = e.target.value;
var _this = this;
Fast.api.ajax({
url:"signup_info/getMemberInfo",
data:{members_student_no:value}
},function (ret) {
_this.tmp_members = ret;
return false;
},function(){
_this.tmp_members = {};
layer.msg('查询不到该学生,请重新输入');
return false;
});
},
getTeachers(e){
var _this = this;
var value = e.target.value;
Fast.api.ajax({
url:"signup_info/getTeacher",
data:{job_num:value}
},function (ret) {
_this.tmp_teachers = ret;
return false;
}, function(ret) {
_this.tmp_teachers = {};
layer.msg('查询不到该教师,请重新输入');
return false;
});
},
exit_teacher() {
var _this = this
_this.tmp_teachers = {};
_this.teachersFormVisible = false;
},
exit_members() {
var _this = this
_this.tmp_members = {};
_this.membersFormVisible = false;
},
formTSubmit:function () {
var _this = this;
if($.isEmptyObject(_this.tmp_teachers)) {
layer.msg('请添加指导教师');
return false;
}
var exist = false;
if(!$.isEmptyObject(_this.form.teachers.teachers)) {
$.each(_this.form.teachers.teachers,function(i,v){
if(v.id == _this.tmp_teachers.id) {
layer.msg('该教师已选择');
exist = true;
}
});
}
if(exist === true) {
_this.tmp_teachers = {};
_this.teachersFormVisible = false;
return false;
}
console.log('教师信息',_this.tmp_teachers);
_this.form.teachers.teachers.push(_this.tmp_teachers);
_this.tmp_teachers = {};
_this.teachersFormVisible = false;
},
teacherRemove:function(row) {
var _this = this;
$.each(_this.form.teachers.teachers , function (k,v) {
if (v.id == row.id){
_this.form.teachers.teachers.splice(k,1);
return false;
}
});
if($.isEmptyObject(_this.form.teachers.teachers)) {
_this.form.teachers.teachers = [];
}
},
formSubmit:function () {
var _this = this;
if($.isEmptyObject(_this.tmp_members)) {
layer.msg('请添加成员');
return false;
}
var exist = false;
if(!$.isEmptyObject(_this.form.members.members)) {
$.each(_this.form.members.members,function(i,v){
if(v.id == _this.tmp_members.id) {
layer.msg('该成员已选择');
exist = true;
}
});
}
console.log(_this.form.members.members);
if(exist === true) {
_this.tmp_members = {};
_this.membersFormVisible = false;
return false;
}
_this.form.members.members.push(_this.tmp_members);
_this.tmp_members = {};
_this.membersFormVisible = false;
},
membersRemove(row){
var _this = this;
$.each(_this.form.members.members , function (k,v) {
if (v.id == row.id){
_this.form.members.members.splice(k,1);
return false;
}
});
if($.isEmptyObject(_this.form.members.members)) {
_this.form.members.members = [];
}
},
submit(form) {
this.$refs[form].validate((valid) => {
if (valid) {
$.ajax({
type:'post',
url:'/index/science_competition/putData',
data:{form:this.form,matchGroupId:this.matchData.match_group_id,match_id:this.matchData.match_id,match_type_id:this.match_type_id,item_id:this.id},
dataType:'json',
success:function(res){
if(res.code != 1) {
layer.msg(res.msg, {icon: 5});
}else{
layer.msg(res.msg, {icon: 1});
setTimeout(function () {
window.location.href = res.url;
},800);
}
},
error:function(error){
layer.msg('网络失败,请重试', {icon: 5});
}
});
}
});
},
goIndex(id) {
window.location.href = "/index/science_competition/detail/id/"+id;
},
}
});
}
}
return Controller;
});