const app = getApp() const config = require("../../config/config"); const Http = require("../../utils/HttpBasics"); Component({ properties: { background: { type: String, value: '#F4F5F9' }, color: { type: String, value: '#000' }, text: { type: String, value: 'Wechat' }, showLocationIf: { type: Boolean, value: false }, back: { type: Boolean, value: false }, home: { type: Boolean, value: false } }, data: { showGroupIf: JSON.parse(wx.getStorageSync('tenantData')).length>0?true:false, tenantData: JSON.parse(wx.getStorageSync('tenantData')), tenantId: wx.getStorageSync('tenantId'), array: [], index: 1, statusBarHeight: app.statusBarHeight + 'px', navigationBarHeight: (app.statusBarHeight + 44) + 'px' }, methods: { backHome: function () { wx.switchTab({ url: '/index/index', }) }, bindPickerChange: function (e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ index: e.detail.value }) let selectIndex = 0; this.data.tenantData.map((item, index) => { if (e.detail.value == item.tenantId) { selectIndex = index; wx.setStorageSync('tenantId', item.tenantId) } }) let param = { tenantId: this.data.tenantData[selectIndex].parentTenantId, subTenantId: this.data.tenantData[e.detail.value].tenantId } this.checkAble = true; wx.showLoading({ title: '切换中...', }) Http.post({ url: config.api.selectMall, data: param }).then(res => { wx.setStorageSync('tenantId', this.data.tenantData[e.detail.value].tenantId) wx.hideLoading(); wx.showToast({ title: '切换成功!', icon: 'success', duration: 2000 }) wx.reLaunch({ url: '/index/index', }) }) .catch(err => { wx.showModal({ title: '提示', content: err.message, showCancel: false, success: function (res) { // 重启首页 if (res.confirm) { wx.reLaunch({ url: '/pages/index/index', }) } } }) this.alphaClick(); }) }, back: function () { wx.navigateBack({ delta: 1 }) } }, attached: function(){ console.log(JSON.parse(wx.getStorageSync('tenantData')), wx.getStorageSync('tenantId'),11111) let list = []; let tindex = 0; this.data.tenantData.map((item,index)=>{ list.push(item.name) if (item.tenantId == wx.getStorageSync('tenantId')){ tindex = index } }) console.log(list,tindex,9999) this.setData({ array:list, index: tindex }) let pages = getCurrentPages(); if (pages.length <= 1) { this.setData({ back: false }) } } })