初始化
This commit is contained in:
99
pages/index/index.js
Normal file
99
pages/index/index.js
Normal file
@@ -0,0 +1,99 @@
|
||||
// index.js
|
||||
// 获取应用实例
|
||||
const app = getApp()
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
autho: null,
|
||||
selectGroupIndex: -1,
|
||||
ishotel: false,
|
||||
hotelIndex: -1,
|
||||
issel:false
|
||||
},
|
||||
///选择酒店
|
||||
SelHotel: function (e) {
|
||||
let index = e.currentTarget.dataset['index'];
|
||||
this.setData({
|
||||
hotelIndex: index
|
||||
})
|
||||
wx.setStorageSync(this.data.userInfo.Id + '_xiaoxi_hotelId', this.data.autho[this.data.selectGroupIndex].Hotels[this.data.hotelIndex].HotelId)
|
||||
},
|
||||
//确定选择酒店
|
||||
ShowSelHotel: function (e) {
|
||||
let id = e.currentTarget.dataset['id'];
|
||||
if(id==-1){
|
||||
id = this.data.autho[this.data.selectGroupIndex].Hotels[this.data.hotelIndex].HotelId;
|
||||
}
|
||||
if(this.data.hotelIndex>=0){
|
||||
wx.navigateTo({
|
||||
url: '/pages/Hosts/Hosts?HotelId=' + id
|
||||
})
|
||||
}else{
|
||||
app.toast(2,'未选择酒店')
|
||||
}
|
||||
},
|
||||
//选择酒店组
|
||||
bindgroup: function (e) {
|
||||
let index = e.currentTarget.dataset['index']
|
||||
this.setData({
|
||||
selectGroupIndex: index,
|
||||
hotelIndex: 0,
|
||||
ishotel: true
|
||||
})
|
||||
wx.setStorageSync(this.data.userInfo.Id + '_xiaoxi_hotelId', this.data.autho[this.data.selectGroupIndex].Hotels[this.data.hotelIndex].HotelId)
|
||||
wx.setStorageSync(this.data.userInfo.Id + '_xiaoxi_selectGroupId', this.data.autho[this.data.selectGroupIndex].HotelGroupsId)
|
||||
},
|
||||
//登录
|
||||
onLoad: async function (option) {
|
||||
this.setData({
|
||||
userInfo: app.globalData.userinfo,
|
||||
autho: app.globalData.autho
|
||||
})
|
||||
if (this.data.userInfo == null) {
|
||||
app.checkLoginReadyCallback = res => {
|
||||
this.setData({
|
||||
userInfo: app.globalData.userinfo,
|
||||
autho: app.globalData.autho
|
||||
})
|
||||
this.ReaSel()
|
||||
};
|
||||
} else {
|
||||
this.ReaSel()
|
||||
}
|
||||
|
||||
},
|
||||
//读取历史选择酒店
|
||||
ReaSel: function () {
|
||||
let _xiaoxi_hotelId = wx.getStorageSync(this.data.userInfo.Id + '_xiaoxi_hotelId')
|
||||
let _xiaoxi_selectGroupId = wx.getStorageSync(this.data.userInfo.Id + '_xiaoxi_selectGroupId')
|
||||
let _xiaoxi_selectGroupIndex = -1;
|
||||
let _xiaoxi_hotelIndex = -1;
|
||||
this.data.autho.forEach((element, index) => {
|
||||
if (element.HotelGroupsId == _xiaoxi_selectGroupId) {
|
||||
_xiaoxi_selectGroupIndex = index;
|
||||
element.Hotels.forEach((elements, indexs) => {
|
||||
if (elements.HotelId == _xiaoxi_hotelId) {
|
||||
_xiaoxi_hotelIndex = indexs;
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
this.setData({
|
||||
selectGroupIndex: _xiaoxi_selectGroupIndex,
|
||||
hotelIndex: _xiaoxi_hotelIndex
|
||||
})
|
||||
//非选择 读取上次进行跳转
|
||||
if(!this.data.issel && this.data.hotelIndex>-1){
|
||||
wx.navigateTo({
|
||||
url: '/pages/Hosts/Hosts?HotelId='+this.data.autho[this.data.selectGroupIndex].Hotels[this.data.hotelIndex].HotelId
|
||||
})
|
||||
}
|
||||
// console.log(this.data.autho.length==1 && this.data.autho[0].Hotels.length==1 && option.issel!=0)
|
||||
//非选择 如果只有一个酒店就直接进行跳转
|
||||
if(this.data.autho.length==1 && this.data.autho[0].Hotels.length==1 && !this.data.issel){
|
||||
wx.navigateTo({
|
||||
url: '/pages/Hosts/Hosts?HotelId='+this.data.autho[0].Hotels[0].HotelId
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user