<template>
    <!--培训计划报名选课组件1开始-->
    <div class="trainplan_bmselect_pc_1">
        <!--筛选-->
        <div class="screening">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <div class="screening-body">
                            <div class="screening-body-hd">
                                <ul>
                                    <li  @click="bigClass(item,$event)" v-for="(item,i) in sclassList"  :class="{'on':item.isChecked}" :key="i">
                                        {{item.typeName}}
                                    </li>

                                </ul>
                            </div>
                            <div class="screening-body-bd">
                                <div class="screening-body-part">

                                    <div v-for="(item,i) in classificationList" :key="i" class="screening-body-list clearfix"><!--条目 :class="{'active':list.active==='on'}"-->
                                        <span class="tit">{{item.catName}}</span>
                                        <ul>
                                            <li v-for="(list,j) in item.children" :id="'cc_'+list.proCatId"  class="twoClass"  :key="j" @click.stop="classEnv(list,$event)" >
                                                <span v-if="j!=0">|</span>
                                                {{list.catName}}</li>
                                        </ul>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--选择培训计划-->
        <div class="choose-plan">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <div class="choose-plan-body">
                            <span class="choose-plan-title">选择培训计划</span>
                            <div class="choose-plan-hd">
                                <ul>

                                    <li class="clearfix on"  v-for="(item,i) in menuList" :key="i">
                                        <a @click="switchPlan()" href="javascript:void(0)">{{item.proName}}</a>
                                        <span class="tp-close" @click="removeItem(item)"></span>
                                    </li>

                                </ul>
                            </div>
                            <div class="choose-plan-bd">
                                <div class="choose-plan-part">
                                    <div class="common-table">
                                        <table>
                                            <thead>
                                            <tr>
                                                <td>知识点</td>
                                                <td>学时要求</td>
                                                <td>课程</td>
                                                <td>学时</td>
                                                <td>学时是否满足</td>
                                            </tr>
                                            </thead>
                                            <tr v-for="(list,i)  in knownList" :key="i" >
                                                <td style="text-align:center;" class="blacktext textleft">{{list.name}}</td>
                                                <td class="orangetext"><span v-if="Number(list.studyLength)>0">最少{{Number(list.studyLength)}}学时</span><span v-if="Number(list.tkMaxStudylength)>0">,最多{{Number(list.tkMaxStudylength)}}学时</span></td>
                                                <td style="text-align:center;" class="textleft">{{ kCourseList[list.knownId] | toStr }}</td>
                                                <td :id="'a'+list.knownId" >{{kCourseLen[list.knownId] | toNum}}</td>
                                                <td>
                                                  <img style="display:none;width:24px;" class="ierror" :id="'c'+list.knownId"  src="../../theme-chalk/src/images/error.png" alt="">
                                                  <img style="display:none;width:24px;" class="iright" :id="'d'+list.knownId"  src="../../theme-chalk/src/images/tp-gou.png" alt="">
                                                </td>
                                            </tr>



                                            <tr>
                                                <td colspan="5" class="textright">总学时：<span
                                                        class="orangetext" id="tstudyLen">{{totalens}}</span>学时
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                    <span class="tp-tip">注：安徽省三项岗位人员培训报名唯一官方入口，其他平台报名均不认学时！</span>
                                    <span class="orangebtn"><a href="javascript:void(0)" @click="goes()" >继续完成报名</a></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--课程计划 courseList-->

        <div class="class-plan"  v-if="newKeyList.length>0">
            <div class="container">

                <div class="row" style="margin-top:20px;" v-for="(item,i) in newKeyList" :key="i">

                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                            <div class="class-plan-title">{{item | toName(knownList)}}</div>
                        </div>

                    <div class="col-lg-3 col-md-3 col-sm-4 col-xs-6" v-for="(list,j) in courseList[item]" :key="j" ><!--循环-->
                        <div class="jpclass-list tpclassbg">
                            <span class="sp1">
                                <a target="_blank" :href="list.thirdCsPlayUrl" v-if="list.csPhoto" style="cursor: pointer;"><img  :src="list.csPhoto" alt=""></a>
                                <a target="_blank" :href="list.thirdCsPlayUrl" v-else  style="cursor: pointer;"><img  src="../../theme-chalk/src/images/jpclass-icon.png" alt=""></a>
                                <span class="spp1" :id="'cc'+list.ccId">学员评分：{{list.ccId | setStart(statistical) }}星</span>
                                <span class="spp2">

                                  <img  v-if="list.isGood" src="../../theme-chalk/src/images/jpclass-icon.png" alt="">
                                </span>
                            </span>
                            <span class="sp2"><a  style="cursor: pointer;" target="_blank" :href="list.thirdCsPlayUrl">{{list.csName}}</a></span>
                            <span class="sp3">
                                <p><i>学时：</i>{{list.csStudylength}}学时</p>
                                <p><i>价格：</i>{{list.csAmount}}元</p>
                                <p><i>来源：</i>{{list.bsName}}</p>
                            </span> <!-- v-if="list.isSelect"-->
                            <span class="sp4" :id="'o_'+list.csId"><a href="javascript:void(0)" :id="'p'+list.knownId+'_'+list.csId" @click="addPlan(list,$event)" :class="{'unjoin':plan1,'unjoin_active':list.isSelect}">{{joinTxt}}</a></span>
                            <span class="sp4" :id="'o1_'+list.csId" style="display:none;"><a href="javascript:void(0)" :id="'p'+list.knownId+'_'+list.csId" style="cursor:not-allowed;"  :class="{'unjoin':plan1,'unjoin_active':list.isSelect}">已购买</a></span>

                            <span class="sp5" :id="'p_'+list.csId" style="display:none;"><img src="../../theme-chalk/src/images/after-select.png" alt=""></span>
                        </div>
                    </div>
                </div>





            </div>
        </div>
    </div>
</template>

<script>
import formMixin from "../../../src/mixins/formMixin";
import lenye_base from "lenye_base";
import * as $ from "fy-kit";
import msg from "../../message";
export default {
  name: "ElSignup",
  mixins: [formMixin],
  props: {
    placeholder: {
      type: String,
      default: "总访问量a"
    },
    hasWx: {
      type: Boolean,
      default: true
    }
  },
  components:{
    msg
  },
  filters: {
    toStr(value) {
      var arr = [];
      if (value) {
        value.forEach((list, i) => {
          arr.push(list.split("_")[1]);
        });
      }
      return arr.toString();
    },

    toNum(value) {
      if (value) {
        var result = 0;
        for (var i = 0; i < value.length; i++) {
          result = $.string.jia(result, Number(value[i].split("_")[1]));
        }
        return result;
      }
    },
    toName(val, option) {
      var name = "";
      option.forEach((list, i) => {
        if (list.knownId == val) {
          name = list.name;
        }
      });

      return name;
    },
    setStart(val, option) {
      var start = 0;
      option.forEach((list, i) => {
        if (list.objId == val) {
          start = Number(list.starNum);
        }
      });
      if (!start) {
        $._.default("#cc" + val).hide();
      }
      return start;
    }
  },
  data() {
    return {
      plan1: true,
      sclassList: [],
      classificationList: [],
      menuList: [], //选中项目
      courseList: [],
      newKeyList: [],
      knownList: [],
      kCourseList: {},
      kCourseLen: {},
      totalens: localStorage.totalen || 0,
      cacalTxt: "取消计划",
      joinTxt: "加入计划",
      statistical: [],
      accorType:1
    };
  },
  watch: {},
  created() {
   var userData = $.util.storage('userData').get().getValue();
    if(userData){
      this.accType();
    }

  },
  mounted() {

   // var s = Datas();
    //console.log( $('div').css("color","green"),"string......");
    console.log("lenye_bas1e", lenye_base.site_data.getsiteData());
    console.log("lenye_bas1e", lenye_base.base_data.getapiUrl());
    console.log("apiapi...", lenye_base.api_url.base);

    this.init();
    this.sclass();


  },
  methods: {

    goes(){

     if(!localStorage.userData){
       msg.warning("请登录后继续完成报名！");
       return  false;
     }
     var isError = true;
     $._.default('.iright').each(function(i,ele){
        if($._.default(ele).css("display")=='none'){
          isError = false;
        }
     })
     if(isError){
       if(Number($._.default('#tstudyLen').html())===0){
          msg.warning('请选择课程后操作!');
       }else{
         window.location.href = "/projectsignconfirm";
       }
     }else{
       msg.warning('请满足知识点学时要求！')
     }


    },
    addPlan(arr, ev) {
      var $this = $._.default(ev.target);
      var _this = $._.default(ev.target);
     // console.log(arr, "arr");
      var bsName = arr.bsName ? '_'+arr.bsName : '_no'

      if ($this.hasClass("unjoin_active")) {
        $this.removeClass("unjoin_active");
        //当前点击
        var hasSelect = JSON.parse(localStorage.hasSelect);
        hasSelect.remove("p" + arr.knownId + "_" + arr.csId);
        localStorage.hasSelect = JSON.stringify(hasSelect);
        //列表中...
        var kCourseList = JSON.parse(localStorage.kCourseList);
        kCourseList[arr.knownId].remove(arr.csId + "_" + arr.csName+bsName);
        localStorage.kCourseList = JSON.stringify(kCourseList);
        this.kCourseList = kCourseList;
        //course legth
        var kCourseLen = JSON.parse(localStorage.kCourseLen);
        kCourseLen[arr.knownId].remove(arr.csId + "_" + arr.csStudylength);
        localStorage.kCourseLen = JSON.stringify(kCourseLen);
        this.kCourseLen = kCourseLen;

        var totalen = Number(localStorage.totalen);
        var totalens = $.string.jian(totalen, Number(arr.csStudylength));
        this.totalens = totalens;
        localStorage.totalen = totalens;

        _this.html(this.joinTxt);
        this.couseParams(arr.csId);
        //alert(111)
      } else {
        $this.addClass("unjoin_active");
        var kCourseList = JSON.parse(localStorage.kCourseList);
        kCourseList[arr.knownId].push(arr.csId + "_" + arr.csName+bsName);
        localStorage.kCourseList = JSON.stringify(kCourseList);
        this.kCourseList = kCourseList;

        var kCourseLen = JSON.parse(localStorage.kCourseLen);
        kCourseLen[arr.knownId].push(arr.csId + "_" + arr.csStudylength);
        localStorage.kCourseLen = JSON.stringify(kCourseLen);

        this.kCourseLen = kCourseLen;

        var hasSelect = JSON.parse(localStorage.hasSelect);
        //hasSelect[arr.knownId].push(arr.csId);
        hasSelect.push("p" + arr.knownId + "_" + arr.csId);
        // hasSelect.push('p'+arr.csId);
        localStorage.hasSelect = JSON.stringify(hasSelect);

        //set totalen
        var totalen = Number(localStorage.totalen);
        var totalens = $.string.jia(totalen, Number(arr.csStudylength));
        this.totalens = totalens;
        localStorage.totalen = totalens;
        _this.html(this.cacalTxt);
        //alert(222)
        //couse params
        this.couseParams(arr.csId,1);
      }

      this.checkReg();
    },
    //couse params
    async couseParams(csId,num){
      var Params = JSON.parse(localStorage.Params);
      if(num===1){
        let spcId  =  await this.courseClassSpecifications(csId);
       var params = {
            itemId:csId,
            itemSpcId:spcId,
            itemNum:1, //数量
            itemType:1, //类型
          }

       Params.products.push(params);
       localStorage.Params = JSON.stringify(Params);
      }else{
        var newObj =  $.array.removeObjById(Params.products,'itemId',csId);
        Params.products = newObj;
        localStorage.Params = JSON.stringify(Params);
      }

    },
    totalen() {
      /*
      var kCourseLen = JSON.parse(localStorage.kCourseLen);
      var totalArr = [];
      kCourseLen.forEach((list,i)=>{
        totalArr.push(list)
      })
      */
    },
    reClass() {
      if (
        localStorage.menuList &&
        JSON.parse(localStorage.menuList).length > 0
      ) {
        var menuList = JSON.parse(localStorage.menuList);
        menuList.forEach((item, i) => {
          $._.default("#cc_" + item.proCatId).removeClass("active");
        });

        var defaultArr = [];
        this.menuList = [];
        localStorage.menuList = JSON.stringify(defaultArr);
      }
    },
    //切换大类
    bigClass(list, ev) {
      this.classNull();
      // console.log(ev.target)
      var defaultObj = {};
      localStorage.iSclassList = JSON.stringify(defaultObj);

      this.reClass();
      //防止通过数据多个选择为空，导致多选情况。
      $._.default(".twoClass").removeClass("active");

      list["isChecked"] = true;
      localStorage.iSclassList = JSON.stringify(list);
      // debugger
      var datas = this.sclassList;
      datas.forEach((item, i) => {
        if (item.typeId == JSON.parse(localStorage.iSclassList).typeId) {
          item["isChecked"] = true;
        } else {
          item["isChecked"] = false;
        }
      });
      this.sclassLis = datas;
      console.log(list.typeId, "list.typeId");
      this.classification(list.typeId);
    },
    //移除已选分类
    removeItem(list) {
      this.classificationList.forEach((lists, i) => {
        lists.children.forEach((item, j) => {
          if (item.proCatId === list.proCatId) {
            item.active = "off";
          }
        });
      });
      $._.default("#cc_" + list.proCatId).removeClass("active");
      this.removeCs(list);

      this.classNull();
    },
    //class null
    classNull() {
      this.knownList = [];

      var arr = JSON.stringify([]);
      var obj = JSON.stringify({});
      var kCourseList = JSON.parse(localStorage.kCourseList);
      var kCourseLen = JSON.parse(localStorage.kCourseLen);
     // this.knownList.forEach((list, i) => {
     //   kCourseList[list.knownId] = [];
      //  kCourseLen[list.knownId] = [];
      //});

      //localStorage.kCourseList = JSON.stringify(kCourseList);
      //localStorage.kCourseLen = JSON.stringify(kCourseLen);
      localStorage.kCourseList = obj;
      localStorage.kCourseLen = obj;

      localStorage.totalen = 0;

      this.kCourseList = localStorage.kCourseList;
      this.kCourseLen = localStorage.kCourseLen;
      this.totalens = localStorage.totalen;

      localStorage.newKeyList = arr;
      localStorage.courseList = obj;
      localStorage.hasSelect = arr;
      this.newKeyList = [];
      this.courseList = {};

      //报名参数
      localStorage.Params = obj;

    },

    //移除common
    removeCs(list) {
      var copyList = [];
      var newList = JSON.parse(localStorage.menuList);
      newList.forEach(item => {
        if (item.proCatId != list.proCatId) {
          copyList.push(item);
        }
      });
      localStorage.menuList = JSON.stringify(copyList);
      this.setTitleFun();
    },
    //选择分类
    classEnv(list, ev) {
      var target = $._.default(ev.target);
      if (target.hasClass("active")) {
        //移除
        target.removeClass("active");
        this.removeCs(list);
        this.classNull();
      } else {
        this.classNull();
        this.reClass(); //todo...
        //防止通过数据多个选择为空，导致多选情况。
        $._.default(".twoClass").removeClass("active");

        this.getPro(list.typeId, list.proCatId, 1);
        target.addClass("active");
      }
    },
    //默认大类
    sclass() {
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/schoolclass-service/common/proClassify/queryList.do",
          lenye_base.base_data.getformatting({
            siteIds: lenye_base.site_data.getsiteData().siteId
          })
        )
        .then(({ data }) => {
          var jSclassList = JSON.parse(localStorage.iSclassList);
          if (jSclassList && jSclassList.typeId) {
            //alert('111')
            /*data.unshift({
              typeName: "全部",
              typeId: "",
              isChecked: false
            });
            */
            data.forEach((item, i) => {
              if (item.typeId === jSclassList.typeId) {
                item["isChecked"] = true;
              } else {
                item["isChecked"] = false;
              }
            });

            this.sclassList = data;
            //data[0].array

            this.classification(jSclassList.typeId);
          } else {
            //alert('222')
            data.forEach((item, i) => {
              item["isChecked"] = false;
            });
            /*data.unshift({
              typeName: "全部",
              typeId: "",
              isChecked: true
            });
            */
            data.forEach((item, i) => {
              if (i===0) {
                item["isChecked"] = true;
              } else {
                item["isChecked"] = false;
              }
            });
            this.sclassList = data;
            //default big class
            this.classification(data[0].typeId);
          }
        });
    },
    //默认分类
    classification(typeId) {
      // alert(333)
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/schoolclass-service/common/proCategory/queryUsableTree.do",
          lenye_base.base_data.getformatting({
            siteId: lenye_base.site_data.getsiteData().siteId,
            cascade: 2,
            typeId
          })
        )
        .then(({ data }) => {
          if (
            localStorage.menuList &&
            JSON.parse(localStorage.menuList).length > 0
          ) {
            var menuList = JSON.parse(localStorage.menuList);
            this.getPro(typeId, menuList[0].proCatId, 2);
          }

          this.classificationList = data;
          // console.log(this.classificationList,"this.classificationList")
          //this.getPro();
          this.setTitleFun();
        });
    },
    unique(arr) {
      return Array.from(new Set(arr));
    },
    //评分
    score(arr) {
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/interact-service/common/itaInteractionTimes/queryPage.do",
          lenye_base.base_data.getformatting({
            list: arr
          })
        )
        .then(({ data }) => {
          this.statistical = data;
        });
    },
    isCourse(studyUserId,csId){
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/course-service/common/crsCustLearnCourse/queryPage.do",
          lenye_base.base_data.getformatting({
            studyUserId,
            csId
          })
        )
        .then(res => {
          if(res.success == '1'){
            if(res.data.length>0){
              res.data.forEach((list,i)=>{
                $._.default('#p_'+list.csId).show();
                if(this.accorType!=2){
                  $._.default('#o_'+list.csId).hide();
                  $._.default('#o1_'+list.csId).show();
                }
              })
            }
          }else{
            msg(res.message);
          }
        })
    },
    accType() {
        $.util
          .ajax(
            lenye_base.base_data.getapiUrl() +
            '/base-service/api2/custUserIdentity/queryUserIdentities.do',
            lenye_base.base_data.getformatting({})
          )
          .then(res => {
            if (res.success === '1') {
              // this.datas = res.data;
              if (res.data && res.data[0] && res.data[0].idtCode) {
                if (res.data[0].idtCode == 'company') {
                  this.accorType = 2;
                } else {
                  this.accorType = 3;
                }
              } else {
                this.accorType = 1;
              }
            } else {
              msg.error(res.message);
            }
          });
      },
    //course
    getCourse(czId) {
      localStorage.czId = czId;
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/schoolclass-service/common/clzClazzCourse/queryShowPage.do",
          lenye_base.base_data.getformatting({
            czId,
            rows:999
          })
        )
        .then(({ data }) => {
          if (!data) {
            return;
          }


         if(localStorage.userData){
           var csIds = [];
           var studyUserId =  JSON.parse(localStorage.userData).custId;
           data.forEach((list,i)=>{
             csIds.push(list.csId);
           })

           this.isCourse(studyUserId,csIds.toString());
         }




          var params = $.array.subArr(data, "ccId", "type", "course");
          var newParams = $.array.replaceArr(params, "ccId", "objId");
          this.score(newParams);

          var setIdArr = $.array.replaceArr(data, "tkId", "knownId");
          var setNameArr = $.array.replaceArr(setIdArr, "tkName", "knownName");
          var data = $.array.replaceArr(setNameArr, "csTag", "isGood");

          //todo.. 接口咱不满足，模拟接口返回数据

           //console.log(data,"data...")


          data.forEach((list, i) => {
            //模拟加数据

            list["isSelect"] = false; //是否已选择



           /* list["score"] = 4.8;  //评分
            list["isGood"] = false; //是否推荐
            if (i % 2 == 0) {
              list["knownName"] = "知识点001";
              list["knownId"] = "known1001";
            } else {
              list["knownName"] = "知识点002";
              list["knownId"] = "known1002";
            }
            */

          });

          // debugger;

          //知识点分类，获取知识点
          var resetData = [];
          data.forEach((list, i) => {
            resetData.push(list.knownId);
          });

          localStorage.newKeyList = JSON.stringify(this.unique(resetData));
          // console.log(this.unique(resetData),"this.unique(resetData)");
          this.newKeyList = this.unique(resetData);

          //格式转换
          var newObj = {};
          this.newKeyList.forEach((list, i) => {
            newObj[list] = [];
          });
          data.forEach((list, i) => {
            newObj[list.knownId].push(list);
          });

          this.courseList = newObj;
          localStorage.courseList = JSON.stringify(newObj);

          //样式修改
          this.style();
        });
    },
    style() {
      var hasSelect = JSON.parse(localStorage.hasSelect);
      if (hasSelect.length > 0) {
        hasSelect.forEach((item, j) => {
          setTimeout(() => {
            $._.default(document.getElementById(item)).addClass("unjoin_active");
            $._.default("#" + item).html(this.cacalTxt);
          }, 300);
        });
      }
    },

    //known
    getKnown(tcId) {
      localStorage.tcId = tcId;
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/schoolclass-service/common/proTeachcontentKnowledge/queryList.do",
          lenye_base.base_data.getformatting({
            tcId
          })
        )
        .then(({ data }) => {

          var setIdArr = $.array.replaceArr(data, "tkId", "knownId");
          var setNameArr = $.array.replaceArr(setIdArr, "tkName", "name");
          var knownList = $.array.replaceArr(
            setNameArr,
            "tkMinStudylength",
            "studyLength"
          );




         /* var knownList = [
            {
              knownId: "known1001",
              name: "知识点001",
              studyLength: "10",
              tkMaxStudylength:'14',
            },
            {
              knownId: "known1002",
              name: "知识点002",
              studyLength: "20",
              tkMaxStudylength:'30',
            },
            {
              knownId: "1003",
              name: "知识点003",
              studyLength: "30",
              tkMaxStudylength:'40',
            }
          ];*/



          this.setKnown(knownList);
        });
    },
    setKnown(knownList) {
      //渲染知识点
      this.knownList = knownList;
      //渲染知识点id
      var kCourseList = JSON.parse(localStorage.kCourseList);
      knownList.forEach((list, i) => {
        if (!kCourseList[list.knownId]) {
          kCourseList[list.knownId] = [];
        }
      });
      localStorage.kCourseList = JSON.stringify(kCourseList);

      var kCourseLen = JSON.parse(localStorage.kCourseLen);
      knownList.forEach((list, i) => {
        if (!kCourseLen[list.knownId]) {
          kCourseLen[list.knownId] = [];
        }
      });
      localStorage.kCourseLen = JSON.stringify(kCourseLen);

      //hasSelect course
      /*
      var hasSelect = JSON.parse(localStorage.hasSelect);
      knownList.forEach((list, i) => {
        if (!hasSelect[list.knownId]) {
          hasSelect[list.knownId] = [];
        }
      });
      localStorage.hasSelect = JSON.stringify(hasSelect);
      */

      this.kCourseList = kCourseList;
      this.kCourseLen = kCourseLen;

      this.checkReg();
    },
    checkReg() {
      var kCourseLen = JSON.parse(localStorage.kCourseLen);

      var newNum = [];

      this.knownList.forEach((list, i) => {
        //1、获取课程总课时

        //1.1 缓存有
        var totals = 0;
        if (kCourseLen[list.knownId] && kCourseLen[list.knownId].length > 0) {
          kCourseLen[list.knownId].forEach((list, i) => {
            newNum.push(Number(list.split("_")[1]));
          });
          console.log(newNum, "newNum");
          totals = $.array.total(newNum);
        }
        //1.2 缓存没有

        //2、获取知识点要求课时
        var studyLength = Number(list.studyLength);
        var studyLengthMax = Number(list.tkMaxStudylength);
        console.log(studyLength+"——》studyLength")
        //alert
        setTimeout(() => {
          // console.log($._.default("#a"+list.knownId).html()+"——》list.knownId");
          var getTotal =Number($._.default("#a"+list.knownId).html());
          if(studyLength>0 && studyLengthMax>0){
             if (getTotal >= studyLength && getTotal <= studyLengthMax) {
              $._.default("#d" + list.knownId).show(); //right
              $._.default("#c" + list.knownId).hide();
            }else {
              $._.default("#d" + list.knownId).hide();
              $._.default("#c" + list.knownId).show();
            }
          }else if(studyLength==0 && studyLengthMax>0){
             if (getTotal <= studyLengthMax) {
              $._.default("#d" + list.knownId).show(); //right
              $._.default("#c" + list.knownId).hide();
            }else {
              $._.default("#d" + list.knownId).hide();
              $._.default("#c" + list.knownId).show();
            }
          }else if(studyLength>0 && studyLengthMax==0){
            if (getTotal >= studyLength) {
              $._.default("#d" + list.knownId).show(); //right
              $._.default("#c" + list.knownId).hide();
            }else {
              $._.default("#d" + list.knownId).hide();
              $._.default("#c" + list.knownId).show();
            }
          }else if(studyLength==0 && studyLengthMax==0){
            if (getTotal >= 0) {
              $._.default("#d" + list.knownId).show(); //right
              $._.default("#c" + list.knownId).hide();
            }else {
              $._.default("#d" + list.knownId).hide();
              $._.default("#c" + list.knownId).show();
            }
          }

        }, 0);
      });
    },
    async getParams(czId){
      let spcId  =  await this.classSpecifications(czId);
      //debugger;
      var obj = {};
      var products = [];
      if(localStorage.Params){
       let Params =  JSON.parse(localStorage.Params);
       if(Params.products){
         products = Params.products;
       }
      }else{
        localStorage.Params = JSON.stringify(obj);
      }



      var params = {
          objId:czId,
          objType:'4',
          shoppingNum:1,
          spcId:spcId,
          siteId:lenye_base.site_data.getsiteData().siteId,
          products:products
        }
        localStorage.Params = JSON.stringify(params);

    },
    //course gg
    async courseClassSpecifications(csId){
      let res = await $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/course-service/common/crsSpecification/queryPage.do",
          lenye_base.base_data.getformatting({
            csId
          })
        )
       if(res.success=='1'){
           return res.data[0].csSpcId;
        }else{
          msg.error(res.message);
        }
    },
    //class gg
    async classSpecifications(czId){
      let res = await $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/schoolclass-service/common/clzSpecification/queryPage.do",
          lenye_base.base_data.getformatting({
            czId
          })
        )
       if(res.success=='1'){
           return res.data[0].czSpcId;
        }else{
          msg.error(res.message);
        }
    },
    getClass(tcId) {
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/schoolclass-service/common/clzClazz/queryPageUse.do",
          lenye_base.base_data.getformatting({
            tcId
          })
        )
        .then(({ data }) => {
          if (data && data[0] && data[0].czId) {
            this.getCourse(data[0].czId);
            this.getParams(data[0].czId);
          } else {
            // alert("班级id不能为空！");
          }
        });
    },
    //计划
    getPlan(proCatId, proId, num, children) {
      console.log(children, "children");
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/schoolclass-service/common/proProgram/queryProTeachcontentPage.do",
          lenye_base.base_data.getformatting({
            proCatId,
            proId
          })
        )
        .then(({ data }) => {
          // debugger;
          var list = data[0];
          if (data && data[0]) {
            if (Number(num) === 1) {
              console.log(data && data[0], "ccc+++");
              list["proCatId"] = proCatId;
              var newList = JSON.parse(localStorage.menuList);
              newList.push(list);
              localStorage.menuList = JSON.stringify(newList);
              this.setTitleFun();
              //console.log(data && data[0],"ccc+++")
              this.getClass(list.tcId);
              console.log(list.tcId, "list");
              this.getKnown(list.tcId);
              //alert("未选...");
            } else if (Number(num) === 2) {
              //alert(222);
              //alert("已选...")
              this.menuList = JSON.parse(localStorage.menuList);
              //console.log('cd...')
              for (let k = 0; k < this.menuList.length; k++) {
                if (list.proId === this.menuList[k].proId) {
                  $._.default("#cc_" + this.menuList[k].proCatId).addClass("active");
                }
              }

              this.getClass(list.tcId);
              this.getKnown(list.tcId);
            }
          }
        });
    },
    //项目
    getPro(typeId, proCatId, num, children) {
      //console.log(typeId, "=typeId");
      //console.log(proCatId, "=proCatId");

      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/schoolclass-service/common/proProgram/queryUsablePage.do",
          lenye_base.base_data.getformatting({
            siteIds: lenye_base.site_data.getsiteData().siteId,
            proCatId,
            typeId
          })
        )
        .then(({ data }) => {
          if (data && data[0]) {
            this.getPlan(proCatId, data[0].proId, num);
          }
        });
    },
    //common/proProgram/queryUsablePage.do
    setTitleFun() {
      this.menuList = JSON.parse(localStorage.menuList) || [];
    },
    startStorage() {
      var nullArr = [];
      var selected = {};
      //分类
      if (!localStorage.menuList) {
        localStorage.menuList = JSON.stringify(nullArr);
      }
      //大类
      if (!localStorage.iSclassList) {
        localStorage.iSclassList = JSON.stringify(selected);
      }
      //known
      if (!localStorage.kCourseList) {
        localStorage.kCourseList = JSON.stringify(selected);
      }
      if (!localStorage.kCourseLen) {
        localStorage.kCourseLen = JSON.stringify(selected);
      }

      //course list name
      if (!localStorage.newKeyList) {
        localStorage.newKeyList = JSON.stringify(nullArr);
      }
      //course list
      if (!localStorage.courseList) {
        localStorage.courseList = JSON.stringify(selected);
      }

      //hasSelect course
      if (!localStorage.hasSelect) {
        localStorage.hasSelect = JSON.stringify(nullArr);
      }

      //totalen
      if (!localStorage.totalen) {
        localStorage.totalen = 0;
      }
    },
    init() {
      Array.prototype.remove = function (val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        }
      this.startStorage();
    },
    grxy() {
      this.active = 0;
    },
    cyqy() {
      this.active = 1;
    },
    pxjg() {
      this.active = 2;
    }
  }
};
</script>
