Files
CompanyProject/衣莎项目/源码/YiShaXiYi/pages/index/index.js
2024-09-27 01:32:49 +08:00

209 lines
5.4 KiB
JavaScript

// pages/index/index.js
const app = getApp();
const regeneratorRuntime = app.loadAsync()
const model = app.loadModel("index")
const util = app.loadUtils("util")
const http = app.loadHttp()
const api = app.loadApi()
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
system: app.globalData.system, //设备相关信息
pageTitle: "伊莎洗衣", //头部标题
isLocation: true, //是否显示定位
titleColor: { //头部背景和文字颜色
bColor: "#1dbf53",
tColor: "#ffffff"
},
swiperList: [{
id: 0,
type: 'image',
url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84001.jpg'
}],
brandImg: [{
imgUrl: "/static/img/icon/xy.png",
title: "洗衣"
}, {
imgUrl: "/static/img/icon/xx.png",
title: "洗鞋"
}, {
imgUrl: "/static/img/icon/xjf.png",
title: "洗家纺"
}, {
imgUrl: "/static/img/icon/xscp.png",
title: "奢侈品养护"
}, {
imgUrl: "/static/img/icon/xjz.png",
title: "家政服务"
}, {
imgUrl: "/static/img/icon/xrzq.png",
title: "新人专区"
}, {
imgUrl: "/static/img/icon/hyzx.png",
title: "会员专享"
}, {
imgUrl: "/static/img/icon/cz.png",
title: "在线充值"
}],
currentSwiper: 0,
cityInfo: {
city: "定位中",
location: ""
},//最新门店
isVideo: false,//弹出video
preferential: ['', ''],//每周特惠
newsData: ['', '', ''],//新闻列表
},
ready() {
// this.add()
model.storage.deleteStorage('nearestStore')
Promise.all([this.storeMenu(), this.benefitProduct(), this.getBanner(), this.getNews()])
.then(res => {
app.globalData.showSkeleton = false
})
},
/**
* 组件的方法列表
*/
methods: {
swiperChange: function (e) {
this.setData({
currentSwiper: e.detail.current
})
},
// 显示
// disVideo() {
// this.setData({
// isVideo: !this.data.isVideo
// })
// },
// 授权和获取用户当前经纬度,并展示最近门店
async add() {
// 判断本地是否有最近门店,只在第一次进小程序请求后端获取最近门店
let storageAdd = await model.storage.getSetting("nearestStore")
let cityInfo = {}
if (!!storageAdd) {
cityInfo = {
city: storageAdd.name.substring(0, 4),
location: "/pages/nearbyStore/nearbyStore"
}
this.setData({
cityInfo: cityInfo
})
return
}
let res = await model.getauth.userLocation()
cityInfo = {
city: res.name.substring(0, 4),
location: "/pages/nearbyStore/nearbyStore"
}
this.setData({
cityInfo: cityInfo
})
},
// 首页banner获取
async getBanner() {
let res = await http.http.request1({ url: `${http.api.banner}`, method: "GET" })
this.setData({
swiperList: res.data.data
})
},
// 获取金刚区icon和跳转url
async storeMenu() {
let data = {}
if (app.globalData.userInfo.group_type !== ''
&& app.globalData.userInfo.group_type == 39
&& app.globalData.userInfo.group_type !== void 0
) {
data.group_type = app.globalData.userInfo.group_type
}
let res = await http.http.request1({ url: `${http.api.storeMenu}`, method: "POST", data: data })
this.setData({
brandImg: res.data.data
})
},
// 金刚区跳转
async goDiamondInfo(e) {
let url = e.currentTarget.dataset.url
let name = e.currentTarget.dataset.name
if (!url) {
wx.showToast({
title: '敬请期待',
icon: 'none',
duration: 1200
})
return
}
if (name !== '家政' && name !== '会员专享') {
let isLogin = await util.isLoginJump()
if (isLogin == 1) return;
}
if ((name == '洗衣' || name == '洗鞋' || name == '洗家纺' || name == '奢侈品养护') && app.globalData.userInfo.group_type == 39) {
wx.navigateTo({
url: '/pages/auth/auth?index=6&group_type=' + app.globalData.userInfo.group_type
})
return
}
// 洗衣价目表
wx.navigateTo({
url: url
})
},
// 每周特惠
async benefitProduct() {
let res = await http.http.request1({ url: `${http.api.benefitProduct}`, method: "POST" })
this.setData({
preferential: res.data.data
})
},
// 每周特惠点击商品进入商品详情
goShopInfo(e) {
let id = e.currentTarget.dataset.id
wx.navigateTo({
url: "/mall/index/shopInfo/shopInfo?id=" + id
})
},
// 点击更多
shopMore(e) {
let url = e.currentTarget.dataset.url
wx.navigateTo({
url: url
})
},
// 获取新闻列表
async getNews() {
let data = {
type: 1,
page: 1,
limit: 3
}
let res = await http.http.request1({ url: `${http.api.news}`, method: "GET", data: data })
this.setData({
newsData: res.data.data.list
})
},
// 轮播图跳转
goUrl(e) {
let url = e.currentTarget.dataset.url
wx.navigateTo({
url: url
})
},
imgerr(e) {
console.log(e);
}
},
onPageScroll: function () {
console.log(1);
}
})