<template>
  <div>
    <div class="con-title">我的重修</div>
    <template v-if="isNext">
      <div class="con-box">
        <h1 style="text-align: center; font-size: 25px;">关于紫荆—玛丽伍德MBA项目课程重修安排的通知</h1>
        <h3>紫荆-玛丽伍德FMBA同学：</h3>
        <p>
          根据《清控紫荆（北京）教育科技股份有限公司学生学籍管理规定》和玛丽伍德大学相关学籍管理规定及结合本学期教学工作安排，现将紫荆-玛丽伍德FMBA学生课程重修工作安排如下：
        </p>
        <h3>一、重修对象</h3>
        <p>紫荆-玛丽伍德FMBA课程考核不及格申请重修者,其中中方和美方每门课程成绩均要求在80分及以上为及格。</p>
        <h3>二、重修规则</h3>
        <p>（一）课程重修成绩按学期记载；</p>
        <p>（二）一门课程重修累计不得超过1次；</p>
        <p>（三）一门课程重修时间不能超过3个月；</p>
        <p>（四）一门课程重修成绩覆盖原成绩；</p>
        <p>（五）重修费用：1000元/学分*每门课程实际学分；</p>
        <p>（六）一门课程重修需要在3个月内完成学习任务，考核规则与之前相同；</p>
        <p>（七）一门课程重修1次没有通过，将不能获得课程学分，影响毕业和取得学位证书。</p>
        <h3>三、重修安排</h3>
        <h3>（一）重修时间安排</h3>
        <h3>1、课程重修科目为挂科科目，重修时间参考学期课程安排</h3>
        <h3>2、特别提示：</h3>
        <p>有不及格课程未能在毕业前完成重修或者重修课程依旧不及格者将不能如期毕业。</p>
        <h3>（二）申请方式：</h3>
        <p>
          申请重修的同学可以在学习平台我的学分栏目点击“重修申请”，仔细阅读重修通知，点击”申请“。下载重修申请表，填写并上传重修申请表及缴费凭证，即日起先办理完缴费可提前开通重修课程。
        </p>
        <h3>（三）重修费用缴纳方式：</h3>
        <p>1、银行汇款</p>
        <p>户名：清控紫荆（北京）教育科技股份有限公司</p>
        <p>开户行：中国民生银行北京魏公村支行</p>
        <p>帐号： 694485289</p>
        <!-- <p>备注：{{info.class_name}}{{info.semester_name}}+{{name}}+{{info.course_name}}</p> -->
        <p>备注：姓名+课程</p>
        <p>2、支付宝转账</p>
        <p>支付宝账号：service@ezijing.com</p>
        <!-- <p>备注：{{info.class_name}}{{info.semester_name}}+{{name}}+{{info.course_name}}</p> -->
        <p>备注：姓名+课程</p>
        <p>3、缴费后联系班主任老师确认重修申请及缴费信息。</p>
        <el-button style="display: block; margin: 0 auto;" type="success" size="medium" @click="nextPage" plain
          >同意申请</el-button
        >
      </div>
    </template>
    <template v-else>
      <div class="con-box">
        <el-row type="flex" justify="center">
          <el-col :xs="24" :sm="24" :md="16" :lg="12" :xl="8">
            <el-form ref="setSubmitForm" :label-width="labelWidth">
              <el-form-item label="重修申请表" prop="file">
                <el-upload
                  ref="upFile"
                  class="upload-demo"
                  action=""
                  :multiple="false"
                  :limit="1"
                  :show-file-list="false"
                  :on-change="handleChange1"
                  :http-request="uploadFile1"
                  :file-list="filesArr1"
                >
                  <el-button size="mini" type="primary">点击上传</el-button>
                  <div slot="tip" class="el-upload__tip">
                    （请下载重修申请表，填写完整再上传）<a
                      href="https://zws-imgs-pub.oss-cn-beijing.aliyuncs.com/static/public/713efef7718281271b2ad3eea135e327.docx"
                      >模板下载</a
                    >
                  </div>
                  <template v-if="successFileUrl1">
                    {{ successFileUrl1.replace(/.*\/([^\/]*\.[^.]+)$/gi, '$1') }}
                  </template>
                </el-upload>
                <template v-if="successFileUrl1"> 下载已上传的 <a :href="successFileUrl1">文件附件</a> </template>
              </el-form-item>
              <el-form-item label="缴费凭证" prop="file">
                <el-upload
                  ref="upFile"
                  class="upload-demo"
                  action=""
                  :multiple="false"
                  :limit="1"
                  :show-file-list="false"
                  :on-change="handleChange2"
                  :http-request="uploadFile2"
                  :file-list="filesArr2"
                >
                  <el-button size="mini" type="primary">点击上传</el-button>
                  <div slot="tip" class="el-upload__tip">缴费请尽量填写备注：班级期数+学生姓名+重修课程名称</div>
                  <template v-if="successFileUrl2">
                    {{ successFileUrl2.replace(/.*\/([^\/]*\.[^.]+)$/gi, '$1') }}
                  </template>
                </el-upload>
                <template v-if="successFileUrl2"> 下载已上传的 <a :href="successFileUrl2">图片附件</a> </template>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="goSubmit">保存并提交</el-button>
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>
      </div>
    </template>
  </div>
</template>

<script>
import cAction from '@action'

export default {
  components: {},
  data() {
    const info = JSON.parse(window.localStorage.getItem('rebuild') || '{}')
    if (!info.course_name) {
      this.$message('禁止直接打开该页面。')
      this.$router.push({ path: '/' })
    }
    return {
      labelWidth: '110px',
      isNext: true,
      name: (window.G && window.G.UserInfo && window.G.UserInfo.realname) || '[姓名]',
      info: info,
      successFileUrl1: '',
      filesArr1: [],
      file1: {},
      successFileUrl2: '',
      filesArr2: [],
      file2: {}
    }
  },
  mounted() {},
  methods: {
    nextPage() {
      // this.isNext = false
      this.$router.push({ path: '/app/offices', query: { channel: 'retake' } })
    },
    handleChange1(file, filelist) {
      this.file1.name = file.raw.name
      this.file1.type = file.raw.type
      this.file1.lastModifiedDate = file.raw.lastModifiedDate
      this.file1.size = file.raw.size
      this.file1.file = file.raw
    },
    uploadFile1() {
      const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
      cAction.Other.uploadFile(this.file1)
        .then(data => {
          this.successFileUrl1 = data.url
          this.filesArr1.pop()
        })
        .catch(e => {
          this.filesArr1.pop()
          this.$message.error(e.message)
        })
        .finally(() => {
          loading.close()
        })
    },
    handleChange2(file, filelist) {
      this.file2.name = file.raw.name
      this.file2.type = file.raw.type
      this.file2.lastModifiedDate = file.raw.lastModifiedDate
      this.file2.size = file.raw.size
      this.file2.file = file.raw
    },
    uploadFile2() {
      const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
      cAction.Other.uploadFile(this.file2)
        .then(data => {
          this.successFileUrl2 = data.url
          this.filesArr2.pop()
        })
        .catch(e => {
          this.filesArr2.pop()
          this.$message.error(e.message)
        })
        .finally(() => {
          loading.close()
        })
    },
    goSubmit() {
      if (!this.successFileUrl1) {
        this.$message.error('重修申请表未上传！')
        return
      }
      if (!this.successFileUrl2) {
        this.$message.error('缴费凭证未上传！')
        return
      }
      const obj = {
        course_id: this.info.course_id,
        semester_id: this.info.semester_id,
        apply: this.successFileUrl1,
        payorder: this.successFileUrl2
      }
      const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
      cAction.Grade.rebuildSubmit(obj)
        .then(data => {
          if (data.success) {
            // 提交 重修后，删除localstorage
            window.localStorage.removeItem('rebuild')
            this.$message.success('重修申请提交成功！')
            this.$router.push({ path: '/app/grade/credit' })
          }
        })
        .catch(e => {
          this.$message.error(e.message)
        })
        .finally(() => {
          loading.close()
        })
    }
  }
}
</script>

<style lang="scss" scoped></style>
