<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-form ref="curriculumddForm" :model="updateCurriculum" label-position="left" label-width="120px"
              style='margin-left:20px'>
      <el-row :gutter="24" >
        <el-col :xs="23" :sm="23" :md="12" :lg="8" :xl="8">
          <div class="grid-content bg-purple">
            <el-form-item  :label="$t('college.c_name')" >
              <div class="block">
                <el-input style="width: 100%;"  :disabled=true class="filter-item" v-model="updateCurriculum.c_name" >
                </el-input>
              </div>
            </el-form-item>
          </div>
        </el-col>
        <el-col :xs="23" :sm="23" :md="11" :lg="8" :xl="8">
          <div class="grid-content bg-purple" >
            <el-form-item  :label="$t('college.c_type')">
              <div class="block">
                <el-select style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.c_type" @change="contentChange()">
                  <el-option v-for="item in contentOption"  :key="item.wct_code" :label="item.wct_name" :value="item.wct_code" >
                  </el-option>
                </el-select>
              </div>
            </el-form-item>
          </div>
        </el-col>
        <el-col :xs="23" :sm="23" :md="12" :lg="7" :xl="7">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('college.c_step')">
                <el-select style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.c_step">
                  <el-option v-for="item in wcTypeOption" :key="item.value" :label="item.label" :value="item.value" >
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
        </el-col>
      </el-row>
      
      <el-row :gutter="24" >
        <el-col :xs="23" :sm="23" :md="12" :lg="8" :xl="8">
          <div class="grid-content bg-purple">
            <el-form-item  :label="$t('college.istest')">
              <div class="block">
                <el-switch :disabled=true v-model="updateCurriculum.istest" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
              </div>
            </el-form-item>
          </div>
        </el-col>
        <el-col :xs="23" :sm="23" :md="12" :lg="8" :xl="8">
          <div class="grid-content bg-purple">
            <el-form-item  :label="$t('college.c_desc')" :disabled=true>
              <div class="block">
                <el-input style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.c_desc">
                </el-input>
              </div>
            </el-form-item>
          </div>
        </el-col>
        <el-col :xs="23" :sm="23" :md="11" :lg="7" :xl="7">
          <div class="grid-content bg-purple" >
            <el-form-item  :label="$t('college.credit')">
              <div class="block">
                <el-input-number style="width: 100%;" :disabled=true controls-position="right" class="filter-item" v-model="updateCurriculum.credit">
                </el-input-number>
              </div>
            </el-form-item>
          </div>
        </el-col>
        
      </el-row>
      <el-row :gutter="24" >
        <el-col :xs="23" :sm="23" :md="12" :lg="8" :xl="8">
          <div class="grid-content bg-purple">
            <el-form-item  :label="$t('college.isvideo')" >
              <div class="block">
                <el-switch :disabled=true v-model="updateCurriculum.isvideo" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
              </div>
            </el-form-item>
          </div>
        </el-col>
        <el-col :xs="23" :sm="23" :md="11" :lg="8" :xl="8">
          <div class="grid-content bg-purple" >
            <el-form-item  :label="$t('college.video_href')">
              <div class="block">
                 <el-input  style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.video_href" >
                </el-input>
              </div>
            </el-form-item>
          </div>
        </el-col>
        <el-col :xs="23" :sm="23" :md="12" :lg="7" :xl="7">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('college.video_length')">
                <el-input  style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.video_length" >
                </el-input>
              </el-form-item>
            </div>
        </el-col>
      </el-row>
      <el-row :gutter="24" >
        <el-col :xs="23" :sm="23" :md="12" :lg="8" :xl="8">
          <div class="grid-content bg-purple">
            <el-form-item  :label="$t('college.t_name')">
              <div class="block">
                <el-input style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.t_name" >
                </el-input>
              </div>
            </el-form-item>
          </div>
        </el-col>
        <el-col :xs="23" :sm="23" :md="11" :lg="8" :xl="8">
          <div class="grid-content bg-purple" >
            <el-form-item  :label="$t('college.t_desc')">
              <div class="block">
                <el-input style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.t_desc" >
                </el-input>
              </div>
            </el-form-item>
          </div>
        </el-col>
        <el-col :xs="23" :sm="23" :md="12" :lg="7" :xl="7">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('college.t_image_href')">
                <el-input style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.t_image_href" >
                </el-input>
              </el-form-item>
            </div>
        </el-col>
      </el-row>

      <el-row :gutter="24" >
        <el-col :xs="23" :sm="23" :md="12" :lg="8" :xl="8">
          <div class="grid-content bg-purple">
            <el-form-item  :label="$t('college.img_list_href')">
              <div class="block">
                <el-input style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.img_list_href" >
                </el-input>
              </div>
            </el-form-item>
          </div>
        </el-col>
        
        <el-col :xs="23" :sm="23" :md="11" :lg="8" :xl="8">
          <div class="grid-content bg-purple" >
            <el-form-item  :label="$t('college.img_head_href')">
              <div class="block">
                <el-input style="width: 100%;" :disabled=true class="filter-item" v-model="updateCurriculum.img_head_href" >
                </el-input>
              </div>
            </el-form-item>
          </div>
        </el-col>
      </el-row>

      <el-row :gutter="24" >
        <el-col :xs="23" :sm="23" :md="23" :lg="23" :xl="23">
          <div class="grid-content bg-purple">
            <el-form-item  :label="$t('college.c_content')">
              <div class="editor-container">
                <el-input :disabled="true" type="textarea"  autosize ref="tinymce-comment"  v-model="updateCurriculum.c_content"></el-input>
              </div>
            </el-form-item>
          </div>
        </el-col>
        
      </el-row>
      </el-form>
    </div>
  </div>
</template>
<script>
  import waves from '@/directive/waves' // 水波纹指令
  import { parseTime } from '@/utils'
  import { getWXContentTypes } from '@/api/wxmini'
  import { getCollegeCurriculumCore } from '@/api/college'
  // 富文本
  import Tinymce from '@/components/Tinymce'
  import Upload from '@/components/Upload/singleImage3'
  import MDinput from '@/components/MDinput'
  import Multiselect from 'vue-multiselect'// 使用的一个多选框组件，element-ui的select不能满足所有需求
  import Sticky from '@/components/Sticky' // 粘性header组件
  export default {
    // name: 'curriculumcoreadd', // 不支持keep-alive
    components: { Tinymce, MDinput, Upload, Multiselect, Sticky },
    directives: {
      waves
    },
    data() {
      return {
        tableKey: 0,
        buttonloading: false,
        contentOption: [],
        wcTypeOption: [],
        view: {
          name: undefined,
          path: undefined,
          title: undefined
        },
        updateCurriculum: {
          c_name: null,
          c_type: null,
          c_step: null,
          isvideo: false,
          video_href: null,
          istest: false,
          credit: null,
          video_length: null,
          img_list_href: null,
          img_head_href: null,
          c_desc: null,
          c_content: null,
          t_image_href: null,
          t_name: null,
          t_desc: null,
          create_user: null
        },
        dialogPvVisible: false,
        video_status: null,
        test_status: null,
        pvData: [],
        downloadLoading: false
      }
    },
    created() {
      getWXContentTypes().then(response => {
        this.contentOption = response.data
      })
      this.video_status = false
      this.getList()
    },
    destroyed() {
      this.view.name = 'curriculumcoreshow'
      this.view.path = '/college/curriculumcoreshow'
      this.view.title = 'curriculumcoreshow'
      this.$store.dispatch('delVisitedViews', this.view)
    },
    methods: {
      getList() {
        var queryPara = {
          id: this.$route.params.contentID
        }
        getCollegeCurriculumCore(queryPara).then(response => {
          this.updateCurriculum.id = this.$route.params.contentID
          this.updateCurriculum.c_name = response.data.c_name
          this.updateCurriculum.c_type = response.data.c_type
          this.updateCurriculum.c_step = response.data.c_step
          this.updateCurriculum.istest = response.data.istest
          this.updateCurriculum.c_desc = response.data.c_desc
          this.updateCurriculum.credit = response.data.credit
          this.updateCurriculum.isvideo = response.data.isvideo
          this.updateCurriculum.video_href = response.data.video_href
          this.updateCurriculum.video_length = response.data.video_length
          this.updateCurriculum.t_name = response.data.t_name
          this.updateCurriculum.t_desc = response.data.t_desc
          this.updateCurriculum.t_image_href = response.data.t_image_href
          this.updateCurriculum.img_list_href = response.data.img_list_href
          this.updateCurriculum.img_head_href = response.data.img_head_href
          this.updateCurriculum.c_content = response.data.c_content
          this.wcTypeOption = this.range(1, response.data.wct_step, 1)
        })
      },
      range(start, end, step) {
        var arr = []
        for (let i = start; i <= end; i++) {
          var tempOption = {
            label: null,
            value: null
          }
          if (i % step === 0) {
            tempOption.value = i
            tempOption.label = i
            arr.push(tempOption)
          }
        }
        return arr
      },
      formatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => {
          if (j === 'timestamp') {
            return parseTime(v[j])
          } else {
            return v[j]
          }
        }))
      }
    }
  }
</script>
<style>
.el-form--label-left .el-form-item__label{
  text-align:right
}
.el-rate{
  line-height: 0;
  margin-top:8px;
}
.el-checkbox.el-checkbox {
    margin-left: 30px;
}
</style>
<style rel="stylesheet/scss" lang="scss" scoped>
  @import "src/styles/mixin.scss";
  .title-prompt{
    position: absolute;
    right: 0px;
    font-size: 12px;
    top:10px;
    color:#ff4949;
  }
  .createPost-container {
    position: relative;
    .createPost-main-container {
      padding: 40px 45px 20px 50px;
      .postInfo-container {
        position: relative;
        @include clearfix;
        margin-bottom: 10px;
        .postInfo-container-item {
          float: left;
        }
      }
      .editor-container {
        min-height: 500px;
        margin: 0 0 30px;
        .editor-upload-btn-container {
            text-align: right;
            margin-right: 10px;
            .editor-upload-btn {
                display: inline-block;
            }
        }
      }
    }
    .word-counter {
      width: 40px;
      position: absolute;
      right: -10px;
      top: 0px;
    }
  }
</style>