123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561 |
- <script>
- $(document).ready(function () {
- //科目组
- var subject=[];
- var subjectName=[];
- // subject[1]=[];
- // subject[2]=[];
- // subject[3]=[];
- //
- // subjectName[1]=[];
- // subjectName[2]=[];
- // subjectName[3]=[];
- var selectedDataAll=[];
- var selectedDataValue =[];
- var selectedClassId=0;
- var selectedClassName='';
- var firstSubjectType=0;
- <?php
- if(isset($subjects)){
- foreach ($subjects as $type => $val){
- echo "subject[".$type."]=[];";
- echo "subjectName[".$type."]=[];";
- }
- foreach ($subjects as $type => $val){
- if($val){
- foreach ($val as $v){
- echo "subject[".$type."].push('".$v['subjectId']."');";
- echo "subjectName[".$type."].push('".$v['name']."');";
- }
- }
- }
- // if(isset($subjects[1])){
- // foreach ($subjects[1] as $val){
- // echo "subject[1].push('".$val['dictCode']."');";
- // echo "subjectName[1].push('".$val['name']."');";
- // }
- // }
- // if(isset($subjects[2])){
- // foreach ($subjects[2] as $val){
- // echo "subject[2].push('".$val['dictCode']."');";
- // echo "subjectName[2].push('".$val['name']."');";
- // }
- // }
- // if(isset($subjects[3])){
- // foreach ($subjects[3] as $val){
- // echo "subject[3].push('".$val['dictCode']."');";
- // echo "subjectName[3].push('".$val['name']."');";
- // }
- // }
- }
- ?>
- firstSubjectType=Object.keys(subject)[0];
- function setSubject(type){
- var html='';
- if(subject[type].length>0){
- for(var i=0;i<subject[type].length;i++){
- html+='<option value="'+subject[type][i]+'">'+subjectName[type][i]+'</option>';
- }
- }
- $('#subjectId').html(html);
- }
- setSubject(firstSubjectType);
- $('.goodTypeInput').click(function(){
- console.log($(this).val());
- setSubject($(this).val());
- $('input[name=grade]').eq(0).attr('disabled',false);
- $('input[name=grade]').eq(1).attr('disabled',false);
- $('input[name=grade]').eq(2).attr('disabled',false);
- if($(this).val()==10){
- $('input[name=grade]').eq(0).attr('disabled',true);
- $('input[name=grade]').eq(1).attr('disabled',true);
- $('input[name=grade]').eq(2).click();
- }else if($(this).val()==11){
- $('input[name=grade]').eq(0).click();
- // $('input[name=grade]').eq(2).attr('disabled',true);
- }
- });
- $('#startTime').datetimepicker({
- format: "Y-m-d", //格式化日期
- timepicker: false //关闭时间选项
- });
- /*
- $('#endTime').datetimepicker({
- format: "Y-m-d", //格式化日期
- timepicker: false //关闭时间选项
- });
- */
- // 全选按钮
- $("input[name='select-all']").change(function() {
- var type = $("input[name='select-all']").prop("checked")
- if(type){
- obj=$("#studentListContent").find("input");
- for(var i=0;i<obj.length;i++){
- if(obj.eq(i).attr('disabled')==undefined){
- obj.eq(i).prop("checked", true);
- }
- }
- }else{
- $("#studentListContent").find("input").prop("checked", false);
- }
- });
- //编辑页面数据
- <?php if ($selectedStudent):?>
- var maxD = "<?php echo $startDate;?>";
- <?php else:?>
- var date = new Date;
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- var day = date.getDate(); //获取当前日(1-31)
- var minD = year + '-' + month + '-' + '1';
- var maxD = year + '-' + month + '-' + day;
- <?php endif;?>
- // $("#startTime").attr("value", maxD);
- // 单选按钮
- $('body').on('change', "input[name='studentId']", function () {
- // getsStudentSelected();
- });
- // 全选按钮
- $('body').on('click', ".btn-select_all", function () {
- var obj = $(this).parent().find("input");
- if($(this).hasClass('isSelected')){
- obj.each(function () {
- if(!$(this).is(':disabled')){
- $(this).prop("checked", false);
- }
- })
- $(this).removeClass("isSelected");
- }else{
- obj.each(function () {
- if(!$(this).is(':disabled')){
- $(this).prop("checked", true);
- }
- })
- $(this).addClass("isSelected");
- }
- // getsStudentSelected();
- });
- //筛选班级(包含学生)
- getClassFist($("input[name='grade']:checked").attr('load-grade'));
- $('body').on('click','.filter-goodsType input',function () {
- getClass($("input[name='grade']:checked").val());
- });
- $('.filter-grade input').click(function () {
- var grade = $(this).val();
- var loadGrade=$(this).attr('load-grade');
- if(grade==1){
- $('.real-grade').html('实际年级:高一');
- }else if(grade==2){
- $('.real-grade').html('实际年级:高二');
- }else if(grade==3){
- $('.real-grade').html('实际年级:高三');
- }else if(grade==6){
- $('.real-grade').html('实际年级:六年级');
- }else if(grade==7){
- $('.real-grade').html('实际年级:七年级');
- }else if(grade==8){
- $('.real-grade').html('实际年级:八年级');
- }else if(grade==9){
- $('.real-grade').html('实际年级:九年级');
- }else{
- $('.real-grade').html('');
- }
- getClass(loadGrade);
- initUsefulType();
- });
- // 提交
- var flag = true;
- $(".btn-trial").on("click", function () {
- console.log(selectedDataAll);
- var subject_id=$('#subjectId').val();
- if (selectedDataAll.length >0) {
- var products = $("input[name='goodsTypeId']:checked").val();
- var grade = parseInt($("input[name='grade']:checked").val());
- var startTime = $("#startTime").val();
- var endTime = $("#endTime").val();
- var trialType = $("input[name=UsefulType]").val();
- var yearSemester = $("#semesterId").val();
- if($.inArray(grade,[1,2,3,6,7,8,9])==-1){
- layer.alert("没有查询到实际年级");
- return false;
- }
- /*
- var start = new Date(startTime.replace("-", "/").replace("-", "/"));
- var end = new Date(endTime.replace("-", "/").replace("-", "/"));
- if(end<=start){
- layer.alert("首次阅卷时间应晚于开始时间", {'icon':3});
- return false;
- }
- */
- <?php if (isset($_GET['orderId']) && $_GET['orderId']) :?>
- var orderId = "<?php echo $_GET['orderId'];?>";
- console.log(orderId);
- var data = {
- goodsTypeId: products,
- grade: grade,
- startTime: startTime,
- endTime: endTime,
- studentList:JSON.stringify(selectedDataAll),
- orderId: orderId,
- subjectId:subject_id,
- trialType:trialType,
- yearSemester:yearSemester
- };
- <?php else:?>
- var data = {
- goodsTypeId: products,
- grade: grade,
- startTime: startTime,
- endTime: endTime,
- studentList:JSON.stringify(selectedDataAll),
- subjectId:subject_id,
- trialType:trialType,
- yearSemester:yearSemester
- };
- <?php endif;?>
- if (flag){
- flag = false;
- $.ajax({
- type: 'post',
- url: "<?php echo Yii::app()->createUrl('imsSale/saveTrial')?>",
- dataType: 'json',
- data: data,
- success: function (data) {
- console.log(data);
- if (data.status){
- layer.alert(data.msg, {icon:1,closeBtn:0},function () {
- location.href="<?php echo Yii::app()->createUrl('imsSale/trialTable')?>"
- });
- }else{
- flag = true;
- layer.alert(data.msg, {icon:2});
- }
- },
- error: function () {
- flag = true;
- layer.alert("提交失败!", {icon:2});
- }
- });
- }else{
- layer.msg("稍安勿躁,正在处理中...");
- }
- } else {
- layer.alert("请选择至少一个学生", {'icon':7});
- }
- });
- $('#subjectId').change(function(){
- // $('.student-name_box').html('');
- //$('.student-selected').html('');
- // $('.student-list-content').html('');
- //$('.active').removeClass('active');
- //$('.student-list_box').find('.active').removeClass('active');
- var grade = $("input[name='grade']:checked").attr('load-grade');
- console.log(grade);
- getClass(grade);
- initUsefulType();
- });
- //根据年级获取班级
- function getClass(grade) {
- $('.student-list-content').html('');
- selectedDataAll=[];
- selectedDataValue=[];
- var subjectId=$('#subjectId').val();
- $.ajax({
- type: 'post',
- url: "<?php echo Yii::app()->createUrl('imsSale/getClassList');?>",
- data: {grade: grade,subjectId:subjectId},
- dataType: 'json',
- success: function (data) {
- if (data.status) {
- var html = '';
- for (var i = 0; i < data.data.length; i++) {
- var item = data.data[i];
- if (item['class_id']) {
- html+='<li class="classified" classId="'+item['class_id']+'">'+item['class_name']+'</li>';
- }
- }
- } else {
- var html = '<li>暂无班级数据</li>';
- }
- $('.class-list').html(html);
- }
- })
- }
-
- function getClassFist(grade) {
- var subjectId=$('#subjectId').val();
- $.ajax({
- type: 'post',
- url: "<?php echo Yii::app()->createUrl('imsSale/getClassList');?>",
- data: {grade: grade,subjectId:subjectId},
- dataType: 'json',
- success: function (data) {
- if (data.status) {
- var html = '';
- for (var i = 0; i < data.data.length; i++) {
- var item = data.data[i];
- if (item['class_id']) {
- html+='<li class="classified" classId="'+item['class_id']+'">'+item['class_name']+'</li>';
- }
- }
- } else {
- var html = '<li>暂无班级数据</li>';
- }
- $('.class-list').html(html);
- }
- })
- }
- //班级切换
- $(".class-list").on("click", "li", function(event) {
- if(!$(this).hasClass('subjectObj')){
- $(".class-list li").removeClass("active");
- $(this).addClass("active");
- selectedClassId=classId=$(this).attr('classId');
- selectedClassName=className=$(this).html();
- $("input[name='select-all']").prop("checked",false);
- trialType=$('input[name="UsefulType"]').val();
- if(trialType==-1){
- layer.msg('请选确定订单类型');
- return false;
- }
- getStudent(classId,className,'');
- }
- });
- function getStudent(classId,className,studentName){
- grade=$("input[name='grade']:checked").attr('load-grade');
- semester=$('#semesterId').val();
- startTime=$('#startTime').val();
- var postData = {
- 'classId' : classId,
- 'goodsTypeId' : $('input[name="goodsTypeId"]:checked').val(),
- 'subjectId':$('#subjectId').val(),
- 'studentName':studentName,
- 'trialType':$('input[name="UsefulType"]').val(),
- 'semesterId':semester,
- 'grade':grade,
- 'startTime':startTime
- };
- $.ajax({
- url:'<?php echo $this->createUrl('imsSale/getStudent')?>',
- type:'POST',
- dataType:'json',
- data:postData,
- success:function(res){
- if(res.status==1){
- var studentHtml='';
- for(var i=0;i<res.data.list.length;i++){
- if($.inArray(res.data.list[i]['student_id'],res.data.student)!=-1){
- //continue;
- 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>';
- }else{
- if($.inArray(res.data.list[i]['student_id'],selectedDataValue)!=-1){
- 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>';
- }else{
- studentHtml+='<label><input type="checkbox" name="studentName" classId="'+classId+'" className="'+className+'" value="'+res.data.list[i]['student_id']+'" />'+res.data.list[i]['realname']+'</label>';
- }
- }
- }
- $('.student-list-content').html(studentHtml);
- }else{
- $('.student-list-content').html('');
- }
- }
- });
- }
- // 添加学生
- $("#btnAddStudent").on("click", function() {
- getStudentSelected();
- });
- // 移出学生
- $("#btnRemoveStudent").on("click", function() {
- removeStudentSelected();
- });
- //搜索学生
- $('.btn-search-student').click(function(){
- studentName=$('input[name=search-student-name]').val();
- if(studentName!=''){
- getStudent(selectedClassId,selectedClassName,studentName);
- }
- });
- function getStudentSelected() {
- var selectedData = $("#studentListContent input[name='studentName']:checked"); //获取所以选中学生
- var studentName = '';
- for (var i = 0; i < selectedData.length; i++) {
- if (!isSelected(selectedData[i].value)) {
- studentName = $(selectedData[i]).parent().text();
- var student ={
- name:studentName,
- value:selectedData[i].value,
- class:$(selectedData[i]).attr('className'),
- classId:$(selectedData[i]).attr('classId'),
- };
- selectedDataAll.push(student);
- selectedDataValue.push(selectedData[i].value);
- }else{
- //console.log(selectedData[i].value)
- }
- showSelectedStudent();
- }
- }
- function removeStudentSelected() {
- var selectedStudent = $("#selectedListContent input[name='selectedStudent']:checked"); //获取所有选中学生
- var selectedData = $("#studentListContent input[name='studentName']:checked"); //获取所以选中学生
- for (var i = 0; i < selectedStudent.length; i++) {
- $(selectedStudent[i]).parent().remove();
- if(selectedDataValue.length>0){
- for(var k=0;k<selectedDataValue.length;k++){
- if(selectedDataValue[k]===selectedStudent[i].value){
- selectedDataValue.splice(k,1);
- selectedDataAll.splice(k,1);
- }
- }
- }
- for (var j = 0; j < selectedData.length; j++) {
- if(selectedData[j].value===selectedStudent[i].value){
- $(selectedData[j]).prop("checked", false);
- }
- }
- }
- $('#studentSelectedLength').text(selectedDataAll.length);
- };
- function showSelectedStudent() {
- var selectedDataList = [];
- for (var i = 0; i < selectedDataAll.length; i++) {
- selectedDataList.push('<label><input type="checkbox" name="selectedStudent" value="'+ selectedDataAll[i].value +'" />'+selectedDataAll[i].name+'</label>');
- }
- $('#selectedListContent').html(selectedDataList);
- $('#studentSelectedLength').text(selectedDataAll.length);
- }
- function isSelected(val){
- return selectedDataValue.indexOf(val) > -1
- };
- $('.goodTypeInput').change(function(){
- var holidayHomework=<?php echo ProductDownload::PRODUCT_TYPE_HOLIDAY_HOMEWORK; ?>;
- var goodsTypeId=parseInt($(this).val());
- if(goodsTypeId==holidayHomework){
- $('.good-type-prompt').text('*注:假期作业的试用订单,每个年级最多仅能设置10个。');
- }else{
- $('.good-type-prompt').text('');
- }
- initUsefulType();
- })
- $('#startTime').blur(function(){
- beginTime=$(this).val();
- if(beginTime!=''){
- $.ajax({
- url:'<?php echo $this->createUrl('imsSale/getSemesterByBeginTime')?>',
- type:'POST',
- dataType:'json',
- data:{beginTime:beginTime},
- success:function(res){
- console.log(res);
- if(res.status==1 && res.data.length>0){
- var html='';
- for(var i=0;i<res.data.length;i++){
- html+= '<option value="'+res.data[i]['semesterId']+'">'+res.data[i]['semesterName']+'</option>';
- }
- $('#semesterId').html(html);
- initUsefulType();
- }else{
- $('#semesterId').html('');
- layer.msg('未查询到学期数据');
-
- }
- }
- });
- }
- });
- $('#semesterId').change(function(){
- initUsefulType();
- });
- //获取试用类型
- function getUsefulType(beginTime,goodsTypeId,grade,selSubject,semesterId){
- $.ajax({
- url:'<?php echo $this->createUrl('imsSale/getUsefulType')?>',
- type:'POST',
- dataType:'json',
- data:{beginTime:beginTime,goodsTypeId:goodsTypeId,grade:grade,subject:selSubject,yearSemester:semesterId},
- success:function(res){
- console.log(res);
- if(res.status==1 ){
- $('input[name=typeName]').val(res.data['typeName']);
- $('input[name=UsefulType]').val(res.data['type']);
- }else{
- layer.msg('未查询到数据');
- }
- }
- });
- }
- function initUsefulType(){
- goodsTypeId=$('input[name=goodsTypeId]:checked').val();
- grade=$('input[name=grade]:checked').val();
- subjectId=$('#subjectId').val();
- beginTime=$('#startTime').val();
- semesterId=$('#semesterId').val();
- $('.student-list-content').html('');
- $('#selectedListContent').html('');
- selectedDataAll=[];
- selectedDataValue=[];
- if(goodsTypeId!=null && grade!=null && subjectId!=null && beginTime!=null && semesterId!=null){
- getUsefulType(beginTime,goodsTypeId,grade,subjectId,semesterId);
- }
- }
- })
- </script>
|