examinee_edit.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>科目章节设置</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  9. <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  10. <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
  11. <style type="text/css">
  12. .seach_items {float:right;margin-left: 10px;}
  13. </style>
  14. </head>
  15. <body>
  16. <div class="layui-fluid">
  17. <div class="layui-card">
  18. <div class="layui-card-body" pad15>
  19. <div class="layui-row layui-col-space15">
  20. <div class="layui-col-md4">
  21. <div class="LAY-btns" style="margin-bottom: 5px;">
  22. <div class="seach_items">
  23. <button class="layui-btn" id="search_user">查询</button>
  24. </div>
  25. <div class="seach_items">
  26. <input type="text" id="id_name" autocomplete="off" class="layui-input" placeholder="名称"/>
  27. </div>
  28. <div style="clear: both;"></div>
  29. </div>
  30. <table class="layui-hide" id="subject_datagrid"></table>
  31. <button class="layui-btn" id="add_check" style="margin-top: 5px">添加选中</button>
  32. </div>
  33. <div class="layui-col-md4">
  34. <div class="LAY-btns" style="margin-bottom: 10px;">
  35. <div class="layui-col-xs2">
  36. <label class="layui-form-label">选中的人员</label>
  37. </div>
  38. <div style="clear: both;"></div>
  39. </div>
  40. <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
  41. <button class="layui-btn" id="remove_check" style="margin-top: 10px">删除选中</button>
  42. </div>
  43. <button class="layui-btn" id="id_save" lay-submit lay-filter="component-form-element"
  44. style="display: none">保存
  45. </button>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. <script src="../../layuiadmin/layui/layui.js?t=1"></script>
  51. <script>
  52. layui.config({
  53. base: '../../../layuiadmin/' //静态资源所在路径
  54. }).extend({
  55. index: 'lib/index' //主入口模块
  56. }).use(['index', 'table', 'form'], function(){
  57. var $ = layui.$;
  58. var table = layui.table
  59. ,form = layui.form
  60. ,admin = layui.admin;
  61. var exam_id = layui.view.getParameterByName('exam_id');
  62. if (!exam_id){
  63. layer.msg('请选择考试!', {icon: 2});
  64. return false
  65. }
  66. admin.req({
  67. url: '/admin/exam/' + exam_id + '/examinee/',
  68. type:'get',
  69. done: function (res) {
  70. tableIns.reload({
  71. data: res.data,
  72. cols: [cols],
  73. });
  74. }
  75. });
  76. table.render({
  77. elem: '#subject_datagrid'
  78. ,url: '/admin/user/?type=2'
  79. ,cols: [[
  80. {type:'checkbox'}
  81. ,{field:'username', title:'姓名'}
  82. ,{field:'department_text', title:'部门'}
  83. ]]
  84. ,height: 'full-145'
  85. ,page: true
  86. , done: function () {
  87. }
  88. });
  89. $('#search_user').on('click', function () {
  90. table.reload('subject_datagrid', {
  91. where: {username: $('#id_name').val()}
  92. , page: {curr: 1}
  93. });
  94. })
  95. var cols = [
  96. {type:'checkbox'},
  97. {field: 'username', title: '姓名'},
  98. {field: 'department_text', title: '部门'},
  99. ]
  100. var layTableId = "layTable";
  101. var tableIns = table.render({
  102. elem: '#dataTable',
  103. id: layTableId,
  104. data: [],
  105. page: false,
  106. limit:1000000,
  107. loading: true,
  108. height: 'full-145',
  109. even: true, //不开启隔行背景
  110. cols: [cols],
  111. done: function (data, date, total) {
  112. }
  113. });
  114. $('#add_check').on('click', function () {
  115. var selectData = layui.table.checkStatus('subject_datagrid').data;
  116. // 获取左边表格选中数据后 刷新右边表格
  117. var oldData = [];
  118. oldData = table.cache[layTableId];
  119. for (var i=0; i<selectData.length; i++){
  120. var is_have = false;
  121. for (var j=0; j<oldData.length; j++){
  122. if (selectData[i].id === oldData[j].id){
  123. is_have = true
  124. }
  125. }
  126. if(!is_have){
  127. oldData.push({
  128. id: selectData[i].id,
  129. username: selectData[i].username,
  130. department_text: selectData[i].department_text
  131. })
  132. }
  133. }
  134. tableIns.reload({
  135. data: oldData,
  136. cols: [cols],
  137. });
  138. })
  139. $('#remove_check').on('click', function () {
  140. var oldData = table.cache[layTableId];
  141. for (var x in oldData){
  142. if (oldData[x].LAY_CHECKED){
  143. oldData.splice(x)
  144. }
  145. }
  146. tableIns.reload({
  147. data: oldData,
  148. cols: [cols],
  149. });
  150. })
  151. form.on('submit(component-form-element)', function(data){
  152. var users = table.cache[layTableId];
  153. if (users.length === 0){
  154. layer.msg('请添加考生!', {icon: 2});
  155. return false
  156. }
  157. if (!exam_id){
  158. layer.msg('请选择考试!', {icon: 2});
  159. return false
  160. }
  161. user_ids = [];
  162. for (var i=0; i<users.length; i++){
  163. user_ids.push(users[i].id)
  164. }
  165. admin.req({
  166. url: '/admin/exam/' + exam_id + '/add_examinee/'
  167. , data: {user_ids: JSON.stringify(user_ids)}
  168. , type: 'post'
  169. ,done: function(res){
  170. parent.layui.onSubmitChild(res.data);
  171. }
  172. });
  173. return false;
  174. });
  175. parent.layui.submitChild = function () {
  176. $("#id_save").click();
  177. };
  178. });
  179. </script>
  180. </body>
  181. </html>