123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- <template>
- <view class="content">
- <view
- class="dddd"
- style="height: 10rpx"></view>
- <view
- class="flex cate-wrap"
- :style="{ height: height }">
- <scroll-view
- scroll-y="true"
- class="left-wrap"
- :style="{ height: height }">
- <view
- class="left-item"
- v-for="(leftitem, leftindex) in flist"
- :class="{ 'action-item': currentIndex == leftindex }"
- @click="leftClick(leftindex)">
- {{ leftitem.cate_name }}
- </view>
- </scroll-view>
- <scroll-view
- scroll-y="true"
- class="right-wrap"
- :style="{ height: height }"
- @scrolltolower="getProducts()">
- <view
- class="main"
- v-for="gooditem in list"
- @click="navto('/pages/index/product?id=' + gooditem.id)">
- <view class="img">
- <image
- :src="gooditem.image"
- mode=""></image>
- </view>
- <view class="main1">
- <view
- class="wenzi"
- @click="navToList(item.id, titem.id)">
- <text style="margin-bottom: 5rpx">{{
- gooditem.store_name
- }}</text>
- </view>
- <view class="wenzi2">
- <view class="">
- <text>¥{{ gooditem.price }}</text>
- </view>
- <!-- <view class="image">
- <image
- src="../../static/icon/cart (2).png"
- style="width: 44rpx; height: 44rpx"
- mode=""></image>
- </view> -->
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- </template>
- <script>
- import { getProducts } from "@/api/product.js";
- import { getList } from "@/api/category.js";
- export default {
- data() {
- return {
- sizeCalcState: false,
- tabScrollTop: 0,
- currentId: 9,
- flist: [],
- height: "",
- currentIndex: 0,
- list: [],
- page: 1,
- limit: 20,
- loadingType: "more",
- loaded: false,
- };
- },
- onLoad() {
- this.loadData();
- },
- // 监听导航栏输入框点击事件
- onNavigationBarSearchInputClicked(e) {
- uni.navigateTo({
- url: "/pages/product/search",
- });
- },
- onReady(res) {
- var _this = this;
- uni.getSystemInfo({
- success: resu => {
- const query = uni.createSelectorQuery();
- query.select(".cate-wrap").boundingClientRect();
- query.exec(function (res) {
- _this.height = resu.windowHeight - res[0].top + "px";
- console.log("打印页面的剩余高度", _this.height);
- });
- },
- fail: res => {},
- });
- },
- methods: {
- leftClick(index) {
- this.currentIndex = index;
- this.getProducts("reload");
- },
- getProducts(type) {
- let index = this.flist[this.currentIndex].id;
- if (type == "reload") {
- this.list = [];
- this.page = 1;
- this.loadingType = "more";
- this.loaded = false;
- }
- if (
- this.loadingType == "loading" ||
- this.loadingType == "noMore"
- ) {
- return;
- }
- this.loadingType = "loading";
- getProducts({
- cid: index,
- }).then(res => {
- this.list = this.list.concat(res.data);
- if (this.limit == res.data.length) {
- this.loadingType = "more";
- } else {
- this.loadingType = "noMore";
- }
- this.loaded = true;
- });
- },
- // 载入数据
- async loadData() {
- let obj = this;
- getList({})
- .then(({ data }) => {
- obj.flist = data.map(function (s) {
- return s;
- });
- obj.getProducts();
- })
- .catch(err => {
- console.log(err);
- });
- },
- //一级分类点击
- tabtap(item) {
- console.log(item);
- // 判断有没有初始化页面高度对象数据
- if (!this.sizeCalcState) {
- this.calcSize();
- }
- // 获取当前点击的id
- this.currentId = item.id;
- console.log(item.top);
- this.tabScrollTop = item.top;
- console.log(this.tabScrollTop);
- },
- //右侧栏滚动
- asideScroll(e) {
- // 判断有没有初始化页面高度对象数据
- if (!this.sizeCalcState) {
- this.calcSize();
- }
- let scrollTop = e.detail.scrollTop;
- let box = 0; //列表包裹框高度初始化
- let bottom = 10; //距离页面底部多少像素左侧列表切换到最后一个一级分类
- // 查询当前页面对象
- let view = uni.createSelectorQuery().select(".content");
- view.fields(
- {
- id: true,
- dataset: true,
- rect: true,
- size: true,
- scrollOffset: true,
- },
- function (e) {
- // 保存包裹框高度
- box = e.height;
- }
- ).exec();
- // 获取所有距离顶部大于滚轮距离页面高度的所有分类
- let tabs = this.flist
- .filter(item => item.top - 10 <= scrollTop)
- .reverse();
- if (tabs.length > 0) {
- // 判断是否已经到达滚轮底部
- if (box + scrollTop + bottom >= e.detail.scrollHeight) {
- this.currentId = this.flist[this.flist.length - 1].id;
- } else {
- this.currentId = tabs[0].id;
- }
- }
- },
- //计算右侧栏每个tab的高度等信息
- calcSize() {
- let h = 0;
- this.flist.forEach(item => {
- let view = uni
- .createSelectorQuery()
- .select("#main-" + item.id);
- view.fields(
- {
- size: true,
- },
- data => {
- item.top = h;
- h += data.height;
- item.bottom = h;
- }
- ).exec();
- });
- this.sizeCalcState = true;
- },
- navToList(sid, tid) {
- // 点击导航跳转到详细页面
- uni.navigateTo({
- url:
- "/pages/product/list?fid=" +
- this.currentId +
- "&sid=" +
- sid +
- "&tid=" +
- tid,
- });
- },
- navto(url) {
- uni.navigateTo({
- url,
- });
- },
- },
- };
- </script>
- <style lang="scss">
- .cate-wrap {
- width: 750rpx;
- .left-wrap {
- width: 180rpx;
- flex-shrink: 0;
- background-color: #f2f2f2;
- .left-item {
- width: 180rpx;
- height: 100rpx;
- line-height: 100rpx;
- font-size: 28rpx;
- font-weight: 500;
- color: #666666;
- text-align: center;
- }
- .action-item {
- background-color: #fff;
- font-weight: bold;
- position: relative;
- &::before {
- content: "";
- position: absolute;
- top: 0;
- left: 0;
- width: 3rpx;
- height: 100rpx;
- background: #ff7144;
- }
- }
- }
- .right-wrap {
- flex-wrap: 1;
- background-color: #fff;
- .right-item {
- width: 520rpx;
- height: 240rpx;
- padding: 30rpx 0;
- margin: 0 auto;
- border-bottom: 1px solid #eee;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- .good-img {
- width: 180rpx;
- height: 180rpx;
- border-radius: 20rpx;
- }
- .good-info {
- flex-direction: column;
- justify-content: space-between;
- align-items: flex-start;
- height: 100%;
- padding-left: 25rpx;
- .good-name {
- font-size: 30rpx;
- font-weight: bold;
- color: #333333;
- }
- .good-price {
- font-size: 34rpx;
- font-weight: bold;
- color: #ff4c4c;
- }
- }
- }
- .right {
- display: flex;
- justify-content: flex-end;
- align-items: center;
- margin-left: 25rpx;
- }
- .image {
- margin-left: 30rpx;
- }
- }
- // 右侧商品样式重构
- .main {
- display: flex;
- // align-items: center;
- width: 750rpx;
- // height: 100vh;
- overflow: hidden;
- background-color: #fff;
- }
- .img image {
- // margin-right: 10rpx;
- margin-top: 15rpx;
- margin-left: 20rpx;
- width: 180rpx;
- height: 180rpx;
- object-fit: cover;
- }
- .main1 {
- display: flex;
- width: 320rpx;
- padding-left: 20rpx;
- box-sizing: border-box;
- flex-direction: column;
- justify-content: space-around;
- background-color: #fff;
- .wenzi {
- width: 269rpx;
- height: 29rpx;
- font-size: 30rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #333333;
- display: inline;
- line-height: 35rpx;
- .wenzi1 {
- width: 181rpx;
- height: 25rpx;
- font-size: 26rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #666;
- display: inline;
- }
- }
- .wenzi2 {
- width: 100%;
- height: 26rpx;
- font-size: 34rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #ff4c4c;
- line-height: 35rpx;
- display: flex;
- justify-content: space-between;
- }
- }
- .main1 .wenzi text {
- margin-bottom: 20rpx;
- }
- }
- </style>
|