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

    <!-- <draggable v-model="myArray" class="cart-list"> -->
    <draggable class="cart-list" v-model="cartList">
      <div class="cart-course" v-for="item in cartList" :key="item.courseId">
        <div class="img">
          <img src="../../../assets/custom/test.png" 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>
          </div>
        </div>
        <div class="handler">
          <img src="../../../assets/custom/icon/icon-handle.png" alt />
        </div>
      </div>
    </draggable>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import draggable from "vuedraggable";
export default {
  data() {
    return {};
  },
  computed: {
    // ...mapGetters(["cartList"]),
    cartList: {
      get() {
        console.log('get()');
        return this.$store.state.customStore.cartList;
      },
      set(value) {
        console.log('set(value)', value);
        this.$store.dispatch("setCartList", value);
      }
    }
  },

  components: {
    draggable
  },
  methods: {}
};
</script>
<style lang="less" scoped>
.sorted-cart-wrapper {
  font-family: PingFang SC !important;
  width: 440px;
  height: 790px;
  background: #fff;
  box-shadow: 0px 0px 30px 0px rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  .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;
      &::after {
        position: absolute;
        left: 0;
        bottom: -15px;
        z-index: 1;
        content: "";
        width: 410px;
        height: 1px;
        background: #e4e7ed;
      }
      .img {
        position: relative;
        top: 0;
        left: 0;
        width: 120;
        height: 68px;
        margin-right: 15px;
        img {
          width: 120;
          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: -16px;
          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 {
        width: 35px;
        img {
          cursor: pointer;
          width: 20px;
          height: 20px;
          float: right;
        }
      }
    }
  }
}
</style>