<template>
  <div
    :style="{
			'background-color': goodsInfo.backgroundColor,
			'background-image': goodsInfo.backgroundPicUrl,
			'border-color': goodsInfo.goodsStyle == 2 ? 'rgb(226, 226, 226)' : ''
		}"
  >
    <div
      v-for="(item, gli) in goodList"
      :key="gli"
      class="good-one"
      @click="openGood(item)"
      :style="{
				border: goodsInfo.goodsStyle == 2 ? '1px solid rgb(226, 226, 226)' : '',
				background: goodsInfo.goodsStyle == 1 || goodsInfo.goodsStyle == 2 ? '#FFF' : ''
			}"
    >
      <div class="tips" v-if="goodsInfo.showGoodsTag||goodsInfo.customizeGoodsTag">
        <image :src="goodsInfo.goodsTagPicUrl" mode="widthFix" style="width: 100%;" />
      </div>
      <image
        style="width: calc(100vw - 24px); height: 66vw;"
        :mode="goodsInfo.fill == 1 ? 'aspectFill' : 'aspectFit'"
        :src="item.picUrl"
        v-if="goodsInfo.goodsCoverProportion == '3-2'"
      />
      <image
        style="
          width: calc(100vw - 24px);
          height: 100vw;
          border-radius: 10rpx 10rpx 0 0;
        "
        v-if="goodsInfo.goodsCoverProportion == '1-1'"
        :mode="goodsInfo.fill == 1 ? 'aspectFill' : 'aspectFit'"
        :src="item.picUrl"
      />
      <div class="good-info">
        <div class="good-name" v-if="goodsInfo.showGoodsName">{{ item.name }}</div>
        <div class="good-price-info">
          <span class="price" :style="{ color: mainColor }">
            <text style="font-size:13px;margin-right:5px">￥</text>
            <text>{{ item.pintuanPrice }}</text>
          </span>
          <span class="buy" v-if="goodsInfo.showBuyBtn" @click.stop="showSkuHandler(item)">
            <u-icon name="cart-o" size="40" :color="mainColor" v-if="goodsInfo.buyBtn == 'cart'" />
            <u-icon
              name="add-o"
              size="40"
              :color="mainColor"
              v-else-if="goodsInfo.buyBtn == 'add'"
            />
            <u-button
              type="primary"
              size="mini"
              :ripple="true"
              :color="goodsInfo.buttonColor"
              :custom-style="btnStyle"
              :plain="goodsInfo.buyBtnStyle == 2 || goodsInfo.buyBtnStyle == 4"
              :shape="goodsInfo.buyBtnStyle == 3 || goodsInfo.buyBtnStyle == 4 ? 'circle' : 'square'"
              v-else
            >{{ goodsInfo.buyBtnText }}</u-button>
          </span>
        </div>
      </div>
    </div>
    <!-- <good-sku v-if="showSku" :option-type="2" borderRadius="20" v-model="showSku" :good="sku"></good-sku> -->
	<good-sku v-if="showSku&&u.TenantId!=27" :option-type="2" borderRadius="20" v-model="showSku" :good="sku"></good-sku>
	<good-sku2 v-if="showSku&&u.TenantId==27" :option-type="2" borderRadius="20" v-model="showSku" :good="sku"></good-sku2>
    <auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth="gbAuth"></auth>
  </div>
</template>

<script>
import goodSku from "../goods/goodsku";
import goodSku2 from "../goods/goodsku2";
import auth from "@/components/auth/index.vue";
export default {
  components: {
    goodSku,
	goodSku2,
    auth,
  },
  props: ["goodList", "goodsInfo"],
  data() {
    return {
      mainColor: "",
      activeKey: 0,
      showSku: false,
      sku: {},
      showAuth: false,
      u: {},
      btnStyle: {},
    };
  },
  created() {
	  this.u = uni.getStorageSync("mall_UserInfo");
    this.mainColor = this.$uiConfig.mainColor;
    this.btnStyle = {
      backgroundColor: this.goodsInfo.buttonColor ?? this.mainColor,
      color:
        this.goodsInfo.buyBtnStyle == 2 || this.goodsInfo.buyBtnStyle == 4
          ? this.goodsInfo.buttonColor
          : "#FFF",
    };
  },
  methods: {
    openGood(item) {
      uni.navigateTo({ url: "/pages/goods/goods?GoodsId=" + item.id });
    },
    showSkuHandler(g) {
      this.sku = g;
      this.u = uni.getStorageSync("mall_UserInfo");
      if (!this.u) {
        this.u = {
          nickName: "未登录",
          avatarUrl: "",
        };
        this.showAuth = true;
      } else {
        this.showSku = true;
      }
    },
    reloadUserinfo() {
      this.u = uni.getStorageSync("mall_UserInfo");
      // this.showAuth = false;
    },
    //关闭登录窗口
    gbAuth() {
      this.showAuth = false;
    },
  },
};
</script>

<style>
.good-one {
  margin: 12px;
  position: relative;
  border: 1rpx solid transparent;
  border-radius: 10rpx;
  padding-bottom: 10rpx;
  overflow: hidden;
}
.good-one .tips {
  width: 64rpx;
  height: 64rpx;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
}
.good-one .guding {
  position: relative;
}
.good-one .guding .img-box {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
}
.good-one .good-info {
  padding: 12rpx;
  padding-bottom: 0;
  margin-top: -5px;
}
.good-one .good-info .good-name {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 13px;
}
.good-one .good-info .good-price-info {
  display: flex;
}
.good-one .good-info .good-price-info .price {
  color: #ff4544;
  font-size: 14px;
  flex: 1;
}
.good-one .good-info .good-price-info .buy {
  width: 24px;
  text-align: right;
  flex: 1;
}
</style>
