Commit 92a480dcd20b409a320c6edf8b21cda6c3986071
1 parent
37c0bd4e
自定义分类
Showing
2 changed files
with
203 additions
and
47 deletions
pages/goods/categoryList/categoryList.js
| ... | ... | @@ -173,7 +173,7 @@ Page({ |
| 173 | 173 | if (0 != this.data.cat_id) { |
| 174 | 174 | url += "&cat_id=" + this.data.cat_id; |
| 175 | 175 | } |
| 176 | - | |
| 176 | + | |
| 177 | 177 | // this.requestGoodsList(url); |
| 178 | 178 | getApp().getConfig2(function (rs) { |
| 179 | 179 | //计算等级价相关 |
| ... | ... | @@ -202,9 +202,9 @@ Page({ |
| 202 | 202 | //调用底部导航 |
| 203 | 203 | //t.editTabBar(that,getApp().globalData.setting.stoid,getApp().globalData.url); |
| 204 | 204 | //this.requestFirstCategoris(); |
| 205 | - setTimeout(function () { | |
| 205 | + // setTimeout(function () { | |
| 206 | 206 | //if (getApp().globalData.user_id) getApp().requestCardNum(that); |
| 207 | - }, 500) | |
| 207 | + // }, 500) | |
| 208 | 208 | |
| 209 | 209 | if (this.data.load) return false; |
| 210 | 210 | |
| ... | ... | @@ -228,11 +228,17 @@ Page({ |
| 228 | 228 | if (e.categoryset.indexOf("," + 2 + ",") != -1) { that.setData({ is_show_gb: 1 }); } |
| 229 | 229 | if (e.categoryset.indexOf("," + 4 + ",") != -1) { that.setData({ is_show_xm: 1 }); } |
| 230 | 230 | that.setData({ store_config: e, is_do: 1 }); |
| 231 | - | |
| 231 | + //请求自定义分类数据 | |
| 232 | + // that.requestFirstCategoris_diy() | |
| 232 | 233 | //---有勾品类--- |
| 233 | 234 | if (that.data.is_show_pl) { |
| 234 | - that.requestFirstCategoris(); | |
| 235 | + if (is_newsgoodstype==1) { //如果是风格2,则请求自定义分类 | |
| 236 | + that.requestFirstCategoris_diy(); | |
| 237 | + }else{ | |
| 238 | + that.requestFirstCategoris(); | |
| 239 | + } | |
| 235 | 240 | } |
| 241 | + | |
| 236 | 242 | if (that.data.is_show_xm != 1 && that.data.is_show_gb != 1 && that.data.is_show_pp != 1 && that.data.is_show_pl) { |
| 237 | 243 | that.data.pl_timer = setInterval(function () { |
| 238 | 244 | if (that.data.one_level_classify.length > 0) { |
| ... | ... | @@ -300,17 +306,159 @@ Page({ |
| 300 | 306 | |
| 301 | 307 | }, |
| 302 | 308 | |
| 309 | + | |
| 310 | + //---------------自定义分类请求接口,数据进行拼装------------------ | |
| 311 | + requestFirstCategoris_diy: function () { | |
| 312 | + var t = this; | |
| 313 | + let that=this; | |
| 314 | + e.get("/api/weshop/customizeCategory/page", { | |
| 315 | + data: { store_id: oo.stoid, pageSize: 6600, is_show: 1 }, | |
| 316 | + success: function (e) { | |
| 317 | + | |
| 318 | + if (e.data.code !=0) { | |
| 319 | + that.requestFirstCategoris(); | |
| 320 | + return | |
| 321 | + } | |
| 322 | + var arr = new Array(); | |
| 323 | + var dda = e.data.data.pageData; | |
| 324 | + if (dda != null && dda != "" && dda != undefined) { | |
| 325 | + t.setData({ is_pl_time: 1 }); | |
| 326 | + } | |
| 327 | + | |
| 328 | + if (t.data.is_used_share == 0) {//is_used_share控制新旧版本 | |
| 329 | + for (var i = 0; i < dda.length; i++) { | |
| 330 | + if (parseInt(dda[i].level) == 1) { | |
| 331 | + var item = { items: dda[i], array: new Array(),diy_class:1 } //增加一个diy_class 标识表示为自定义分类 | |
| 332 | + arr.push(item); | |
| 333 | + } else if (parseInt(dda[i].level) == 2) { | |
| 334 | + for (var j = 0; j < arr.length; j++) { | |
| 335 | + if (parseInt(dda[i].parent_id) == parseInt(arr[j].items.id)) { | |
| 336 | + arr[j].array.push(dda[i]); break; | |
| 337 | + } | |
| 338 | + } | |
| 339 | + } else { | |
| 340 | + continue; | |
| 341 | + } | |
| 342 | + } | |
| 343 | + t.setData({ catelist: arr }); | |
| 344 | + } else if (t.data.is_used_share == 1 || t.data.is_used_share == 2) { | |
| 345 | + | |
| 346 | + //---------新的版本---------------- | |
| 347 | + for (var i = 0; i < dda.length; i++) { | |
| 348 | + //--要排队的元素--- | |
| 349 | + var need_to_insert = dda[i]; | |
| 350 | + if (parseInt(need_to_insert.level) == 1) { | |
| 351 | + //判断数组的长度看看有没有2级菜单 | |
| 352 | + var item = { items: need_to_insert, array: new Array(),diy_class:1 } //增加一个diy_class 标识表示为自定义分类 | |
| 353 | + arr.push(item); | |
| 354 | + } else if (parseInt(need_to_insert.level) == 2) { | |
| 355 | + | |
| 356 | + for (var j = 0; j < arr.length; j++) { | |
| 357 | + | |
| 358 | + | |
| 359 | + if (parseInt(need_to_insert.parent_id) == parseInt(arr[j].items.id)) { | |
| 360 | + | |
| 361 | + var ishaf_two = { items: need_to_insert, arrays: new Array(),diy_class:1 }; | |
| 362 | + arr[j].array.push(ishaf_two); arr.ishaf_two = 0; | |
| 363 | + } | |
| 364 | + } | |
| 365 | + } else if (parseInt(need_to_insert.level) == 3) {//判断有3级的时候在二级里添加一个数组 | |
| 366 | + | |
| 367 | + for (var dd = 0; dd < arr.length; dd++) { | |
| 368 | + for (var pp = 0; pp < arr[dd].array.length; pp++) { | |
| 369 | + //--判断二级-- | |
| 370 | + var two_item = arr[dd].array; | |
| 371 | + | |
| 372 | + if (two_item && two_item.length > 0) { | |
| 373 | + | |
| 374 | + if (parseInt(need_to_insert.parent_id) == parseInt(two_item[pp].items.id)) { | |
| 375 | + | |
| 376 | + arr[dd].array[pp].arrays.push(need_to_insert); arr.ishaf_three = 0; break; | |
| 377 | + } | |
| 378 | + } | |
| 379 | + } | |
| 380 | + } | |
| 381 | + } | |
| 382 | + } | |
| 383 | + for (var i = 0; i < arr.length; i++) { | |
| 384 | + arr[i]['items']['is_show_class'] = false; | |
| 385 | + var mobile_name = arr[i]['items']['name'] | |
| 386 | + //if(mobile_name.length > 4){ | |
| 387 | + //arr[i]['items']['name'] = mobile_name.substring(0, 4) | |
| 388 | + //} | |
| 389 | + } | |
| 390 | + if (t.data.is_show_pl == 1 && t.data.is_show_pp != 1 && t.data.is_show_gb != 1) { | |
| 391 | + arr[0]['items']['is_show_class'] = true; | |
| 392 | + } | |
| 393 | + //console.log(arr) | |
| 394 | + t.setData({ one_level_classify: arr }); | |
| 395 | + //---有勾品类--- | |
| 396 | + // if (that.data.is_show_pl) { | |
| 397 | + that.requestFirstCategoris(); | |
| 398 | + // } | |
| 399 | + if (t.data.select_classify_on == 0) { | |
| 400 | + var item = arr[0]; | |
| 401 | + | |
| 402 | + var name = item.items.name; | |
| 403 | + var cid = item.items.id; | |
| 404 | + var arr = item.array; | |
| 405 | + | |
| 406 | + console.log("11111", item); | |
| 407 | + console.log(arr.length); | |
| 408 | + | |
| 409 | + if (arr.length == 0) { | |
| 410 | + t.setData({ | |
| 411 | + select_classify_on: 0, index: 0, classify_name: name, cat_id: cid, | |
| 412 | + goodslist: null, is_level_three: 0 | |
| 413 | + }); | |
| 414 | + | |
| 415 | + if (t.data.is_used_share == 2) | |
| 416 | + t.style(t.data.stylePage, cid) | |
| 417 | + | |
| 418 | + return false; | |
| 419 | + } | |
| 420 | + if (arr.length != 0) { | |
| 421 | + var is_lev_thr = 0 | |
| 422 | + for (var i = 0; i < arr.length; i++) { | |
| 423 | + if (arr[i].arrays.length > 0) { is_lev_thr = 1; break; } | |
| 424 | + } | |
| 425 | + t.setData({ is_level_three: is_lev_thr ,cat_id:cid}); | |
| 426 | + | |
| 427 | + if (this.data.is_level_three != 1) { | |
| 428 | + t.setData({ index: 0, classify_name: name, goodslist: arr }); | |
| 429 | + // t.setData({ index: 0, classify_name: name }); | |
| 430 | + } else { | |
| 431 | + // t.setData({ index: 0}); | |
| 432 | + t.setData({ index: 0, goodslist: arr }); | |
| 433 | + } | |
| 434 | + } | |
| 435 | + | |
| 436 | + if (t.data.is_used_share == 2){ | |
| 437 | + t.style(t.data.stylePage, cid) | |
| 438 | + } | |
| 439 | + | |
| 440 | + } | |
| 441 | + | |
| 442 | + } | |
| 443 | + } | |
| 444 | + }); | |
| 445 | + }, | |
| 446 | + | |
| 303 | 447 | //---------------分类请求接口,数据进行拼装------------------ |
| 304 | 448 | requestFirstCategoris: function () { |
| 449 | + | |
| 305 | 450 | var t = this; |
| 306 | 451 | e.get("/api/weshop/goodscategory/page", { |
| 307 | 452 | data: { store_id: oo.stoid, pageSize: 6600, is_show: 1 }, |
| 308 | 453 | success: function (e) { |
| 454 | + if (e.data.code !=0) { | |
| 455 | + return | |
| 456 | + } | |
| 309 | 457 | var arr = new Array(); |
| 310 | 458 | var dda = e.data.data.pageData; |
| 311 | 459 | if (dda != null && dda != "" && dda != undefined) { |
| 312 | 460 | t.setData({ is_pl_time: 1 }); |
| 313 | - } | |
| 461 | + } | |
| 314 | 462 | |
| 315 | 463 | if (t.data.is_used_share == 0) {//is_used_share控制新旧版本 |
| 316 | 464 | for (var i = 0; i < dda.length; i++) { |
| ... | ... | @@ -377,46 +525,53 @@ Page({ |
| 377 | 525 | arr[0]['items']['is_show_class'] = true; |
| 378 | 526 | } |
| 379 | 527 | //console.log(arr) |
| 380 | - t.setData({ one_level_classify: arr }); | |
| 381 | - if (t.data.select_classify_on == 0) { | |
| 382 | - var item = arr[0]; | |
| 383 | - | |
| 384 | - var name = item.items.name; | |
| 385 | - var cid = item.items.id; | |
| 386 | - var arr = item.array; | |
| 387 | - | |
| 388 | - console.log("11111", item); | |
| 389 | - console.log(arr.length); | |
| 390 | - | |
| 391 | - if (arr.length == 0) { | |
| 392 | - t.setData({ | |
| 393 | - select_classify_on: 0, index: 0, classify_name: name, cat_id: cid, | |
| 394 | - goodslist: null, is_level_three: 0 | |
| 395 | - }); | |
| 396 | - | |
| 397 | - if (t.data.is_used_share == 2) | |
| 398 | - t.style(t.data.stylePage, cid) | |
| 399 | - | |
| 400 | - return false; | |
| 401 | - } | |
| 402 | - if (arr.length != 0) { | |
| 403 | - var is_lev_thr = 0 | |
| 404 | - for (var i = 0; i < arr.length; i++) { | |
| 405 | - if (arr[i].arrays.length > 0) { is_lev_thr = 1; break; } | |
| 528 | + if (t.data.one_level_classify.length>0) { | |
| 529 | + let one_level_classify = t.data.one_level_classify; | |
| 530 | + one_level_classify.push(...arr) | |
| 531 | + t.setData({ one_level_classify: one_level_classify }); | |
| 532 | + }else{ | |
| 533 | + t.setData({ one_level_classify: arr }); | |
| 534 | + if (t.data.select_classify_on == 0) { | |
| 535 | + var item = arr[0]; | |
| 536 | + | |
| 537 | + var name = item.items.name; | |
| 538 | + var cid = item.items.id; | |
| 539 | + var arr = item.array; | |
| 540 | + | |
| 541 | + console.log("11111", item); | |
| 542 | + console.log(arr.length); | |
| 543 | + | |
| 544 | + if (arr.length == 0) { | |
| 545 | + t.setData({ | |
| 546 | + select_classify_on: 0, index: 0, classify_name: name, cat_id: cid, | |
| 547 | + goodslist: null, is_level_three: 0 | |
| 548 | + }); | |
| 549 | + | |
| 550 | + if (t.data.is_used_share == 2) | |
| 551 | + t.style(t.data.stylePage, cid) | |
| 552 | + | |
| 553 | + return false; | |
| 554 | + } | |
| 555 | + if (arr.length != 0) { | |
| 556 | + var is_lev_thr = 0 | |
| 557 | + for (var i = 0; i < arr.length; i++) { | |
| 558 | + if (arr[i].arrays.length > 0) { is_lev_thr = 1; break; } | |
| 559 | + } | |
| 560 | + t.setData({ is_level_three: is_lev_thr ,cat_id:cid}); | |
| 561 | + | |
| 562 | + if (this.data.is_level_three != 1) { | |
| 563 | + t.setData({ index: 0, classify_name: name, goodslist: arr }); | |
| 564 | + } else { | |
| 565 | + t.setData({ index: 0, goodslist: arr }); | |
| 566 | + } | |
| 406 | 567 | } |
| 407 | - t.setData({ is_level_three: is_lev_thr ,cat_id:cid}); | |
| 568 | + if (t.data.is_used_share == 2){ | |
| 408 | 569 | |
| 409 | - if (this.data.is_level_three != 1) { | |
| 410 | - t.setData({ index: 0, classify_name: name, goodslist: arr }); | |
| 411 | - } else { | |
| 412 | - t.setData({ index: 0, goodslist: arr }); | |
| 570 | + t.style(t.data.stylePage, cid) | |
| 413 | 571 | } |
| 572 | + | |
| 414 | 573 | } |
| 415 | - | |
| 416 | - t.style(t.data.stylePage, cid) | |
| 417 | - | |
| 418 | 574 | } |
| 419 | - | |
| 420 | 575 | } |
| 421 | 576 | } |
| 422 | 577 | }); |
| ... | ... | @@ -914,6 +1069,7 @@ Page({ |
| 914 | 1069 | requestGoodsList: function (t) { |
| 915 | 1070 | var that = this; |
| 916 | 1071 | that.data.requestUrl = t; |
| 1072 | + console.error(666666); | |
| 917 | 1073 | e.get("/api/weshop/goods/page?1=1", { |
| 918 | 1074 | data: { page: that.data.stylePage, cat_id: that.data.cat_id, parent_id: 0, orderField: 'sort', orderType: 'asc', is_mainshow: 1, isonsale: 1, store_id: oo.stoid, is_recommend: 1 }, |
| 919 | 1075 | success: function (data) { | ... | ... |
pages/goods/categoryList/categoryList.wxml
| ... | ... | @@ -306,9 +306,9 @@ |
| 306 | 306 | </swiper> |
| 307 | 307 | </view> |
| 308 | 308 | <view class="my-container"> |
| 309 | - <view class="classify_name fs28 flex-space-between ai-center" data-pid="0" data-cid="{{cat_id}}" bindtap='select_more'> | |
| 309 | + <view class="classify_name fs28 flex-space-between ai-center" data-pid="0" data-cid="{{cat_id}}" bindtap="{{(one_level_classify[select_classify_on].diy_class) ? '' :'select_more'}} "> | |
| 310 | 310 | <view class="classify_title ellipsis-1">{{classify_name}}</view> |
| 311 | - <view class="flex select_more ai-center"> | |
| 311 | + <view class="flex select_more ai-center" wx:if="{{!(one_level_classify[select_classify_on].diy_class)}}"> | |
| 312 | 312 | <view class="red-co fs24">更多</view> |
| 313 | 313 | <view class="bg_right width_height" style="margin-top: 0;"></view> |
| 314 | 314 | </view> |
| ... | ... | @@ -340,10 +340,10 @@ |
| 340 | 340 | <block wx:for="{{goodslist}}" wx:for-item="goods" wx:for-index="inds"> |
| 341 | 341 | <view> |
| 342 | 342 | |
| 343 | - <view class="classify_name fs28 flex-space-between ai-center" data-pid="{{goods.items.parent_id}}" data-cid="{{goods.items.id}}" bindtap='select_more'> | |
| 343 | + <view class="classify_name fs28 flex-space-between ai-center" data-pid="{{goods.items.parent_id}}" data-cid="{{goods.items.id}}" bindtap="{{one_level_classify[select_classify_on][diy_class] ? '' :'select_more'}} "> | |
| 344 | 344 | |
| 345 | 345 | <view class="classify_title ellipsis-1" style="margin-left: 25rpx;">{{goods.items.name}}</view> |
| 346 | - <view class="flex select_more ai-center"> | |
| 346 | + <view class="flex select_more ai-center" wx:if="{{!one_level_classify[select_classify_on].diy_class}}"> | |
| 347 | 347 | <view class="red-co fs24">更多</view> |
| 348 | 348 | <view class="bg_right width_height" style="margin-top: 0;"></view> |
| 349 | 349 | </view> |
| ... | ... | @@ -351,7 +351,7 @@ |
| 351 | 351 | |
| 352 | 352 | <block wx:if="{{goods.arrays.length>0}}"> |
| 353 | 353 | <view class="classify_content-frame flex-wrap" style="margin-left: 50rpx;"> |
| 354 | - <view class="type_img_frame t-c ib" data-cid="{{item.id}}" data-pid="three" wx:for="{{goods.arrays}}" wx:for-index="index" wx:for-item="item" bindtap="go_cate"> | |
| 354 | + <view class="type_img_frame t-c ib" data-cid="{{item.id}}" data-pid="three" wx:for="{{goods.arrays}}" data-url="{{item.weapp_path_url}}" wx:for-index="index" wx:for-item="item" bindtap="{{goods.diy_class ? 'go_ad':'go_cate'}}"> | |
| 355 | 355 | <image class=" type_img" src="{{item.icoimg==null||item.icoimg==''?iurl+'/miniapp/images/no_cate_def.png':item.icoimg}}" binderror="goods_bnerr" data-err="goodslist[{{index}}].logo"></image> |
| 356 | 356 | <view class="brand_img_name fs24 ellipsis-1 pdh10">{{item.name}}</view> |
| 357 | 357 | </view> |
| ... | ... | @@ -365,7 +365,7 @@ |
| 365 | 365 | |
| 366 | 366 | <block wx:else> |
| 367 | 367 | <view class="classify_content-frame flex-wrap" style="margin-left: 50rpx;"> |
| 368 | - <view class="type_img_frame t-c ib" data-cid="{{item.items.id}}" data-pid="three" wx:for="{{goodslist}}" wx:for-index="index" wx:for-item="item" bindtap="go_cate"> | |
| 368 | + <view class="type_img_frame t-c ib" data-cid="{{item.items.id}}" data-pid="three" wx:for="{{goodslist}}" data-url="{{item.items.weapp_path_url}}" wx:for-index="index" wx:for-item="item" bindtap="{{item.diy_class ? 'go_ad':'go_cate'}}"> | |
| 369 | 369 | <image class=" type_img" src="{{item.items.icoimg==null||item.items.icoimg==''?iurl+'/miniapp/images/no_cate_def.png':item.items.icoimg}}" binderror="goods_bnerr" data-err="goodslist[{{index}}].logo"></image> |
| 370 | 370 | <view class="brand_img_name fs24 ellipsis-1 pdh10">{{item.items.name}}</view> |
| 371 | 371 | </view> | ... | ... |