<template>
  <view class="content">
    <view class="top-box">
      <view class="progress">
        <!-- {{ current + 1 + "/" + bannerList.length }} -->
        <view class="indicator" v-for="item in advList.length">
          <view :class="['block', item == current ? 'active' : '']"> </view>
        </view>
      </view>
      <!-- <view class="goods-box">
        <view class="goods-title">
          {{ bannerList[current].title }}
        </view>
        <view class="goods-subtitle">
          {{ bannerList[current].subtitle }}
        </view>
      </view> -->
      <swiper class="swiper" @change="swiperChange" :indicator-dots="false" circular :current="current"
        indicatorMode="line" :autoplay="true" :interval="3000" :duration="1000">
        <swiper-item v-for="(item, index) in advList" :key="index">
          <image class="swiper-item" mode="" :src="item.advertsImg"> </image>
        </swiper-item>
      </swiper>
    </view>

    <view class="card-box">
      <view class="card-item" @click="toTeaShop">
        <view class="card-title">
          <view class="card-item-title">
            <view class="card-img">
              <image class="card-item-img" src="https://oss.dev.zonelife.cn/static/guida/img/milktea/index/self.png">
              </image>
            </view>
            <view class="title-moji">到店自提</view>
            <view class="subtitle">提前点单免排队</view>
          </view>

        </view>
      </view>

      <view class="card-item">
        <view class="card-title">
          <view class="card-item-title">
            <view class="card-img">
              <image class="card-item-img" src="https://oss.dev.zonelife.cn/static/guida/img/milktea/index/send.png">
              </image>
            </view>
            <view class="title-moji">更多选择</view>
            <view class="subtitle">尽情期待...</view>
          </view>

        </view>
      </view>
    </view>

    <view class="swiper-box" style="height: 200rpx">
      <swiper class="swiper" @change="swiperChange" :indicator-dots="false" circular :autoplay="false" :interval="3000"
        :duration="1000">
        <swiper-item v-for="(item, index) in advList1" :key="item.id" @click="jump(item.jumpUrl)">
          <image class="swiper-item" mode="" :src="item.advertsImg"> </image>
        </swiper-item>
      </swiper>
    </view>

    <view class="sub-title">
      <view>精选推荐</view>
    </view>

    <view class="goods-list">
      <zs-list class="store-box" mt="0" @load="loadMore" :status="status">
        <view class="left">
          <view class="store-item" v-for="(item, index) in list" :key="index" @click="goGoodsDetail(item)">
            <zs-img :src="item.goodsImg" width="340rpx" height="340rpx" mode="widthFix"></zs-img>
            <view class="info">
              <view class="title">
                {{ item.goodsName }}
              </view>
              <view class="goods-price">
                <view> ￥{{ item.realPrice }} </view>
                <view class="distance"> 销售{{ item.saleNum }} </view>
              </view>
            </view>
          </view>
        </view>
        <view class="right">
          <view class="store-item" v-for="(item, index) in list1" :key="index" @click="goGoodsDetail(item)">
            <zs-img :src="item.goodsImg" width="340rpx" height="340rpx" mode="widthFix"></zs-img>
            <view class="info">
              <view class="title">
                {{ item.goodsName }}
              </view>
              <view class="goods-price">
                <!-- <image
                  class="position"
                  src="../../static/position.png"
                  mode=""
                ></image> -->
                <view> ￥{{ item.realPrice }}</view>
                <view class="distance">
                  销售{{ item.saleNum }}
                </view>
              </view>
            </view>
          </view>
        </view>
      </zs-list>
    </view>
  </view>
</template>

<script>
import { getUserDetail, getMenu, getAdv } from "@/api/common.js";
import { appSearch } from "@/api/shop.js";
// 腾讯地图
// // var QQMapWX = require("../../libs/qqmap-wx-jssdk.min.js");
// var qqmapsdk = new QQMapWX({ key: "KX5BZ-B64RC-RO62W-AMWAZ-VVTC3-YAFXF" });
export default {
  data() {
    return {
      advList: [],
      advList1: [],
      discountsList: [], //菜单
      current: 0,
      loading: false,
      navBarHeight: 0,
      bannerList: [
        {
          src: "http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/LasLcHe8z6F9c7c569e98cf778f866ac466404589d03.png/1.png",
          theme: "#FD9E59",
          title: "春季新品",
          subtitle: "蜜桃乌龙海盐芝士茶",
        },
        {
          src: "http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/QdulVZUZ9HYH190ae2e9392281ee1b845573e68ece1e.png/1.png",
          theme: "#FDD34C",
          title: "清仓处理",
          subtitle: "农夫山泉矿泉水",
        },
        {
          src: "http://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/N7kknVWzDPKLbb7e15025599a818bbf11e3b030b6765.png/1.png",
          theme: "#B0ACF9",
          title: "正在热卖",
          subtitle: "哇哈哈AD盖",
        },
      ],
      list: [],
      list1: [],
      status: "more",
      query: {
        queryName: "",
        "location.lat": 0,
        "location.lon": 0,
        pageCurrent: 1,
        pageSize: 10,
        status:3
      },
    };
  },
  onLoad() { },
  created() {
    this.loading = true;
    this.navBarHeight = this.$navHight(1);
    this.navBarHeight = this.navBarHeight + 10 + "px";
    Promise.all([this.getMenu(), this.getBanner(), this.getAdv()]).then((res) => {
      this.search();
    });
  },
  methods: {
    goGoodsDetail(item) {
      uni.setStorageSync("shopInfo", JSON.stringify(item));
      uni.navigateTo({
        url: `../detail/goodsDetail/index?id=${item.goodsId}`,
      });
    },
    // swiper变动
    swiperChange(val) {
      this.current = val.target.current;
    },
    toTeaShop(){
      const shopId = uni.getStorageSync("gdTeaId");
      uni.navigateTo({
          url: `../pages/index/searchResult?column=奶茶&goodsCateId=46&shopId=${shopId}&columnId=66`,
        });
    },

    // Banner
    getBanner() {
      return new Promise((resolve, reject) => {
        getAdv({
          currentPage: 1,
          pageSize: 99,
          belongType: 1,
          advertsType: 3,
        }).then((res) => {
          if (res.state == "Success") {
            this.advList = res.content.records.filter((e, i) => {
              return i < 10;
            });
            this.loading = false;
            resolve(2);
          }
        });
      });
    },
    // 广告位
    getAdv() {
      return new Promise((resolve, reject) => {
        getAdv({
          currentPage: 1,
          pageSize: 99,
          belongType: 1,
          advertsType: 4,
        }).then((res) => {
          if (res.state == "Success") {
            this.advList1 = res.content.records.filter((e, i) => {
              return i < 10;
            });;
            this.loading = false;
            resolve(2);
          }
        });
      });
    },

    // 金刚区
    getMenu() {
      return new Promise((resolve, reject) => {
        getMenu({ currentPage: 1, pageSize: 10 }).then((res) => {
          if (res.state == "Success") {
            this.discountsList = res.content.records.slice(0, 5);
            resolve(1);
          }
        });
      });
    },
    // 跳转优惠详情
    goDetail(url, id, banner, title) {
      url = "/pages/home/detail";
      uni.navigateTo({
        url: `${url}`,
        success(res) {
          // res.eventChannel.emit("banner", banner);
        },
      });
    },
    search() {
      if (this.status == "noMore") return;
      this.status = "loading";
      const shopId = uni.getStorageSync("gdTeaId");
      appSearch({
        ...this.query,
        shopId,
        qualityType: 1,
      }).then((res) => {
        if (res.state == "Success") {
          this.loading = false;
          let list = [];
          let list1 = [];
          res.content.records.map((item, index) => {
            if (index % 2) {
              list1.push(item);
            } else {
              list.push(item);
            }
          });
          this.list = this.list.concat(list);
          this.list1 = this.list1.concat(list1);
          let total = this.list.length + this.list1.length;
          if (total >= res.content.total) {
            this.status = "noMore";
          } else {
            this.status = "more";
            this.query.currentPage++;
          }
        }
      });
    },
    loadMore() {
      console.log("loadMore");
      if (this.query["location.lat"] && this.query["location.lon"]) {
        this.search();
      }
    },
  },
};
</script>

<style lang="scss">
page {
  background-color: #fafafa;
}

.content {
  // padding-top: 24%;
  display: flex;
  flex-direction: column;
  background-color: #fafafa;
  justify-content: center;

  .top-box {
    background: linear-gradient(180deg, var(--bg) 0%, #fff 100%);
    // padding: 100rpx 32rpx 0;
    height: 716rpx;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;

    .progress {
      position: absolute;
      top: 35%;
      right: 80%;
      display: flex;
      z-index: 2;
      color: #ffffff;
      font-size: 16rpx;
      // background: rgba(255, 255, 255, 0.3);
      padding: 2rpx 10rpx;
      border-radius: 14rpx;

      .block {
        width: 30rpx;
        height: 10rpx;
        margin-left: 10rpx;
        background: #fff;
        border-radius: 10px;
      }

      .active {
        background: #b4b4b4;
      }
    }

    .goods-box {
      position: absolute;
      top: 10%;
      z-index: 22;
      margin-left: 20rpx;

      .goods-title {
        font-size: 70rpx;
        color: #000;
        margin-bottom: 10rpx;
      }

      .goods-subtitle {
        font-size: 35rpx;
        color: #8b8b8b;
      }
    }

    .swiper {
      height: 100%;
      border-radius: 16rpx;

      .swiper-item {
        width: 100%;
        height: 100%;
        // border-radius: 16rpx;
      }
    }
  }

  .card-box {
    background-color: white;
    border-radius: 15rpx;
    padding: 40rpx 20rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 9999;
    margin: -15% 20rpx 20rpx 20rpx;

    .title-moji {
      font-size: 40rpx;
      margin-bottom: 10rpx;
      text-align: center;
    }

    .subtitle {
      text-align: center;
      font-size: 30rpx;
      color: #8b8b8b;
    }

    .card-item {
      position: relative;
      flex: 1;
    }

    .card-item:nth-child(1) {
      ::after {
        content: "";
        position: absolute;
        margin: 0 auto;
        right: 0;
        top: 30rpx;
        width: 1px;
        height: 120rpx;
        background: #FFD9D9;
      }
    }

    .card-img {
      display: flex;
      justify-content: center;
      // padding: 40rpx 0 50rpx 0;

      .card-item-img {
        width: 90rpx;
        height: 90rpx;
      }
    }

    // height: 300rpx;
  }
}

.search-box {
  width: 100vw;
}

.swiper-box {
  position: relative;
  margin: 0 24rpx 10rpx;
  padding-top: 20rpx;
  width: 702rpx;
  height: 280rpx;
  border-radius: 16rpx;

  .progress {
    position: absolute;
    top: 38rpx;
    right: 20rpx;
    z-index: 2;
    color: #ffffff;
    font-size: 16rpx;
    background: rgba(255, 255, 255, 0.3);
    padding: 2rpx 10rpx;
    border-radius: 14rpx;
  }

  .swiper {
    position: relative;
    height: 100%;
    padding: 0 10rpx;

    .swiper-item {
      width: 100%;
      height: 100%;
      border-radius: 16rpx;
      object-fit: cover;
    }
  }
}

.discount-list {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  // padding: 30rpx 0;
  // margin: 0 0rpx 0rpx;
  background: #fafafa;
  border-radius: 16rpx;
  position: relative;
  top: 0rpx;
  padding-top: 20rpx;

  .discount-item {
    width: 20%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 10rpx;
    margin-bottom: 10rpx;
    position: relative;

    .icon {
      width: 56rpx;
      height: 56rpx;
    }

    .title {
      font-size: 26rpx;
      margin-top: 10rpx;
    }

    .tag {
      position: absolute;
      top: -20rpx;
      left: 50%;
      background: #ff0615;
      box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
      border-radius: 12rpx 14rpx 14rpx 0rpx;
      color: #fff;
      white-space: nowrap;
      font-size: 18rpx;
      line-height: -14rpx;
      height: 24rpx;
      padding: 0 10rpx;
      // width: fit-content;
      background-size: 100% 34rpx;
    }

    .desc {
      color: #ff0817;
      font-size: 16rpx;
      text-align: center;
      margin-top: 4rpx;
    }
  }
}

.sub-title {
  margin: 20rpx 0;
  padding-left: 40rpx;
  font-size: 30rpx;
  font-weight: bold;
}

.goods-list {
  border-radius: 16rpx 16rpx 0 0;
}

.zs-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 0 24rpx;

  .left {
    .adv-swiper {
      width: 340rpx;
      height: 444rpx;
      margin-bottom: 25rpx;

      .adv-item {
        width: 340rpx;
        height: 444rpx;
      }
    }
  }

  .right {}

  .store-item {
    width: 340rpx;
    margin-bottom: 25rpx;
    // box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0, 0, 0, 0.08);
    border-radius: 16rpx;
    background: #fff;

    .icon {
      width: 100%;
      height: 300rpx;
      border-radius: 16rpx 16rpx 0 0;
    }

    .info {
      padding: 20rpx;
      background: #fff;
      border-radius: 0 0 16rpx 16rpx;
      position: relative;

      .title {
        // font-weight: bold;
        width: 100%;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
      }

      .tags {
        display: flex;
        align-items: center;

        .tag-item {
          line-height: 50rpx;
          border-radius: 8rpx;
          padding: 6rpx 0;
          font-size: 24rpx;
          margin-left: 10rpx;
          display: flex;

          .label {
            background: #fff;
            color: #fe5b47;
            padding: 0 10rpx;
            border-radius: 8rpx 0 0 8rpx;
          }

          .value {
            color: #fff;
            background: rgba(255, 255, 255, 0.2);
            padding: 0 14rpx;
            border-radius: 0 8rpx 8rpx 0;
          }
        }
      }

      .goods-price {
        display: flex;
        align-items: center;
        margin-top: 15rpx;
        justify-content: space-between;
        color: #202020;

        .distance {
          color: #999;
        }

        .position {
          color: 999;
          width: 25rpx;
          height: 29rpx;
          margin-right: 8rpx;
        }
      }
    }
  }
}
</style>
