setting.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. {extend name="public/layout"/} {block name="title"}集团-添加学练{/block} {block name="body"}
  2. <style type="text/css">
  3. html, body {
  4. display: block;
  5. min-width: 100%;
  6. height: 100%;
  7. background-color: #fff;
  8. overflow-x: auto;
  9. overflow-y: hidden;
  10. min-width: 740px;
  11. }
  12. .layui-fluid {
  13. display: block;
  14. background-color: #ffffff;
  15. height: 100%;
  16. margin: 0;
  17. box-sizing: border-box;
  18. }
  19. .toptext{
  20. font-size: 12px;
  21. color: #b4b4b4;
  22. position: absolute;
  23. right: 20%;
  24. top: 4px;
  25. }
  26. .clearfix::after {
  27. clear: both;
  28. content: ' ';
  29. display: table;
  30. }
  31. .clearfix::before {
  32. content: ' ';
  33. display: table;
  34. }
  35. .width33{
  36. width: 33.3%;
  37. }
  38. .width67{
  39. width: 66.7%;
  40. }
  41. .layui-fluid{
  42. padding-top: 20px;
  43. padding-bottom: 60px;
  44. }
  45. .footer{
  46. position: absolute;
  47. width: 100%;
  48. bottom: 0;
  49. left:0;
  50. border-top: 1px solid #ccc;
  51. height: 60px;
  52. }
  53. .footer button{
  54. display: block;
  55. width: 88px;
  56. height: 32px;
  57. background-color: #249efb;
  58. color: #fff;
  59. text-align: center;
  60. line-height: 32px;
  61. border: unset;
  62. cursor: pointer;
  63. border-radius: 4px;
  64. overflow: hidden;
  65. margin: 0 auto;
  66. position: relative;
  67. top: 14px;
  68. }
  69. .left{
  70. float: left;
  71. }
  72. .mainbox{
  73. width: 100%;
  74. height: 100%;
  75. }
  76. .leftbox{
  77. display: block;
  78. height: 100%;
  79. overflow: hidden;
  80. }
  81. .setitbox{
  82. display: block;
  83. width: 100%;
  84. text-align: center;
  85. }
  86. .setitbox div{
  87. width: 45%;
  88. background-color: #f2f2f2;
  89. margin-right: 10%;
  90. height: 32px;
  91. font-size: 16px;
  92. line-height: 32px;
  93. cursor: pointer;
  94. }
  95. .setitbox div.trainbox{
  96. margin-right: 0;
  97. }
  98. .setitbox div.nowset{
  99. background-color: #249efb;
  100. color: #fff;
  101. }
  102. .right{
  103. float: right;
  104. }
  105. .scenetitle{
  106. margin-top: 10px;
  107. width: 100%;
  108. height: 32px;
  109. background-color: #f2f2f2;
  110. line-height: 32px;
  111. padding: 0 10px;
  112. box-sizing: border-box;
  113. }
  114. .scenebox{
  115. display: block;
  116. width: 100%;
  117. height: calc(100vh - 155px);
  118. overflow: auto;
  119. padding-left: 16px;
  120. box-sizing: border-box;
  121. }
  122. .everyscenebox{
  123. display: block;
  124. height: 40px;
  125. line-height: 40px;
  126. padding: 0 10px;
  127. }
  128. .everyscenebox input{
  129. position: relative;
  130. top: 20px;
  131. transform: translateY(-50%);
  132. }
  133. .leftscenebox{
  134. overflow: hidden;
  135. text-overflow: ellipsis;
  136. white-space: nowrap;
  137. width: 140px;
  138. }
  139. .search_input {
  140. width: 38% !important;
  141. margin-right: 1%;
  142. float: left;
  143. height: 38px;
  144. border: 1px solid #e6e6e6;
  145. }
  146. .search_input .layui-select {
  147. width: 100%;
  148. border: 0 !important;
  149. }
  150. .rightbox{
  151. padding-left: 30px;
  152. box-sizing: border-box;
  153. position: relative;
  154. height: calc(100vh - 60px);
  155. }
  156. .rightbox::before{
  157. content: ' ';
  158. display: block;
  159. width: 1px;
  160. height: 100%;
  161. background-color: #f2f2f2;
  162. position: absolute;
  163. left: 15px;
  164. top: -20px;
  165. }
  166. .tablebox{
  167. display: block;
  168. width: 100%;
  169. height: calc(100vh - 100px);
  170. }
  171. .percentbox{
  172. display: inline-block;
  173. width: 40px;
  174. height: 24px;
  175. }
  176. </style>
  177. <body>
  178. <div class="toptext">每日学练个数不得低于已设置“添加学练”随机数的总和</div>
  179. <div class="layui-fluid clearfix">
  180. <div class="clearfix mainbox">
  181. <div class="left width33 leftbox">
  182. <div class="setitbox clearfix ">
  183. <div class="left nowset testbox">设置试题</div>
  184. <div class="trainbox left">设置课件</div>
  185. </div>
  186. <div class="clearfix scenetitle">
  187. <div class="left">场景类别</div>
  188. <div class="right">选择</div>
  189. </div>
  190. <div class="scenebox questionbox">
  191. <div class="clearfix everyscenebox" style="margin-left: -15px;">
  192. <div class="left leftscenebox">所有分类</div>
  193. <input class="right" data-type="question" data-idx="-1" type="checkbox" />
  194. </div>
  195. </div>
  196. <div class="scenebox trainclassbox" style="display:none;">
  197. <div class="clearfix everyscenebox" style="margin-left: -15px;">
  198. <div class="left leftscenebox">所有场景</div>
  199. <input class="right" data-type="train" data-idx="-1" type="checkbox" />
  200. </div>
  201. </div>
  202. </div>
  203. <div class="left width67 rightbox">
  204. <div class="clearfix">
  205. <div class="search_input">
  206. <form class="layui-form">
  207. <select name="cate" id="cate" class="layui-select " lay-filter="selectTest">
  208. <option value="">全部分类</option>
  209. <option value="question">试题</option>
  210. <option value="train">课件</option>
  211. </select>
  212. </form>
  213. </div>
  214. </div>
  215. <div class="tablebox">
  216. <table id="LAY-employee-list" lay-filter="LAY-employee-list" style="margin-top:15px;"></table>
  217. </div>
  218. </div>
  219. </div>
  220. <div class="footer">
  221. <button type="button">保存</button>
  222. </div>
  223. </div>
  224. </body>
  225. {/block} {block name="js"}
  226. <script type="text/html" id="editbox">
  227. <input class="percentbox" data-type="{{d.type}}" data-tid="{{d.id}}" onkeyup="checkInt(this)" type="text" value="{{d.percent}}" />{if !empty($data['amount'])}<span style="font-size: 16px;padding-left: 5px">/{$data['amount']}</span>{/if}
  228. </script>
  229. <script>
  230. var detailarr = [];
  231. function checkInt (obj) {
  232. obj.value = obj.value.replace(/[^\d]/g, ""); //清除"-","数字"和"."以外的字符
  233. obj.value = obj.value.replace(/^[0]/, ""); //禁止第一个字符为.
  234. obj.value=obj.value<0?0: obj.value;
  235. obj.value = obj.value > 100 ? 100 : obj.value;
  236. for(let i in detailarr){
  237. if(obj.dataset.type== detailarr[i].type&& obj.dataset.tid== detailarr[i].id){
  238. detailarr[i].percent= obj.value;
  239. }
  240. }
  241. }
  242. layui.use(['form', 'table'], function () {
  243. var form = layui.form,
  244. table = layui.table,
  245. $ = layui.$;
  246. detailarr = [];
  247. var questionarr=[],trainarr=[];
  248. $('.testbox').click(function(){
  249. $('.testbox').addClass('nowset');
  250. $('.trainbox').removeClass('nowset');
  251. $('.questionbox').show();
  252. $('.trainclassbox').hide();
  253. })
  254. $('.trainbox').click(function () {
  255. $('.trainbox').addClass('nowset');
  256. $('.testbox').removeClass('nowset');
  257. $('.trainclassbox').show();
  258. $('.questionbox').hide();
  259. })
  260. $.ajax({
  261. url: "{:url('day_study/getTrainType')}",
  262. type: 'post',
  263. data: {},
  264. dataType: 'json',
  265. success: function (res) {
  266. if (res.code === 0) {
  267. var str='';
  268. trainarr= res.data;
  269. var flag=true;
  270. for (var i in res.data) {
  271. if(res.data[i].selected==1){
  272. str += '<div class="clearfix everyscenebox">' +
  273. `<div class="left leftscenebox" title="${res.data[i].type}">` + res.data[i].type + '</div>' + '<span style="margin-left:20px;">题量:' + res.data[i].child_count + '</span>'+
  274. '<input class="right" data-type="train" type="checkbox" data-idx="' + i + '" checked /> ' +
  275. '</div>';
  276. var obj = {
  277. id: res.data[i].id,
  278. type: 'train',
  279. percent: res.data[i].percent
  280. };
  281. detailarr.push(obj);
  282. }else{
  283. flag = false;
  284. str += '<div class="clearfix everyscenebox">' +
  285. `<div class="left leftscenebox" title="${res.data[i].type}">` + res.data[i].type + '</div>' + '<span style="margin-left:20px;">题量:' + res.data[i].child_count + '</span>'+
  286. '<input class="right" data-type="train" type="checkbox" data-idx="' + i + '" /> ' +
  287. '</div>';
  288. }
  289. }
  290. if(flag){
  291. $('.trainclassbox input[type="checkbox"]')[0].checked = true;
  292. }
  293. $('.trainclassbox').append(str);
  294. } else {
  295. layer.msg(res.msg, {
  296. anim: 6
  297. , time: 2000
  298. });
  299. }
  300. }
  301. });
  302. $.ajax({
  303. url: "{:url('day_study/getQuestionCate')}",
  304. type: 'post',
  305. data: {},
  306. dataType: 'json',
  307. success: function (res) {
  308. if (res.code === 0) {
  309. var str = '';
  310. questionarr= res.data;
  311. var flag=true;
  312. for (var i in res.data) {
  313. if (res.data[i].selected == 1){
  314. str += '<div class="clearfix everyscenebox">' +
  315. `<div class="left leftscenebox" title="${res.data[i].name}">` + res.data[i].name + '</div>' + '<span style="margin-left:20px;">题量:' + res.data[i].child_count + '</span>'+
  316. '<input class="right" data-type="question" data-idx="' + i + '" type="checkbox" checked /> ' +
  317. '</div >';
  318. var obj = {
  319. id: res.data[i].id,
  320. type: 'question',
  321. percent: res.data[i].percent
  322. };
  323. detailarr.push(obj);
  324. }else{
  325. str += '<div class="clearfix everyscenebox">' +
  326. `<div class="left leftscenebox" title="${res.data[i].name}">` + res.data[i].name + '</div>' + '<span style="margin-left:20px;">题量:' + res.data[i].child_count + '</span>'+
  327. '<input class="right" data-type="question" data-idx="' + i + '" type="checkbox" /> ' +
  328. '</div >';
  329. flag=false;
  330. }
  331. }
  332. if (flag) {
  333. $('.questionbox input[type="checkbox"]')[0].checked = true;
  334. }
  335. $('.questionbox').append(str);
  336. } else {
  337. layer.msg(res.msg, {
  338. anim: 6
  339. , time: 2000
  340. });
  341. }
  342. }
  343. });
  344. var tableIns=table.render({
  345. elem: '#LAY-employee-list'
  346. , url: "{:url('day_study/setting_detail')}"
  347. , cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增
  348. , cols: [[
  349. { field: 'type', title: '学练类别', templet:function(d){
  350. return d.type == 'question' ? '试题' : '课件';
  351. }}
  352. , { field: 'name', title: '试题场景'}
  353. , { field: 'child_type', title: '试题类别', }
  354. , { field: 'child_count', title: '试题数量'}
  355. , { field: 'percent', width: 137, title: '随机出题', templet:'#editbox', fixed: 'right' }
  356. ]],
  357. page: true,
  358. limit: 10,
  359. height: 'full-220',
  360. text: '对不起,加载出现异常!'
  361. });
  362. form.on('select(selectTest)', function (data) {
  363. tableIns.reload({
  364. where: { //设定异步数据接口的额外参数,任意设
  365. type: data.value
  366. }
  367. , page: {
  368. curr: 1 //重新从第 1 页开始
  369. }
  370. });
  371. });
  372. $('.mainbox').on('click','input[type="checkbox"]',function () {
  373. if($(this).data('type')=='question'&& $(this).data('idx')=='-1'){
  374. if(this.checked){
  375. for (var i = 1; i < $('.questionbox input[type="checkbox"]').length; i++) {
  376. var num = $('.questionbox input[type="checkbox"]')[i].dataset.idx;
  377. $('.questionbox input[type="checkbox"]')[i].checked = true;
  378. var obj={
  379. id: questionarr[num].id,
  380. type:'question',
  381. percent:''
  382. };
  383. detailarr.push(obj);
  384. }
  385. }else{
  386. for (var i = 1; i < $('.questionbox input[type="checkbox"]').length; i++) {
  387. var num= $('.questionbox input[type="checkbox"]')[i].dataset.idx;
  388. $('.questionbox input[type="checkbox"]')[i].checked = false;
  389. for(var j=0;j< detailarr.length;j++){
  390. if(detailarr[j].id== questionarr[num].id){
  391. detailarr.splice(j,1)
  392. }
  393. }
  394. }
  395. }
  396. }else if($(this).data('type') == 'question' && $(this).data('idx') != '-1'){
  397. if(!this.checked){
  398. $('.questionbox input[type="checkbox"]')[0].checked=false;
  399. var num = $(this).data('idx');
  400. for (var j = 0; j < detailarr.length; j++) {
  401. if (detailarr[j].id == questionarr[num].id) {
  402. detailarr.splice(j, 1)
  403. }
  404. }
  405. }else{
  406. var flag=true;
  407. for (var i = 1; i < $('.questionbox input[type="checkbox"]').length; i++){
  408. if(!$('.questionbox input[type="checkbox"]')[i].checked){
  409. flag=false;
  410. }
  411. }
  412. if(flag){
  413. $('.questionbox input[type="checkbox"]')[0].checked = true;
  414. }
  415. var obj = {
  416. id: questionarr[$(this).data('idx')].id,
  417. type: 'question',
  418. percent: ''
  419. };
  420. detailarr.push(obj);
  421. }
  422. }
  423. if($(this).data('type') == 'train' && $(this).data('idx') == '-1'){
  424. if (this.checked) {
  425. for (var i = 1; i < $('.trainclassbox input[type="checkbox"]').length; i++) {
  426. var num = $('.trainclassbox input[type="checkbox"]')[i].dataset.idx;
  427. $('.trainclassbox input[type="checkbox"]')[i].checked = true;
  428. var obj = {
  429. id: trainarr[num].id,
  430. type: 'train',
  431. percent: ''
  432. };
  433. detailarr.push(obj);
  434. }
  435. } else {
  436. for (var i = 1; i < $('.trainclassbox input[type="checkbox"]').length; i++) {
  437. var num = $('.trainclassbox input[type="checkbox"]')[i].dataset.idx;
  438. $('.trainclassbox input[type="checkbox"]')[i].checked = false;
  439. for (var j = 0; j < detailarr.length; j++) {
  440. if (detailarr[j].id == trainarr[num].id) {
  441. detailarr.splice(j, 1)
  442. }
  443. }
  444. }
  445. }
  446. } else if ($(this).data('type') == 'train' && $(this).data('idx') != '-1') {
  447. if (!this.checked) {
  448. $('.trainclassbox input[type="checkbox"]')[0].checked = false;
  449. var num = $(this).data('idx');
  450. for (var j = 0; j < detailarr.length; j++) {
  451. if (detailarr[j].id == trainarr[num].id) {
  452. detailarr.splice(j, 1)
  453. }
  454. }
  455. } else {
  456. var flag = true;
  457. for (var i = 1; i < $('.trainclassbox input[type="checkbox"]').length; i++) {
  458. if (!$('.trainclassbox input[type="checkbox"]')[i].checked) {
  459. flag = false;
  460. }
  461. }
  462. if (flag) {
  463. $('.trainclassbox input[type="checkbox"]')[0].checked = true;
  464. }
  465. var obj = {
  466. id: trainarr[$(this).data('idx')].id,
  467. type: 'train',
  468. percent: ''
  469. };
  470. detailarr.push(obj);
  471. }
  472. }
  473. setfun();
  474. })
  475. function setfun(){
  476. $.ajax({
  477. url: "{:url('day_study/setting')}",
  478. type: 'post',
  479. data: {
  480. setting: detailarr.length? detailarr:''
  481. },
  482. processdata: false, // 告诉jquery不要处理发送的数据
  483. contenttype: false, // 告诉jquery不要设置content-type请求头
  484. success: function (res) {
  485. if (res.code === 0) {
  486. table.reload('LAY-employee-list');
  487. } else {
  488. layer.msg(res.msg, {
  489. anim: 6
  490. , time: 2000
  491. });
  492. }
  493. }
  494. });
  495. }
  496. $('.footer button').click(function(){
  497. var index = parent.layer.getFrameIndex(window.name);
  498. $.ajax({
  499. url: "{:url('day_study/setting')}",
  500. type: 'post',
  501. data: {
  502. setting: detailarr.length ? detailarr : ''
  503. },
  504. processdata: false, // 告诉jquery不要处理发送的数据
  505. contenttype: false, // 告诉jquery不要设置content-type请求头
  506. success: function (res) {
  507. if (res.code === 0) {
  508. parent.location.reload();
  509. parent.layer.close(index);
  510. } else {
  511. layer.msg(res.msg, {
  512. anim: 6
  513. , time: 2000
  514. });
  515. }
  516. }
  517. });
  518. })
  519. })
  520. </script>
  521. {/block}