<template>
  <view>
    <cu-custom bgColor="bg-gradual-blueness" :isBack="true">
      <block slot="backText">返回</block>
      <block slot="content">我的学习</block>
    </cu-custom>
    <view class="container">
      <scroll-view @scrolltolower="scrolltolower" scroll-y style="height: calc(100vh - 65px)">
        <view v-if="list.length > 0">
          <view class="studies_wrap" v-for="(item, index) in list" :key="index">
            <view class="studies_wrap-top">
              <view class="studies_wrap_title">班级名称: {{ item.NAME }}</view>
              <view class="studies_wrap_state">
                <view class="fcb" v-if="item.STUDYSTATE === '1'">学习中</view>
                <view class="fcg" v-if="item.STUDYSTATE === '2'">已学完</view>
                <view class="fch" v-if="item.STUDYSTATE === '0'">未学习</view>
                <view class="fch" v-if="item.STUDYSTATE === '3'">已完成</view>
                <view class="fch" v-if="item.STUDYSTATE === '4'">未完成</view>
                <view class="fch" v-if="item.STUDYSTATE === '5'">待评估</view>
                <view class="fch" v-if="item.STUDYSTATE === '6'">评估未合格</view>
              </view>
            </view>
            <view class="studies_wrap-main">
              <view class="">行业类型:{{ item.CORP_TYPE_NAME }}</view>
              <view class="">岗位类型:{{ item.POSTTYPE_NAME }}</view>
              <view class="">
                培训时间:{{ item.START_TIME }} 至 {{ item.END_TIME }}
              </view>
            </view>
            <view class="studies_wrap-bottom">
              <view class="flex">
                <image src="/static/study/time.png" alt=""/>
                <view>
                  <uni-countdown :second="item.second"/>
                </view>
              </view>
              <view class="">
                <button
                    class="cu-btn round bg-blue"
                    v-show="
                      item.STUDYSTATE >= '2' &&
                      item.STAGEEXAMSTATE >= '2' &&
                      (item.ISSTRENGTHEN === '1' || item.ISSTRENGTHEN === '2') &&
                      item.STRENGTHENEXAMSTATE === '0'
                    "
                    type="primary"
                    round
                    @click="fnJudgeToStrengthen(item)"
                >
                  加强学习
                </button>
                <button
                    class="cu-btn round bg-blue"
                    v-show="item.STUDYSTATE <= '1' && item.STATE === '5'"
                    @click="fnJudgeSignature(item)"
                >
                  立即学习
                </button>
                <button
                    class="cu-btn round bg-green"
                    v-show="
                      item.STUDYSTATE === '2' &&
                      item.STATE !== '6' &&
                      item.EXAMINATION === 1 &&
                      item.STAGEEXAMSTATE === '1' &&
                      item.ksCount < item.NUMBEROFEXAMS
                    "
                    @click="fnStageExam(item)"
                >
                  立即考试
                </button>
              </view>
            </view>
          </view>
        </view>
        <view v-if="list.length===0" class="dy-null">
          <view class="dy-null-img">
            <image src="../../../static/null.png" mode=""></image>
          </view>
          <view class="dy-null-title">
            暂无数据
          </view>
        </view>
      </scroll-view>
    </view>
    <view class="cu-modal" :class="modalName=='Modal'?'show':''">
      <landscape-sign @confirm="subCanvas" @cancel="hideModal"></landscape-sign>
    </view>
  </view>
</template>

<script>
import LandscapeSign from "@/components/landscape_sign/index.vue";
import {basePath, loginUser} from "@/common/tool";

export default {
  components: {
    LandscapeSign,
  },
  data() {
    return {
      list: [],
      showCount: 10,
      currentPage: 1,
      totalPage: 0,
      modalName: '',
      CLASS_ID: '',
      POST_ID: '',
      STAGESTUDENTRELATION_ID: '',
      STUDENT_ID: '',
    }
  },
  onShow() {
    this.list = []
    this.currentPage = 1
    this.totalPage = 0
    this.showCount = 10
    this.getData()
  },
  methods: {
    scrolltolower() {
      this.currentPage++
      if (this.totalPage >= this.currentPage) {
        this.getData()
      }
    },
    getData() {
      uni.showLoading({
        title: '请稍候'
      })
      uni.request({
        url: basePath + '/app/stagestudentrelation/pageTaskByUser',
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          CORPINFO_ID: loginUser.CORPINFO_ID,
          USER_ID: loginUser.USER_ID,
          showCount: this.showCount,
          currentPage: this.currentPage,
        },
        success: (res) => {
          uni.hideLoading(); //结束加载中动画
          var resData = res.data;
          if ("success" == resData.result) {
            for (let i = 0; i < resData.varList.length; i++) {
              resData.varList[i].second = (new Date(resData.varList[i].END_TIME.replace(/-/g, '/')).getTime() - new Date().getTime()) / 1000
            }
            this.list = [...this.list,...resData.varList];
          }
        }
      });
    },
    fnJudgeSignature(item) {
      if (item.STUDYSTATE === "0") {
        this.CLASS_ID = item.CLASS_ID;
        this.POST_ID = item.POST_ID;
        this.STAGESTUDENTRELATION_ID = item.STAGESTUDENTRELATION_ID;
        this.STUDENT_ID = item.STUDENT_ID;
        this.modalName = 'Modal';
      } else {
        this.fnNavigationCurriculumSchedule(
            item.CLASS_ID,
            item.POST_ID,
            item.STUDENT_ID
        );
      }
    },
    fnJudgeToStrengthen({CLASS_ID,POST_ID,STUDENT_ID}){
      uni.navigateTo({
        url: `/pages/application/onlinexxks/strengthen_video_study?CLASS_ID=${CLASS_ID}&POST_ID=${POST_ID}&STUDENT_ID=${STUDENT_ID}`,
      });
    },
    hideModal() {
      this.modalName = ''
    },
    subCanvas({base64}) {
      uni.showLoading({
        title: '请稍候'
      })
      uni.request({
        url: basePath + '/app/stagestudentrelation/sign',
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          FFILE:base64,
          STUDYSTATE: 1,
          CLASS_ID: this.CLASS_ID,
          STAGESTUDENTRELATION_ID: this.STAGESTUDENTRELATION_ID,
          USER_ID: loginUser.USER_ID,
          OPERATOR: loginUser.NAME,
        },
        success: (res) => {
          uni.hideLoading(); //结束加载中动画
          var result = res.data.result;
          if ("success" == result) {
            this.hideModal()
            this.fnNavigationCurriculumSchedule(this.CLASS_ID, this.POST_ID, this.STUDENT_ID)
          }
        }
      });
    },
    fnNavigationCurriculumSchedule(CLASS_ID, POST_ID, STUDENT_ID) {
      uni.navigateTo({
        url: `/pages/application/onlinexxks/curriculum_schedule?CLASS_ID=${CLASS_ID}&POST_ID=${POST_ID}&STUDENT_ID=${STUDENT_ID}`,
      });
    },
    fnStageExam(item){
      uni.navigateTo({
        url:'/pages/application/onlinexxks/course_exam?STAGEEXAMPAPERINPUT_ID=' + item.STAGEEXAMPAPERINPUT_ID+'&STAGEEXAMPAPER_ID='+item.STAGEEXAMPAPERINPUT_ID+'&CLASS_ID='+item.CLASS_ID+'&POST_ID='+ item.POST_ID+'&STUDENT_ID='+item.STUDENT_ID+'&NUMBEROFEXAMS='+ item.NUMBEROFEXAMS+'&entrySite=list'
      })
    }
  },
}
</script>

<style scoped lang="scss">
.container {
  box-sizing: border-box;
  padding: 0 20upx 20upx;

  .studies_wrap {
    width: 100%;
    padding: 0 20upx;
    background: #ffffff;
    border-radius: 10upx;
    box-sizing: border-box;
    margin-top: 20upx;

    .studies_wrap-top {
      width: 100%;
      display: flex;
      justify-content: space-between;
      border-bottom: 1upx solid #eee;
      padding: 20upx 0;

      .studies_wrap_title {
        font-weight: bold;
        font-size: 30upx;
      }

      .studies_wrap_state {
        font-size: 30upx;
        flex-basis: 130upx;
        margin-left: 20upx;
      }
    }

    .studies_wrap-main {
      line-height: 50upx;
      margin-top: 10upx;
      font-size: 30upx;
      color: #666;
    }

    .studies_wrap-bottom {
      width: 100%;
      display: flex;
      border-top: 1upx solid #eee;
      padding: 20upx 0;
      margin-top: 10upx;
      font-size: 30upx;
      color: #999;
      justify-content: space-between;
      align-items: center;

      .flex {
        display: flex;
        align-items: center;

        image {
          width: 40upx;
          height: 42upx;
        }

        view {
          margin-left: 10upx;
        }
      }
    }
  }

  .fcb {
    color: #3377ff;
  }

  .fcg {
    color: #33c76d;
  }

  .fch {
    color: #999;
  }
}
</style>