<template>
  <view class="u-good-list">
    <u-row gutter="20">
      <u-col span="6" v-for="(cx, ci) in g" :key="ci">
        <view class="good" @click="clickHandler(cx)">
          <view class="good-img">
            <image
              mode="aspectFill"
              :src="cx.cover_pic"
              style="width: 100%; height: 100%;"
            />
          </view>
          <view class="good-name" v-if="setting.is_show_goods_name==1">{{ cx.name }}</view>
          <view class="good-info">
            <view class="price" :style="{ color: mainColor }">
			￥{{cx.price}}</view>
			<!-- v-if="setting.is_show_sales_num=='1'" -->
            <view class="sell">{{ cx.sales }}</view>
            <view v-if="setting.is_show_cart==1" class="cart" @click.stop="showSkuHandler(cx)">
              <u-icon name="cart-o" size="40" :color="mainColor" />
            </view>
          </view>
        </view>
      </u-col>
    </u-row>
    <good-sku
      v-if="showSku"
      :option-type="2"
      borderRadius="20"
      v-model="showSku"
      :good="sku"
    ></good-sku>
  </view>
</template>

<script>
import goodSku from "../goods/goodsku";
export default {
  components: {
    goodSku,
  },
  props: ["list"],
  data() {
    return {
      g: [],
      showSku: false,
      sku: {},
      mainColor: "",
      setting:{}
    };
  },
  mounted() {
    this.g = this.list;
    this.mainColor = this.$uiConfig.mainColor;
    this.initConfig()
  },
  watch: {
    list: {
      deep: true,
      immediate: true,
      handler: function (newVal, oldVal) {
        this.g = newVal;
      },
    },
  },
  methods: {
    initConfig() {
      this.setting = uni.getStorageSync("basedata").mall.setting
    },
    clickHandler(item) {
		console.log("GoodsId",item)
      uni.navigateTo({ url: '/pages/goods/goods?GoodsId='+item.id });
    },
    showSkuHandler(g) {
      this.sku = g;
      this.showSku = true;
    },
  },
};
</script>

<style>
.u-good-list .good {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}
.u-good-list .good .good-img {
  width: calc(50vw - 15px);
  height: calc(50vw - 15px);
  display: block;
}
.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;
}
.u-good-list .good .good-info {
  display: flex;
  margin: 7px 10px;
  margin-top: 0;
  align-items: flex-end;
  padding-bottom: 5px;
}
.u-good-list .good .good-info .price {
  font-size: 14px;
  color: #ff4544;
  flex: 1;
}
.u-good-list .good .good-info .sell {
  font-size: 11px;
  color: gray;
  flex: 1;
}
.u-good-list .good .good-info .cart {
  width: 40rpx;
  text-align: right;
}
</style>
