| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- // pages/category/category.js
- // pages/home/home.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- topBarHeight: app.globalData.statBarHeight,
- loading: true,
- loadding: false,
- scrollTop: 0,
- current: 0,
- pages: null,
- picTitle: "",
- company: wx.getStorageSync('company'),
- userInfo: wx.getStorageSync('userInfo'),
- categoryList: [],
- category1Index: 0,
- category2Index: 0,
- category3Index: -1,
- goodsList: [],
- brandList: [],
- query: {
- all: 1
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- async onLoad(options) {
- let categoryId = options.categoryId;
- let userInfo = wx.getStorageSync('userInfo');
- if (!userInfo || !userInfo.userId) {
- // app.globalData.tabbar.list[0].show = true;
- // app.globalData.tabbar.list[1].show = false;
- wx.navigateTo({
- url: '/pages/login/login',
- })
- return;
- }
- let {
- data: categoryList
- } = await app.ajax.get({
- url: "/admin/bxdcategory/query"
- });
- let category1Index = this.data.category1Index;
- let categoryLists = categoryList.data.filter(v => v.status == 1);
- if (categoryId) {
- category1Index = categoryLists.findIndex(v => v.categoryId == categoryId);
- }
- this.setData({
- categoryList: categoryLists,
- category1Index: category1Index || 0
- });
- this.getBrandList();
- this.getGoodsList();
- this.setData({
- loading: false
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- selectCategory(e) {
- let name = e.currentTarget.dataset.name;
- if (this.data["" + e.currentTarget.dataset.name] == e.currentTarget.dataset.index) {
- return;
- }
- if (name.indexOf('1') != -1) {
- this.setData({
- ["" + name.replace('1', '2')]: 0,
- ["" + name.replace('1', '3')]: -1,
- goodsList: []
- })
- } else if (name.indexOf('2') != -1) {
- this.setData({
- ["" + name.replace('2', '3')]: -1,
- goodsList: []
- })
- } else if (name.indexOf('3') != -1) {
- this.setData({
- goodsList: []
- })
- }
- let query = this.data.query;
- delete query['brandNameList'];
- this.setData({
- ["" + e.currentTarget.dataset.name]: e.currentTarget.dataset.index,
- current: 0,
- query
- });
- this.getBrandList();
- this.getGoodsList();
- },
- async getGoodsList() {
- if (this.data.pages != null && this.data.current >= this.data.pages) {
- return;
- }
- 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];
- }
- // //console.log(category1, category2, category3)
- this.setData({
- current: this.data.current + 1,
- loadding: true
- });
- try {
- let {
- data
- } = await app.ajax.get({
- url: "/admin/bxdprod/browsePage",
- data: {
- picTitle: this.data.picTitle,
- mini: 1,
- current: this.data.current,
- size: 20,
- categoryIdList: this.getCategoryIdList(category1),
- virtualInventoryId: wx.getStorageSync('virtualInventoryId'),
- ...this.data.query
- }
- });
- let goodsList = this.data.goodsList;
- this.setData({
- goodsList: goodsList.concat(data.data.records),
- pages: data.data.pages || null,
- loadding: false
- })
- } catch (e) {
- this.setData({
- loadding: false
- })
- }
- },
- 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.map(v => {
- v = {
- name: v,
- check: false
- }
- return v;
- })
- })
- },
- onBrand(e) {
- let brandList = this.data.brandList;
- brandList[e.currentTarget.dataset.index].check = !brandList[e.currentTarget.dataset.index].check;
- this.setData({
- brandList
- })
- },
- getCategoryIdList(categorie) {
- let result = [];
- result.push(categorie.categoryId);
- if (categorie.categories && categorie.categories.length > 0) {
- for (let i = 0; i < categorie.categories.length; i++) {
- let tmp = this.getCategoryIdList(categorie.categories[i]);
- result.push(result, tmp);
- }
- }
- return result.join(",");
- },
- searchGoods(e) {
- this.setData({
- picTitle: e.detail.value,
- goodsList: [],
- current: 0,
- pages: null
- })
- this.getGoodsList();
- },
- goodsScroll(e) {
- //console.log(e)
- },
- 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,
- pages: null,
- current: 0
- });
- this.getGoodsList();
- },
- 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(",")
- },
- goodsList: [],
- current: 0,
- pages: null,
- 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"];
- delete query["shaixuan"];
- query["all"] = 1;
- this.setData({
- brandList,
- query,
- showDialog: false,
- goodsList: [],
- current: 0,
- pages: null,
- });
- this.getGoodsList()
- },
- onMenu(e) {},
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- onPageScroll(e) {
- this.setData({
- scrollTop: e.scrollTop
- });
- },
- scrollTop: function () {
- wx.pageScrollTo({
- scrollTop: 0,
- duration: 300
- });
- },
- })
|