examinee_edit.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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:'name', title:'姓名'}
  82. ,{field:'username', title:'帐号'}
  83. ,{field:'department_text', title:'部门'}
  84. ]]
  85. ,height: 'full-145'
  86. ,page: true
  87. , done: function () {
  88. }
  89. });
  90. $('#search_user').on('click', function () {
  91. table.reload('subject_datagrid', {
  92. where: {username: $('#id_name').val()}
  93. , page: {curr: 1}
  94. });
  95. })
  96. var cols = [
  97. {type:'checkbox'},
  98. {field: 'name', title: '姓名'},
  99. {field: 'username', title: '帐号'},
  100. {field: 'department_text', title: '部门'},
  101. ]
  102. var layTableId = "layTable";
  103. var tableIns = table.render({
  104. elem: '#dataTable',
  105. id: layTableId,
  106. data: [],
  107. page: false,
  108. limit:1000000,
  109. loading: true,
  110. height: 'full-145',
  111. even: true, //不开启隔行背景
  112. cols: [cols],
  113. done: function (data, date, total) {
  114. }
  115. });
  116. $('#add_check').on('click', function () {
  117. var selectData = layui.table.checkStatus('subject_datagrid').data;
  118. // 获取左边表格选中数据后 刷新右边表格
  119. var oldData = [];
  120. oldData = table.cache[layTableId];
  121. for (var i=0; i<selectData.length; i++){
  122. var is_have = false;
  123. for (var j=0; j<oldData.length; j++){
  124. if (selectData[i].id === oldData[j].id){
  125. is_have = true
  126. }
  127. }
  128. if(!is_have){
  129. oldData.push({
  130. id: selectData[i].id,
  131. name: selectData[i].name,
  132. username: selectData[i].username,
  133. department_text: selectData[i].department_text
  134. })
  135. }
  136. }
  137. tableIns.reload({
  138. data: oldData,
  139. cols: [cols],
  140. });
  141. })
  142. $('#remove_check').on('click', function () {
  143. var oldData = table.cache[layTableId];
  144. var newData = []
  145. for (var i=0; i<oldData.length; i++){
  146. if (!oldData[i].LAY_CHECKED){
  147. newData.push(oldData[i])
  148. }
  149. }
  150. tableIns.reload({
  151. data: newData,
  152. cols: [cols],
  153. });
  154. })
  155. form.on('submit(component-form-element)', function(data){
  156. var users = table.cache[layTableId];
  157. if (users.length === 0){
  158. layer.msg('请添加考生!', {icon: 2});
  159. return false
  160. }
  161. if (!exam_id){
  162. layer.msg('请选择考试!', {icon: 2});
  163. return false
  164. }
  165. user_ids = [];
  166. for (var i=0; i<users.length; i++){
  167. user_ids.push(users[i].id)
  168. }
  169. admin.req({
  170. url: '/admin/exam/' + exam_id + '/add_examinee/'
  171. , data: {user_ids: JSON.stringify(user_ids)}
  172. , type: 'post'
  173. ,done: function(res){
  174. parent.layui.onSubmitChild(res.data);
  175. }
  176. });
  177. return false;
  178. });
  179. parent.layui.submitChild = function () {
  180. $("#id_save").click();
  181. };
  182. });
  183. </script>
  184. </body>
  185. </html>