// pages/index/index.js // pages/home/home.js const app = getApp(); Page({ /** * 页面的初始数据 */ data: { userInfo: wx.getStorageSync('userInfo'), topBarHeight: app.globalData.statBarHeight, scrollTop: 0, animationData: null, showDialog: false, company: wx.getStorageSync('company'), picTitle: '', current: 0, pages: null, loadding: false, loading: true, contact: {}, businessList: [], home: { businessList: [{ id: 1, img: 'http://voms.cdn.bosind.com/mini/11.png' }, { id: 2, img: 'http://voms.cdn.bosind.com/mini/12.png' }, { id: 3, img: 'http://voms.cdn.bosind.com/mini/13.png' }, { id: 4, img: 'http://voms.cdn.bosind.com/mini/14.png' }, { id: 5, img: 'http://voms.cdn.bosind.com/mini/15.png' }, { id: 6, img: 'http://voms.cdn.bosind.com/mini/16.png' }, { id: 7, img: 'http://voms.cdn.bosind.com/mini/17.png' }, { id: 8, img: 'http://voms.cdn.bosind.com/mini/18.png' }, ] }, banner: [], menuList: [], goodsList: [], brandList: [ // { // id: 0, // name: "小米", // check: true // }, // { // id: 1, // name: "华为", // check: false // }, // { // id: 2, // name: "苹果", // check: false // }, // { // id: 3, // name: "三星", // check: false // }, // { // id: 4, // name: "锤子", // check: false // }, ], queryIndex: 0, query: { all: 1 } }, /** * 生命周期函数--监听页面加载 */ async onLoad(options) { let userInfo = wx.getStorageSync('userInfo'); this.setData({ userInfo }) // if (typeof this.getTabBar === 'function' && this.getTabBar()) { // if (userInfo && userInfo.userId) { // app.globalData.tabbar.list[0].show = false; // } else { // app.globalData.tabbar.list[0].show = true; // } // } let that = this; app.indeCallBack = e => { if (!userInfo || !userInfo.userId) { that.onShow(); } }; }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { let userInfo = wx.getStorageSync('userInfo'); this.setData({ userInfo }) if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selectIndex: 0, tabbar: app.globalData.tabbar }) } }, /** * 生命周期函数--监听页面显示 */ async onShow() { let userInfo = wx.getStorageSync('userInfo'); let company = wx.getStorageSync('company'); this.setData({ userInfo, company }) let param = {}; if (company) { param = { companyId: company.companyId } } let { data: indexData } = await app.ajax.get({ url: '/admin/miniConfig/index', noCompany: true, isToken: false, data: param }); this.setData({ banner: indexData.data.BANNER.split(','), businessList: indexData.data.OUR_BUSINESS ? JSON.parse(indexData.data.OUR_BUSINESS) : [], contact: indexData.data.CONTACT_US ? JSON.parse(indexData.data.CONTACT_US) : [] }); app.globalData.tabbar = JSON.parse(indexData.data.TABBAR); if (typeof this.getTabBar === 'function' && this.getTabBar()) { setTimeout(() => { this.getTabBar().setData({ selectIndex: 0, tabbar: app.globalData.tabbar }) }, 500); } if (!userInfo || !userInfo.userId) { return; } // if (userInfo && userInfo.userId) { // app.globalData.tabbar.list[0].show = false; // app.globalData.tabbar.list[1].show = true; // this.getTabBar().setData({ // selectIndex: 1, // tabbar: app.globalData.tabbar // }) // } else { // app.globalData.tabbar.list[0].show = true; // app.globalData.tabbar.list[1].show = false; // this.getTabBar().setData({ // selectIndex: 1, // tabbar: app.globalData.tabbar // }) // wx.switchTab({ // url: '/pages/login/login', // }) // return; // } let { data } = await app.ajax.gets("/admin/bxdcategory/query"); let menuDataList = data.data.filter(v => v.status == 1); let menuList = []; for (var i = 0; i < menuDataList.length; i += 10) { menuList.push(menuDataList.slice(i, i + 10)); } //console.log(menuList) this.setData({ menuList }) // this.getBrandList(); this.getGoodsList(); }, onMenu(e) { //console.log(e) wx.navigateTo({ url: `/pages/category/category?categoryId=${e.currentTarget.dataset.item.categoryId}`, }) }, powerDrawer() { app.dialog(this, 'close'); }, shaixuan() { app.dialog(this, 'open'); }, submitShaixuan(e) { let query = this.data.query; query = { shaixuan: 1 }; this.setData({ query: { ...query, ...e.detail.value, brandNameList: this.data.brandList.filter(v => v.check).map(v => v.name).join(",") }, showDialog: false }); this.getGoodsList() }, submitShaixuanReset(e) { let query = this.data.query; let brandList = this.data.brandList; brandList = brandList.map(v => { v.check = false; return v; }); delete query["brandNameList"]; delete query["startPrice"]; delete query["endPrice"]; query["all"] = 1; this.setData({ brandList, query }) }, onBrand(e) { let brandList = this.data.brandList; brandList[e.currentTarget.dataset.index].check = !brandList[e.currentTarget.dataset.index].check; this.setData({ brandList }) }, query(e) { let param = e.currentTarget.dataset.param; let query = this.data.query; if (!param) { this.setData({ query: {} }); } if (param) { let pars = query[param]; query = {}; if (pars != undefined) { query[param] = pars; } if (query[param] == undefined) { query[param] = false; } else if (query[param] == false) { query[param] = true; } else if (query[param] == true) { delete query[param]; } if (!param || query[param] == undefined) { query = { all: 1 } } } else { query = { all: 1 } } let brandList = this.data.brandList; brandList = brandList.map(v => { v.check = false; return v; }); this.setData({ query, brandList }); this.getBrandList(); this.getGoodsList(); }, async getBrandList() { let category1 = this.data.categoryList[this.data.category1Index]; if (this.data.category2Index > -1) { category1 = this.data.categoryList[this.data.category1Index].categories[this.data.category2Index]; } if (this.data.category3Index > -1) { category1 = this.data.categoryList[this.data.category1Index].categories[this.data.category2Index].categories[this.data.category3Index]; } let { data } = await app.ajax.get({ url: "/admin/bxdbrand/queryMoreCategoryBrandList", data: { categoryIds: category1.categoryId } }); this.setData({ brandList: data.data }) }, async getGoodsList() { this.setData({ current: 1, loadding: true }); //console.log('virtualInventoryId', wx.getStorageSync('virtualInventoryId')) try { let { data } = await app.ajax.get({ url: "/admin/bxdprod/browsePage", data: { picTitle: this.data.picTitle, mini: 1, current: 1, size: 20, virtualInventoryId: wx.getStorageSync('virtualInventoryId'), ...this.data.query }, // isLoading: this.data.loading }); let goodsList = data.data.records.map(v => { v["picText"] = v.pic ? v.pic.split(",")[0] : '/images/empty.png'; return v; }); this.setData({ goodsList: goodsList, pages: data.data.pages || null, loadding: false, loading: false, }) } catch (e) { this.setData({ loadding: false }) } }, async getGoodsPageList() { if (this.data.current >= this.data.pages) { return; } this.setData({ current: this.data.current + 1, loadding: true }); //console.log('virtualInventoryId', wx.getStorageSync('virtualInventoryId')) try { let { data } = await app.ajax.get({ url: "/admin/bxdprod/browsePage", data: { picTitle: this.data.picTitle, mini: 1, current: this.data.current, size: 20, virtualInventoryId: wx.getStorageSync('virtualInventoryId'), ...this.data.query }, // isLoading: this.data.loading }); let goodsList = data.data.records.map(v => { v["picText"] = v.pic ? v.pic.split(",")[0] : '/images/empty.png'; return v; }); this.setData({ goodsList: this.data.goodsList.concat(goodsList), pages: data.data.pages || null, loadding: false, loading: false, }) } catch (e) { this.setData({ loadding: false }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { this.getGoodsPageList(); }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, onPageScroll(e) { this.setData({ scrollTop: e.scrollTop }); }, scrollTop: function () { wx.pageScrollTo({ scrollTop: 0, duration: 300 }); }, })