|
|
@@ -0,0 +1,300 @@
|
|
|
+const content = {
|
|
|
+ pageNumber: 1,
|
|
|
+ pageTotal: 1
|
|
|
+ },
|
|
|
+ _Http = getApp().globalData.http;
|
|
|
+let sa_brandid = null,
|
|
|
+ downCount = null;
|
|
|
+Component({
|
|
|
+ options: {
|
|
|
+ addGlobalClass: true
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ CustomBar: getApp().globalData.CustomBar,
|
|
|
+ typeList: [],
|
|
|
+ list: [],
|
|
|
+ filtratelist: [],
|
|
|
+ popupShow: false,
|
|
|
+ showAction: false,
|
|
|
+ activeKey: 0,
|
|
|
+ sidebarItems: [],
|
|
|
+ firstClassList: [],
|
|
|
+ currentFirstClass: null,
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ openAction() {
|
|
|
+ this.setData({
|
|
|
+ showAction: true
|
|
|
+ })
|
|
|
+ },
|
|
|
+ closeAction() {
|
|
|
+ this.setData({
|
|
|
+ showAction: false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 获取领域 */
|
|
|
+ getTradefie() {
|
|
|
+ _Http.basic({
|
|
|
+ "id": 20221223141802,
|
|
|
+ content: {
|
|
|
+ nocache: true,
|
|
|
+ pageNumber: 1,
|
|
|
+ pageSize: 9999,
|
|
|
+ where: {
|
|
|
+ condition: ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, false).then(res => {
|
|
|
+ console.log("获取领域", res)
|
|
|
+ if (res.msg == '成功' && res.data.length > 1) {
|
|
|
+ res.data.unshift({
|
|
|
+ rowindex: 0,
|
|
|
+ subvalues: [],
|
|
|
+ sys_enterprise_tradefieldid: 0,
|
|
|
+ tradefield: "全部",
|
|
|
+ color: "#3874F6"
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ tradefieList: res.data.map(v => {
|
|
|
+ v.name = v.tradefield
|
|
|
+ return v
|
|
|
+ })
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onSelect(e) {
|
|
|
+ let tradefield = e.detail.tradefield
|
|
|
+ content.where.tradefield = tradefield == '全部' ? '' : tradefield;
|
|
|
+ this.setData({
|
|
|
+ tradefieList: this.data.tradefieList.map(v => {
|
|
|
+ if (tradefield == v.tradefield) {
|
|
|
+ v.color = "#3874F6"
|
|
|
+ } else {
|
|
|
+ delete v.color
|
|
|
+ }
|
|
|
+ return v
|
|
|
+ }),
|
|
|
+ showAction: false,
|
|
|
+ tradefield: content.where.tradefield
|
|
|
+ })
|
|
|
+ this.getList(true);
|
|
|
+ },
|
|
|
+ init() {
|
|
|
+ content.where = {
|
|
|
+ condition: "",
|
|
|
+ itemclassid: "",
|
|
|
+ tradefield: ""
|
|
|
+ }
|
|
|
+ this.getBrand();
|
|
|
+ this.getTradefie();
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ /* 获取品牌 */
|
|
|
+ getBrand() {
|
|
|
+ _Http.basic({
|
|
|
+ "id": 20220924163702,
|
|
|
+ content: {
|
|
|
+ nocache: true,
|
|
|
+ pageSize: 999,
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("查询品牌", res)
|
|
|
+ if (res.msg != '成功') return wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ if (res.data.length != 0) {
|
|
|
+ sa_brandid = res.data[0].sa_brandid;
|
|
|
+ this.getTypeList();
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '未查询到授权品牌',
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 获取分类 */
|
|
|
+ getTypeList() {
|
|
|
+ _Http.basic({
|
|
|
+ "id": "20220922110403",
|
|
|
+ pageSize: 1000,
|
|
|
+ content: {
|
|
|
+ nocache: true,
|
|
|
+ sa_brandid: sa_brandid,
|
|
|
+ where: {
|
|
|
+ istool: 0,
|
|
|
+ ishide: 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("营销类别", res)
|
|
|
+ if (res.data.length) {
|
|
|
+ // 保存完整的分类数据
|
|
|
+ this.allCategories = res.data[0].ttemclass;
|
|
|
+ console.log('allCategories:', this.allCategories);
|
|
|
+
|
|
|
+ const firstClassList = this.allCategories.map(v => {
|
|
|
+ v.name = v.itemclassname;
|
|
|
+ return v;
|
|
|
+ });
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ firstClassList: firstClassList,
|
|
|
+ currentFirstClass: this.allCategories[0]
|
|
|
+ });
|
|
|
+
|
|
|
+ // 初始显示第一个一级分类的末级分类
|
|
|
+ this.updateSidebarItems(this.allCategories[0]);
|
|
|
+ }
|
|
|
+ this.getList(true);
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 更新侧边栏分类 */
|
|
|
+ updateSidebarItems(firstClass) {
|
|
|
+ const sidebarItems = [];
|
|
|
+ let id = 0;
|
|
|
+
|
|
|
+ // 递归遍历分类,找出末级分类
|
|
|
+ const findLeafCategories = (categories, parentName = '') => {
|
|
|
+ if (!categories || categories.length === 0) {
|
|
|
+ console.log('没有子分类');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ categories.forEach(category => {
|
|
|
+ if (category.subdep && category.subdep.length > 0) {
|
|
|
+ // 不是末级分类,继续遍历子分类
|
|
|
+ findLeafCategories(category.subdep, category.itemclassname);
|
|
|
+ } else {
|
|
|
+ // 是末级分类,添加到侧边栏
|
|
|
+ let title = category.itemclassname;
|
|
|
+ if (parentName) {
|
|
|
+ // 三级分类,拼接二级和三级分类名称
|
|
|
+ title = `${parentName}-${category.itemclassname}`;
|
|
|
+ }
|
|
|
+ sidebarItems.push({
|
|
|
+ id: id++,
|
|
|
+ title: title,
|
|
|
+ itemclassid: category.itemclassid
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 从选中的一级分类开始遍历
|
|
|
+ findLeafCategories(firstClass.subdep || []);
|
|
|
+ console.log('侧边栏分类:', sidebarItems);
|
|
|
+
|
|
|
+ // 添加"全部"选项
|
|
|
+ sidebarItems.unshift({
|
|
|
+ id: -1,
|
|
|
+ title: "全部",
|
|
|
+ itemclassid: ""
|
|
|
+ });
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ sidebarItems: sidebarItems,
|
|
|
+ activeKey: 0
|
|
|
+ });
|
|
|
+
|
|
|
+ // 设置为一级分类的ID
|
|
|
+ if (firstClass && firstClass.itemclassid) {
|
|
|
+ content.where.itemclassid = firstClass.itemclassid;
|
|
|
+ console.log('设置分类ID:', content.where.itemclassid);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 一级分类切换事件 */
|
|
|
+ firstClassChange(e) {
|
|
|
+ // 确保e.detail是一个数字索引
|
|
|
+ let index = e.detail;
|
|
|
+ if (typeof index === 'object' && index !== null) {
|
|
|
+ index = index.index || index.name || 0;
|
|
|
+ }
|
|
|
+ console.log('选中的索引:', index);
|
|
|
+
|
|
|
+ // 确保allCategories存在
|
|
|
+ if (!this.allCategories || this.allCategories.length === 0) {
|
|
|
+ console.log('allCategories未定义或为空');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('allCategories:', this.allCategories);
|
|
|
+ const selectedClass = this.allCategories[index];
|
|
|
+ console.log('选中的分类:', selectedClass);
|
|
|
+
|
|
|
+ if (selectedClass) {
|
|
|
+ this.setData({
|
|
|
+ currentFirstClass: selectedClass
|
|
|
+ });
|
|
|
+ this.updateSidebarItems(selectedClass);
|
|
|
+ this.getList(true);
|
|
|
+ } else {
|
|
|
+ console.log('未找到选中的分类');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /* 侧边栏切换事件 */
|
|
|
+ onSidebarChange(event) {
|
|
|
+ const activeKey = event.detail;
|
|
|
+ const selectedItem = this.data.sidebarItems[activeKey];
|
|
|
+ content.where.itemclassid = selectedItem.itemclassid;
|
|
|
+ this.setData({
|
|
|
+ activeKey: activeKey
|
|
|
+ });
|
|
|
+ this.getList(true);
|
|
|
+ },
|
|
|
+ /* 获取产品 */
|
|
|
+ getList(init = false) {
|
|
|
+ wx.hideLoading()
|
|
|
+ if (init.detail != undefined) init = init.detail;
|
|
|
+ if (init) content.pageNumber = 1;
|
|
|
+ if (content.pageNumber > content.pageTotal) return;
|
|
|
+ content.brandids = [sa_brandid];
|
|
|
+ _Http.basic({
|
|
|
+ "id": 20220926142203,
|
|
|
+ content
|
|
|
+ }).then(res => {
|
|
|
+ console.log("商品列表", res)
|
|
|
+ if (res.msg != '成功') return wx.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ this.selectComponent('#ListBox').RefreshToComplete();
|
|
|
+ if (init) this.selectComponent('#ListBox').goTop()
|
|
|
+ content.pageNumber = res.pageNumber + 1;
|
|
|
+ content.pageTotal = res.pageTotal;
|
|
|
+ this.setData({
|
|
|
+ list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 开始搜索 */
|
|
|
+ onSearch({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ content.where.condition = detail;
|
|
|
+ wx.showLoading({
|
|
|
+ title: '搜索中...',
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ 'condition': detail
|
|
|
+ })
|
|
|
+ this.getList(true)
|
|
|
+ },
|
|
|
+ onChange({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ content.where.condition = detail
|
|
|
+ this.setData({
|
|
|
+ 'condition': detail
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+})
|