<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">
                <text class="mon_t">¥ {{ item.standPrice }}</text>
                <text v-if="item.linePrice" class="sale"> ¥ </text>
                <text v-if="item.linePrice" class="price_line"
                  >&nbsp;{{ 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({ scene }) {
    this.courseList = [];
    if (scene) {
      let optObj = {};
      let arrs = decodeURIComponent(scene).split("&");
      for (let i = 0; i < arrs.length; i++) {
        optObj[arrs[i].split("=")[0]] = arrs[i].split("=")[1];
      }
      this.$store.commit("setSac", optObj.sac);
      this.getCourseList(optObj.sharekey);
      this.shareActivityCode(optObj.sac);
    }
  },
  methods: {
    getCourseList(id) {
      this.$api.actGoodsList(id).then((res) => {
        if (res.data.code == 200) {
          this.courseList = res.data.data;
        } else {
          uni.showToast({
            title: res.data.msg,
            icon: "error",
          });
        }
      });
    },
    toBuy(item) {
      if (item.goodsType == 2) {
        uni.navigateTo({
          url: "/pages2/bank/detail?id=" + item.goodsId,
        });
      } else {
        uni.navigateTo({
          url:
            "/pages3/course/detail?id=" +
            item.goodsId +
            "&goodsType=" +
            item.goodsType,
        });
      }
    },
    shareActivityCode(sac) {
      let token = uni.getStorageSync("token");
      token &&
        uni.request({
          url: BASE_URL + "/app/user/edit/shareActivityCode",
          method: "POST",
          data: {
            shareActivityCode: sac,
          },
          header: {
            AuthorizationToken: "WX " + token,
            TenantId: tenantId,
          },
          success: (res) => {},
          fail: (err) => {},
        });
    },
  },
};
</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: 10rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;

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

          .mon_t {
            font-weight: bold;
            color: #fc3f3f;
            font-size: 36rpx;
          }

          .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;
          }
        }
      }
    }
  }
  .tip {
    text-align: center;
    color: #a7b0b8;
    padding: 16rpx 30rpx 0;
  }
}
</style>
