<template>
  <transition mode="out-in" appear>
    <div class="goodlist" v-show="tagclick.type == 'goodlist'">
      <div class="head-pages">
        <div>
          <span>{{ current + 1 }}</span><span>/{{ tagclick.data.products ? tagclick.data.products.length : "-" }}</span>
        </div>
        <ui-icon @click.stop="close" type="state_f"></ui-icon>
      </div>
      <div class="swiper-container" id="goodlist">
        <ul class="swiper-wrapper">
          <li class="swiper-slide" v-for="(i, index) in tagclick.data.products" :key="index">
            <div>
              <!-- <viewimg :list="[i.pic]" :keyid="`viewimg_${index + 1}`" /> -->
              <img :src="i.pic" alt="">
              <div class="info">
                <p>{{ i.name }}</p>

              </div>
              <div class="goods-button">
                <span v-if="i.saleChannel == 1" class="tipss">{{ $t('common.onlyOffLine') }}</span>
                <template v-else>
                  <div @click.stop="viewDetail(i)">{{ $t('common.viewDetail') }}</div>
                </template>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </transition>
</template>

<script setup>
import { onMounted, watch, toRaw, computed, defineEmits, ref, defineProps, nextTick } from "vue";
import { useApp, getApp } from "@/app";
import { useStore } from "vuex";
import * as apis from "@/apis/index.js";
import { Loading, Dialog } from "@/global_components/";
import browser from "@/utils/browser";
import viewimg from "@/views/viewimg";

import { useI18n, getLocale } from '@/i18n'
const { t } = useI18n({ useScope: 'global' })


// get_product_info
const store = useStore();
const isshoppingguide = computed(() => store.getters["shoppingguide"]);

const tagclick = computed(() => store.getters["tag/tagClickType"]);

const emit = defineEmits(["close"]);

const current = ref(0);

const mysw = ref(null);

const viewDetail = (item) => {
  if (isshoppingguide.value) {
    return;
  }
  apis.burying_point({ type: 3, productId: item.id });

  browser.openLink(item.url)

};


const close = () => {
  emit("close");
};

const brandScroll = () => {
  nextTick(() => {
    let t = setTimeout(() => {
      clearTimeout(t);
      mysw.value = new Swiper("#goodlist", {
        effect: "coverflow",
        grabCursor: true,
        centeredSlides: true,
        slidesPerView: "auto",
        coverflowEffect: {
          rotate: 0,
          stretch: -40,
          depth: 100,
          modifier: 1,
          slideShadows: false,
        },
        on: {
          touchMove(swiper, e) {
            e.stopPropagation();
            e.preventDefault();
          },
          slideChangeTransitionEnd(swiper, e) {
            current.value = swiper.activeIndex
          },

        },
      });
    }, 100);
  });
};

onMounted(() => {
  brandScroll();
});
</script>

<style lang="scss" scoped>
.goodlist {
  position: fixed;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: 500px;
  z-index: 101;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;

  .head-pages {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    width: 76%;

    >div {
      span {
        font-size: 14px;

        &:last-of-type {
          color: rgba(255, 255, 255, 0.5);
        }
      }
    }

    >i {
      color: rgba(0, 0, 0, 1);
      font-size: 20px;
    }
  }

  #goodlist {
    width: 100%;
    overflow: hidden;
    padding-right: 2px;
    position: relative;

    >ul {
      >li {
        width: 76%;
        border-radius: 2px;
        position: relative;
        font-size: 0;
        overflow: hidden;

        >div {
          background: #fff;
          padding-bottom: 14px;

          >img{
            width: 100%;
          }

          .info {
            font-size: 14px;
            color: #131d34;
            padding: 16px 20px;

            >p {
              font-size: 16px;
              width: 100%;
              line-height: 1.5;
              word-break: break-all;
            }

            >div {
              color: var(--editor-main-color);
              padding: 8px 0px 10px;
              border-bottom: 1px solid #ebebeb;

              >span {
                font-size: 16px;

                &:first-of-type {
                  font-size: 12px;
                  margin-right: 4px;
                }
              }
            }

            >ul {
              padding: 12px 0;
              border-bottom: 1px solid #ebebeb;

              >li {
                margin: 10px 0;
                color: #909090;

                &:last-of-type {
                  display: flex;
                  justify-content: space-between;
                  align-items: center;
                }

                >span {
                  font-size: 12px;
                }

                >ul {
                  display: block;

                  >li {
                    display: inline-block;

                    >span {
                      display: inline-block;
                      border: 1px solid #ebebeb;
                      padding: 2px 4px;
                      min-width: 73px;
                      height: 30px;
                      line-height: 30px;
                      margin: 8px 8px 0 0;
                      text-align: center;
                      border-radius: 4px;
                      font-size: 12px;
                    }

                    &.active {
                      >span {
                        border: solid 1px var(--editor-main-color);
                        color: var(--editor-main-color);
                      }
                    }
                  }
                }

                .number {
                  display: flex;

                  i {
                    font-size: 12px;
                    border: 1px solid #ebebeb;
                    padding: 2px 8px;
                    border-radius: 15px;
                  }

                  input {
                    max-width: 40px;
                    text-align: center;
                    color: #131d34;
                  }
                }
              }
            }
          }

          .goods-button {
            display: flex;
            justify-content: space-between;
            font-size: 16px;
            padding: 0 20px;

            >div {
              height: 42px;
              background: #ff8e24;
              border-radius: 4px;
              width: 100%;
              text-align: center;
              line-height: 42px;

              &:last-of-type {
                background: var(--editor-main-color);
              }
            }

            .tipss {
              color: #909090;
              display: inline-block;
              margin: 0 auto;
            }
          }
        }
      }
    }
  }
}
</style>
