闫增涛
2024-04-09 3d73fb33c46aada16a6060adcd4ea14bb33b6b2a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// pages/bookServices/assort/index.js
import { getPublicImage } from "../../../assets/js/middleGround/tool";
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    barHeight: "",
    navBarHeight: "",
    placeholderstyle: "font-size:28rpx",
    assortList: [],
    assortCheck: {
      name: "",
      code: "",
    },
    startList: [],
 
    startCheck: {
      id: "",
      code: "",
    },
    bookList: [],
    loading: false,
    listLoding: false,
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight =
      (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    this.setData({
      barHeight: systInfo.statusBarHeight,
      navBarHeight: navBarHeight,
    });
    this.getAssortList();
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        active: 1,
      });
    }
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
 
  // 获取侧边栏列表
  getAssortList() {
    this.setData({
      loading: true,
    });
    const query = {
      path: "*",
      filterList: [
        {
          value: "Normal",
          field: "state",
        },
      ],
      queryType: "\\",
      searchList: [],
      size: "30",
      start: "0",
      storeRefCode: app.config.goodsStore,
      sort: { type: "Asc", field: "LinkOrder" },
    };
    app.MG.store.getStoreChannelList(query).then((res) => {
      const list = res.datas.filter(
        (item) => item.refCode != "jsek_homepageBookService"
      );
      this.setData({
        assortList: list,
        loading: false,
      });
      this.setData({
        assortCheck: {
          name: res.datas[0].name,
          code: res.datas[0].refCode,
        },
      });
      this.getStairList(res.datas[0].refCode);
    });
  },
  // 侧边栏切换
  changeAssort(e) {
    this.setData({
      assortCheck: {
        name: e.detail.label,
        code: e.detail.value,
      },
    });
    this.getStairList(e.detail.value);
  },
  // 获取一级分类
  getStairList(path) {
    this.setData({
      listLoding: true,
    });
    const query = {
      path,
      filterList: [
        {
          value: "Normal",
          field: "state",
        },
      ],
      queryType: "\\",
      searchList: [],
      size: "30",
      start: "0",
      storeRefCode: app.config.goodsStore,
      sort: { type: "Asc", field: "LinkOrder" },
    };
    app.MG.store.getStoreChannelList(query).then(async (res) => {
      // 获取二级分类
      for (let index = 0; index < res.datas.length; index++) {
        const item = res.datas[index];
        item.icon
          ? (item.icon = getPublicImage(item.icon, 500))
          : (item.icon = item.icon);
        item.children = await this.getSecondList(item);
      }
      console.log(res.datas);
      // 一级分类赋值
      this.setData({
        startList: res.datas,
        listLoding: false,
        "startCheck.id": res.datas[0].id,
        "startCheck..code": "",
      });
    });
  },
 
  // 获取一级分类下二级分类
  async getSecondList(tab) {
    const path = `${this.data.assortCheck.code}\\${tab.refCode}`;
    let datas;
    const query = {
      path,
      filterList: [
        {
          value: "Normal",
          field: "state",
        },
      ],
      coverSize: {
        width: 500,
      },
      queryType: "\\",
      searchList: [],
      size: "30",
      start: "0",
      storeRefCode: app.config.goodsStore,
      sort: { type: "Asc", field: "LinkOrder" },
    };
    await app.MG.store.getStoreChannelList(query).then((res) => {
      for (let index = 0; index < res.datas.length; index++) {
        const element = res.datas[index];
        if (element.icon) element.icon = getPublicImage(element.icon, 500);
      }
      datas = res.datas;
    });
    return datas;
  },
  tabClick(e) {
    const data = e.currentTarget.dataset.tabdata;
    this.setData({
      "startCheck.id": data.id,
      "startCheck.code": data.refCode,
    });
    console.log(data);
  },
  // 跳转列表页
  goPageList(e) {
    const tab = e.currentTarget.dataset.tabdata;
    const stair = e.currentTarget.dataset.stair;
    this.setData({
      "startCheck.id": tab.id,
      "startCheck.code": tab.refCode,
    });
    if (stair) {
      const secondCode = `${stair.pathLinks[0].linkPath}\\${stair.id}`;
      wx.navigateTo({
        url: `/packageBookService/pages/bookServices/list/index?assorName=${this.data.assortCheck.name}&assortCode=${this.data.assortCheck.code}&stairCode=${this.data.startCheck.code}&secondCode=${secondCode}`,
      });
    } else {
      wx.navigateTo({
        url: `/packageBookService/pages/bookServices/list/index?assorName=${this.data.assortCheck.name}&assortCode=${this.data.assortCheck.code}`,
      });
    }
  },
  navToSearchPage(e) {
    wx.navigateTo({
      url: `/packageBookService/pages/bookServices/list/index?assorName=${this.data.assortCheck.name}&assortCode=${this.data.assortCheck.code}&stairCode=${this.data.startCheck.code}&searchValue=${e.detail.value}`,
    });
  },
});