<template>
  <div class="sorted-cart-wrapper">
    <div class="cart-header">
      <span class="title">已选项目课程（共{{this.cartList.length}}节）</span>
      <span class="sub">可上下拖拽课程行，调整课程在列表页的展示顺序</span>
    </div>

    <div v-if="projectId && (isPreview == 1 || projectStatus != 1)" class="cart-list">
      <div class="cart-course is-preview"  v-for="(item, index) in cartList" :key="index">
        <div class="img">
          <img :src="item.courseImageUrl" alt />
          <span class="level">{{item.typeStr}}</span>
        </div>
        <div class="detail">
          <span class="title">{{item.courseName | shortName}}</span>
          <div class="chapter">
            <span>{{item.docName | shortName(5)}}</span>
            <span class="section-num">{{item.chapterSum}}章{{item.lectureNum}}节 {{item.totalTime}}分</span><span v-if="true" class="exam-num">{{item.testCount}}场考试</span>
          </div>
        </div>
        <div class="handler">
          <img src="../../../assets/custom/icon/icon-handle.png" alt />
        </div>
      </div>
    </div>

    <draggable v-else class="cart-list" v-model="cartList">
      <div class="cart-course" v-for="(item, index) in cartList" :key="index">
        <div class="img">
          <img :src="item.courseImageUrl" alt />
          <span class="level">{{item.typeStr}}</span>
        </div>
        <div class="detail">
          <span class="title">{{item.courseName | shortName}}</span>
          <div class="chapter">
            <span>{{item.docName}}</span>
            <span class="section-num">{{item.chapterSum}}章{{item.lectureNum}}节 {{item.totalTime}}分</span><span v-if="item.testCount" class="exam-num">{{item.testCount}}场考试</span>
          </div>
        </div>
        <div class="handler">
          <img src="../../../assets/custom/icon/icon-handle.png" alt />
        </div>
      </div>
    </draggable>
  </div>
</template>
<script>
import draggable from "vuedraggable";
export default {
  data() {
    return {};
  },
  props: {
    isPreview: String | Number,
    projectStatus: String | Number,
    projectId: String | Number,
  },
  computed: {
    cartList: {
      get() {
        return this.$store.state.customStore.cartList;
      },
      set(value) {
        this.$store.dispatch("setCartList", value);
      }
    }
  },

  components: {
    draggable
  },
  methods: {}
};
</script>
<style lang="less" scoped>
.sorted-cart-wrapper {
  position: relative;
  top: 0;
  left: 0;
  z-index: 1;
  font-family: PingFang SC !important;
  width: 480px;
  height: 790px;
  background: #fff;
  box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  .mask {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    width: 440px;
    height: 790px;
    // background: ;
  }
  .cart-header {
    display: flex;
    flex-direction: column;
    height: 70px;
    padding: 0 15px;
    background: #f9f9f9;
    .title {
      padding: 15px 0 28px 0;
      height: 18px;
      line-height: 18px;
      font-size: 18px;
      font-weight: 700;
      color: #000000;
    }
    .sub {
      height: 14px;
      line-height: 14px;
      font-size: 14px;
      font-weight: 400;
      color: #999999;
    }
  }
  .cart-list {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    height: 710px;
    overflow: auto;
    .cart-course {
      cursor: pointer;
      user-select: none;
      position: relative;
      display: flex;
      flex-direction: row;
      // width: 410px;
      margin: 15px;
      align-items: center;
      border-radius: 4px;
      &.is-preview {
        cursor: default;
      }
      &::after {
        position: absolute;
        left: 0;
        bottom: -15px;
        z-index: 1;
        content: "";
        width: 100%;
        height: 1px;
        background: #e4e7ed;
      }
      .img {
        position: relative;
        top: 0;
        left: 0;
        width: 120px;
        height: 68px;
        margin-right: 15px;
        img {
          width: 120px;
          height: 68px;
          border-radius: 4px;
        }
        .level {
          position: absolute;
          top: 0;
          left: 0;
          width: 44px;
          height: 22px;
          line-height: 22px;
          text-align: center;
          font-size: 14px;
          font-weight: 500;
          color: #fff;
          background: rgba(0, 0, 0, 0.5);
          border-radius: 4px 0px 4px 0px;
        }
      }
      .detail {
        position: relative;
        display: flex;
        flex-direction: column;
        flex: 1;
        height: 60px;
        .title {
          position: relative;
          top: -5px;
          left: 0;
          font-size: 16px;
          line-height: 20px;
          font-weight: 600;
          color: #373839;
        }
        .chapter {
          position: absolute;
          bottom: -15px;
          left: 0;
          font-size: 14px;
          font-weight: 400;
          color: #999999;
          .section-num::before,
          .exam-num::before {
            content: "";
            position: relative;
            top: 2.5px;
            left: 0;
            display: inline-block;
            height: 14px;
            line-height: 14px;
            margin: 0 10px;
            width: 1px;
            background: #999999;
          }
        }
      }
      .handler {
        cursor: pointer;
        width: 35px;
        img {
          // cursor: pointer;
          width: 20px;
          height: 20px;
          float: right;
        }
      }
    }
  }
}
</style>