_trial.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <script>
  2. $(document).ready(function () {
  3. //科目组
  4. var subject=[];
  5. var subjectName=[];
  6. // subject[1]=[];
  7. // subject[2]=[];
  8. // subject[3]=[];
  9. //
  10. // subjectName[1]=[];
  11. // subjectName[2]=[];
  12. // subjectName[3]=[];
  13. var selectedDataAll=[];
  14. var selectedDataValue =[];
  15. var selectedClassId=0;
  16. var selectedClassName='';
  17. var firstSubjectType=0;
  18. <?php
  19. if(isset($subjects)){
  20. foreach ($subjects as $type => $val){
  21. echo "subject[".$type."]=[];";
  22. echo "subjectName[".$type."]=[];";
  23. }
  24. foreach ($subjects as $type => $val){
  25. if($val){
  26. foreach ($val as $v){
  27. echo "subject[".$type."].push('".$v['subjectId']."');";
  28. echo "subjectName[".$type."].push('".$v['name']."');";
  29. }
  30. }
  31. }
  32. // if(isset($subjects[1])){
  33. // foreach ($subjects[1] as $val){
  34. // echo "subject[1].push('".$val['dictCode']."');";
  35. // echo "subjectName[1].push('".$val['name']."');";
  36. // }
  37. // }
  38. // if(isset($subjects[2])){
  39. // foreach ($subjects[2] as $val){
  40. // echo "subject[2].push('".$val['dictCode']."');";
  41. // echo "subjectName[2].push('".$val['name']."');";
  42. // }
  43. // }
  44. // if(isset($subjects[3])){
  45. // foreach ($subjects[3] as $val){
  46. // echo "subject[3].push('".$val['dictCode']."');";
  47. // echo "subjectName[3].push('".$val['name']."');";
  48. // }
  49. // }
  50. }
  51. ?>
  52. firstSubjectType=Object.keys(subject)[0];
  53. function setSubject(type){
  54. var html='';
  55. if(subject[type].length>0){
  56. for(var i=0;i<subject[type].length;i++){
  57. html+='<option value="'+subject[type][i]+'">'+subjectName[type][i]+'</option>';
  58. }
  59. }
  60. $('#subjectId').html(html);
  61. }
  62. setSubject(firstSubjectType);
  63. $('.goodTypeInput').click(function(){
  64. console.log($(this).val());
  65. setSubject($(this).val());
  66. $('input[name=grade]').eq(0).attr('disabled',false);
  67. $('input[name=grade]').eq(1).attr('disabled',false);
  68. $('input[name=grade]').eq(2).attr('disabled',false);
  69. if($(this).val()==10){
  70. $('input[name=grade]').eq(0).attr('disabled',true);
  71. $('input[name=grade]').eq(1).attr('disabled',true);
  72. $('input[name=grade]').eq(2).click();
  73. }else if($(this).val()==11){
  74. $('input[name=grade]').eq(0).click();
  75. // $('input[name=grade]').eq(2).attr('disabled',true);
  76. }
  77. });
  78. $('#startTime').datetimepicker({
  79. format: "Y-m-d", //格式化日期
  80. timepicker: false //关闭时间选项
  81. });
  82. /*
  83. $('#endTime').datetimepicker({
  84. format: "Y-m-d", //格式化日期
  85. timepicker: false //关闭时间选项
  86. });
  87. */
  88. // 全选按钮
  89. $("input[name='select-all']").change(function() {
  90. var type = $("input[name='select-all']").prop("checked")
  91. if(type){
  92. obj=$("#studentListContent").find("input");
  93. for(var i=0;i<obj.length;i++){
  94. if(obj.eq(i).attr('disabled')==undefined){
  95. obj.eq(i).prop("checked", true);
  96. }
  97. }
  98. }else{
  99. $("#studentListContent").find("input").prop("checked", false);
  100. }
  101. });
  102. //编辑页面数据
  103. <?php if ($selectedStudent):?>
  104. var maxD = "<?php echo $startDate;?>";
  105. <?php else:?>
  106. var date = new Date;
  107. var year = date.getFullYear();
  108. var month = date.getMonth() + 1;
  109. var day = date.getDate(); //获取当前日(1-31)
  110. var minD = year + '-' + month + '-' + '1';
  111. var maxD = year + '-' + month + '-' + day;
  112. <?php endif;?>
  113. // $("#startTime").attr("value", maxD);
  114. // 单选按钮
  115. $('body').on('change', "input[name='studentId']", function () {
  116. // getsStudentSelected();
  117. });
  118. // 全选按钮
  119. $('body').on('click', ".btn-select_all", function () {
  120. var obj = $(this).parent().find("input");
  121. if($(this).hasClass('isSelected')){
  122. obj.each(function () {
  123. if(!$(this).is(':disabled')){
  124. $(this).prop("checked", false);
  125. }
  126. })
  127. $(this).removeClass("isSelected");
  128. }else{
  129. obj.each(function () {
  130. if(!$(this).is(':disabled')){
  131. $(this).prop("checked", true);
  132. }
  133. })
  134. $(this).addClass("isSelected");
  135. }
  136. // getsStudentSelected();
  137. });
  138. //筛选班级(包含学生)
  139. getClassFist($("input[name='grade']:checked").attr('load-grade'));
  140. $('body').on('click','.filter-goodsType input',function () {
  141. getClass($("input[name='grade']:checked").val());
  142. });
  143. $('.filter-grade input').click(function () {
  144. var grade = $(this).val();
  145. var loadGrade=$(this).attr('load-grade');
  146. if(grade==1){
  147. $('.real-grade').html('实际年级:高一');
  148. }else if(grade==2){
  149. $('.real-grade').html('实际年级:高二');
  150. }else if(grade==3){
  151. $('.real-grade').html('实际年级:高三');
  152. }else if(grade==6){
  153. $('.real-grade').html('实际年级:六年级');
  154. }else if(grade==7){
  155. $('.real-grade').html('实际年级:七年级');
  156. }else if(grade==8){
  157. $('.real-grade').html('实际年级:八年级');
  158. }else if(grade==9){
  159. $('.real-grade').html('实际年级:九年级');
  160. }else{
  161. $('.real-grade').html('');
  162. }
  163. getClass(loadGrade);
  164. initUsefulType();
  165. });
  166. // 提交
  167. var flag = true;
  168. $(".btn-trial").on("click", function () {
  169. console.log(selectedDataAll);
  170. var subject_id=$('#subjectId').val();
  171. if (selectedDataAll.length >0) {
  172. var products = $("input[name='goodsTypeId']:checked").val();
  173. var grade = parseInt($("input[name='grade']:checked").val());
  174. var startTime = $("#startTime").val();
  175. var endTime = $("#endTime").val();
  176. var trialType = $("input[name=UsefulType]").val();
  177. var yearSemester = $("#semesterId").val();
  178. if($.inArray(grade,[1,2,3,6,7,8,9])==-1){
  179. layer.alert("没有查询到实际年级");
  180. return false;
  181. }
  182. /*
  183. var start = new Date(startTime.replace("-", "/").replace("-", "/"));
  184. var end = new Date(endTime.replace("-", "/").replace("-", "/"));
  185. if(end<=start){
  186. layer.alert("首次阅卷时间应晚于开始时间", {'icon':3});
  187. return false;
  188. }
  189. */
  190. <?php if (isset($_GET['orderId']) && $_GET['orderId']) :?>
  191. var orderId = "<?php echo $_GET['orderId'];?>";
  192. console.log(orderId);
  193. var data = {
  194. goodsTypeId: products,
  195. grade: grade,
  196. startTime: startTime,
  197. endTime: endTime,
  198. studentList:JSON.stringify(selectedDataAll),
  199. orderId: orderId,
  200. subjectId:subject_id,
  201. trialType:trialType,
  202. yearSemester:yearSemester
  203. };
  204. <?php else:?>
  205. var data = {
  206. goodsTypeId: products,
  207. grade: grade,
  208. startTime: startTime,
  209. endTime: endTime,
  210. studentList:JSON.stringify(selectedDataAll),
  211. subjectId:subject_id,
  212. trialType:trialType,
  213. yearSemester:yearSemester
  214. };
  215. <?php endif;?>
  216. if (flag){
  217. flag = false;
  218. $.ajax({
  219. type: 'post',
  220. url: "<?php echo Yii::app()->createUrl('imsSale/saveTrial')?>",
  221. dataType: 'json',
  222. data: data,
  223. success: function (data) {
  224. console.log(data);
  225. if (data.status){
  226. layer.alert(data.msg, {icon:1,closeBtn:0},function () {
  227. location.href="<?php echo Yii::app()->createUrl('imsSale/trialTable')?>"
  228. });
  229. }else{
  230. flag = true;
  231. layer.alert(data.msg, {icon:2});
  232. }
  233. },
  234. error: function () {
  235. flag = true;
  236. layer.alert("提交失败!", {icon:2});
  237. }
  238. });
  239. }else{
  240. layer.msg("稍安勿躁,正在处理中...");
  241. }
  242. } else {
  243. layer.alert("请选择至少一个学生", {'icon':7});
  244. }
  245. });
  246. $('#subjectId').change(function(){
  247. // $('.student-name_box').html('');
  248. //$('.student-selected').html('');
  249. // $('.student-list-content').html('');
  250. //$('.active').removeClass('active');
  251. //$('.student-list_box').find('.active').removeClass('active');
  252. var grade = $("input[name='grade']:checked").attr('load-grade');
  253. console.log(grade);
  254. getClass(grade);
  255. initUsefulType();
  256. });
  257. //根据年级获取班级
  258. function getClass(grade) {
  259. $('.student-list-content').html('');
  260. selectedDataAll=[];
  261. selectedDataValue=[];
  262. var subjectId=$('#subjectId').val();
  263. $.ajax({
  264. type: 'post',
  265. url: "<?php echo Yii::app()->createUrl('imsSale/getClassList');?>",
  266. data: {grade: grade,subjectId:subjectId},
  267. dataType: 'json',
  268. success: function (data) {
  269. if (data.status) {
  270. var html = '';
  271. for (var i = 0; i < data.data.length; i++) {
  272. var item = data.data[i];
  273. if (item['class_id']) {
  274. html+='<li class="classified" classId="'+item['class_id']+'">'+item['class_name']+'</li>';
  275. }
  276. }
  277. } else {
  278. var html = '<li>暂无班级数据</li>';
  279. }
  280. $('.class-list').html(html);
  281. }
  282. })
  283. }
  284. function getClassFist(grade) {
  285. var subjectId=$('#subjectId').val();
  286. $.ajax({
  287. type: 'post',
  288. url: "<?php echo Yii::app()->createUrl('imsSale/getClassList');?>",
  289. data: {grade: grade,subjectId:subjectId},
  290. dataType: 'json',
  291. success: function (data) {
  292. if (data.status) {
  293. var html = '';
  294. for (var i = 0; i < data.data.length; i++) {
  295. var item = data.data[i];
  296. if (item['class_id']) {
  297. html+='<li class="classified" classId="'+item['class_id']+'">'+item['class_name']+'</li>';
  298. }
  299. }
  300. } else {
  301. var html = '<li>暂无班级数据</li>';
  302. }
  303. $('.class-list').html(html);
  304. }
  305. })
  306. }
  307. //班级切换
  308. $(".class-list").on("click", "li", function(event) {
  309. if(!$(this).hasClass('subjectObj')){
  310. $(".class-list li").removeClass("active");
  311. $(this).addClass("active");
  312. selectedClassId=classId=$(this).attr('classId');
  313. selectedClassName=className=$(this).html();
  314. $("input[name='select-all']").prop("checked",false);
  315. trialType=$('input[name="UsefulType"]').val();
  316. if(trialType==-1){
  317. layer.msg('请选确定订单类型');
  318. return false;
  319. }
  320. getStudent(classId,className,'');
  321. }
  322. });
  323. function getStudent(classId,className,studentName){
  324. grade=$("input[name='grade']:checked").attr('load-grade');
  325. semester=$('#semesterId').val();
  326. startTime=$('#startTime').val();
  327. var postData = {
  328. 'classId' : classId,
  329. 'goodsTypeId' : $('input[name="goodsTypeId"]:checked').val(),
  330. 'subjectId':$('#subjectId').val(),
  331. 'studentName':studentName,
  332. 'trialType':$('input[name="UsefulType"]').val(),
  333. 'semesterId':semester,
  334. 'grade':grade,
  335. 'startTime':startTime
  336. };
  337. $.ajax({
  338. url:'<?php echo $this->createUrl('imsSale/getStudent')?>',
  339. type:'POST',
  340. dataType:'json',
  341. data:postData,
  342. success:function(res){
  343. if(res.status==1){
  344. var studentHtml='';
  345. for(var i=0;i<res.data.list.length;i++){
  346. if($.inArray(res.data.list[i]['student_id'],res.data.student)!=-1){
  347. //continue;
  348. studentHtml+='<label><input type="checkbox" disabled name="studentName" classId="'+classId+'" className="'+className+'" value="'+res.data.list[i]['student_id']+'" />'+res.data.list[i]['realname']+'</label>';
  349. }else{
  350. if($.inArray(res.data.list[i]['student_id'],selectedDataValue)!=-1){
  351. studentHtml+='<label><input type="checkbox" checked name="studentName" classId="'+classId+'" className="'+className+'" value="'+res.data.list[i]['student_id']+'" />'+res.data.list[i]['realname']+'</label>';
  352. }else{
  353. studentHtml+='<label><input type="checkbox" name="studentName" classId="'+classId+'" className="'+className+'" value="'+res.data.list[i]['student_id']+'" />'+res.data.list[i]['realname']+'</label>';
  354. }
  355. }
  356. }
  357. $('.student-list-content').html(studentHtml);
  358. }else{
  359. $('.student-list-content').html('');
  360. }
  361. }
  362. });
  363. }
  364. // 添加学生
  365. $("#btnAddStudent").on("click", function() {
  366. getStudentSelected();
  367. });
  368. // 移出学生
  369. $("#btnRemoveStudent").on("click", function() {
  370. removeStudentSelected();
  371. });
  372. //搜索学生
  373. $('.btn-search-student').click(function(){
  374. studentName=$('input[name=search-student-name]').val();
  375. if(studentName!=''){
  376. getStudent(selectedClassId,selectedClassName,studentName);
  377. }
  378. });
  379. function getStudentSelected() {
  380. var selectedData = $("#studentListContent input[name='studentName']:checked"); //获取所以选中学生
  381. var studentName = '';
  382. for (var i = 0; i < selectedData.length; i++) {
  383. if (!isSelected(selectedData[i].value)) {
  384. studentName = $(selectedData[i]).parent().text();
  385. var student ={
  386. name:studentName,
  387. value:selectedData[i].value,
  388. class:$(selectedData[i]).attr('className'),
  389. classId:$(selectedData[i]).attr('classId'),
  390. };
  391. selectedDataAll.push(student);
  392. selectedDataValue.push(selectedData[i].value);
  393. }else{
  394. //console.log(selectedData[i].value)
  395. }
  396. showSelectedStudent();
  397. }
  398. }
  399. function removeStudentSelected() {
  400. var selectedStudent = $("#selectedListContent input[name='selectedStudent']:checked"); //获取所有选中学生
  401. var selectedData = $("#studentListContent input[name='studentName']:checked"); //获取所以选中学生
  402. for (var i = 0; i < selectedStudent.length; i++) {
  403. $(selectedStudent[i]).parent().remove();
  404. if(selectedDataValue.length>0){
  405. for(var k=0;k<selectedDataValue.length;k++){
  406. if(selectedDataValue[k]===selectedStudent[i].value){
  407. selectedDataValue.splice(k,1);
  408. selectedDataAll.splice(k,1);
  409. }
  410. }
  411. }
  412. for (var j = 0; j < selectedData.length; j++) {
  413. if(selectedData[j].value===selectedStudent[i].value){
  414. $(selectedData[j]).prop("checked", false);
  415. }
  416. }
  417. }
  418. $('#studentSelectedLength').text(selectedDataAll.length);
  419. };
  420. function showSelectedStudent() {
  421. var selectedDataList = [];
  422. for (var i = 0; i < selectedDataAll.length; i++) {
  423. selectedDataList.push('<label><input type="checkbox" name="selectedStudent" value="'+ selectedDataAll[i].value +'" />'+selectedDataAll[i].name+'</label>');
  424. }
  425. $('#selectedListContent').html(selectedDataList);
  426. $('#studentSelectedLength').text(selectedDataAll.length);
  427. }
  428. function isSelected(val){
  429. return selectedDataValue.indexOf(val) > -1
  430. };
  431. $('.goodTypeInput').change(function(){
  432. var holidayHomework=<?php echo ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK; ?>;
  433. var goodsTypeId=parseInt($(this).val());
  434. if(goodsTypeId==holidayHomework){
  435. $('.good-type-prompt').text('*注:假期作业的试用订单,每个年级最多仅能设置10个。');
  436. }else{
  437. $('.good-type-prompt').text('');
  438. }
  439. initUsefulType();
  440. })
  441. $('#startTime').blur(function(){
  442. beginTime=$(this).val();
  443. if(beginTime!=''){
  444. $.ajax({
  445. url:'<?php echo $this->createUrl('imsSale/getSemesterByBeginTime')?>',
  446. type:'POST',
  447. dataType:'json',
  448. data:{beginTime:beginTime},
  449. success:function(res){
  450. console.log(res);
  451. if(res.status==1 && res.data.length>0){
  452. var html='';
  453. for(var i=0;i<res.data.length;i++){
  454. html+= '<option value="'+res.data[i]['semesterId']+'">'+res.data[i]['semesterName']+'</option>';
  455. }
  456. $('#semesterId').html(html);
  457. initUsefulType();
  458. }else{
  459. $('#semesterId').html('');
  460. layer.msg('未查询到学期数据');
  461. }
  462. }
  463. });
  464. }
  465. });
  466. $('#semesterId').change(function(){
  467. initUsefulType();
  468. });
  469. //获取试用类型
  470. function getUsefulType(beginTime,goodsTypeId,grade,selSubject,semesterId){
  471. $.ajax({
  472. url:'<?php echo $this->createUrl('imsSale/getUsefulType')?>',
  473. type:'POST',
  474. dataType:'json',
  475. data:{beginTime:beginTime,goodsTypeId:goodsTypeId,grade:grade,subject:selSubject,yearSemester:semesterId},
  476. success:function(res){
  477. console.log(res);
  478. if(res.status==1 ){
  479. $('input[name=typeName]').val(res.data['typeName']);
  480. $('input[name=UsefulType]').val(res.data['type']);
  481. }else{
  482. layer.msg('未查询到数据');
  483. }
  484. }
  485. });
  486. }
  487. function initUsefulType(){
  488. goodsTypeId=$('input[name=goodsTypeId]:checked').val();
  489. grade=$('input[name=grade]:checked').val();
  490. subjectId=$('#subjectId').val();
  491. beginTime=$('#startTime').val();
  492. semesterId=$('#semesterId').val();
  493. $('.student-list-content').html('');
  494. $('#selectedListContent').html('');
  495. selectedDataAll=[];
  496. selectedDataValue=[];
  497. if(goodsTypeId!=null && grade!=null && subjectId!=null && beginTime!=null && semesterId!=null){
  498. getUsefulType(beginTime,goodsTypeId,grade,subjectId,semesterId);
  499. }
  500. }
  501. })
  502. </script>