<template>
  <!-- 我的收藏-韩国馆专用 -->
  <view
    class="favoriteStyle"
    :style="{ height: contentHeight }"
    v-if="!isloading"
  >
    <u-tabs
      :list="list"
      :is-scroll="false"
      :current="current"
      @change="change"
      :active-color="mainColor"
    ></u-tabs>
    <template>
      <u-empty
        v-if="goodslist.length == 0"
        text="没有任何收藏哦~"
        mode="favor"
      ></u-empty>
      <view
        v-if="goodslist.length > 0"
        style="
          height: calc(100vh - 50px);
          width: calc(100vw - 20px);
          margin-left: 10px;
          overflow: hidden;
          padding-top: 10px;
        "
      >
        <scroll-view
          :scroll-y="true"
          :enable-back-to-top="true"
          :enable-flex="true"
          @scrolltolower="lower"
          style="height: 100%; padding-bottom: 0px"
        >
          <view class="u-good-list" v-if="current === 1">
            <u-row gutter="20">
              <u-col span="6" v-for="(cx, ci) in goodslist" :key="ci">
                <view class="good" @click="clickHandler(cx)">
                  <view class="good-img">
                    <image
                      mode="aspectFill"
                      :src="cx.BannerList[0]"
                      style="width: 100%; height: 100%"
                    />
                  </view>
                  <view class="good-name">
                    <text>{{ cx.SourceName }}</text>
                    <view class="SourceFullName">{{
                      cx.SourceFullName
                    }}</view></view
                  >
                  <!-- <view
                    class="good-info"
                    v-if="setting && setting.is_show_korea == 0"
                  >
                    <view class="price" :style="{ color: mainColor }"
                      >￥{{ cx.SellingPrice }}</view
                    >
                    <view class="sell">已售{{ cx.SalesNum }}件</view>
                    <view class="cart" @click.stop="showSkuHandler(cx)">
                      <u-icon name="cart-o" size="40" :color="mainColor" />
                    </view>
                  </view> -->
                </view>
              </u-col>
            </u-row>
          </view>
          <view v-if="current === 0">
            <view v-for="(item, index) in goodslist" :key="index">
              <div
                class="good_study_one"
                @click="openGood(item.Id, item.ProjectType)"
                :style="{
                  borderRadius: '15px',
                }"
              >
                <view class="img-box">
                  <view class="img-show">
                    <image
                      style="
                        width: 100%;
                        height: 100%;
                        border-radius: 10rpx 10rpx 0 0;
                      "
                      mode="aspectFill"
                      :src="item.BannerList[0]"
                    />
                  </view>
                </view>
                <div class="good-info">
                  <div class="good-name">
                    <div class="span-name">{{ item.SourceName }}</div>
                    <div class="span-type">
                      {{ item.ProjectType }}
                    </div>
                  </div>
                  <div class="good-price-info">
                    <u-icon name="location" color="#999" size="24"></u-icon>
                    <span class="price" style="margin-left: 5px">{{
                      item.Address
                    }}</span>
                  </div>
                </div>
              </div>
            </view>
          </view>
          <u-loadmore
            :status="status"
            :load-text="loadText"
            :font-size="24"
            :margin-top="20"
            :margin-bottom="20"
            bg-color="#f3f4f6"
          />
        </scroll-view>
      </view>
    </template>
    <good-sku
      v-if="showSku"
      :option-type="2"
      borderRadius="20"
      v-model="showSku"
      :good="sku"
    ></good-sku>
    <auth
      v-if="showAuth"
      @changeuserinfo="reloadUserinfo"
      @gbAuth="gbAuth"
    ></auth>
  </view>
</template>

<script>
import auth from "../../components/auth/index.vue";
import goodSku from "../../components/goods/goodsku.vue";
export default {
  data() {
    return {
      pageTitle: "我的收藏",
      loading: true,
      contentHeight: 0,
      showAuth: false,
      mainColor: "",
      list: [{ name: "载体" }, { name: "品牌" }],
      msg: {
        pageIndex: 1,
        pageSize: 10,
        // Name: "",
      },
      sku: {},
      showSku: false,
      goodslist: [],
      topiclist: [],
      current: 0,
      page_count: 1,
      status: "loadmore",
      loadText: {
        loadmore: "轻轻上拉，加载更多",
        loading: "努力加载中",
        nomore: "没有更多了",
      },
      setting: {},
      typeList: [],
    };
  },
  components: {
    auth,
    goodSku,
  },
  created() {
    this.contentHeight = this.$utils.calcContentHeight(-40) + "px";
    this.mainColor = this.$uiConfig.mainColor;
    this.setting = uni.getStorageSync("basedata").mall.setting;
  },
  mounted() {
    let currentPages = getCurrentPages();
    let u = "/" + currentPages[currentPages.length - 1].route;
    let pages = wx.getStorageSync("basedata")
      ? wx.getStorageSync("basedata").bar_title
      : [];
    pages.forEach((x) => {
      if (x.value == u) {
        this.pageTitle = x.new_name ? x.new_name : x.name;
      }
    });
    uni.setNavigationBarTitle({
      title: this.pageTitle,
    });
  },
  onLoad() {
    this.u = uni.getStorageSync("mall_UserInfo");
    if (!this.u) {
      this.u = {
        nickName: "未登录",
        avatarUrl: "",
      };
      this.showAuth = true;
    } else {
      this.getList();
    }
  },

  methods: {
    // 购物车
    showSkuHandler(g) {
      g.id = g.Id;
      console.log("g", g);
      this.sku = g;
      this.showSku = true;
    },
    change(index) {
      this.current = index;
      this.msg.pageIndex = 1;
      this.goodslist = [];
      this.getList();
    },

    getList() {
      uni.showLoading({
        title: "加载中",
      });
      this.request2(
        {
          url: "/api/AppletTrade/GetMyCollectPage  ",
          data: { ...this.msg, ...{ Type: this.current + 1 } },
        },
        (res) => {
          uni.hideLoading();

          if (res.resultCode == 1) {
            this.goodslist = this.goodslist.concat(res.data.pageData);
            this.page_count = res.data.pageCount;
            console.log(209, this.goodslist);
            if (this.page_count == 1) {
              this.status = "nomore";
            }
          }
        }
      );
    },
    reloadUserinfo() {
      this.u = uni.getStorageSync("mall_UserInfo");
      // this.showAuth=false;
      this.getList();
    },
    //关闭登录窗口
    gbAuth() {
      uni.navigateBack();
    },
    clickHandler(cx) {
      uni.navigateTo({
        url: "/pages/kotra/brand/detail?id=" + cx.SourceId,
      });
    },
    lower(e) {
      if (this.msg.pageIndex < this.page_count) {
        this.msg.pageIndex++;
        this.status = "loading";
        this.getList();
      } else {
        this.status = "nomore";
      }
    },
    openGood(id, type) {
      uni.navigateTo({
        url: "/pages/kotra/carrier/detail?id=" + id + "&&type=" + type,
      });
    },
  },
};
</script>

<style >
.favoriteStyle {
  background: #f3f4f6;
}

.favoriteStyle .u-good-list .good {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}
.favoriteStyle .u-good-list .good .good-img {
  width: calc(50vw - 15px);
  height: calc(50vw - 15px);
  display: block;
}
.favoriteStyle .u-good-list .good .good-name {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 3px;
  font-size: 13px;
  margin: 7px 10px;
  height: 36px;
}
.favoriteStyle .u-good-list .good .good-info {
  display: flex;
  margin: 7px 10px;
  margin-top: 0;
  align-items: flex-end;
  padding-bottom: 5px;
}
.favoriteStyle .u-good-list .good .good-info .price {
  font-size: 14px;
  color: #ff4544;
  flex: 1;
}
.favoriteStyle .u-good-list .good .good-info .sell {
  font-size: 11px;
  color: gray;
  flex: 1;
}
.favoriteStyle .u-good-list .good .good-info .cart {
  width: 40rpx;
  text-align: right;
}
.SourceFullName {
  color: #999999;
  font-size: 22rpx;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.good_study_one {
  margin: 12px;
  position: relative;
  border: 1rpx solid transparent;
  border-radius: 10rpx;
  overflow: hidden;
}

.good_study_one .tips {
  width: 64rpx;
  height: 64rpx;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
}

.good_study_one .guding {
  position: relative;
}

/* .good_study_one .guding .img-box {
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
	} */
.good_study_one .img-box {
  width: 100%;
  height: 0;
  padding-top: 49%;
  position: relative;
  overflow: hidden;
}

.good_study_one .img-box .img-show {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.good_study_one .good-info {
  padding: 12px;
  background-color: #fff;
}

.good_study_one .good-info .good-name {
  display: flex;
  align-items: center;
}
.good_study_one .good-info .good-name .span-name {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: 28rpx;
  font-weight: bold;
  color: #111;
  padding-bottom: 5px;
  flex: 1;
}
.good_study_one .good-info .good-name .span-type {
  font-weight: 500;
  color: #999999;
  font-size: 24rpx;
  margin-left: 10px;
}
.good_study_one .good-info .good-price-info {
  display: flex;
}

.good_study_one .good-info .good-price-info .price {
  color: #999999;
  font-size: 24rpx;
  flex: 1;
}

.good_study_one .good-info .good-price-info .buy {
  width: 24px;
  text-align: right;
}
</style>
