<template>
  <div class="handle-sync">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/resource' }">资源管理</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/resource/sync' }">同步资源</el-breadcrumb-item>
      <el-breadcrumb-item>{{ $route.query.id ? '编辑资源' : '添加资源' }}</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form :model="form" ref="form" :rules="rules" label-width="150px">
      <el-form-item label="资源名称：" prop="name">
        <el-input v-model="form.name" placeholder="输入资源名称" auto-complete="off" clearable></el-input>
      </el-form-item>
      <el-form-item
        label="上传人"
        v-if="$route.query.id"
      >{{form.createUserRealName}} {{form.createDate ? parseTime(form.createDate) : '--'}}</el-form-item>

      <el-form-item label="当前状态" v-if="$route.query.id">
        <span
          :class="{red: form.isAudited === 3,
						green: form.isAudited === 4,
						blue: form.isAudited === 2,
                		yellow: form.isAudited === 1}"
          v-html="showLabel(form.isAudited, schemaAuditedData)"
        ></span>
        / 浏览{{form.clickTotal || 0}}次，收藏{{form.enshrineTotal || 0}}次，下载{{form.downloadTotal || 0}}次
        <el-button
          type="text"
          class="red"
          @click="handleUnPublished"
          v-if="form.isAudited === 4"
        >取消发布</el-button>
        <el-button type="text" class="green" @click="handlePublished" v-else>发布</el-button>
      </el-form-item>
      <el-form-item label="审核人" v-if="$route.query.id">
        {{form.verifiedUserRealName}} {{form.verifiedDate ? parseTime(form.verifiedDate) : '--'}}
        <!-- 海淀区 - 清华附中 -  李娜（校管理员）   2018-11-13 17:09:04<br />
        海淀区 - 区教委 - 学习资源处 - 王垚（教研员）   2018-11-13 17:09:04-->
      </el-form-item>
      <el-form-item label="所属课程：" prop="semester">
        <section>
          <el-select
            v-model="form.semester"
            placeholder="选择学期"
            @change="selectSemester"
            clearable
            class="school-section"
          >
            <el-option
              :label="item.semesterName"
              :value="item.id"
              :key="key"
              v-for="(item, key) in semester"
            ></el-option>
          </el-select>
          <el-cascader
            placeholder="选择开课院系"
            v-model="form.academic"
            class="grade"
            @change="selectAcademic"
            filterable
            :options="academicList"
            :props="{ label: 'unitName', value: 'id', children: 'unitBaseInfoList'}"
            clearable
            change-on-select
          ></el-cascader>
          <el-select
            v-model="form.course"
            placeholder="选择课程（老师）"
            clearable
            filterable
            @change="selectCourse"
            class="school-section"
          >
            <el-option
              :label="item.snName"
              :value="item.courseId"
              :key="key"
              v-for="(item, key) in course"
            ></el-option>
          </el-select>
          <div class="clear"></div>
        </section>
      </el-form-item>
      <el-form-item label="所属目录：" prop="fileDir">
        <el-select
            v-model="form.courseLessonNum"
            placeholder="选择课时"
            style="float: left"
            class="class-lesson"
            :disabled="!form.course"
            @change="form.catalog=[]"
            clearable>
            <el-option
                :label="item.name"
                :value="item.id"
                :key="key"
                v-for="(item, key) in courseLessonData"
            ></el-option>
        </el-select>
        <el-cascader
          clearable
          class="class-lesson"
          :disabled="!form.courseLessonNum"
          placeholder="选择课程下的文件目录"
          :options="dirData"
          v-model="form.fileDir"
          @change="selectFileDir"
          filterable
          :props="{
		    	label: 'name',
		    	value: 'id',
				checkStrictly: true
		    }"
        ></el-cascader>
      </el-form-item>
      <!-- <el-form-item label="是否公开：" prop="ifOpen">
  	      <el-radio-group v-model="form.ifOpen">
              <el-radio :label="1">公开</el-radio>
			  <el-radio :label="0">不公开</el-radio>
          </el-radio-group>
      </el-form-item>-->
      <el-form-item label="类型：" prop="type">
        <el-radio-group v-model="form.type">
          <el-radio :label="Number(key)" :key="key" v-for="(item, key) in typeSchema">{{item.name}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="选择文件：" prop="file" ref="imgLoad">
        <el-upload
          class="upload-demo"
          :action="uploadUrl"
          :headers="{
			  	token: user.token
			  }"
          :on-remove="handleRemove"
          :on-success="handleSuccess"
          :before-upload="beforeUpload"
          :file-list="fileList"
        >
          <el-button size="small" type="primary">点击上传</el-button>
          <div
            slot="tip"
            class="el-upload__tip"
          >支持扩展名：.txt .doc .xls .pdf .ppt .jpg/jpeg .png .gif .bmp .mp4 .wmv .flv .f4v .avi .mp3 .wma</div>
        </el-upload>
      </el-form-item>
      <el-form-item label="状态：" prop="enabled">
        <el-radio-group v-model="form.enabled">
          <el-radio :label="1">启用</el-radio>
          <el-radio :label="0">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-button type="primary" @click="handleClick" class="save" :disabled="disabled">保 存</el-button>
      <el-button @click="cancel" class="cancel" :disabled="disabled">取 消</el-button>
    </el-form>
  </div>
</template>

<script src="./index.js"></script>
<style src="./index.scss" rel="stylesheet/scss" lang="scss"></style>