<template>
  <!-- 审核 -->
  <div class="product-details">
    <div class="message">
      <div>
        <el-image :src="data.picture_url" />
      </div>
      <div class="text">
        <p class="p1">
          {{ data.name }}
        </p>
        <!-- <p class="p2">
          <span>xx课程</span>
        </p> -->
        <p class="p3">
          {{ data.teacher_list.length > 0 ? data.teacher_list[0].teacher_name : '' }}
        </p>
      </div>
      <div class="price">
        <p>¥ {{ data.price }}</p>
      </div>
    </div>
    <div class="total">
      <p class="total-price">
        <span> 一件商品，总金额： </span>
        <span class="co-value">¥ {{ data.price }}</span>
      </p>
      <p class="discount">
        <span> 优惠折扣： </span>
        <span class="co-value">-¥ {{ discount_money }}</span>
      </p>
      <p class="p4">
        <span></span>
        <span class="co-value useCode">使没使用优惠码</span>
      </p>
      <p class="payable">
        <span> 应付： </span>
        <span class="co-value">¥ {{ receivables_money }}</span>
      </p>
    </div>
    <div class="submitBtn">
      <div class="text">
        <img src="../../assets/course_details/auditimg.png" alt="" />
        参加本课程学习需提交申请，审核通过后完成付款即可参加学习。
      </div>
      <button @click="buy">提交申请</button>
    </div>
  </div>
</template>

<script>
import { ApplyJoinCourse } from '@/api/course';

export default {
  props: {
    data: {
      default: () => {
        return {};
      },
      type: Object
    },
    id: {
      default: '',
      type: String
    },
    goodsType: {
      default: '201',
      type: String
    }
  },
  data() {
    return {
      discount_code: '', // 优惠码
      discount_money: 0.0, // 优惠金额
      receivables_money: this.data.price // 应收款
    };
  },
  // 方法集合
  methods: {
    // 提交申请
    buy() {
      ApplyJoinCourse({
        course_id: this.id, // 课程 ID
        discount_code: this.discount_code // 优惠码 （目前暂时没有用到）
      }).then(() => {
        this.$message.success('申请加入课程成功');
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.product-details {
  .message {
    width: 656px;
    height: 152px;
    background: rgba(70, 70, 70, 0.03);
    border-radius: 8px;
    display: flex;

    .el-image {
      width: 120px;
      height: 120px;
      margin-left: 16px;
      margin-top: 16px;
    }

    .text {
      margin-left: 24px;

      .p1 {
        width: 360px;
        max-height: 48px;
        font-size: 16px;
        line-height: 20px;
        color: #2c2c2c;
        margin-top: 22px;
        word-break: break-all;
        // 多行文本的情况下，用省略号 “...” 隐藏超出范围的文本
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        overflow: hidden;
      }

      .p2 {
        margin-top: 10px;

        span {
          width: 64px;
          height: 24px;
          background: #ffefd8;
          border-radius: 4px;
          font-weight: bold;
          font-size: 12px;
          text-align: center;
          color: $basicColor;
          line-height: 24px;
          padding: 2px 8px;
        }
      }

      .p3 {
        margin-top: 10px;
      }
    }

    .price {
      p {
        margin-left: 67px;
        margin-top: 22px;
        font-weight: bold;
        font-size: 16px;
        text-align: right;
        color: #ff4c00;
      }
    }
  }

  .promotionCode {
    display: flex;
    justify-content: flex-start;
    align-self: center;
    width: 100%;
    margin-top: 24px;
    height: 58px;
    line-height: 56px;
    border-top: 1px solid rgba(44, 44, 44, 0.15);
    border-bottom: 1px solid rgba(44, 44, 44, 0.15);

    .sp1 {
      font-size: 16px;
      color: #000;
    }

    input {
      padding: 0 24px;
      flex: 1;
      height: 56px;
      outline: none;
      border: none;
      box-sizing: border-box;
    }

    .sp2 {
      cursor: pointer;
      font-size: 16px;
      color: $basicColor;
    }
  }

  .total {
    width: 656px;
    text-align: right;
    color: #000;
    font-size: 16px;
    padding-top: 24px;

    .useCode {
      font-size: 12px;
      color: rgba(0, 0, 0, 0.5);
    }

    > p {
      > span {
        display: inline-block;
      }

      .co-value {
        width: 160px;
      }
    }

    &-price > span {
      line-height: 24px;
    }

    .discount {
      margin: 16px 0 10px;
    }

    .payable {
      > span {
        line-height: 36px;
      }

      .co-value {
        font-size: 24px;
        color: #ff4c00;
      }
    }
  }

  .submitBtn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;

    .text {
      width: 520px;
      height: 40px;
      background: #ff6c69;
      border-radius: 4px;
      color: white;
      display: flex;
      align-items: center;

      img {
        width: 24px;
        margin-left: 18px;
        margin-right: 10px;
      }
    }

    button {
      width: 120px;
      height: 40px;
      background: $basicColor;
      border-radius: 4px;
      color: white;
      line-height: 40px;
      border: none;
      cursor: pointer;
    }
  }
}
</style>
