【订单详情】

1. 处理 nav + scroll 相关的变量和方法
pull/1/MERGE
YunaiV 2023-06-08 01:08:13 +08:00
parent 16b6a37074
commit 8b2291d8b4
1 changed files with 134 additions and 129 deletions

View File

@ -1,17 +1,19 @@
<template>
<view class="product-con">
<!-- 顶部的 nav tab -->
<view class='navbar' :style="{ height: navH+'rpx', opacity: opacity }">
<view class='navbarH' :style='"height:"+navH+"rpx;"'>
<view class='navbarCon acea-row row-center-wrapper' :style="{ paddingRight: navbarRight + 'px' }">
<view class="header acea-row row-center-wrapper">
<view class="item" :class="navActive === index ? 'on' : ''" v-for="(item,index) in navList"
:key='index' @tap="tap(index)">
<view class="item" :class="navActive === index ? 'on' : ''"
v-for="(item,index) in navList" :key='index' @tap="tap(index)">
{{ item }}
</view>
</view>
</view>
</view>
</view>
<!-- 返回键 -->
<view id="home" class="home acea-row row-center-wrapper iconfont icon-xiangzuo" :class="opacity > 0.5?'on':''"
:style="{ top: homeTop + 'rpx' }" v-if="returnShow" @tap="returns">
</view>
@ -376,7 +378,6 @@
autoplay: false, // TODO
interval: 3000, // TODO
duration: 500, // TODO
clientHeight: "", // TODO
systemStore: {}, // TODO
good_list: [], // TODO
isDown: true, // TODO
@ -384,17 +385,6 @@
weixinStatus: false, // TODO
H5ShareBox: false, // TODO
activityH5: [], // TODO
navH: "", // nav
navList: [], // nav
navActive: 0, // nav
opacity: 0, // TODO
scrollY: 0, // TODO
topArr: [], // TODO
toView: '', // TODO
height: 0, // TODO
heightArr: [], // TODO
lock: false, // TODO
scrollTop: 0, // TODO
tagStyle: { //
img: 'width:100%;display:block;',
table: 'width:100%',
@ -405,10 +395,23 @@
imagePath: '', // TODO
imgTop: '', // TODO
errT: '', // TODO
type: "", // TODO
// ========== nav + scroll ==========
returnShow: true, // []
homeTop: 20, // top
navbarRight: 0, // TODO
returnShow: true, // // TODO
type: "" // TODO
clientHeight: "", // height
height: 0, // height
scrollY: 0, // Y
scrollTop: 0, // top
lock: false, // scroll
topArr: [], // nav top
heightArr: [], // nav height
navH: "", // nav
navbarRight: 0, // nav right
opacity: 0, // nav
navList: [], // nav
navActive: 0, // navList
};
},
computed: mapGetters(['isLogin', 'uid', 'chatUrl']),
@ -482,9 +485,6 @@
//
this.getGoodsDetails();
if (true) {
return;
}
this.getCouponList();
this.getProductReplyList();
this.getProductReplyCount();
@ -504,6 +504,7 @@
// #endif
});
},
// TODO
/**
* 用户点击右上角分享
*/
@ -519,26 +520,6 @@
},
// #endif
methods: {
getChat(uid) {
window.yzf && window.yzf.init({
sign: '37ef9b97872756ce2a1596ec4fe9b66b0b4cbeec7b36239a65924fa6cbd5c29ac6b013c274511b2eee929e72312baeeeb97aae86',
token: '', //
userAvator: '', //
userNick: '', //
uid: uid, //,
title: '', //
isRMB: '', //,false
data: {
c1: '',
c2: '',
c3: '',
c4: '',
c5: ''
},
selector: 'chat-btn',
callback: function(type, data) {}
})
},
kefuClick() {
location.href = this.chatUrl;
},
@ -569,37 +550,6 @@
iptCartNum: function(number) {
this.$set(this.attr.productSelect, 'cart_num', number ? number : 1);
},
// 退
returns: function() {
uni.navigateBack()
},
tap: function(index) {
var id = "past" + index;
var that = this;
this.$set(this, 'toView', id);
this.$set(this, 'navActive', index);
this.$set(this, 'lock', true);
this.$set(this, 'scrollTop', index > 0 ? that.topArr[index] - (app.globalData.navHeight / 2) : that
.topArr[index]);
},
scroll: function(e) {
var that = this,
scrollY = e.detail.scrollTop;
var opacity = scrollY / 200;
opacity = opacity > 1 ? 1 : opacity;
that.$set(that, 'opacity', opacity);
that.$set(that, 'scrollY', scrollY);
if (that.lock) {
that.$set(that, 'lock', false)
return;
}
for (var i = 0; i < that.topArr.length; i++) {
if (scrollY < that.topArr[i] - (app.globalData.navHeight / 2) + that.heightArr[i]) {
that.$set(that, 'navActive', i)
break
}
}
},
/**
* 去商品详情页
*/
@ -711,16 +661,6 @@
this.getCouponList();
},
setClientHeight: function() {
let that = this;
if (!that.good_list.length) return;
let view = uni.createSelectorQuery().in(this).select("#list0");
view.fields({
size: true,
}, data => {
that.$set(that, 'clientHeight', data.height + 20)
}).exec();
},
/**
* 优品推荐
*/
@ -736,6 +676,8 @@
});
}
this.$set(this, 'good_list', goodArray);
// nav bar
let navList = ['商品', '评价', '详情'];
if (goodArray.length) {
navList.splice(2, 0, '推荐')
@ -753,46 +695,53 @@
* 获取产品详情
*/
getGoodsDetails: function() {
let that = this;
ProductSpuApi.getSpuDetail(that.id).then(res => {
ProductSpuApi.getSpuDetail(this.id).then(res => {
let productInfo = res.data;
let spu = res.data;
let skus = res.data.skus;
that.$set(that, 'productInfo', productInfo);
that.$set(that, 'spu', spu);
that.$set(that, 'userCollect', res.data.userCollect); // TODO
that.$set(that.attr, 'properties', ProductUtil.convertProductPropertyList(skus));
that.$set(that, 'skuMap', ProductUtil.convertProductSkuMap(skus));
that.$set(that.sharePacket, 'priceName', res.data.priceName); // TODO share packet
that.$set(that.sharePacket, 'isState', Math.floor(res.data.priceName) === 0);
that.$set(that, 'activityH5', res.data.activityAllH5 ? res.data.activityAllH5 : []);
this.$set(this, 'productInfo', productInfo);
this.$set(this, 'spu', spu);
this.$set(this, 'userCollect', res.data.userCollect); // TODO
this.$set(this.attr, 'properties', ProductUtil.convertProductPropertyList(skus));
this.$set(this, 'skuMap', ProductUtil.convertProductSkuMap(skus));
this.$set(this.sharePacket, 'priceName', res.data.priceName); // TODO share packet
this.$set(this.sharePacket, 'isState', Math.floor(res.data.priceName) === 0);
this.$set(this, 'activityH5', res.data.activityAllH5 ? res.data.activityAllH5 : []);
//
uni.setNavigationBarTitle({
title: productInfo.name.substring(0, 7) + "..."
})
if (that.isLogin) {
that.getCartCount();
// TODO
if (this.isLogin) {
this.getCartCount();
//#ifdef H5
that.make(that.uid);
that.ShareInfo();
this.make(this.uid);
this.ShareInfo();
this.getImageBase64(this.productInfo.image);
// #endif
// #ifdef MP
that.getQrcode();
this.getQrcode();
// #endif
}
setTimeout(function() {
that.infoScroll();
//
setTimeout(() => {
this.infoScroll();
}, 500);
// #ifdef MP
that.imgTop = spu.picUrl
this.imgTop = spu.picUrl
// #endif
// #ifndef H5
that.downloadFilestoreImage();
this.downloadFilestoreImage();
// #endif
that.selectDefaultSku();
// sku
this.selectDefaultSku();
}).catch(err => {
return that.$util.Tips({
return this.$util.Tips({
title: err.toString()
}, {
tab: 3,
@ -812,28 +761,6 @@
that.$set(that, 'replyCount', res.data.sumCount);
});
},
infoScroll: function() {
var that = this,
topArr = [],
heightArr = [];
for (var i = 0; i < that.navList.length; i++) { //productList
//
var query = uni.createSelectorQuery().in(this);
var idView = "#past" + i;
// if (!that.data.good_list.length && i == 2) {
// var idView = "#past" + 3;
// }
query.select(idView).boundingClientRect();
query.exec(function(res) {
var top = res[0].top;
var height = res[0].height;
topArr.push(top);
heightArr.push(height);
that.$set(that, 'topArr', topArr);
that.$set(that, 'heightArr', heightArr);
});
}
},
/**
* 拨打电话
*/
@ -1301,6 +1228,84 @@
})
}
},
// ========== nav ==========
/**
* 后退
*/
returns: function() {
uni.navigateBack()
},
/**
* 点击指定 nav bar
*
* @param index 新的 navList 位置
*/
tap: function(index) {
this.$set(this, 'navActive', index);
this.$set(this, 'lock', true);
this.$set(this, 'scrollTop', index > 0 ? this.topArr[index] - (app.globalData.navHeight / 2)
: this.topArr[index]);
},
/**
* 计算并设置客户端 height 高度
*/
setClientHeight: function() {
if (!this.good_list.length) {
return;
}
let view = uni.createSelectorQuery().in(this).select("#list0");
view.fields({
size: true,
}, data => {
this.$set(this, 'clientHeight', data.height + 20)
}).exec();
},
/**
* 滚动
*
* @param e 滚动事件
*/
scroll: function(e) {
const scrollY = e.detail.scrollTop;
let opacity = scrollY / 200;
opacity = opacity > 1 ? 1 : opacity;
this.$set(this, 'opacity', opacity);
this.$set(this, 'scrollY', scrollY);
if (this.lock) {
this.$set(this, 'lock', false)
return;
}
// nav
for (let i = 0; i < this.topArr.length; i++) {
if (scrollY < this.topArr[i] - (app.globalData.navHeight / 2) + this.heightArr[i]) {
this.$set(this, 'navActive', i)
break
}
}
},
/**
* 处理器滚动条
*/
infoScroll: function() {
const topArr = [];
const heightArr = [];
for (let i = 0; i < this.navList.length; i++) {
//
const query = uni.createSelectorQuery().in(this);
const idView = "#past" + i;
query.select(idView).boundingClientRect();
query.exec((res) => {
const top = res[0].top;
const height = res[0].height;
topArr.push(top);
heightArr.push(height);
this.$set(this, 'topArr', topArr);
this.$set(this, 'heightArr', heightArr);
});
}
},
fen2yuan(price) {
return Util.fen2yuan(price)
}