Chore(首页):代码格式化&去掉多余的引用

This commit is contained in:
lifizer
2024-05-20 11:13:04 +08:00
parent 4a4f8ffdd2
commit de82fafe9c
+149 -192
View File
@@ -191,7 +191,7 @@
<view class="item flex" v-for="(item,index) in bastList" :key="index" slot="slot{{index}}"> <view class="item flex" v-for="(item,index) in bastList" :key="index" slot="slot{{index}}">
<template v-if="item.storeName==='swiper'"> <template v-if="item.storeName==='swiper'">
<swiper class="item bannar-swiper" autoplay circular> <swiper class="item bannar-swiper" autoplay circular>
<swiper-item v-for="swipe in bannarList" :key="swipe"> <swiper-item v-for="swipe in bannerList" :key="swipe">
<image :src="swipe.pic" mode="aspectFit" @click="goGoodsConByProductID(swipe)"/> <image :src="swipe.pic" mode="aspectFit" @click="goGoodsConByProductID(swipe)"/>
</swiper-item> </swiper-item>
</swiper> </swiper>
@@ -244,34 +244,21 @@
</template> </template>
<script> <script>
import {mapGetters} from 'vuex';
import PromotionGood from '@/components/PromotionGood';
import CouponWindow from '@/components/CouponWindow';
import CountDown from "@/components/CountDown";
import hxNavbar from "@/components/hx-navbar/hx-navbar.vue"
import imgBox from '@/components/imageTypeSet/imagebox.vue' import imgBox from '@/components/imageTypeSet/imagebox.vue'
import { mapGetters } from 'vuex'
import {getCouponReceive, noticeDetail, noticeList} from "@/api/user"; import { getCouponReceive, noticeDetail, noticeList } from '@/api/user'
import {getHomeData, getShareImage} from '@/api/public'; import { getHomeData, getShareImage } from '@/api/public'
import {getProducts} from "@/api/store"; import { getProducts } from '@/api/store'
import {sharpBannar} from "@/api/goods"; import { sharpBannar } from '@/api/goods'
import NP from "number-precision"; import NP from 'number-precision'
import { pageListenMixins } from '@/mixins/pageListenMixins' import { pageListenMixins } from '@/mixins/pageListenMixins'
var that;
export default { export default {
name: 'Index', name: 'IndexPage',
components: { components: {
imgBox, imgBox
PromotionGood,
CouponWindow,
CountDown,
hxNavbar
}, },
mixins: [pageListenMixins], mixins: [pageListenMixins],
data: function () { data() {
return { return {
currentIndex: 0, currentIndex: 0,
speed: 200, speed: 200,
@@ -293,7 +280,7 @@ export default {
menus: [], menus: [],
menuArr: [[], []], menuArr: [[], []],
roll: [], roll: [],
cityName: "", cityName: '',
activity: [], activity: [],
groupGoods: [], groupGoods: [],
activityOne: {}, activityOne: {},
@@ -370,9 +357,9 @@ export default {
liveList: [], liveList: [],
broadcastStyle2: { broadcastStyle2: {
speed: 100, speed: 100,
font_size: "32", //字体大小(rpx) font_size: '32', //字体大小(rpx)
text_color: "#333", //字体颜色 text_color: '#333', //字体颜色
back_color: "red", //背景色 back_color: 'red', //背景色
}, },
bslImglist: [], bslImglist: [],
statusBarHeight: 64, statusBarHeight: 64,
@@ -380,8 +367,8 @@ export default {
preSaleList: [], // 预售商品 preSaleList: [], // 预售商品
month: 0, // 每日特价:月 month: 0, // 每日特价:月
date: 0, // 每日特价:日 date: 0, // 每日特价:日
bannarList: [], // 尖货推荐横幅 bannerList: [], // 尖货推荐横幅
shareAppImg: "", // 发送给朋友 shareAppImg: '', // 发送给朋友
isOldUser: true, // 老用户弹窗 isOldUser: true, // 老用户弹窗
oldUserPopup: {}, oldUserPopup: {},
contentHomestay: {}, contentHomestay: {},
@@ -392,48 +379,40 @@ export default {
scrollTop: 0 scrollTop: 0
} }
}, },
computed: mapGetters(["userInfo", 'isLogin']), computed: mapGetters(['userInfo', 'isLogin']),
onLoad: function (options) { onLoad(options) {
that = this; const _this = this
this.init(); _this.init()
getShareImage().then(({data}) => this.shareAppImg = data); getShareImage().then(({ data }) => _this.shareAppImg = data)
uni.getSystemInfo({ uni.getSystemInfo({
success: (e) => { success: (e) => {
let statusBar = 0; let statusBar = 0
let customBar = 0; let customBar = 0
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
statusBar = e.statusBarHeight statusBar = e.statusBarHeight
const custom = uni.getMenuButtonBoundingClientRect() const custom = uni.getMenuButtonBoundingClientRect()
customBar = custom.bottom + custom.top - e.statusBarHeight customBar = custom.bottom + custom.top - e.statusBarHeight
// #endif // #endif
_this.statusBarHeight = customBar
that.statusBarHeight = customBar; // 两列商品宽度
//两列商品宽度 _this.hotGoodsColumnWidth = (e.screenWidth - uni.upx2px(90)) / 2 + 'px'
that.hotGoodsColumnWidth = (e.screenWidth - uni.upx2px(90)) / 2 + 'px'; // 状态栏图片高度
//状态栏图片高度 _this.bgImgHeight = statusBar + 'px'
that.bgImgHeight = statusBar + 'px';
} }
}); })
this.testAni()
}, },
onShow: function () { onShow() {
const today = new Date(); const today = new Date()
this.month = today.getMonth() + 1; this.month = today.getMonth() + 1
this.date = today.getDate(); this.date = today.getDate()
// 如果已经登录获取用户信息
//如果已经登录获取用户信息
if (this.isLogin) { if (this.isLogin) {
this.$store.dispatch("getUser", true); this.$store.dispatch('getUser', true)
// 获取最新一条消息
//获取最新一条消息 this.getUnreadMsgList()
this.getUnreadMsgList();
} }
// 获取团购商品 // 获取团购商品
this.getGroupGoods(); this.getGroupGoods()
// fix bug#1113 // fix bug#1113
// if (this.bastList.length > 0) { // if (this.bastList.length > 0) {
// this.getBastList() // this.getBastList()
@@ -457,105 +436,101 @@ export default {
}, },
methods: { methods: {
init() { init() {
let that = this; const _this = this
sharpBannar().then(response => {
sharpBannar().then(({data}) => { _this.bannerList = response.data.banner
this.bannarList = data.banner uni.showLoading({ title: '加载中' })
uni.showLoading({
title: '加载中'
});
getHomeData().then(res => { getHomeData().then(res => {
that.logoUrl = res.data.logoUrl; const { data } = res
that.$set(that, 'banner', res.data.banner); _this.logoUrl = data.logoUrl
_this.$set(_this, 'banner', data.banner)
that.$set(that, 'menus', res.data.menus) _this.$set(_this, 'menus', data.menus)
res.data.menus?.forEach((item, index) => { data.menus?.forEach((item, index) => {
if (index % 2 === 0) { if (index % 2 === 0) {
that.menuArr[0].push(item) _this.menuArr[0].push(item)
} else { } else {
that.menuArr[1].push(item) _this.menuArr[1].push(item)
} }
}) })
that.$set(that, 'roll', res.data.roll); _this.$set(_this, 'roll', data.roll)
that.$set(that, 'userList', res.data.lotteryRecord); //滚动会员信息 // 滚动会员信息
that.$set(that, 'info', res.data.info); _this.$set(_this, 'userList', data.lotteryRecord)
that.$set(that, 'firstList', res.data.firstList.map((item) => { _this.$set(_this, 'info', data.info)
item.price = that.$force2Decimal(item.price); _this.$set(_this, 'firstList', data.firstList.map((item) => {
//如果已经登录获取用户信息 item.price = _this.$force2Decimal(item.price)
if (that.$store.getters.token && that.userInfo) { // 如果已经登录获取用户信息
var p = NP.times(item.price, NP.divide(parseFloat(that.userInfo.discount), if (_this.$store.getters.token && _this.userInfo) {
100)) const p = NP.times(item.price, NP.divide(parseFloat(_this.userInfo.discount), 100))
item.vipPrice = that.$force2Decimal(p); item.vipPrice = _this.$force2Decimal(p)
} }
return item; return item
})); }))
that.$set(that, 'oldUserPopup', res.data.oldUserPopup) _this.$set(_this, 'oldUserPopup', data.oldUserPopup)
that.$set(that, 'contentHomestay', res.data.contentHomestay) _this.$set(_this, 'contentHomestay', data.contentHomestay)
that.$set(that, 'contentFestival', res.data.contentFestival) _this.$set(_this, 'contentFestival', data.contentFestival)
that.$set(that, 'countyFamous', res.data.countyFamous) _this.$set(_this, 'countyFamous', data.countyFamous)
// 处理时令尝鲜轮播图所需数据 // 处理时令尝鲜轮播图所需数据
const foodLen = res.data.seasonalFood.productsCarousels.length; const foodLen = data.seasonalFood.productsCarousels.length
const foods = res.data.seasonalFood.productsCarousels; const foods = data.seasonalFood.productsCarousels
let groupList = []; const groupList = []
if (foodLen) { if (foodLen) {
const count = 4; const count = 4
for (let i = 0; i < foodLen; i += count) { for (let i = 0; i < foodLen; i += count) {
groupList.push(foods.slice(i, i + count)) groupList.push(foods.slice(i, i + count))
} }
} }
res.data.seasonalFood.groupList = groupList; data.seasonalFood.groupList = groupList
that.$set(that, 'seasonalFood', res.data.seasonalFood) _this.$set(_this, 'seasonalFood', data.seasonalFood)
if (that.firstList.length > 0) { if (_this.firstList.length > 0) {
that.newGoods = that.firstList[0]; _this.newGoods = _this.firstList[0]
} }
that.$set(that, 'likeInfo', res.data.likeInfo.map((item) => { _this.$set(_this, 'likeInfo', data.likeInfo.map((item) => {
item.price = that.$force2Decimal(item.price); item.price = _this.$force2Decimal(item.price)
item.otPrice = that.$force2Decimal(item.otPrice); item.otPrice = _this.$force2Decimal(item.otPrice)
//如果已经登录获取用户信息 // 如果已经登录获取用户信息
if (that.$store.getters.token && that.userInfo) { if (_this.$store.getters.token && _this.userInfo) {
var p = NP.times(item.price, NP.divide(parseFloat(that.userInfo.discount), const p = NP.times(item.price, NP.divide(parseFloat(_this.userInfo.discount), 100))
100)) item.vipPrice = _this.$force2Decimal(p)
item.vipPrice = that.$force2Decimal(p);
} }
return item; return item
})); }))
setTimeout(() => { setTimeout(() => {
//伴手礼图片 // 伴手礼图片
var imgs = []; const imgs = []
that.likeInfo.forEach((item) => { _this.likeInfo.forEach((item) => {
imgs.push(item.image); imgs.push(item.image)
}) })
that.$set(that, 'bslImglist', imgs); _this.$set(_this, 'bslImglist', imgs)
_this.seriesWidth = 770 * imgs.length - 20
that.seriesWidth = 770 * imgs.length - 20; _this.duration = Math.floor(_this.seriesWidth / _this.speed * 1000)
that.duration = Math.floor(that.seriesWidth / that.speed * 1000);
}, 1) }, 1)
for (let i = 0; i < res.data.bastList.length; i++) { for (let i = 0; i < data.bastList.length; i++) {
res.data.bastList[i].hide = true; data.bastList[i].hide = true
} }
that.$set(that, 'bastList', res.data.bastList); _this.$set(_this, 'bastList', data.bastList)
that.$set(that, 'lovely', res.data.lovely); _this.$set(_this, 'lovely', data.lovely)
that.$set(that, 'benefit', res.data.benefit); _this.$set(_this, 'benefit', data.benefit)
that.$set(that, 'couponList', res.data.couponList); _this.$set(_this, 'couponList', data.couponList)
that.$set(that, 'companyName', res.data.companyName); _this.$set(_this, 'companyName', data.companyName)
that.$set(that, 'companyAddress', res.data.companyAddress); _this.$set(_this, 'companyAddress', data.companyAddress)
that.$set(that, 'companyTel', res.data.companyTel); _this.$set(_this, 'companyTel', data.companyTel)
that.$set(that, 'companyLogo', res.data.companyLogo); _this.$set(_this, 'companyLogo', data.companyLogo)
that.$set(that, 'dailyGoodsList', res.data.dailyGoodsList); _this.$set(_this, 'dailyGoodsList', data.dailyGoodsList)
that.$set(that, 'preSaleList', res.data.preSaleList); _this.$set(_this, 'preSaleList', data.preSaleList)
uni.hideLoading()
uni.hideLoading(); }).catch(() => {
}); uni.hideLoading()
}); })
})
}, },
getBastList() { getBastList() {
getHomeData().then(res => { getHomeData().then(res => {
@@ -569,61 +544,48 @@ export default {
}) })
}, },
getGroupGoods() { getGroupGoods() {
var params = { getProducts({
page: 1, page: 1,
limit: 1, limit: 1,
sid: 19, //团购id=19 sid: 19, //团购id=19
news: 0, news: 0,
priceOrder: "", priceOrder: '',
salesOrder: "" salesOrder: ''
} }).then(res => {
var _this = this; this.groupGoods = res.data
getProducts(params)
.then(res => {
_this.groupGoods = res.data;
})
.catch(err => {
})
},
clickItem(data) {
this.goGoodsCon(data);
},
msgConfirm: function () {
that.$refs.popup.close();
},
goPreSale: function () {
this.$yrouter.push("/v4/views/preSale/preSale")
},
goOffer: function () {
this.$yrouter.push("/v4/views/offer/offer")
},
setMsgReaded: function (mid) {
noticeDetail({
id: mid
}) })
}, },
getUnreadMsgList: function () { clickItem(data) {
var params = { this.goGoodsCon(data)
},
msgConfirm: function () {
this.$refs.popup.close()
},
goPreSale: function () {
this.$yrouter.push('/v4/views/preSale/preSale')
},
goOffer: function () {
this.$yrouter.push('/v4/views/offer/offer')
},
setMsgReaded(mid) {
noticeDetail({ id: mid })
},
getUnreadMsgList() {
noticeList({
limit: 10, limit: 10,
page: 1 page: 1
} }).then(res => {
let that = this;
noticeList(params).then(res => {
if (res.data && res.data.length > 0) { if (res.data && res.data.length > 0) {
var msg = res.data[0]; const msg = res.data[0]
if (msg.readFlag == 'RF0') { if (msg.readFlag == 'RF0') {
that.unReadMessageInfo = msg; this.unReadMessageInfo = msg
that.$refs.popup.open(); this.$refs.popup.open()
that.setMsgReaded(msg.id); this.setMsgReaded(msg.id)
} }
} }
}) })
}, },
call() {
call: function () {
if (this.companyTel != undefined && this.companyTel.length > 0) { if (this.companyTel != undefined && this.companyTel.length > 0) {
uni.makePhoneCall({ uni.makePhoneCall({
// 手机号 // 手机号
@@ -636,10 +598,8 @@ export default {
} }
}); });
} else { } else {
this.$dialog.error('电话为空'); this.$dialog.error('电话为空')
} }
}, },
goRoll(item) { goRoll(item) {
if (item.uniapp_url) { if (item.uniapp_url) {
@@ -647,7 +607,7 @@ export default {
} }
}, },
goGoodSearch() { goGoodSearch() {
this.$yrouter.push('/pages/shop/GoodSearch/index'); this.$yrouter.push('/pages/shop/GoodSearch/index')
}, },
goGoodsCon(item) { goGoodsCon(item) {
this.$yrouter.push({ this.$yrouter.push({
@@ -655,7 +615,7 @@ export default {
query: { query: {
id: item.id id: item.id
} }
}); })
}, },
goGoodsConByProductID(item, from) { goGoodsConByProductID(item, from) {
this.$yrouter.push({ this.$yrouter.push({
@@ -665,19 +625,16 @@ export default {
activityId: item.id, activityId: item.id,
from from
} }
}); })
}, },
changeOldPopup(state) { changeOldPopup(state) {
this.isOldUser = state; this.isOldUser = state
}, },
goHomeStay(stay) { goHomeStay(stay) {
if (stay.uniappUrl) { if (stay.uniappUrl) {
this.$global.commonJump(stay.uniappUrl) this.$global.commonJump(stay.uniappUrl)
return return
} }
if (stay.type === 2 && stay.isLinkToProduct) { if (stay.type === 2 && stay.isLinkToProduct) {
this.$yrouter.push({ this.$yrouter.push({
path: '/pages/shop/GoodsCon/index', path: '/pages/shop/GoodsCon/index',
@@ -691,13 +648,20 @@ export default {
uni.navigateTo({url: '/pkg_product/views/homestay?id=' + stay.id}) uni.navigateTo({url: '/pkg_product/views/homestay?id=' + stay.id})
} }
}, },
goFestival() { goFestival() {
uni.navigateTo({url: '/pkg_product/views/festival'}) uni.navigateTo({url: '/pkg_product/views/festival'})
}, },
tapOld() { tapOld() {
this.isOldUser = false this.isOldUser = false
const {type, text, jumpTime, pageLevel, url, params, couponId} = this.oldUserPopup const {
type,
text,
jumpTime,
pageLevel,
url,
params,
couponId
} = this.oldUserPopup
if (couponId != null) { if (couponId != null) {
getCouponReceive(couponId).then(res => { getCouponReceive(couponId).then(res => {
if (res.status === 200) { if (res.status === 200) {
@@ -725,13 +689,6 @@ export default {
this.$global.levelJump(pageLevel, url, params) this.$global.levelJump(pageLevel, url, params)
} }
}, },
testAni() {
const query = uni.createSelectorQuery().in(this).select('.index')
query.fields({size: true, scrollOffset: true}, (data) => {
console.log(JSON.stringify(data))
}).exec()
},
setTopHandle() { setTopHandle() {
uni.pageScrollTo({ uni.pageScrollTo({
scrollTop: 0, scrollTop: 0,
@@ -739,7 +696,7 @@ export default {
}) })
} }
} }
}; }
</script> </script>
<style scoped lang="less"> <style scoped lang="less">