allocation.vue 9.07 KB
<template>
  <div class="container">
    <div class="left">
      <div class="title-type">
        <div
          :class="['type', titleActiveIndex == index ? 'active' : '']"
          v-for="(item, index) in titleTypeList"
          :key="index"
          @click="handleTitleClick(index)"
        >
          {{ item.title }}
        </div>
      </div>
      <div class="content gl-form-page">
        <el-form :inline="true" :model="courseForm" class="form-inline">
          <el-form-item>
            <el-input
              prefix-icon="el-icon-search"
              v-model="courseForm.tagSearch"
              placeholder="课程/标签搜索"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="search" size="small"
              >查询</el-button
            >
            <el-button @click="resetForm" size="small">重置</el-button>
          </el-form-item>
        </el-form>
        <el-checkbox-group v-model="selected" @change="handleCheckedChange">
          <el-checkbox
            v-for="course in courseList"
            :key="course.id"
            :label="course.courseId"
          >
            <div class="title">{{ course.courseName }}</div>
            <el-tooltip
              effect="light"
              placement="top"
              popper-class="tools-gltip"
            >
              <div slot="content" class="process-info">
                <div v-if="course.status">
                  学习进度:<span>
                    {{ statusObj[course.status] }}
                  </span>
                </div>
                <div>
                  考核成绩:<span>{{ course.totalScore || 0 }}分</span>
                </div>
                <div>
                  完成时间:<span>{{ course.finishDate || "-" }}</span>
                </div>
              </div>
              <div class="status orange" v-if="course.status">
                {{ statusObj[course.status] }}
              </div>
            </el-tooltip>
          </el-checkbox>
        </el-checkbox-group>
      </div>
    </div>
    <div class="right">
      <div class="title-type">
        <div class="select">已选课程</div>
        <div class="time">
          共{{ selectObj.count }}节 {{ selectObj.courseTotalDuration }}min
        </div>
      </div>
      <div class="reminder">
        <img
          class="error-circle"
          src="../../images/error-circle.png"
        />提示:总课程时长建议< 60 min
      </div>
      <div class="select-list">
        <div
          class="select-item"
          v-for="(selectCourse, index) in selectCourseList"
          :key="selectCourse.courseId"
        >
          <div class="item-content">
            {{ selectCourse.courseName
            }}<span class="item-time"
              >{{ selectCourse.courseTotalDuration }}min</span
            >
          </div>
          <div class="del" @click="delCourse(selectCourse)">删除</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getStaffTagCourseList } from "@/api/serviceCentre"
export default {
  name: "allocation",
  data() {
    return {
      courseForm: {
        tagSearch: "",
        queryAll: false
      },

      selected: [],
      selectCourseList: [],
      titleActiveIndex: 0,
      titleTypeList: [
        { title: "推荐课程", queryAll: false },
        { title: "自选课程", queryAll: true }
      ],
      cityOptions: ["上海", "北京", "广州", "深圳"],
      statusObj: {
        1: "未学习",
        2: "未完成",
        3: "待考核",
        4: "未通过",
        5: "已完成"
      },
      selectObj: {
        courseTotalDuration: 0,
        count: 0
      }
    }
  },
  props: {
    courseList: {
      type: Array,
      default: () => []
    }
  },
  mounted() {
    console.log(this.courseList, "courseList")
  },
  methods: {
    reset() {
      this.selected = []
      this.selectCourseList = []
    },
    handleCheckedChange(val) {
      console.log(val)
      this.selected = val ? val : []
      this.handleCourse()
    },
    handleCourse() {
      this.selectObj = {
        courseTotalDuration: 0,
        count: 0
      }
      this.selectCourseList = this.courseList.filter((item) => {
        const isSelected = this.selected.includes(item.courseId)
        if (isSelected) {
          this.selectObj.courseTotalDuration += item.courseTotalDuration
          this.selectObj.count += 1
        }
        return isSelected
      })
      this.$emit("handleCourse", this.selectCourseList)
    },
    delCourse(val) {
      this.selectObj = {
        courseTotalDuration: 0,
        count: 0
      }
      let currentIndex = this.selectCourseList.findIndex(
        (item) => item.courseId == val.courseId
      )
      let selectedIndex = this.selected.findIndex(
        (item) => item == val.courseId
      )
      this.selected.splice(selectedIndex, 1)
      this.selectCourseList.splice(currentIndex, 1)
      this.selectCourseList.forEach((item) => {
        this.selectObj.courseTotalDuration += item.courseTotalDuration
        this.selectObj.count += 1
      })
      this.$emit("handleCourse", this.selectCourseList)
    },
    handleTitleClick(index) {
      this.titleActiveIndex = index
      this.courseForm.queryAll = this.titleTypeList[index].queryAll
      console.log(this.courseForm, " this.courseForm")
      this.search()
    },
    resetForm() {
      this.courseForm.tagSearch = ""
      this.search()
    },
    search() {
      this.$EventBus.$emit("fromAllocation", this.courseForm)
    }
  }
}
</script>
<style scoped lang="scss">
.container {
  display: flex;
  align-content: center;
  .left {
    width: 383px;
    height: 468px;
    border: 1px solid #e5e5e5;
  }
  .right,
  .left {
    width: 383px;
    height: 468px;
    border: 1px solid #e5e5e5;
  }
  .right {
    margin-left: 20px;
    .title-type {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 40px;
      box-sizing: border-box;
      padding: 10px 16px;
      border-bottom: 1px solid #e5e5e5;
      background: #f5f6fa;
      .select {
        color: #333333;
        font-size: 14px;
      }
      .time {
        color: #666666;
        font-size: 14px;
      }
    }
    .reminder {
      height: 32px;
      display: flex;
      align-items: center;
      padding: 6px 11px;
      box-sizing: border-box;
      color: #666666;
      font-size: 12px;
      font-weight: 400;
      background: #fef4e8;
      border-bottom: 1px solid #e5e5e5;
      .error-circle {
        width: 14px;
        height: 14px;
        margin-right: 8px;
      }
    }
    .select-list {
      height: 365px;
      overflow-y: auto;
      overflow-x: hidden;
      .select-item {
        display: flex;
        align-items: center;
        border-bottom: 1px solid #e5e5e5;
        .item-content {
          color: #333333;
          font-size: 14px;
          line-height: 20px;
          padding: 14px 16px;
          white-space: wrap;
          border-right: 1px solid #e5e5e5;
          min-width: 284px;
        }
        .item-time {
          font-size: 12px;
          color: #666666;
        }
        .del {
          padding: 0 18px;
          color: #2a58ad;
          font-size: 14px;
          white-space: nowrap;
        }
      }
    }
  }
  .left {
    .title-type {
      display: flex;
      align-items: center;
      height: 40px;
      padding: 0px 16px;
      border-bottom: 1px solid #e5e5e5;
      background: #f5f6fa;
      .type {
        padding: 10px;
        line-height: 20px;
        color: #666666;
        font-size: 14px;
        margin-right: 10px;
        cursor: pointer;
      }
      .active {
        color: #2a58ad;
        border-bottom: 2px solid #2a58ad;
      }
    }
    .content {
      padding: 16px 7px 16px 16px;
    }
  }
  .gl-form-page {
    .form-inline {
      margin-bottom: 16px;
    }
    .el-form-item__content {
      height: 32px;
    }
    .el-form .el-button {
      width: 52px;
      height: 32px;
    }
    ::v-deep {
      .el-checkbox-group {
        height: 365px;
        overflow-y: auto;
        overflow-x: hidden;
      }
      .el-checkbox {
        margin-right: 0px;
        display: flex;
        align-items: center;
        margin-bottom: 16px;
      }
      .el-checkbox__label {
        display: flex;
        align-items: center;
        color: #333333;
        font-size: 14px;
        .title {
          width: 268px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .status {
          padding: 2px 8px;
          font-size: 12px;
          font-weight: 500;
          border-radius: 2px;
        }
        .orange {
          color: #f59619;
          border: 1px solid #f59619;
        }
        .green {
          color: #2cca74;
          border: 1px solid #2cca74;
        }
      }
    }
  }
}

.tools-gltip {
  width: 238px !important;
  height: 95px !important;
  background: #fff;
  .process-info {
    width: 238px;
    height: 94px;
    color: #666666;
    font-size: 14px;
    div {
      margin-bottom: 8px;
      span {
        color: #333333;
      }
    }
  }
}
</style>