MobileProductDetail.vue 11.8 KB
<template>
  <div>
    <v-breadcrumbs
      divider="/"
      dense
      style="
        padding-top: 8px;
        font-size: 14px;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
      "
    >
      <template v-for="(item, index) in items" :key="index">
        <v-breadcrumbs-item
          :disabled="item.disabled"
          :href="item.href"
          :class="{
            'breadcrumb-last': index === items.length - 1,
          }"
          :style="
            index === items.length - 1
              ? 'color: black; font-weight: bold;'
              : 'color:black'
          "
        >
          {{ item.title }}
        </v-breadcrumbs-item>
        <span
          v-if="index < items.length - 1"
          class="breadcrumb-divider"
          style="margin: 0 4px; font-size: 14px"
          >/</span
        >
      </template>
    </v-breadcrumbs>
  </div>

  <v-container class="ma-0 pa-0 bg-grey-lighten-5">
    <v-carousel
      class="tw-float-left"
      height="450"
      v-model="slide"
      hide-delimiter-background
    >
      <v-carousel-item
        cover
        v-for="(slide, i) in info.productimageliststore"
        :src="slide.url"
        :key="i"
        :alt="info.name"
      >
      </v-carousel-item>
    </v-carousel>
    <h1 class="mb-3 bg-white mb-sm-10 text-h4 font-weight-medium pa-4">
      {{ info.name }}
    </h1>
    <v-row class="mx-4 mt-0 mb-4 bg-white rounded-lg">
      <v-col cols="6">
        <div class="text-body-1 text-grey-darken-3">Brand:</div>
        <div class="text-h6">{{ info.brandName }}</div>
      </v-col>
      <v-col cols="6">
        <div class="text-body-1 text-grey-darken-3">Product Model:</div>
        <div class="text-h6">{{ info.model }}</div>
      </v-col>
      <v-col cols="6" v-if="info.basename1">
        <div class="text-body-1 text-grey-darken-3">{{ info.basename1 }}:</div>
        <div class="text-h6">{{ info.basecore1 }}</div>
      </v-col>
      <v-col cols="6" v-if="info.basename2">
        <div class="text-body-1 text-grey-darken-3">{{ info.basename2 }}:</div>
        <div class="text-h6">{{ info.basecore2 }}</div>
      </v-col>
      <v-col cols="6" v-if="info.basename3">
        <div class="text-body-1 text-grey-darken-3">{{ info.basename3 }}:</div>
        <div class="text-h6">{{ info.basecore3 }}</div>
      </v-col>
    </v-row>
    <div
      v-if="info.ticketTypes?.length"
      class="py-4 mx-4 bg-white rounded-lg tw-flex tw-flex-wrap tw-justify-around"
    >
      <v-sheet
        v-for="item in info.ticketTypes || []"
        :key="item.rank"
        rounded="lg"
        border
        class="tw-w-[40%] mb-4"
      >
        <div
          class="tw-bg-[#dcecfa] tw-h-[64px] !tw-leading-[64px] rounded-lg rounded-b-0 pa-2 tw-text-center text-h6 tw-overflow-hidden tw-text-ellipsis"
        >
          {{ item.typeName }}
        </div>
        <div class="tw-h-[82px] pa-2">
          <div class="text-caption">Product Code</div>
          <div class="text-body-1 !tw-font-[500]">
            {{ item.rank }}
          </div>
        </div>
      </v-sheet>
      <v-btn
        size="large"
        color="blue-darken-1"
        @click="router.push('/contact')"
      >
        Quotation Inquiry
      </v-btn>
    </div>
    <!-- <v-dialog v-model="dialog" activator="parent" width="auto">
          <v-card> Contact us Email: contact@canrd.com QQ: 3003597584 / 2902385824 </v-card>
        </v-dialog> -->
    <div class="tw-pb-[64px] ma-4 rounded-lg">
      <v-tabs
        class="tabs"
        v-model="tab"
        bg-color="#fff"
        slider-color="#1d89e4"
        selected-class="active"
      >
        <v-tab :value="1">Product Details</v-tab>
        <v-tab :value="2">Specification</v-tab>
        <!-- <v-tab :value="3">商品百科</v-tab> -->
      </v-tabs>
      <v-window v-model="tab">
        <v-window-item key="1" :value="1">
          <div v-if="info.advantage" class="tw-mb-[24px]">
            <div class="py-2 pl-2 text-h6">Advantage</div>
            <v-divider class="tw-mb-[12px]"></v-divider>
            <div v-html="info.advantage"></div>
          </div>
          <div v-if="info.physicalproperty" class="tw-mb-[24px]">
            <div class="py-2 pl-2 text-h6">Physical Property</div>
            <v-divider class="tw-mb-[12px]"></v-divider>
            <div v-html="info.physicalproperty"></div>
          </div>
          <div v-if="info.storage" class="tw-mb-[24px]">
            <div class="py-2 pl-2 text-h6">Storage</div>
            <v-divider class="tw-mb-[12px]"></v-divider>
            <div v-html="info.storage"></div>
          </div>
          <div v-if="info.introduction" class="tw-mb-[24px]">
            <div class="py-2 pl-2 text-h6">Introduction</div>
            <v-divider class="tw-mb-[12px]"></v-divider>
            <div v-html="info.introduction"></div>
          </div>
          <div v-if="info.description" class="tw-mb-[24px]">
            <div class="py-2 pl-2 text-h6">Description</div>
            <v-divider class="tw-mb-[12px]"></v-divider>
            <div v-html="info.description"></div>
          </div>
        </v-window-item>
        <v-window-item key="2" :value="2">
          <v-table density="compact" class="table2">
            <tbody>
              <tr
                class="tr"
                v-for="item in info.productAttributeList || []"
                :key="item.name"
              >
                <td class="td tw-w-[400px]">{{ item.name }}</td>
                <td class="td">{{ item.value }}</td>
              </tr>
            </tbody>
          </v-table>
        </v-window-item>
        <!-- <v-window-item key="3" :value="3"> 2 </v-window-item> -->
      </v-window>
    </div>
  </v-container>
</template>

<script setup lang="ts">
import type { Product } from "~/type";
import { onMounted, ref } from "vue";
import { useDialogStore } from "~/stores/dialog";
const dialogStore = useDialogStore();

const props = defineProps<{
  info: Product;
}>();
const info = props.info;
// onMounted(() => {
//   dialogStore.updateDialog(true)
// })
const tab = ref(0);
const slide = ref(0);
const router = useRouter();
const href1 = ref("/products");
const href2 = ref("/products");
const routeQuery = useRouteQuery();
const productStore = useProductListStore();
interface BreadcrumbItem {
  title: string; // 标题
  disabled: boolean; // 是否禁用
  href: string; // 链接地址
}

// 示例数据
const items = ref<BreadcrumbItem[]>([
  {
    title: "Products",
    disabled: false,
    href: "https://www.canrud.com/products",
  },
  {
    title: "CATEGORY",
    disabled: false,
    href: href1.value,
  },
  {
    title: "DEVICE TYPE",
    disabled: false,
    href: href2.value,
  },
  {
    title: "FUNCTION",
    disabled: false,
    href: "/products",
  },
  {
    title: "TITLE",
    disabled: false,
    href: "/products",
  },
]);
watchEffect(() => {
  if (info?.productCrumbsVO?.category1 && productStore.keyword) {
    items.value[1].title = info.productCrumbsVO.category1;
    items.value[1].href =
      "https://www.canrud.com/products?categories=" +
      info.productCrumbsVO.category1;
    href1.value =
      "https://www.canrud.com/products?categories=" +
      info.productCrumbsVO.category1;
    if (info?.productCrumbsVO?.category2) {
      items.value[2].title = info.productCrumbsVO.category2;
      href2.value = href1.value + "," + info.productCrumbsVO.category2;
      items.value[2].href = href1.value + "," + info.productCrumbsVO.category2;
    }
    if (info?.productCrumbsVO?.function) {
      // items.value.push({
      //   title: info.productCrumbsVO.function,
      //   disabled: false,
      //   href: href2.value + "&function=" + info.productCrumbsVO.function,
      // });
      items.value[3].title = info.productCrumbsVO.function;
      items.value[3].href =
        href2.value + "&function=" + info.productCrumbsVO.function;
    }
    items.value[4].title = info.name;
    items.value[4].href = "https://www.canrud.com/products/detail/" + info.id;
  } else if (routeQuery.categories) {
    if (!routeQuery.categories.includes("Energy materials")) {
      routeQuery.updateFunction("Not specified");
    }
    const categories = routeQuery.categories.split(",");
    const mainCategory = categories[0].trim(); // 取第一个值
    const subCategoryName = ref(
      categories[1] ? categories[1].trim() : "Not specified"
    ); // 取第二个值(如果存在)
    if (subCategoryName.value == "Accessories & fixtures") {
      subCategoryName.value = encodeURIComponent("Accessories & fixtures");
      items.value[2].title = "Accessories & fixtures";
    } else {
      items.value[2].title = subCategoryName.value;
    }
    items.value[1].title = mainCategory;
    items.value[1].href =
      "https://www.canrud.com/products?categories=" + mainCategory;
    href1.value = "https://www.canrud.com/products?categories=" + mainCategory;
    // items.value[1].title = subCategoryName.value;
    href2.value = href1.value + "," + subCategoryName.value;
    items.value[2].href = href1.value + "," + subCategoryName.value;
    if (routeQuery?.selectedFunction) {
      // items.value.push({
      //   title: routeQuery.selectedFunction,
      //   disabled: false,
      //   href: href2.value + "&function=" + routeQuery.selectedFunction,
      // });
      items.value[3].title = routeQuery.selectedFunction;
      items.value[3].href =
        href2.value + "&function=" + routeQuery.selectedFunction;
      // routeQuery.updateFunction(null);
    }
    items.value[4].title = info.name;
    items.value[4].href = "https://www.canrud.com/products/detail/" + info.id;
  } else if (info?.productCrumbsVO?.category1) {
    items.value[1].title = info.productCrumbsVO.category1;
    items.value[1].href =
      "https://www.canrud.com/products?categories=" +
      info.productCrumbsVO.category1;
    href1.value =
      "https://www.canrud.com/products?categories=" +
      info.productCrumbsVO.category1;
    if (info?.productCrumbsVO?.category2) {
      items.value[2].title = info.productCrumbsVO.category2;
      href2.value = href1.value + "," + info.productCrumbsVO.category2;
      items.value[2].href = href1.value + "," + info.productCrumbsVO.category2;
    }
    if (info?.productCrumbsVO?.function) {
      // items.value.push({
      //   title: info.productCrumbsVO.function,
      //   disabled: false,
      //   href: href2.value + "&function=" + info.productCrumbsVO.function,
      // });
      items.value[3].title = info.productCrumbsVO.function;
      items.value[3].href =
        href2.value + "&function=" + info.productCrumbsVO.function;
    }
    items.value[4].title = info.name;
    items.value[4].href = "https://www.canrud.com/products/detail/" + info.id;
  }
  // recommendList.value = resData.value.data.records;

  // // recommendImages.value = recommendList.value.slice(0, 10).map((item) => {
  // recommendImages.value = Array.from({ length: 10 }).map((_, index) => {
  //   const item = recommendList.value[index];
  //   if (!item) {
  //     return null;
  //   }
  //   // 检查 productimageliststore 是否为字符串格式,如果是,则尝试解析
  //   if (typeof item.productimageliststore === "string") {
  //     try {
  //       item.productimageliststore = JSON.parse(item.productimageliststore);
  //     } catch (error) {
  //       item.productimageliststore = []; // 解析失败时,设置为空数组
  //     }
  //   }
  //   const ree = (item.productimageliststore = item?.productimageliststore.map(
  //     (productItem: ProductImage) => ({
  //       ...productItem,
  //       // url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`,
  //       url: `/api/show/image?fileKey=${productItem.fileKey}&psize=p512`,
  //       name: item.name,
  //       productUrl: `http://www.canrud.com/products/detail/${item.id}`,
  //     })
  //   ));
  //   return ree;
  // });
});
</script>

<style lang="scss" scoped>
.tabs {
  border-bottom: 2px solid #cbd9e4;
}

.active {
  background-color: #fff;
}
</style>