<template>
  <div class="curricula-manager">
    <div class="curricula-manager-header">
      <el-input
        v-model="input"
        placeholder="请输入"
        suffix-icon="el-icon-search"
        @keyup.enter.native="search"
      ></el-input>
    </div>
    <div class="curricula-manager-body">
      <div class="curricula-manager-body-button">
        <el-button
          v-for="(item, i) in statusList"
          :key="i"
          :class="['bg-color', { active: curTab === i }]"
          @click="selectTab(item.status, i)"
        >
          {{ item.val }}
        </el-button>
      </div>
      <div class="curricula-manager-body-sort">
        <div>
          <span>排序:</span>
          <span v-for="item in sortList" :key="item.id" class="sort-body">
            {{ item.name }}
            <i class="el-icon-sort"></i>
          </span>
        </div>
        <el-button class="add-course" @click="$router.push('/add_course')">
          {{ $t('Learn_New_Courses') }}
        </el-button>
      </div>
    </div>
    <div class="curricula-manager-item">
      <div v-for="item in courseList" :key="item.id">
        <div class="circulation">
          <div class="curricula-manager-item-value">
            <span>{{ item.name }}</span>
            <!-- <span>{{ item.val }}</span> -->
          </div>
          <div class="curricula-manager-item-create">
            <span>{{ item.begin_date }}</span>
            <span class="date-horizontal-bar">-</span>
            <span>{{ item.end_date }}</span>
            <!-- <span class="curricula-manager-item-teacher">授课教师：{{ item.teacher }}</span> -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { updateWordPack } from '@/utils/i18n';
import { pageQueryMyCourseList } from '@/api/table';

export default {
  name: 'CurriculaManager',
  data() {
    return {
      input: '',
      curTab: 0,
      status: '1',
      sortList: [
        {
          id: '1',
          name: '创建时间',
          sortType: 'createTime', // 数组对象中的哪一个属性进行排序
          order: false // 升序还是降序
        },
        {
          id: '2',
          name: '编辑时间',
          sortType: 'editTime',
          order: false
        },
        {
          id: '3',
          name: '开课时间',
          sortType: 'onclassTime',
          order: false
        }
      ],
      statusList: [
        {
          status: '1',
          val: '进行中'
        },
        {
          status: '2',
          val: '待开始'
        },
        {
          status: '3',
          val: '已结束'
        }
      ],
      courseList: []
    };
  },
  created() {
    this.search();
    updateWordPack({
      word_key_list: ['Learn_New_Courses']
    });
  },
  methods: {
    selectTab(status, i) {
      this.status = status;
      this.curTab = i;
      this.search();
    },
    search() {
      const queryCriteria = {
        finish_status: this.status,
        page_capacity: 200,
        cur_page: 1
      };
      pageQueryMyCourseList(queryCriteria).then(response => {
        this.courseList = response.course_list;
      });
    }
  }
};
</script>

<style lang="scss">
$main-w: 953px;

.curricula-manager {
  &-header .el-input {
    width: 244px;
    height: 40px;
    margin: 37px auto 0;
    display: block;
  }

  &-body-button {
    display: flex;
    justify-content: center;
    margin-top: 35px;
    font-size: 16px;

    .el-button {
      width: 97px;
      height: 52px;
    }
    .el-button + .el-button {
      margin-left: 0;
    }
  }

  &-body-sort {
    display: flex;
    justify-content: space-between;
    width: $main-w;
    line-height: 40px;
    margin: 25px auto 15px;

    .add-course {
      @extend .bg-color;
    }
  }

  .bg-color {
    background: #c4c4c4;
    border: 1px solid #c4c4c4;
    border-radius: 0;
    color: #000;

    &.active {
      background: #e6e6e6;
      border-color: #0c0c0c;
    }
  }

  .sort-body {
    margin-left: 20px;
    cursor: pointer;
  }

  &-item {
    .circulation {
      margin: 0 auto 10px;
      width: $main-w;
      height: 92px;
      background-color: #eee;
      padding: 20px 20px 0;
    }
    &-value {
      display: flex;
      justify-content: space-between;
    }
    .date-horizontal-bar {
      margin: 0 15px;
    }
    &-create {
      padding-top: 20px;
    }
    &-teacher {
      margin-left: 40px;
    }
  }
}
</style>
