代码拉取完成,页面将自动刷新
<script>
import {getBannerList, getReommendList, getUserInfo, getStoreList} from 'api/home/index.js';
import {
myCouponList
} from 'api/me/index.js';
import {getGoods} from 'api/order/index.js';
import Vue from 'vue';
import {mapActions} from 'vuex';
import {setToken} from 'utils/auth.js';
import {getDistance} from 'utils/index.js';
export default {
onLaunch: function() {
const that = this;
// 轮播图
getBannerList().then(res => {
this.setBannerList({bannerList: res.data});
});
// 商品
getGoods().then(res => {
this.setGoods({goodsList: res.data});
});
// 门店列表
getStoreList().then(res => {
let store = res.data[0];
store.status = !!Number(store.status);
uni.getLocation({
type: 'wgs84',
success: function (res) {
let distance = getDistance(res.latitude, res.longitude, store.latitude, store.longitude)
that.setStore({store: Object.assign(store, {distance})});
},
fail() {
that.setStore({store: Object.assign(store, {distance: '9999km'})});
}
});
});
uni.getSystemInfo({
success(e) {
Vue.prototype.scrollviewHeilght = e.safeArea.height;
}
});
uni.login({
provider: 'weixin',
success(e) {
let {
code,
errMsg
} = e;
if (errMsg = 'login:ok') {
that.$slLoading('加载中...').then(() => {
// 获取用户信息
getUserInfo(code).then(res => {
const {token, user: userInfo} = res;
if(userInfo) {
setToken(token);
that.setUserInfo({userInfo});
// 获取优惠券
myCouponList().then(res => {
that.setCouponList({couponList: res.rows});
})
// 获取桌子信息
that.setStatusInfo({id: userInfo.id});
}
}).finally(() => {
uni.hideLoading();
})
})
}
}
})
},
onShow: function() {
},
onHide: function() {
},
methods: {
...mapActions(['setBannerList', 'setUserInfo', 'setStore', 'setCategory', 'setGoods', 'setCouponList', 'setStatusInfo'])
}
}
</script>
<style lang="scss">
/*每个页面公共css */
@import "static/css/index.css";
// 引入vant样式
@import "wxcomponents/vant/dist/common/index.wxss";
// 引入iconfont
@import "static/css/iconfont.css";
</style>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。