<template>
  <div>
    <div class="container normal-panel normal-margin">
      <el-button type="warning" size="small" icon="el-icon-s-claim" @click="onSubmit">保 存
      </el-button>
    </div>
    <div style="overflow:hidden">
      <el-row :gutter="16">
        <el-col :span="12">
          <div class="container normal-panel normal-margin">
            <p class="normal-title normal-margin" style="line-height:32px">课程设置</p>
            <el-row :gutter="20">
              <el-form :model="form" size="small" status-icon label-position="left" label-width="100px"
                class="demo-ruleForm">
                <el-col :span="24">
                  <el-form-item label="标题">
                    <el-input v-model="form.title" placeholder="请输入标题"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="开始时间">
                    <el-date-picker style="width:100%" v-model="form.begdate" value-format="yyyy-MM-dd" type="date"
                      placeholder="开始日期">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="下架时间">
                    <el-date-picker style="width:100%" v-model="form.enddate" value-format="yyyy-MM-dd" type="date"
                      placeholder="下架日期">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="一级分类">
                    <el-select style="width:100%;margin-right:16px" size="small" v-model="form.class" clearable>
                      <el-option v-for="item in options1" :key="item.index" :value="item.sat_courseware_classid"
                        :label="item.classname" @click.native="handelSelectClick(item)"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="二级分类">
                    <el-select style="width:100%;margin-right:16px" size="small" v-model="form.sat_courseware_classid"
                      clearable>
                      <el-option v-for="item in options2" :key="item.index" :value="item.sat_courseware_classid"
                        :label="item.classname"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="备注">
                    <el-input v-model="form.title" placeholder="请输入标备注"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="封面">
                    <upload btntype="limage" :folderid="folderid" accept=".JPG,.PNG"
                      :bindData="{ ownertable: 'SAT_COURSEWARE', ownerid: '', usetype: 'cover' }"></upload>
                    <p class="info">注：建议上传图片大小210*120px像素，大小不超过2M，格式为JPG/PNG</p>
                  </el-form-item>
                </el-col>
              </el-form>
            </el-row>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import upload from '@/components/upload/hw_obs_upload.vue'
export default {
  components: {
    upload
  },
  data() {
    return {
      options1: [],
      options2: [],
      folderid: JSON.parse(sessionStorage.getItem('folderid')).appfolderid,
      form: {
        "sat_coursewareid": 0,
        "title": "",
        "sat_courseware_classid": '9999' + JSON.parse(sessionStorage.getItem('active_account')).userid,
        "notes": "",
        "canfiledownload": 1,
        "begdate":(new Date()).toLocaleDateString(),
        "enddate":(new Date()).toLocaleDateString(),
        "tag":[]
      }
    }
  },
  methods: {
    async onSubmit() {
      const res = await this.$api.requested({
        "classname": "webmanage.saletool.courseware.courseware",
        "method": "insertOrUpdate",
        "content": this.form
      })
      res.code === 1 ? this.$router.replace({ path: '/archives_scedit', query: { id: res.data.sat_coursewareid } }) : ''
    },
    // 分类查询
    async coursewareclass() {
      const res = await this.$api.requested({
        "classname": "webmanage.saletool.courseware.coursewareclass",
        "method": "select",
        "content": {
          "parentid": 0
        }
      })
      this.options1 = res.data
    },
    handelSelectClick(val) {
      this.options2 = val.children
      this.params.content.where.sat_courseware_classid_2 = ''
    }
  },
  mounted() {
    this.coursewareclass()
    this.onSubmit()
  }
}

</script>
<style>
</style>