<template>
  <view>
    <view class="page-index" :class="{ bgf: navIndex > 0 }">
      <!-- 上半部分 -->
      <view class="top-box">
        <view class="header">
          <view class="serch-wrapper">
            <view class="logo" @click="goBack">
              <image src="@/static/logo1.png" mode=""></image>
            </view>
            <navigator
              url="/pages/goods_search/index"
              class="input"
              hover-class="none"
              ><text class="iconfont icon-sousuo"></text> 搜索商品</navigator
            >
          </view>
        </view>

        <!-- 快捷入口 -->
        <view class="top-bg-box">
          <view class="nav-list">
            <navigator
              class="item"
              :url="item.url"
              v-for="item in navMenus"
              :key="item.type"
            >
              <uni-icons
                :size="item.size"
                customPrefix="iconfont"
                :type="item.icon"
              ></uni-icons>
              <view class="txt">{{ item.name }}</view>
            </navigator>
          </view>
        </view>
        <!-- 轮播图 -->

        <up-swiper
          class="swiper-box"
          :list="list1"
          image-fit="cover"
          indicator
          indicatorMode="line"
          :circular="true"
          keyName="url"
          @click="clickSwiper"
        ></up-swiper>
        <!-- 活动专区 -->
        <view class="active-contanier">
          <scroll-view
            class="active-scroll"
            scroll-x="true"
            show-scrollbar="false"
            :enable-flex="true"
          >
            <view class="active-scroll-content">
              <view class="active-item" @click="goFlashSale">
                <view class="title-box">
                  <view class="title">福利整点秒杀 </view>
                  <up-count-down
                    :time="
                      (skillPro.storeSeckillProduct?.seckillEndTimeStamp || 0) -
                        Date.now() >
                      0
                        ? (skillPro.storeSeckillProduct?.seckillEndTimeStamp ||
                            0) - Date.now()
                        : 0
                    "
                    format="HH:mm:ss"
                    autoStart
                    millisecond
                    @change="onChange"
                  >
                    <view class="time">
                      <view class="time__custom">
                        <text class="time__custom__item">{{
                          timeData.hours > 10
                            ? timeData.hours
                            : "0" + timeData.hours
                        }}</text>
                      </view>
                      <text class="time__doc">:</text>
                      <view class="time__custom">
                        <text class="time__custom__item">{{
                          timeData.minutes
                        }}</text>
                      </view>
                      <text class="time__doc">:</text>
                      <view class="time__custom">
                        <text class="time__custom__item">{{
                          timeData.seconds
                        }}</text>
                      </view>
                    </view>
                  </up-count-down>
                </view>
                <view class="active-box">
                  <view class="active-item-left">
                    <view class="image-box">
                      <image :src="skillPro.storeSeckillProduct?.image"></image>
                    </view>
                  </view>
                  <view class="active-item-right">
                    <view class="ms">{{
                      skillPro.storeSeckillProduct?.storeName || ""
                    }}</view>

                    <view
                      class="tag"
                      v-for="tag in switchTagName(
                        skillPro.storeSeckillProduct?.attrValue?.[0]?.attrValue
                      )"
                      :key="tag.key"
                    >
                      <text class="tag-text">
                        {{ tag.key }}: {{ tag.value }}</text
                      >
                    </view>
                    <view class="price-box">
                      <view class="price"
                        >¥{{
                          skillPro.storeSeckillProduct?.attrValue?.[0]
                            ? totalPrice(
                                skillPro.storeSeckillProduct.attrValue[0]
                              )
                            : "0.00"
                        }}</view
                      >
                      <view class="btn">立即前往</view>
                    </view>
                  </view>
                </view>
              </view>
              <!-- <view class="active-item" @click="goGroupBuying">
                <view class="title-box">
                  <view class="title">团购拼团 </view>
                  <view class="live">Live</view>
                </view>
                <view class="active-box">
                  <view class="active-item-left">
                    <view class="image-box">
                      <image src="@/static/images/shoulian.png"></image>
                    </view>
                  </view>
                  <view class="active-item-right">
                    <view class="ms">足金房车钱编织手绳秒杀即将开始</view>
                    <view class="tag">
                      <text class="tag-text"> 抽号商品 </text>
                    </view>
                    <view class="price-box">
                      <view class="price">¥{{ 111 }}</view>
                      <view class="btn">立即前往</view>
                    </view>
                  </view>
                </view>
              </view> -->
              <view class="active-item" @click="goFactory">
                <view class="title-box">
                  <view class="title">工厂定制 </view>
                  <view class="live">GO</view>
                </view>
                <view class="active-box">
                  <view class="active-item-left">
                    <view class="image-box">
                      <image
                        :src="
                          factoryPro.image || '@/static/images/xianglian.png'
                        "
                      />
                    </view>
                  </view>
                  <view class="active-item-right">
                    <view class="ms">
                      {{ factoryPro.name || "足金999宝宝锁项链秒杀即将开始" }}
                    </view>
                    <view class="tag">
                      <text class="tag-text">
                        {{ factoryPro.categoryName || "抽号商品" }}
                      </text>
                    </view>
                    <view class="tag">
                      <text class="tag-text">
                        {{ factoryPro.processList[0].name || "抽号商品" }}:
                        {{
                          factoryPro.processList[0].feePerGram || "抽号商品"
                        }}￥/g
                      </text>
                    </view>
                    <view class="price-box">
                      <!-- <view class="price">¥{{ 111 }}</view> -->
                      <view class="btn">立即前往</view>
                    </view>
                  </view>
                </view>
              </view>
              <!-- <view class="active-item">
              <view class="title-box">
                <view class="title">微瑕品 </view>
                <view class="live weixia">正</view>
              </view>
              <view class="active-box">
                <view class="active-item-left">
                  <view class="image-box">
                    <image src="@/static/images/dajintiao.png"></image>
                  </view>
                </view>
                <view class="active-item-right">
                  <view class="ms">足金古法无事牌吊坠秒杀即将开始</view>
                  <view class="tag">
                    <text class="tag-text"> 抽号商品 </text>
                  </view>
                  <view class="price-box">
                    <view class="price">¥{{ 111 }}</view>
                    <view class="btn">立即前往</view>
                  </view>
                </view>
              </view>
            </view> -->
            </view>
          </scroll-view>
        </view>
      </view>

      <!-- <up-sticky :offsetTop="stickyTop" customNavHeight="62px"> -->
      <view class="sticky-box">
        <view class="scroll-view_H">
          <view class="tab nav-bd" id="tab_list">
            <view
              id="tab_item"
              :class="{ active: listActive == index }"
              class="item"
              v-for="(item, index) in goodsNavs"
              :key="index"
              @click="ProductNavTab(item, index)"
            >
              <uni-icons
                customPrefix="iconfont"
                :color="listActive == index ? '#000' : '#000'"
                :type="item.icon"
                :size="item.size"
              ></uni-icons>
              <!-- <i class="item-icon iconfont" :class="item.icon"></i> -->
              <view class="txt">{{ item.name }}</view>
              <!-- <view class="label">{{ item.info }}</view> -->
            </view>
          </view>
        </view>

        <view class="second-nav" v-if="goodsTwoList.length > 0">
          <view
            :class="{ active: currentSecondCategoryId === item.id }"
            class="second-nav-item"
            v-for="(item, index) in goodsTwoList"
            :key="index"
            @click="handleSecondCategoryClick(item.id)"
          >
            <!-- <uni-icons
                customPrefix="iconfont"
                :type="item.icon || 'icon-erjifenlei'"
                :size="25"
              ></uni-icons> -->
            <view class="txt">{{ item.name }}</view>
          </view>
        </view>
      </view>
      <!-- </up-sticky> -->

      <!-- 首发新品 -->
      <view class="index-product-wrapper" :class="iSshowH ? 'on' : ''">
        <view
          class="list-box animated"
          :class="goodsList.length > 0 ? 'fadeIn on' : ''"
        >
          <view
            class="item"
            v-for="(item, index) in calculatedProducts"
            :key="index"
            @click="goDetail(item)"
          >
            <view class="pictrue">
              <image :src="item.image" mode=""></image>
            </view>
            <view class="text-info">
              <view class="title line2"
                ><text class="tip">现货</text>{{ item.storeName }}</view
              >
              <view class="bottom-row">
                <!-- <text class="price">工费: {{ item.price }}/克</text> -->
                <text class="price">¥ {{ item.totalLaborCost }}</text>
                <text class="sales">
                  已售{{ Number(item.sales || 0) + Number(item.ficti || 0) }}件
                </text>
                <!-- <view class="txt">券</view> -->
              </view>
            </view>
          </view>
        </view>
        <view class="loadingicon acea-row row-center-wrapper" v-if="goodScroll">
          <text
            class="loading iconfont icon-jiazai"
            :hidden="loading == false"
          ></text>
        </view>
        <view class="no-data" v-if="isNoDataState">
          <image
            src="https://my-go-easy-im.oss-cn-shenzhen.aliyuncs.com/goeasy-im-%E6%B0%B4%E8%B4%9D%E5%95%86%E5%9F%8E/zhanwu_20250827104005_1720_6.png"
          />
        </view>
        <view class="mores-txt flex" v-if="!goodScroll && !isNoDataState">
          <text>我是有底线的</text>
        </view>
      </view>
      <!-- </view> -->
    </view>
    <drag-button
      :isDock="true"
      :price="viprealGoldprice"
      :existTabBar="true"
      @btnClick="btnClick"
    />
    <!-- 悬浮球固定 -->
    <!-- <view class="Hoverball">
      <text class="title">实时金价</text>
      <text class="price">{{ realGoldprice }}</text>
    </view> -->
  </view>
</template>

<script setup>
// 获取实时金价
import useRealGoldPrice from "@/hooks/useRealGoldPrice";
// 测试拖拽
import dragButton from "@/components/drag-button/drag-button.vue";
import { onLoad, onShow, onReachBottom } from "@dcloudio/uni-app";
import { ref, onMounted, reactive, computed, getCurrentInstance } from "vue";
import Auth from "@/libs/wechat";
import Cache from "@/utils/cache";
import { getIndexData, getCoupons, setCouponReceive } from "@/api/api.js";
import { getProductListAPI } from "@/api/factory.js";
import { getShare, kefuConfig } from "@/api/public.js";
import {
  getGroomList as getGroomListApi,
  getProductByCategoryId,
} from "@/api/store.js";
import { goShopDetail } from "@/libs/order.js";
import { silenceBindingSpread } from "@/utils";
import { getUserLevelInfo } from "@/api/user";
import { useStoreRights } from "@/stores/rights";
const userBenefits = ref({});
// 获取用户权益
const rightsStore = useStoreRights();
// 获取实时金价
const { realGoldprice, fetchGoldPrice } = useRealGoldPrice("RTJ_Au");
const getUserBenefits = async () => {
  try {
    const res = await getUserLevelInfo(appStore.userInfo.userId);
    userBenefits.value = res.data || { sold: 0, buy: 0 }; // 默认权益为0，避免NaN
  } catch (error) {
    console.error("获取用户权益失败:", error);
    userBenefits.value = { sold: 0, buy: 0 }; // 出错时默认权益为0
  }
};
// 黄金调整价
const adjustGoldprice = computed(() => {
  const res = rightsStore.userBenefits.nobleMeta?.find(
    (gold) => gold.name == "黄金"
  );
  return res;
});
const viprealGoldprice = computed(() => {
  const res =
    Number(realGoldprice.value) -
      Number(rightsStore.userBenefits.buy) +
      Number(adjustGoldprice.value?.sellPriceAdjust) || 0;
  return Number(res).toFixed(2);
});
const btnClick = () => {
  uni.navigateTo({
    url: "/pages/mall/dapan",
  });
};
// };
import { useAppStore } from "@/stores/app";

const appStore = useAppStore();
const app = getApp();
const instance = getCurrentInstance();

const navH = ref("");
const marTop = ref(0);
const searchH = ref(0);
const loading = ref(false);

// Authorization
const isShowAuth = ref(false);
const iShidden = ref(false);
const window = ref(false);

// Navigation and Tabs
const navIndex = ref(0);
const ProductNavindex = ref(0);
const listActive = ref(0);
const tabsScrollLeft = ref(0);
const scrollLeft = ref(0);
const lineStyle = ref({});
const duration = ref(0.2);

// Home Page Data
const logoUrl = ref("");
const site_name = ref("");
const imgUrls = ref([]);
const menus = ref([]);
const roll = ref([]);
const explosiveMoney = ref([]);
const goodType = ref(1);
const goodScroll = ref(true);
const iSshowH = ref(false);
const stickyTop = ref(0);
const navMenus = ref([
  {
    name: "商城订单",
    icon: "icon-wodedingdan1",
    type: 1,
    url: "/pages/order_list/index",
    size: 25,
  },
  {
    name: "购物车",
    icon: "icon-gouwuche",
    type: 2,
    url: "/pages/order_addcart/order_addcart",
    size: 26,
  },
  {
    name: "卡卷包",
    icon: "icon-kabao",
    type: 3,
    url: "/pages/users/user_coupon/index",
    size: 28,
  },
  {
    name: "客服消息",
    icon: "icon-xiaoxi",
    type: 4,
    url: "/pages/message_create/message_create",
    size: 26,
  },
]);
// 轮播图数据
const list1 = ref([]);

// Product Lists
const sortProduct = ref([]);
const goodsList = ref([]);
const goodsTwoList = ref([]);
const currentSecondCategoryId = ref(null);
const goodsNavs = ref([
  { name: "新品推荐", type: 1, icon: "icon-xinpintuijian", size: 25 },
  { name: "黄金金条", type: 2, icon: "icon-touzijintiao1", size: 25 },
  { name: "黄金首饰", type: 3, icon: "icon-huangjinshoushi", size: 25 },
  { name: "其他", type: 4, icon: "icon-a-ziyuan97", size: 25 },
]);
const skillPro = ref({});
const factoryPro = ref({});
// 前往福利秒杀
const goFlashSale = () => {
  uni.navigateTo({
    url: "/pages/users/utils/flashSale/newIndex",
  });
};
// 前往团购
const goGroupBuying = () => {
  uni.navigateTo({
    url: "/pages/group_buying/index",
  });
};
// Pagination
const params = ref({
  page: 1,
  limit: 10,
});
const hotScroll = ref(false);
const headerHeight = ref(0);

// Other
const couponList = ref([]);
const configApi = ref({});

// pinia
const isLogin = appStore.isLogin;
const uid = appStore.uidComputed;
const arrTemp = [
  "beforePay",
  "afterPay",
  "refundApply",
  "beforeRecharge",
  "createBargain",
  "pink",
];
// 前往定制工厂
const goFactory = () => {
  uni.navigateTo({
    url: "/pages/users/utils/factory/index",
  });
};
// Coupon Functions
const getCoupon = async (id, index) => {
  try {
    await setCouponReceive(id);
    couponList.value[index].isUse = true;
    uni.showToast({ title: "领取成功" });
  } catch (err) {
    uni.showToast({ title: err.message, icon: "none" });
  }
};

// Tab Navigation Functions
const clickSort = (index) => {
  listActive.value = index;
};

const scroll = (e) => {
  scrollLeft.value = e.detail.scrollLeft;
};

// Home Page Data Functions
const getIndexConfig = async () => {
  try {
    loading.value = true;
    const res = await getIndexData();
    uni.setNavigationBarTitle({ title: "首页" });
    skillPro.value = res.data.storeSeckillProductDetailResponse;
    const factoryProRes = await getProductListAPI(0);
    factoryPro.value = factoryProRes.data[0];

    logoUrl.value = res.data.logoUrl;
    site_name.value = "首页";
    list1.value = res.data.banner.map((v) => {
      return {
        url: v.pic,
        title: "",
        type: "image",
        navUrl: v.url,
      };
    });

    // console.log("list1==========>", list1.value);

    menus.value = res.data.menus;
    roll.value = res.data.roll || [];
    // #ifdef H5
    appStore.SET_CHATURL(res.data.yzfUrl);
    Cache.set("chatUrl", res.data.yzfUrl);
    // #endif

    const iconTypes = [
      "icon-shouye",
      "icon-shouye",
      "icon-shouye",
      "icon-shouye",
    ];
    explosiveMoney.value = res.data.explosiveMoney.map((v, i) => ({
      ...v,
      icon: iconTypes[i] || "icon-shouye",
    }));
    await getGroomList();
    await shareApi();
    await getcouponList();
  } catch (err) {
    console.error(err);
  } finally {
    loading.value = false;
  }
};

const getcouponList = async () => {
  try {
    const res = await getCoupons({ page: 1, limit: 6 });
    couponList.value = res.data;
    // #ifdef MP
    uni.getSetting({
      success(res) {
        window.value =
          !res.authSetting["scope.userInfo"] && couponList.value.length
            ? true
            : false;
        iShidden.value = res.authSetting["scope.userInfo"];
      },
    });
    // #endif
    // #ifndef MP
    window.value = isLogin ? false : res.data.length ? true : false;
    // #endif
  } catch (err) {
    uni.showToast({ title: err.message, icon: "none" });
  }
};

const shareApi = async () => {
  try {
    const res = await getShare();
    configApi.value = res.data;
    // #ifdef H5
    setOpenShare(res.data);
    // #endif
  } catch (err) {
    console.error(err);
  }
};

const getChatUrL = async () => {
  try {
    const res = await kefuConfig();
    appStore.SET_CHATURL(res.data.yzfUrl);
    Cache.set("chatUrl", res.data.yzfUrl);
  } catch (err) {
    console.error(err);
  }
};

const setOpenShare = (data) => {
  if (Auth.isWeixin()) {
    const configAppMessage = {
      desc: data.synopsis,
      title: data.title,
      link: location.href,
      imgUrl: data.img,
    };
    Auth.wechatEvevt(
      ["updateAppMessageShareData", "updateTimelineShareData"],
      configAppMessage
    );
  }
};

// Authorization
const authColse = (e) => {
  isShowAuth.value = e;
};

// Product Navigation
const ProductNavTab = (item, index) => {
  goodsList.value = [];
  goodsTwoList.value = [];
  listActive.value = index;
  goodType.value = item.type;
  ProductNavindex.value = index;
  params.value.page = 1;
  goodScroll.value = true;
  currentSecondCategoryId.value = null;
  getGroomList(true);
};

// Product Details
const goDetail = async (item) => {
  if (item.activityH5 && item.activityH5.type === "2" && !isLogin) {
    toLogin();
  } else {
    await goShopDetail(item, uid);
    uni.navigateTo({ url: `/pages/goods_details/index?id=${item.id}` });
  }
};

const godDetail = async (item) => {
  await goShopDetail(item, uid);
  uni.navigateTo({ url: `/pages/goods_details/index?id=${item.id}` });
};

const isNoDataState = computed(() => {
  return goodsList.value.length === 0 && !loading.value;
});

// Product Lists
const getGroomList = async (onloadH = false) => {
  if (!goodScroll.value) return;
  if (onloadH) iSshowH.value = true;
  try {
    loading.value = true;
    const { data } = await getGroomListApi(goodType.value, params.value);
    iSshowH.value = false;

    goodsList.value = [...goodsList.value, ...data.productList.list] || [];
    goodsTwoList.value = data.secondLevelCategories || [];

    goodScroll.value = data.productList.list.length >= params.value.limit;
    params.value.page++;
    currentSecondCategoryId.value = null;
  } catch (err) {
    console.error(err);
  } finally {
    loading.value = false;
  }
};

async function clickSwiper(index) {
  const imgItem = list1.value[index];
  try {
    if (imgItem.navUrl !== "#") {
      await uni.navigateTo({ url: imgItem.navUrl });
    } else {
      uni.previewImage({
        current: index,
        urls: list1.value.map((item) => item.url) || [],
      });
    }
  } catch (err) {
    uni.previewImage({
      current: index,
      urls: list1.value.map((item) => item.url) || [],
    });
    return;
  }
}

const handleSecondCategoryClick = async (categoryId) => {
  currentSecondCategoryId.value = categoryId;
  params.value.page = 1;
  goodsList.value = [];
  goodScroll.value = false;

  try {
    loading.value = true;
    const { data } = await getProductByCategoryId(categoryId, params.value);
    goodsList.value = data.list;
    goodScroll.value = data.list.length >= params.value.limit;
    params.value.page++;
  } catch (err) {
    console.error(err);
  } finally {
    loading.value = false;
  }
};

const get_host_product = async () => {
  if (hotScroll.value) return;
  try {
    loading.onMounted(() => {});
  } catch (err) {
    console.error(err);
  } finally {
    loading.value = false;
  }
};

onLoad((option) => {
  getUserBenefits();
  uni.getSystemInfo({
    success(res) {
      appStore.SYSTEM_PLATFORM(res.platform);
    },
  });

  // uni.getLocation({
  //   type: "gcj02",
  //   altitude: true,
  //   geocode: true,
  //   success: (res) => {
  //     try {
  //       uni.setStorageSync("user_latitude", res.latitude);
  //       uni.setStorageSync("user_longitude", res.longitude);
  //     } catch {}
  //   },
  // });

  navH.value = app.globalData.navHeight;

  // #ifndef MP
  navH.value = 0;
  // #endif

  isLogin && silenceBindingSpread();
});

onShow(() => {
  getIndexConfig();
  uni.setNavigationBarTitle({ title: site_name.value });
});

onMounted(() => {
  // #ifdef H5
  const appSearchH = uni.createSelectorQuery().select(".serch-wrapper");
  appSearchH
    .boundingClientRect((data) => {
      searchH.value = data.height;
    })
    .exec();
  // #endif

  const query = uni.createSelectorQuery().in(instance.proxy);

  query.select(".header").boundingClientRect((data) => {
    headerHeight.value = Math.ceil(data.height);
  });

  query
    .select(".sticky-box")
    .boundingClientRect((data) => {
      // marTop.value = Util.pxToRpx(data.height);
      // stickyTop.value = data.height;
      console.log({ data });

      marTop.value = data.height + 5;
    })
    .exec();
});

// #ifdef MP
const onShareAppMessage = () => {
  return {
    title: configApi.value.title,
    imageUrl: configApi.value.img,
    desc: configApi.value.synopsis,
    path: "/pages/index/index",
  };
};
// #endif

onReachBottom(() => {
  if (navIndex.value === 0) {
    if (currentSecondCategoryId.value) {
      if (goodScroll.value) {
        getProductByCategoryId(currentSecondCategoryId.value, params.value)
          .then(({ data }) => {
            // console.log("11111=>", data);

            goodsList.value =
              [...goodsList.value, ...data.productList.list] || [];

            goodScroll.value =
              data.productList.list.length >= params.value.limit;
            params.value.page++;
          })
          .catch(console.error);
      }
    } else {
      if (params.value.page !== 1) {
        getGroomList();
      }
    }
  } else {
  }
});

// 定义 onChange 方法
const onChange = (e) => {
  timeData.value = e;
};
const timeData = ref({});
const calculatedProducts = computed(() => {
  // 计算逻辑与原代码一致，但基于响应式数据 products
  return goodsList.value.map((product) => {
    // 1. 将price字符串转为数字
    const price = Number(product.price);
    // 2. 计算乘积
    const total = (price + product.sales) * realGoldprice.value;
    // 3. 向上取整到两位小数（先放大100倍取整，再缩小100倍）
    const roundedTotal = Math.ceil(total * 100) / 100;
    // 4. 格式化保留两位小数
    const formattedTotal = roundedTotal.toFixed(2);

    return {
      ...product,
      calculatedTotal: formattedTotal, // 新增计算结果字段
    };
  });
});
const goBack = () => {
  uni.switchTab({ url: "/pages/index/index" });
};

// 解析商品规格信息
const switchTagName = (jsonStr) => {
  // console.log("jsonStr", jsonStr);
  if (!jsonStr || typeof jsonStr !== "string") {
    return [];
  }

  try {
    const attrObj = JSON.parse(jsonStr);
    if (typeof attrObj !== "object" || attrObj === null) {
      return [];
    }

    return Object.entries(attrObj).map(([key, value]) => ({
      key: String(key),
      value: String(value),
    }));
  } catch (err) {
    console.error("解析商品规格失败：", err);
    return [];
  }
};
// 价格
const totalPrice = (pro) => {
  return (
    Number(pro.weight) * Number(pro.price) +
    Number(pro.additionalAmount)
  ).toFixed(2);
};
</script>

<style>
page {
  display: flex;
  flex-direction: column;
  height: 100%;
  /* #ifdef H5 */
  background-color: #fff;
  /* #endif */
}
</style>
<style lang="scss" scoped>
.Hoverball {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  background: linear-gradient(180deg, #fefcf9 0%, #fff2df 100%);
  box-shadow: 0rpx 3rpx 12rpx 0rpx rgba(0, 0, 0, 0.16);
  width: 105upx;
  height: 105upx;
  border-radius: 50%; // 圆形按钮
  position: fixed; // 固定定位（不随页面滚动）
  z-index: 999999; // 最高层级，避免被其他元素遮挡
  top: 0%;
  right: 0%;

  .title {
    font-size: 19rpx;
    color: #000000;
    margin-bottom: 4rpx; // 文本与价格间距
  }
  .price {
    font-size: 26rpx;
    color: #cc0000;
    font-weight: bold;
  }
  // 贴边/停止拖拽时的过渡动画
  &.transition {
    transition: left 0.3s ease, top 0.3s ease;
  }
}
.couponIndex {
  width: auto;
  height: 238rpx;
  background-image: url("~@/static/images/yhjsy.png");
  background-size: 100% 100%;
  padding-left: 42rpx;
  margin-bottom: 30rpx;

  .titBox {
    padding: 47rpx 0;
    text-align: center;
    height: 100%;

    .tit1 {
      color: #ffebd2;
      font-size: 34rpx;
      font-weight: 600;
    }

    .tit2 {
      color: #ffebd2;
      font-size: 22rpx;
      margin: 10rpx 0 26rpx 0;
    }

    .tit3 {
      color: #ffdaaf;
      font-size: 24rpx;

      .iconfont {
        font-size: 20rpx;
      }
    }
  }

  .listBox {
    padding: 14rpx 0;

    .listActive {
      background-image: url("~@/static/images/lingyhj.png");
      background-size: 100% 100%;
    }

    .listHui {
      background-image: url("~@/static/images/weiling.png");
      background-size: 100% 100%;
    }

    .list {
      width: 170rpx;
      height: 210rpx;
      padding: 16rpx 0;
      text-align: center;
      margin-left: 24rpx;

      .tit {
        font-size: 18rpx;
        padding: 0 26rpx;
      }

      .titActive {
        color: #c99959;
      }

      .price {
        font-size: 46rpx;
        font-weight: 900;
        margin-top: 4rpx;
      }

      .pricehui {
        color: #b2b2b2;
      }

      .fonthui {
        background-color: #f5f5f5 !important;
      }

      .yuan {
        font-size: 24rpx;
      }

      .ling {
        font-size: 24rpx;
        margin-top: 9.5rpx;
        width: 102rpx;
        height: 36rpx;
        line-height: 36rpx;
        background-color: #ffe5c7;
        border-radius: 28rpx;
        margin: auto;
      }

      .priceM {
        color: #ffdaaf;
        font-size: 22rpx;
        margin-top: 14rpx;
      }
    }
  }
}

.sticky-box {
  // display: flex;
  // position: -webkit-sticky;
  // position: sticky;
  z-index: 99;
  flex-direction: row;
  // margin: 0px;
  // background: #fff;
  padding-bottom: 30rpx;
  background: #fff;
  margin-top: 30rpx;

  .active {
    color: #000;
  }

  .nav-bd {
    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 0 20rpx;

    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      border-bottom: 3rpx solid #e6e6e6;
      box-sizing: border-box;

      .txt {
        font-size: 28rpx;
        color: #282828;
      }

      .label {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 124rpx;
        height: 32rpx;
        margin-top: 5rpx;
        font-size: 24rpx;
        color: #999;
      }

      &.active {
        color: $theme-color;
        border-bottom: 2rpx solid #000;

        .txt {
          color: $theme-color;
        }

        .label {
          background: linear-gradient(90deg, $bg-star 0%, $bg-end 100%);
          border-radius: 16rpx;
          color: #fff;
        }
      }
    }
  }
  .second-nav {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;

    &::-webkit-scrollbar {
      display: none;
    }
    -webkit-overflow-scrolling: touch;
    padding: 0 50rpx;
    box-sizing: border-box;

    .second-nav-item {
      font-size: 26rpx;
      padding: 15rpx 0;
      margin: 0 10rpx 0 0;
      color: #000;
      white-space: nowrap;
      // flex: 1;
      width: 33%;
      display: flex;
      justify-content: center;
      align-items: center;

      &.active {
        color: #ef4800;
      }
    }
  }
}
.swiper-box {
  margin: 0 30rpx;
  &::v-deep uni-image {
    width: 100%;
  }
}
// 活动专区
.active-contanier {
  width: 100%;
  box-sizing: border-box;
  padding: 0 30rpx;

  .active-scroll {
    width: 100%;
    white-space: nowrap;

    .active-scroll-content {
      margin: 30rpx 0;
      display: flex;
      flex-direction: row;
      white-space: nowrap;
    }
  }

  .active-item {
    // width: 335rpx;
    width: 48.99%;
    background: #ffffff;
    height: 180rpx;
    box-shadow: 0rpx 3rpx 13rpx 0rpx rgba(0, 0, 0, 0.13);
    border-radius: 20rpx;
    padding: 13rpx 20rpx;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    margin-right: 20rpx;
    flex-shrink: 0;
    .title-box {
      height: 33rpx;
      display: flex;
      font-size: 22rpx;
      align-items: center;

      .title {
        // width: 50%;
        font-weight: bold;
        text-align: center;
      }
    }
    .active-box {
      flex: 1;
      display: flex;
      .active-item-left {
        flex: 1;
        display: flex;
        flex-direction: column;

        .image-box {
          flex: 1;
          // width: 115rpx;
          display: flex;
          align-items: center;
          image {
            border-radius: 5rpx;
            width: 115rpx;
            height: 110rpx;
          }
          .da-jin-tiao {
            width: 51rpx;
          }
        }
      }
      .active-item-right {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        flex: 1;
        min-width: 0;
        width: 0;
        .ms {
          font-size: 16rpx;
          color: #000000;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          display: block;
          max-width: 100%;
          box-sizing: border-box;
        }
        .tag {
          display: flex;
          .tag-text {
            color: #acacac;
            background-color: #ebebeb;
            border-radius: 5rpx;
            font-size: 16rpx;
            text-align: center;
            padding: 0rpx 5rpx;
          }
        }
        .price-box {
          display: flex;
          justify-content: space-between;
          .price {
            font-size: 18rpx;
            font-weight: bold;
            color: #000000;
            margin-right: 10rpx;
          }
          .btn {
            width: 77rpx;
            height: 26rpx;
            background-image: linear-gradient(270deg, #fc962c 0%, #f0470d 100%);
            border-radius: 100rpx;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 14rpx;
            color: #ffffff;
          }
        }
      }
    }
  }
}
.listAll {
  width: 20%;
  text-indent: 62rpx;
  font-size: 30rpx;
  border-left: 1px #eee solid;
  margin: 1% 0;
  padding: 5rpx;
  position: relative;

  image {
    position: absolute;
    left: 20rpx;
    top: 8rpx;
  }
}

.tab {
  position: relative;
  display: flex;
  font-size: 28rpx;
  white-space: nowrap;

  &__item {
    flex: 1;
    padding: 0 20rpx;
    text-align: center;
    height: 60rpx;
    line-height: 60rpx;
    color: #666;

    &.active {
      color: #09c2c9;
    }
  }
}

.tab__line {
  display: block;
  height: 6rpx;
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 1;
  border-radius: 3rpx;
  position: relative;
  background: #2fc6cd;
}

.scroll-view_H {
  width: 100%;
  display: flex;
  overflow-x: auto;
  padding: 12rpx 0;
  background-color: #fff;

  box-sizing: border-box;
  &::-webkit-scrollbar {
    display: none;
  }
  -webkit-overflow-scrolling: touch;

  .tab.nav-bd {
    display: flex;
    align-items: center;
    width: 100%;
  }

  #tab_item.item {
    display: flex;
    flex-direction: column;
    align-items: center;
    // margin: 0 24rpx;
    padding: 8rpx 0;
    cursor: pointer;
    flex: 1;
    transition: all 0.3s ease;

    .uni-icons {
      font-size: 44rpx;
      margin-bottom: 6rpx;
    }

    .txt {
      font-size: 26rpx;
      color: #333;
    }
  }

  #tab_list:first-of-type .item.active {
    .uni-icons {
      color: #000;
    }
    .txt {
      color: #000;
      font-weight: bold;
    }
  }

  .privacy-wrapper {
    z-index: 999;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: #7f7f7f;

    .privacy-box {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      width: 560rpx;
      padding: 50rpx 45rpx 0;
      background: #fff;
      border-radius: 20rpx;

      .title {
        text-align: center;
        font-size: 32rpx;
        text-align: center;
        color: #333;
        font-weight: 700;
      }

      .content {
        margin-top: 20rpx;
        line-height: 1.5;
        font-size: 26rpx;
        color: #666;
        text-indent: 54rpx;

        i {
          font-style: normal;
          color: $theme-color;
        }
      }

      .btn-box {
        margin-top: 40rpx;
        text-align: center;
        font-size: 30rpx;

        .btn-item {
          height: 82rpx;
          line-height: 82rpx;
          background: linear-gradient(90deg, #f67a38 0%, #f11b09 100%);
          color: #fff;
          border-radius: 41rpx;
        }

        .btn {
          padding: 30rpx 0;
        }
      }
    }
  }
}
.page-index {
  position: relative;
  z-index: 1;

  height: 100%;
  .top-box {
    background: linear-gradient(180deg, #ffe079 0%, #ffffff 100%);
  }
}

.header {
  position: sticky;
  top: 0;
  z-index: 200000;
  width: 100%;

  padding: 28rpx 30rpx;

  .serch-wrapper {
    margin-top: var(--status-bar-height);

    display: flex;
    justify-content: center;
    align-items: center;
    /* #ifdef MP-WEIXIN */
    width: 75%;
    /* #endif */

    .logo {
      width: 154rpx;
      height: 47rpx;
      margin-right: 24rpx;
    }

    image {
      width: 118rpx;
      height: 42rpx;
    }

    .input {
      display: flex;
      align-items: center;
      width: 447rpx;
      height: 58rpx;
      background-color: #ffffff;
      border-radius: 10rpx;
      font-size: 22rpx;
      color: #868686;

      .iconfont {
        margin: 0 10rpx;
        font-size: 26rpx;
        color: #666666;
      }
    }
  }

  .tabNav {
    padding-top: 24rpx;
  }
}

.page_content {
  padding: 0 30rpx;
}

.index-product-wrapper {
  padding: 0 30rpx;
  margin-bottom: 110rpx;
  min-height: 700rpx;
  background: #fff;

  &.on {
    min-height: 1500rpx;
  }

  .list-box {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;

    .item {
      width: 48.99%;
      height: 463rpx;
      background-color: #ffffff;
      box-shadow: 0rpx 3rpx 13rpx 0rpx rgba(0, 0, 0, 0.13);
      border-radius: 20rpx;
      margin-bottom: 20rpx;

      overflow: hidden;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .pictrue {
        position: relative;
        image {
          width: 100%;
          height: 330rpx;
        }
      }

      .text-info {
        padding: 10rpx 20rpx 15rpx;

        .title {
          color: #222222;
          display: flex;
          align-items: center;

          .tip {
            width: 61rpx;
            height: auto;
            font-size: 22rpx;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #ffffff;
            position: relative;
            margin-right: 5rpx;
            background-color: #ef4800;
            border-radius: 5rpx;
          }
        }

        .bottom-row {
          color: $theme-color;
          display: flex;
          justify-content: space-between;
          align-items: center;
          font-size: 28rpx;
          margin: 10rpx 0 0;

          .price {
            padding-bottom: 4rpx;
            font-weight: 800;
            white-space: nowrap;
            font-size: 28rpx;
            color: #f16327;
          }

          .sales {
            color: #b4b4b4;
            font-size: 22rpx;
            white-space: nowrap;
            color: #6e6e6e;
          }
        }
      }
    }

    &.on {
      display: flex;
    }
  }
}

.top-bg-box {
  overflow: hidden;
  // background-image: linear-gradient(
  //   to bottom,
  //   $header-color 0%,
  //   $header-color 10%,
  //   #ffe9a1 50%,
  //   transparent 100%
  // );
}

.nav-list {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 40rpx 0;
  margin: 25rpx 0;

  .item {
    text-align: center;
  }
}

.no-data {
  margin: 150rpx auto 0;
  text-align: center;

  img {
    width: 65%;
    height: auto;
  }
}

.mores-txt {
  width: 100%;
  align-items: center;
  justify-content: center;
  height: 70rpx;
  color: #999;
  font-size: 24rpx;

  .iconfont {
    margin-top: 2rpx;
    font-size: 20rpx;
  }
}

.menu-txt {
  font-size: 24rpx;
  color: #454545;
}

.stats {
  position: absolute;
  left: 0px;
  top: 0px;
  z-index: 2000000;
  width: 750rpx;
  height: var(--status-bar-height);
  background: #ffffff;
}

// 倒计时样式
.time {
  @include flex;
  align-items: center;

  &__custom {
    // margin-top: 4px;
    width: 24rpx;
    height: 24rpx;
    background-color: #ef4800;
    border-radius: 4px;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    justify-content: center;
    align-items: center;
    font-size: 12rpx;
    border-radius: 50%;
    margin-left: 10rpx;

    &__item {
      color: #fff;
      font-size: 12rpx;
      text-align: center;
    }
  }

  &__doc {
    color: #ef4800;
    padding: 0px 4rpx;
    margin-bottom: 4rpx;
  }

  &__item {
    color: #606266;
    font-size: 15px;
    margin-right: 4px;
  }
}
.live {
  width: 59rpx;
  height: 20rpx;
  background-color: #ef4800;
  border-radius: 5rpx;
  font-size: 12rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left: 10rpx;
  color: #ffffff;
}
.weixia {
  width: 24rpx;
  height: 24rpx;
  background-color: #ef4800;
  border-radius: 50%;
}
</style>
