define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function ($, undefined, Backend, Table, Form,editable) { var Controller = { index: function () { // $('.btn-add').data('area',['85%','85%']); // $('.btn-edit').data('area',['85%','85%']); // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'teacher/practice/index' + location.search, add_url: 'teacher/practice/add', edit_url: 'teacher/practice/edit', del_url: 'teacher/practice/del', multi_url: 'teacher/practice/multi', import_url: 'teacher/practice/import', table: 'teacher_collection', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'exam_collection_id', sortName: 'exam_collection_id', fixedColumns: true, fixedRightNumber: 1, searchFormVisible:true, search:false, showExport:false, showToggle:false, showColumns: false, columns: [ [ {checkbox: true}, {field: 'exam_collection_id', title: __('编号'),operate: false}, {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, // {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype}, // {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教员自选","3":"任务自选"},formatter: Table.api.formatter.simmethod}, // {field: 'exam_collection_type', title: __('Exam_collection_type'),operate: false,formatter: function (value, row, index) { // return '训练'; // } // }, { field: 'exam_collection_state',searchList:{"2":"打开","3":"关闭"}, title: __('是否开启训练'), align: 'center', table: table, formatter: Table.api.formatter.collectonstate }, // {field: 'task_id', title: __('Task_id')}, {field: 'limit_duration', title: __('Limit_duration')}, {field: 'create_by', title: __('Create_by'), operate: 'LIKE'}, // {field: 'qudui_count', title: __('区队数量'), operate: false}, {field: 'xueyuan_count', title: __('应考人数'), operate: false}, {field: 'yikao_count', title: __('已考人数'), operate: false}, {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, // formatter: Table.api.formatter.operate formatter: Table.api.formatter.buttons, buttons: [ { name: 'dispatch', text: '编辑', icon: 'fa fa-pencil', title: '编辑', classname: 'btn btn-success btn-xs btn-magic btn-dialog', // extend: 'data-area=\'["85%","85%"]\'', url: 'teacher/practice/edit', }, { name: 'dispatch', text: '进入训练', icon: 'fa fa-hand-pointer-o', title: '进入训练', visible: function (rr) { if(rr.exam_collection_state == 2){ return true; } return false; }, classname: 'btn btn-info btn-xs btn-magic btn-addtabs', url: 'teacher/practice/persent', }, { name: 'dispatch', text: '查看学员', icon: 'fa fa-eye', title: '查看学员', visible: function (rr) { if(rr.user_count > 0){ return true; } return false; }, classname: 'btn btn-warning btn-xs btn-magic btn-dialog', extend: 'data-area=\'["85%","85%"]\'', url: 'teacher/collection/viewuser', }, { name: 'dispatch', text: '添加学员', icon: 'fa fa-plus', title: '添加学员', classname: 'btn btn-success btn-xs btn-magic btn-dialog', extend: 'data-area=\'["85%","85%"]\'', url: 'teacher/practice/adduser', }, { name: 'dispatch', text: '删除学员', icon: 'fa fa-pencil', title: '删除学员', visible: function (rr) { if(rr.user_count > 0){ return true; } return false; }, classname: 'btn btn-info btn-xs btn-magic btn-dialog', extend: 'data-area=\'["75%","75%"]\'', url: 'teacher/practice/edituser', }, { name: 'dispatch', text: '删除', icon: 'fa fa-trash', title: '删除', classname: 'btn btn-danger btn-xs btn-magic btn-ajax', url: 'teacher/practice/del', confirm: '确定要删除吗?', success: function (data, ret) { $(".btn-refresh").trigger("click"); }, error: function (data, ret) { Layer.alert(ret.msg); return false; } } ], } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); $(document).on('click', '.btn-start', function () { var ids = Table.api.selectedids(table); Fast.api.ajax({ url: "teacher/practice/start/ids/"+ids, type: "post", }, function () { table.bootstrapTable('refresh'); Layer.close(index); }); }); }, persent: function () { Table.api.init({ extend: { index_url: 'teacher/practice/persent/ids/'+Config.ids + location.search, indexed_url: 'teacher/practice/examing/ids/'+ Config.ids+ location.search, score_url: 'teacher/practice/score/ids/'+Config.ids + location.search, table: 'teacher_exams', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'rel_id', sortName: 'rel_id', toolbar: '#toolbar', fixedColumns: true, fixedRightNumber: 1, searchFormVisible:false, showExport:false, search:false, showExport:false, showToggle:false, showColumns: false, columns: [ [ // {checkbox: true}, {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype}, {field: 'fault_name', title: __('更换件')}, {field: 'create_by', title: __('学员姓名')}, {field: 'request_status', title: __('状态'), formatter: function(value, row,index) { if(value==1){ return '待处理'; }else if(value==2){ return '已送'; }else if(value==3){ return '已驳回'; } } }, {field: 'createtime', title: __('申请时间'), formatter: Table.api.formatter.datetime, operate: false, addclass: 'datetimerange', sortable: true}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, // formatter: Table.api.formatter.operate formatter: Table.api.formatter.buttons, buttons: [ { name: 'dispatch', text: '已送', icon: 'fa fa-check', title: '已送', classname: 'btn btn-success btn-xs btn-magic btn-ajax', url: 'teacher/exams/handle/type/1', visible: function (rr) { if(rr.request_status == 1 || rr.request_status == 0){ return true; } return false; }, success: function (data, ret) { table.bootstrapTable("refresh"); }, },{ name: 'dispatch', text: '驳回', icon: 'fa fa-reply-all', title: '驳回', classname: 'btn btn-danger btn-xs btn-magic btn-ajax', url: 'teacher/exams/handle/type/2', visible: function (rr) { if(rr.request_status == 1 || rr.request_status == 0){ return true; } return false; }, success: function (data, ret) { table.bootstrapTable("refresh"); }, } ], } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); var table1 = $("#table1"); // 初始化表格 table1.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.indexed_url, pk: 'exam_id', sortName: 'exam_id', toolbar: '#toolbar1', fixedColumns: true, fixedRightNumber: 1, searchFormVisible:false, showExport:false, search:false, pagination:false, showExport:false, showToggle:false, showColumns: false, columns: [ [ // {checkbox: true}, {field: 'seat_id', title: __('座号')}, {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype}, {field: 'sim_state', title: __('模拟器状态'), formatter: function(value, row,index) { // if(value=='在线'){ // return ''+value+''; // } // if(value=='离线'){ // return ''+value+''; // } return ''+value+''; } }, {field: 'user_username', title: __('学员学号')}, {field: 'user_nickname', title: __('学员姓名')}, {field: 'exam_status', title: __('考试状态'), formatter: function(value, row,index) { if(value=='未登录'){ return ''+value+''; }else if(value=='已登录未开始考试'){ return ''+value+''; }else if(value=='已开始考试'){ return ''+value+''; }else if(value=='已交卷'){ return ''+value+''; } } }, {field: 'total_score', title: __('考试成绩')}, {field: 'fault_names', title: __('出题题目'),formatter: Table.api.formatter.faultname}, {field: 'operate', title: __('Operate'), table: table1, events: Table.api.events.operate, // formatter: Table.api.formatter.operate formatter: Table.api.formatter.buttons, buttons: [ { name: 'dispatch', text: '成绩详情', icon: 'fa fa-eye', title: '成绩详情', classname: 'btn btn-info btn-xs btn-magic btn-dialog', extend: 'data-area=\'["75%","95%"]\'', visible: function (row) { if(row.total_score>0){ return true; } return false; }, url: 'teacher/exams/view', } ], } ] ] }); // 为表格绑定事件 Table.api.bindevent(table1); var table2 = $("#table2"); // 初始化表格 table2.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.score_url, pk: 'exam_id', sortName: 'exam_id', toolbar: '#toolbar2', fixedColumns: true, pageSize: 10, pagination:false, fixedLeftNumber: 4, searchFormVisible:false, showExport:false, search:false, showExport:false, showToggle:false, showColumns: false, columns: [ [ // {checkbox: true}, {field: 'seat_id', title: __('座号')}, {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype}, {field: 'user_username', title: __('学员学号')}, {field: 'user_nickname', title: __('学员姓名')}, {field: 'total', title: __('考试成绩')}, {field: 'fault_one_score', title: __('故障一扣分'),editable:true}, {field: 'fault_two_score', title: __('故障二扣分'),editable:true}, {field: 'fault_three_score', title: __('故障三扣分'),editable:true}, {field: 'xianxian_score', title: __('故障现象扣分'),editable:true}, {field: 'yuanyin_socre', title: __('可能原因扣分'),editable:true}, {field: 'buwei_score', title: __('故障部位扣分'),editable:true}, {field: 'fangfa_score', title: __('排除方法扣分'),editable:true}, {field: 'overtime_score', title: __('超时扣分'),editable:true}, {field: 'operate', title: __('Operate'), table: table1, events: Table.api.events.operate, // formatter: Table.api.formatter.operate formatter: Table.api.formatter.buttons, buttons: [ { name: 'dispatch', text: '成绩详情', icon: 'fa fa-eye', title: '成绩详情', classname: 'btn btn-info btn-xs btn-magic btn-dialog', extend: 'data-area=\'["75%","95%"]\'', url: 'teacher/exams/view', } ], } ] ] }); // 为表格绑定事件 Table.api.bindevent(table2); //关闭考试 并且 $(document).on('click', '.btn-closes', function () { var ids = Config.ids; Backend.api.closetabs('/admin/teacher/practice/persent/ids/'+Config.ids) // Backend.api.addtabs('teacher/practice','训练列表'); // $.ajax({ // type:'post', // url:'teacher/collection/multi', // data:{ids:ids,params:'exam_collection_state=3'}, //重点必须为一个变量如:data // success:function(data){ // if(data.code==1){ // Backend.api.closetabs('/admin/teacher/exams/persent/ids/'+Config.ids) // Backend.api.addtabs('teacher/collection','考试列表'); // } // }, // error:function(){ // layer.alert("操作失败"); // return; // } // }) }); $("button[name=commonSearch]").css('display','none'); //定时刷新 setInterval(function() { table.bootstrapTable('refresh'); table1.bootstrapTable('refresh'); table2.bootstrapTable('refresh'); }, 30000); }, add: function () { Controller.api.bindevent1(); }, edit: function () { Controller.api.bindevent1(); }, adduser: function () { Controller.api.bindevent2(); }, edituser: function () { Controller.api.bindevent2(); }, api: { bindevent1: function () { Form.api.bindevent($("form[role=form]")); }, initSubTable: function (index, row, $detail,parent_table) { var admin_id = row.id; var cur_table = $detail.html('
').find('table'); var sub_table = $(cur_table); var parent_options = parent_table.bootstrapTable("getOptions"); var parent_selectids = parent_options.selectedIds; var checked = false; if (parent_selectids.indexOf(admin_id) !== -1) { checked = true; } parent_options.subSelectedIds[admin_id] = []; sub_table.bootstrapTable({ // url: 'area/index', toolbar: false, showColumns: false, showToggle: false, showExport: false, search: false, pagination:false, commonSearch: false, sortOrder: 'ASC', checkboxHeader: false, columns: [ {checkbox: true, formatter: function(value,rows,index){ if(Config.user_ids.length==0){ return false; }else if(Config.user_ids.indexOf(rows.id)>-1){ return true; }else{ return {disabled : true} } } }, {field: 'username', title: __('学号')}, {field: 'nickname', title: __('姓名')}, ], data: row.alluser }); Table.api.bindevent(sub_table); if(checked){ sub_table.bootstrapTable("checkAll"); }else{ sub_table.bootstrapTable("uncheckAll"); } sub_table.on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table post-body.bs.table", function (e) { var selectedIds = Table.api.selectedids(sub_table); selectedData = Table.api.selecteddata(sub_table); parent_options.subSelectedIds[admin_id] = selectedIds; parent_options.subSelectedData[admin_id] = selectedData; var allSubselectIds = []; var allSubselectData = []; var allSubselectProjectlib = []; for (var i in parent_options.subSelectedIds) { allSubselectIds.push.apply(allSubselectIds, parent_options.subSelectedIds[i]); } for (var j in parent_options.subSelectedData) { allSubselectData.push.apply(allSubselectData, parent_options.subSelectedData[j]); } parent_options.allSubselectIds = allSubselectIds; parent_options.allSubselectData = allSubselectData; $(".xueyuan_input").val(parent_options.allSubselectIds.length); $(".xueyuan_total").html(parent_options.allSubselectIds.length); $(".depart_ids").val(parent_options.allSubselectIds.join()); }); }, bindevent2: function () { var rel_Ids = []; var qudui_total = 0; var xueyuan_total = 0; Table.api.init({ extend: { index_url: 'department/admin/departadmintotal' + location.search, } }); var table = $("#table1"); // table.on('post-body.bs.table', function (e, data) { // $('#table1').bootstrapTable('expandAllRows'); // }); // var oInit = new Object(); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', fixedColumns: true, fixedRightNumber: 1, searchFormVisible:false, subSelectedIds: {}, subSelectedData: {}, allSubselectIds: [], allSubselectData: [], // pagination:false, detailView: true,//父子表 Search:false, showExport:false, showToggle:false, showColumns: false, columns: [ [ {checkbox: true}, {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, {field: 'department_admin_count', title: __('人员数量'),operate: false}, ] ], onExpandRow: function (index, row, $detail) { Controller.api.initSubTable(index, row, $detail,table); }, onCheck: function (row, $element) { $('.btn-disabled').addClass('disabled'); var id = row.id; $("#sub_" + id).bootstrapTable("checkAll"); var departid = $(".depart_ids").val(); if(!departid){ $(".depart_ids").val(row.user_ids.join()+','); $(".xueyuan_input").val(row.user_ids.length); $(".xueyuan_total").html(row.user_ids.length); }else{ if(departid.indexOf(row.user_ids) !== -1){ }else{ $(".depart_ids").val(departid+row.user_ids.join()+','); var xueyuan_count = $(".xueyuan_input").val(); var count= Number(xueyuan_count)+Number(row.user_ids.length); $(".xueyuan_input").val(count); $(".xueyuan_total").html(count); } } }, onUncheck: function (row) { var id = row.id; $("#sub_" + id).bootstrapTable("uncheckAll"); var departid = $(".depart_ids").val(); if(departid.indexOf(row.user_ids.join()) !== -1){ var newdepartid = departid.replace(row.user_ids.join()+',', ''); if(newdepartid==','){ newdepartid = ''; } $(".depart_ids").val(newdepartid); var xueyuan_count = $(".xueyuan_input").val(); var count= Number(xueyuan_count)-Number(row.user_ids.length); $(".xueyuan_input").val(count); $(".xueyuan_total").html(count); } }, onLoadSuccess: function (data) { var parent_options = table.bootstrapTable("getOptions"); Controller.api.clearSelectIds(parent_options); }, }); // 为表格绑定事件 Table.api.bindevent(table); $(document).on('change', '#c-question_setting_method', function () { if($(this).val()==1){ $(".btn-sm,.btn-task").css('display','none'); $(".fault_total").css('display','block'); $('form[role=form]').validator("setField", { "row[fault_total]": "required", }); }else if($(this).val()==2){ $(".btn-sm").show(); $(".btn-task,.fault_total").css('display','none'); $('form[role=form]').validator("setField", { "row[fault_total]":null, }); }else if($(this).val()==3){ $(".btn-sm,.fault_total").css('display','none'); $('form[role=form]').validator("setField", { "row[fault_total]": null, }); $(".btn-task").show(); } $(".question_ids").val(0); $(".task_id").val(0); $("#c-task_name").val(''); $("#c-fault_name").val(''); $("#c-question_name").val(''); $(".tasks,.questions").css('display','none'); }); //考题 $(document).on('click', '.btn-sm', function () { var simtype = $("#c-sim_type").val(); if(!simtype){ Layer.alert('请选择模拟器类型'); return false } var examid = $(".examid").val(); var title = '选择考题'; Fast.api.open(Fast.api.fixurl("teacher/collection/faults/type/"+simtype+"/ids/"+examid), title, { area: ["85%", "85%"], maxmin: true, moveOut: false, offset: ['40px'], callback: function(value) { if (value.task_id) { $(".questions").css('display','block') $(".question_ids").val(value.task_id); $("#c-question_name").val(value.task_name); $(".tasks").css('display','none') $(".task_id").val(0); $("#c-task_name").val(''); $("#c-fault_name").val(''); } } }); }); //任务 $(document).on('click', '.btn-task', function () { var simtype = $("#c-sim_type").val(); if(!simtype){ Layer.alert('请选择模拟器类型'); return false; } var examid = $(".examid").val(); var title = '选择任务'; parent.Fast.api.open(Fast.api.fixurl("teacher/collection/task/type/"+simtype+"/ids/"+examid), title, { area: ["65%", "70%"], maxmin: true, moveOut: false, offset: ['40px'], callback: function(value) { console.log(value); if (value.task_id) { $(".tasks").css('display','block') $(".task_id").val(value.task_id); $("#c-task_name").val(value.task_name); $("#c-fault_name").val(value.fault_name); $(".questions").css('display','none') $(".question_ids").val(0); $("#c-question_name").val(''); } } }); }); $("button[name=commonSearch]").css('display','none'); $("input[name='btSelectAll']").css('display','none'); Form.api.bindevent($("form[role=form]")); }, clearSelectIds: function (parent_options) { // var toolbar = $("#toolbar"); // var allIds = []; // var parent_options = $("#table").bootstrapTable("getOptions"); parent_options.allSubselectIds = []; // console.log(parent_options.subSelectedIds) parent_options.allSubselectData = []; parent_options.subSelectedIds = {}; parent_options.subSelectedData = {}; // console.log(parent_options) }, } }; return Controller; });