| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- // 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
- });
- },
- })
|