<template>
  <view class="scan_course">
    <nav-bar title="商品列表" class="navbar"></nav-bar>
    <view class="list_item" v-for="(item, index) in courseList" :key="index">
      <view class="course_content">
        <view class="c_title">{{ item.goodsName }}</view>
        <view class="c_downs">
          <view class="img">
            <image :src="$method.splitImgHost(item.coverUrl, true)"></image>
            <view class="time" v-if="item.year">{{
              item.year ? item.year : ""
            }}</view>
          </view>
          <view class="text">
            <view class="desc">
              <view class="left">
                <view
                  class="priceTag"
                  v-if="
                    !item.specTemplateId || (!item.maxPrice && !item.minPrice)
                  "
                >
                  {{ item.standPrice === 0 ? "免费" : `￥${item.standPrice}` }}
                </view>
                <!-- 范围价格 -->
                <view v-else class="priceTag">
                  <view>{{ item.minPrice }}</view>
                  <template v-if="item.minPrice != item.maxPrice">
                    <text>-</text>
                    <view>{{ item.maxPrice }}</view>
                  </template>
                </view>
                <text v-if="item.linePrice" class="sale">¥ </text>
                <text v-if="item.linePrice" class="price_line">
                  {{ item.linePrice }}</text
                >
              </view>
              <view class="right">
                <view class="regiser_row" @click="toBuy(item)">立即购买</view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <!-- <view class="tip"
      >温馨提示：在线课程属虚拟商品，活动期间购买不予退款，请按需购买</view
    > -->
  </view>
</template>

<script>
import { tenantId, BASE_URL } from "@/common/request.js";
export default {
  data() {
    return {
      courseList: [],
    };
  },
  onLoad(options) {
    this.options = options;
    this.getCourseList();
  },
  methods: {
    getCourseList() {
      this.$api.fxGoodsList(this.options.distributionId).then((res) => {
        if (res.data.code == 200) {
          this.courseList = res.data.data;
        } else {
          this.$u.toast(res.data.msg);
        }
      });
    },
    addParam(item) {
      let str = "?id=" + item.goodsId + "&goodsType=" + item.goodsType;
      if (this.options.distributionCode) {
        str += "&distributionCode=" + this.options.distributionCode;
      }
      if (this.options.linkCode) {
        str += "&distributionCode=" + this.options.linkCode;
      }
      return str;
    },
    toBuy(item) {
      if (item.goodsType == 2) {
        uni.navigateTo({
          url: "/pages2/bank/detail" + this.addParam(item),
        });
      } else {
        uni.navigateTo({
          url: "/pages3/course/detail" + this.addParam(item),
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.scan_course {
  padding: 32rpx 32rpx 0;

  .list_item {
    padding: 24rpx;
    // height: 278rpx;
    background: #ffffff;
    box-shadow: 0rpx 0rpx 20rpx 1rpx rgba(1, 99, 235, 0.1);
    border-radius: 24rpx;
    background: #fff;
    margin-bottom: 32rpx;
    display: flex;
    align-items: center;

    .c_title {
      font-size: 32rpx;
      font-weight: bold;
      margin-bottom: 24rpx;
      font-weight: bold;
      color: #222222;
    }

    .c_downs {
      display: flex;
    }

    .img {
      position: relative;
      margin-right: 24rpx;
      border-radius: 16rpx;
      overflow: hidden;
      width: 204rpx;
      height: 120rpx;

      image {
        width: 100%;
        height: 100%;
      }

      .time {
        position: absolute;
        bottom: 0;
        right: 0;
        width: 80rpx;
        height: 32rpx;
        background: rgba(1, 25, 45, 0.4);
        color: #fff;
        text-align: center;
        line-height: 32rpx;
        font-size: 24rpx;
        border-radius: 10rpx 0px 10rpx 0px;
      }
    }

    .text {
      width: 440rpx;
      position: relative;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      height: 120rpx;

      .desc {
        margin-top: 20rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;

        .left {
          flex: 1;
          color: #333;
          font-size: 26rpx;

          .sale {
            color: #999999;
            font-size: 24rpx;
            margin-left: 8rpx;
          }

          .price_line {
            color: #999999;
            font-size: 24rpx;
            text-decoration: line-through;
            font-weight: 400;
          }
        }

        .right {
          font-size: 24rpx;
          font-weight: bold;
          padding-right: 20rpx;

          .regiser_row {
            width: 144rpx;
            height: 52rpx;
            line-height: 52rpx;
            text-align: center;
            border-radius: 16rpx;
            background-color: #fc3f3f;
            color: #fff;
            font-weight: 500;
            font-size: 26rpx;
          }
        }
      }
    }

    .priceTag {
      display: flex;
      font-size: 32rpx;
      font-family: PingFang SC;
      font-weight: bold;
      color: #fc3f3f;
      view::before {
        content: "￥";
        font-size: 24rpx;
        font-weight: bold;
      }
    }
  }
  .tip {
    text-align: center;
    color: #a7b0b8;
    padding: 16rpx 30rpx 0;
  }
}
</style>
