index.js 26.5 KB
Newer Older
李嘉林 committed
1
const app = getApp();
2
const { log } = app;
李嘉林 committed
3
const { goodsApi, DFSImg, $themeToLink, processEnv } = app;
李嘉林 committed
4 5 6 7 8 9 10 11 12 13
function random_string(len) {
  len = len || 32;
  var chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
  var maxPos = chars.length;
  var pwd = "";
  for (let i = 0; i < len; i++) {
    pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return pwd;
}
李嘉林 committed
14 15 16 17 18 19
const componentOptions = {
  // 组件选项
  options: {
    multipleSlots: true
  },
  behaviors: [],
李嘉林 committed
20 21 22
  properties: {
    datas: {
      type: Object
23 24
    },
    datasIndex:{
25 26
      type: Number,
      default: 0
27 28
    },
    goodsListIndex:{
29 30 31 32 33 34
      type: Number,
      default: 0
    },
    storageKey: {
      type: String,
      required: true // 必传
35
    }
李嘉林 committed
36
  },
李嘉林 committed
37 38 39
  // 组件数据
  data: {
    isPageHidden: false, // 页面是否处于隐藏状态
李嘉林 committed
40 41
    titleIcon: "",
    classificationLoadPage: 1,
李嘉林 committed
42
    classificationLoadNum: 4,
李嘉林 committed
43 44
    queryProductInfoLoading: false,
    loading: false,
45
    scrollLoading: false, // 滚动加载优化后添加加载动画
李嘉林 committed
46 47
    finished: false,
    goodsList:[],
48 49 50 51 52
    storageGoodsList:[],
    storageDatasList:[],
    pageSize:10,
    pageNum:1,
    pageGoodsList:[],
李嘉林 committed
53 54 55 56 57 58 59 60 61 62 63 64
    loadingFlag: [],
    filterSearchName: "",
    mainColor: "",
    filterType: -1, //-1 综合、3销量 2价格(升、降) 8上新 99筛选
    filterPriceType: 0, // 0升序 1降序
    submitFliterVal: {
      minPrice: "",
      maxPrice: "",
      attribute: [],
      brandIdList: [], //品牌
      brandActiveNameList: [],
      goodsSpecificationIds: [],
李嘉林 committed
65
      categoryIdList: [],
李嘉林 committed
66
      productAttributeIds: [],
李嘉林 committed
67
    },
李嘉林 committed
68
    randomNumber: "",
李嘉林 committed
69
    selectScreen: false, // 筛选选中状态
李嘉林 committed
70
    clientHeight: 0, //窗口高度
HouTiZhuo committed
71
    swipeInfo: [],
72
    currentSwiperIndex: 0,
73
    swiperHeight: 0,
李嘉林 committed
74 75 76 77 78
  },
  // 数据监听器
  observers: {},
  // 组件生命周期
  lifetimes: {
李嘉林 committed
79
    created() {},
李嘉林 committed
80
    ready() {
李嘉林 committed
81
      let _this = this;
李嘉林 committed
82 83 84 85 86 87 88
      let { clientHeight } = this.data;
      wx.getSystemInfo({
        success: function(res) {
          let clientHeight = parseInt(res.windowHeight);
          _this.setData({ clientHeight });
        }
      });
李嘉林 committed
89 90
      app.getFilterGoodsData = (val) => {
        if (val.randomNumber != _this.data.randomNumber) return;
李嘉林 committed
91 92 93 94 95 96
        let selectScreen = val.submitFliterVal.minPrice!="" 
        || val.submitFliterVal.maxPrice!=""
        || val.submitFliterVal.attribute.length>0
        || val.submitFliterVal.brandIdList.length>0
        || val.submitFliterVal.brandActiveNameList.length>0
        || val.submitFliterVal.goodsSpecificationIds.length>0
李嘉林 committed
97
        || val.submitFliterVal.categoryIdList.length>0
李嘉林 committed
98
        || val.submitFliterVal.productAttributeIds.length>0
李嘉林 committed
99 100
        _this.setData({
          submitFliterVal: val.submitFliterVal,
李嘉林 committed
101 102
          selectScreen,
          loading: true
李嘉林 committed
103 104 105
        })
        _this.init();
      }
李嘉林 committed
106
      this.setData({
李嘉林 committed
107
        "submitFliterVal.brandIdList": this.data.datas.componentData.filterBrand && this.data.datas.componentData.filterBrand.length>0?JSON.parse(JSON.stringify(this.data.datas.componentData.filterBrand)) : [],
李嘉林 committed
108
      })
李嘉林 committed
109 110
      this.init();
    },
李嘉林 committed
111 112 113
    moved() {},
    detached() {}
  },
李嘉林 committed
114
  attached() {},
李嘉林 committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
  definitionFilter() {},
  // 页面生命周期
  pageLifetimes: {
    // 页面被展示
    show() {
      const { isPageHidden } = this.data;

      // show事件发生前,页面不是处于隐藏状态时
      if (!isPageHidden) {
        return;
      }

      // 重新执行定时器等操作
    },
    // 页面被隐藏
    hide() {
      this.setData({
        isPageHidden: true
      });

      // 清除定时器等操作
    },
    // 页面尺寸变化时
    resize() {}
李嘉林 committed
139 140 141
  },
  // 组件方法
  methods: {
李嘉林 committed
142 143 144 145 146 147 148 149 150
    filterInput(e) {
      this.setData({
        filterSearchName: e.detail.value
      })
    },
    filterGoods(e) {
      let { item } = e.currentTarget.dataset;
      let { filterPriceType, filterType } = this.data;
      if(item == 99) {
李嘉林 committed
151
        let _this = this;
152 153 154 155 156
        // 商品产品详情
        let terminalProductIds = _this.data.datas.componentData.goodsList.map(element => {
          return element.terminalProductId;
        });
        // 展示筛选弹窗
李嘉林 committed
157
        app.openFilterGoods({
李嘉林 committed
158
          submitFliterVal: _this.data.submitFliterVal,
李嘉林 committed
159
          categoryId: _this.data.datas.componentData.goodsSource == "classify"?_this.data.datas.componentData.categoryId : "",
李嘉林 committed
160
          filterBrand: _this.data.datas.componentData.filterBrand,
161
          terminalProductIds,
李嘉林 committed
162 163
          randomNumber: _this.data.randomNumber,
          hideBrandSelectFlag: _this.data.datas.componentData.filterBrand.length>0?true:false,
李嘉林 committed
164
          sourceType: 1,
李嘉林 committed
165 166
        });
      } else {
李嘉林 committed
167 168 169 170 171 172 173 174 175 176 177
        if(item == 2) {
          // 价格筛选
          filterPriceType = filterPriceType == 0?1:0
        } else {
          // 还原默认值
          filterPriceType = 1
        }
        this.setData({
          filterType: item,
          filterPriceType
        })
李嘉林 committed
178 179 180
        this.init();
      }
    },
李嘉林 committed
181
    init() {
182
      let _this = this;
李嘉林 committed
183 184 185 186
      let {
        goodsType,
        goodsSource,
        angleSignImg,
李嘉林 committed
187
        titleIcon,
李嘉林 committed
188
      } = this.data.datas.componentData;
柳士祥 committed
189
      angleSignImg = DFSImg(angleSignImg,150,150,1);
李嘉林 committed
190 191 192
      if (titleIcon) {
        titleIcon = DFSImg(titleIcon);
      }
李嘉林 committed
193 194
      this.setData({
        "data.datas.componentData.angleSignImg": angleSignImg,
李嘉林 committed
195 196
        titleIcon,
        mainColor: app.themeColor["--main-color"],
李嘉林 committed
197
        randomNumber: random_string(6),
李嘉林 committed
198
      });
199 200 201
      let ids = this.getStorageSync(`ids`);
      log.info(ids,'---ids--105')
      // 如果不是横向标签组件初始化缓存
李嘉林 committed
202
      if (!this.data.storageKey.includes('transverse-label')) {
203 204 205 206 207 208
        this.setStorageSync("pageGoodsList",[[]])
        this.setStorageSync("storageDatasList",[[]])
        this.setStorageSync("ids",[[]])
        this.setStorageSync("loadingFlag",[false])
        this.setStorageSync("pageNumList",[1])
      }
李嘉林 committed
209
      if (goodsType == 0) {
李嘉林 committed
210
        if (goodsSource != "assign") {
李嘉林 committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
          //商品分类
          this.getProductList(1, 1);
        } else {
          //指定商品
          this.getProductList(2);
        }
      } else if (goodsType == 1) {
        if (goodsSource == "classify") {
          //商品分类
          this.getInterList(1);
        } else {
          //指定商品
          this.getInterList(2);
        }
      }
侯体倬 committed
226 227 228 229 230 231
      
      // 判断是否为滑动组件
      if (this.data.datas.componentData.style === 'swipe') {
        this.getSwipeLen();
        this.getSwipeHeight();
      }
HouTiZhuo committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
    },
    handleSwipeChange(e) {
      this.setData({ currentSwiperIndex: e.detail.current })
    },
    getSwipeLen() {
      const goodsListLen = this.data.datas.componentData.goodsList.length || 0;
      const len = Math.ceil((goodsListLen / this.data.datas.componentData.columnNum));
      const result = [];
      for (let i = 0; i < len; i++) {
        const itemLen = this.getSwipeItemLen(i);
        result.push(itemLen)
      }
      this.setData({ swipeInfo: result });
    },
    getSwipeItemLen(index) {
      const goodsListLen = this.data.datas.componentData.goodsList.length || 0;
      const columnNum = this.data.datas.componentData.columnNum;
      const total = (index + 1) * columnNum;
      return total > goodsListLen ? goodsListLen - (index * columnNum) : columnNum
李嘉林 committed
251
    },
侯体倬 committed
252 253 254 255 256 257 258 259 260 261 262
    getSwipeHeight() {
      wx.createSelectorQuery().in(this).selectAll('.goods-item').boundingClientRect((rects) => {
        if (rects) {
          let maxHeight = 0;
          rects.forEach(item => {
            if (item.height > maxHeight) maxHeight = item.height;
          });
          this.setData({ swiperHeight: maxHeight });
        }
      }).exec();
    },
李嘉林 committed
263
    getProductList(code, type) {
264
      let { goodsSort,attributeValueList } = this.data.datas.componentData;
李嘉林 committed
265 266 267 268 269 270 271
      let goodsList = [];
      if (type == 2) {
        goodsList = this.data.pageGoodsList[this.data.datasIndex];
      } else {
        this.setData({ finished: false });
        goodsList = this.data.datas.componentData.goodsList;
      }
李嘉林 committed
272 273 274 275 276 277
      let {
        classificationLoadPage,
        loading,
        finished,
        queryProductInfoLoading
      } = this.data;
李嘉林 committed
278 279 280 281
      if (queryProductInfoLoading == true) {
        return;
      }
      this.setData({ queryProductInfoLoading: true });
李嘉林 committed
282 283 284
      // type 1初始化 2滚动加载
      //分类查
      if (code == 1) {
李嘉林 committed
285 286 287 288 289 290 291
        if (type == 1) {
          classificationLoadPage = 1;
        } else {
          classificationLoadPage++;
          loading = true;
        }
        this.setData({ classificationLoadPage, loading });
李嘉林 committed
292
        let query = {
李嘉林 committed
293
          categoryIncludeChild: true,
李嘉林 committed
294
          categoryId: this.data.datas.componentData.categoryId,
李嘉林 committed
295
          page: classificationLoadPage,
李嘉林 committed
296
          // rows: this.showRowNum() ? this.data.classificationLoadNum : this.getItemNum(),
李嘉林 committed
297 298
          sortColumn: goodsSort,
          sortType: goodsSort != 2 ? 1 : 0,
299
          whetherShowSoldOutGoods: app.shop_configuration.whetherShowSoldOutGoods,
李嘉林 committed
300 301 302
          whetherQueryCollectCount: true,
          whetherUseVirtualSalesQty: true,
          whetherUseVirtualCollectCount: true,
侯体倬 committed
303
          whetherFindDistributionCommission: this.data.datas.componentData.whetherFindDistributionCommission,
李嘉林 committed
304 305 306 307 308 309 310
          whetherFindRecommendedCardFlag: this.data.datas.componentData.vipPrice
            ? 1
            : 0,
          whetherShowGoodsDefaultTagFlag: this.data.datas.componentData
            .marketingTag
            ? 1
            : 0,
李嘉林 committed
311
          whetherFindMultiShopFlag: 1,
李嘉林 committed
312 313
          brandIdList: this.data.submitFliterVal.brandIdList || [],
          categoryIdList: this.data.submitFliterVal.categoryIdList || [],
314
          whetherQueryGoodsAttributeFlag: attributeValueList.length>0?1:0,
李嘉林 committed
315
        }; // 当前页 // 一页多少条 //查询销售数量 //查询收藏数 //是否使用虚拟销售数量 //是否使用虚拟收藏人数 //是否查询商品佣金(0:不查询,1:展示,为空不查佣金) //是否查询会员价  1是  0否 //是否展示营销标签  1是  0否 //是否查询多商户   //商城使用
李嘉林 committed
316 317
        if(this.data.datas.componentData['goodsSource'] == 'classify') {
          query.rows = this.data.datas.componentData.classificationLoadNum;
hxx committed
318 319
        } else if (this.data.datas.componentData['goodsSource'] == 'intelligenceRec') {
          query.productSourceInquiryType = 0;
李嘉林 committed
320 321 322
        } else {
          query.rows = this.getItemNum();
        }
李嘉林 committed
323 324 325 326 327 328
        // 启用了筛选组件
        if(this.data.datas.componentData.filterComponentsFlag == true){
          query.searchWord = this.data.filterSearchName;
          query.sortColumn = this.data.filterType == -1 ? "" : this.data.filterType
          query.sortType = this.data.filterType == 2 ? this.data.filterPriceType : "";
          query.goodsSpecificationIds = this.data.submitFliterVal.goodsSpecificationIds;
李嘉林 committed
329 330
          query.categoryIdList = this.data.submitFliterVal.categoryIdList;
          query.productAttributeIds = this.data.submitFliterVal.productAttributeIds;
李嘉林 committed
331 332 333
          query.minPrice = this.data.submitFliterVal.minPrice;
          query.maxPrice = this.data.submitFliterVal.maxPrice;
        }
侯体倬 committed
334 335
        const envList = ['xhyx_prod', 'xhyx_beta'];
        if (envList.includes(processEnv.NODE_ENV)) {
336 337 338
          // 隔离门店搜索
          query.searchScopeFlag = 1;
        }
侯体倬 committed
339
        goodsApi[envList.includes(processEnv.NODE_ENV)?'selectProductInfoOnEs':'queryProductInfo'](query).then(res => {
李嘉林 committed
340
          this.setData({ loading: false, queryProductInfoLoading: false });
李嘉林 committed
341
          if (res.data.code == 200) {
李嘉林 committed
342 343 344
            let goodsLists = res.data.data.list;
            if (type == 1) {
              goodsList = goodsLists;
345
            } else if(goodsLists.length>0) {
李嘉林 committed
346 347
              goodsList = [...goodsList, ...goodsLists];
            }
李嘉林 committed
348
            if (goodsLists && goodsLists.length < query.rows) {
李嘉林 committed
349
              this.setData({ finished: true });
李嘉林 committed
350
            }
李嘉林 committed
351
            this.goodsListVal(goodsList, type);
李嘉林 committed
352 353
          }
        });
李嘉林 committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367
      } else {
        // 商品产品详情
        let terminalProductIds = goodsList.map(element => {
          return element.terminalProductId;
        });
        if (terminalProductIds.length == 0) {
          return;
        }
        let briefQuery = {
          sortColumn: goodsSort,
          sortType: goodsSort != 2 ? 1 : 0,
          page: 1,
          rows: terminalProductIds.length,
          terminalProductIds: terminalProductIds,
368
          whetherShowSoldOutGoods: app.shop_configuration.whetherShowSoldOutGoods
李嘉林 committed
369 370 371 372 373 374 375 376
        }; // 当前页 // 一页多少条
        this.briefProduct(briefQuery);
      }
    },
    async briefProduct(query) {
      await goodsApi.queryBriefProductInfo(query).then(res => {
        if (res.data.code == 200) {
          let data = res.data.data.list;
377 378
          let ids = data.map(element => {
            let goodsList = this.render ? res.data.list : res.data.data.list;
李嘉林 committed
379 380
            return element.terminalProductId;
          });
381

382
          let storageIds = this.getStorageSync('ids')
383
          storageIds[this.data.goodsListIndex] = ids
384
          this.setStorageSync('ids',storageIds)
385

386
          let storageDatasList = this.getStorageSync('storageDatasList')
387
          storageDatasList[this.data.goodsListIndex] = this.data.datas.componentData
388
          this.setStorageSync('storageDatasList',storageDatasList)
389 390
          
          this.moreProduct(true);
李嘉林 committed
391 392 393
        }
      });
    },
394 395 396

    async moreProduct(flag) {
      // 没有数据了就不再请求了,直接return
397
      if (this.data.pageGoodsList.length != 0  &&  this.data.pageGoodsList[this.data.datasIndex].length == this.getStorageSync('ids')[this.data.datasIndex].length) return
李嘉林 committed
398 399 400
      this.setData({
        scrollLoading: true
      })
401
      let terminalProductIds = []
李嘉林 committed
402
      terminalProductIds = this.getStorageSync('ids')[this.data.goodsListIndex];
李嘉林 committed
403 404 405 406
      let {
        vipPrice,
        marketingTag,
        whetherFindDistributionCommission,
407 408
        goodsList,
        attributeValueList
李嘉林 committed
409 410 411 412 413 414 415 416 417
      } = this.data.datas.componentData;
      let moreQuery = {
        terminalProductIds,
        whetherQueryCollectCount: true, //查询收藏数
        whetherUseVirtualSalesQty: true, //是否使用虚拟销售数量
        whetherUseVirtualCollectCount: true, //是否使用虚拟收藏人数
        whetherFindDistributionCommission: whetherFindDistributionCommission, //是否查询商品佣金(0:不查询,1:展示,为空不查佣金)
        whetherFindRecommendedCardFlag: vipPrice ? 1 : 0, //是否查询会员价  1是  0否
        whetherShowGoodsDefaultTagFlag: marketingTag ? 1 : 0, //是否展示营销标签  1是  0否
418 419
        whetherFindMultiShopFlag: 1, //是否查询多商户   //商城使用
        whetherQueryGoodsAttributeFlag: attributeValueList.length>0?1:0,
李嘉林 committed
420 421 422 423
      };
      goodsApi.queryMoreProductInfo(moreQuery).then(res => {
        if (res.data.code == 200) {
          goodsList = res.data.data;
李嘉林 committed
424 425
          let pageGoodsList = this.data.pageGoodsList[this.data.goodsListIndex] || [];
          this.goodsListVal(goodsList, 1,flag);
李嘉林 committed
426 427 428
        }
      });
    },
429
    goodsListVal(goodsList, type,flag) {
430
      let { attributeValueList } = this.data.datas.componentData;
李嘉林 committed
431
      goodsList.forEach((item, index) => {
李嘉林 committed
432
        item.marketingTag = item.defaultTags
433 434 435 436
          ? this.filtermark(
              item.defaultTags,
              this.data.datas.componentData.marketingTagList
            )
李嘉林 committed
437 438
          : [];
        item.shopLogoUrl = DFSImg(item.shopLogoUrl);
439
        item.loadState = false
李嘉林 committed
440 441
        item.coverImage = DFSImg(item.coverImage, 400, 400, 1);
        item.productImgUrl = DFSImg(item.productImgUrl, 400, 400, 1);
李嘉林 committed
442 443
        item.minPrice = Number(item.minPrice).toFixed(2);
        item.qty = Number(item.qty);
李嘉林 committed
444
        item.saleQty = item.saleQty ? Number(item.saleQty) : 1;
李嘉林 committed
445
        item.totalCollectionCount = Number(item.totalCollectionCount) || 0;
李嘉林 committed
446 447 448 449 450 451 452 453 454
        item.minPriceAfterRecommendedCardPriceTable = item.minPriceAfterRecommendedCardPriceTable
          ? Number(item.minPriceAfterRecommendedCardPriceTable)
          : "";
        item.minProductGoodsCommission = item.minProductGoodsCommission
          ? Number(item.minProductGoodsCommission).toFixed(2)
          : 0;
        item.minGoodsSuggestedRetailPrice = item.minGoodsSuggestedRetailPrice
          ? Number(item.minGoodsSuggestedRetailPrice).toFixed(2)
          : "";
455 456
        item.showVipPrice = this.showVipPrice(item, index);
        item.showVipTag = this.showVipTag(item, index);
李嘉林 committed
457 458 459 460
        if (item.saleTime) {
          item.getSaleTime = 0;
          item.getSaleTime = this.getSaleTime(item.saleTime);
        }
李嘉林 committed
461 462 463 464 465
        if (item.depositInflationInfoList && item.depositInflationInfoList.length > 0) {
          item.depositInflationInfoList[0].goodsInfo[0].depositPrice = item.depositInflationInfoList[0].goodsInfo[0].depositPrice
          ? Number(item.depositInflationInfoList[0].goodsInfo[0].depositPrice).toFixed(2)
          : 0;
        }
466 467 468 469 470 471 472 473
        item.attributeValueList = [];
        if (attributeValueList.length > 0) {
          // 过滤商品属性
          if (item.attributeList) {
            let list = item.attributeList.filter(item1=>attributeValueList.includes(item1.attributeName)) || [];
            item.attributeValueList = list ? list.map(item1 => item1.attributeValue) : [];
          }
        }
李嘉林 committed
474
      });
475
      
李嘉林 committed
476
      let that = this
477
      // 是否加购
李嘉林 committed
478 479 480 481 482 483 484
      this.getPurchased(goodsList,(list1) => {
        this.collect(list1, (list) => {
          let pageGoodsList = this.getStorageSync('pageGoodsList') || []
          if (flag) {
            pageGoodsList[that.data.goodsListIndex] = list;
          }else{
            pageGoodsList[that.data.datasIndex] = list;
485
          }
李嘉林 committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
          this.setStorageSync('pageGoodsList', pageGoodsList);
  
  
          // 获取是否要开启请求拦截
          let loadingFlag = this.getStorageSync('loadingFlag')
          loadingFlag[that.data.datasIndex] = false
          this.setStorageSync('loadingFlag', loadingFlag);
          that.setData({
            "datas.componentData.goodsList": list,
            pageGoodsList,
            loadingFlag,
            scrollLoading: false,
          })
          if (type == 1) {
            // 初始化
            if (this.selectComponent("#waterfallFlow")) {
              this.selectComponent("#waterfallFlow").initList(list);
            }
          } else {
            // 滚动加载
            if (this.selectComponent("#waterfallFlow")) {
              this.selectComponent("#waterfallFlow").reLoadPro(list);
            }
509
          }
李嘉林 committed
510
        })
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
      });

    },
    // 加购状态
    getPurchased(goodsList,callback) {
      let { purchased } = this.data.datas.componentData;
      let list = goodsList.map(item=>item.productId);
      if(purchased) {
        // if(!this.render) return;
        goodsApi.query_goods_cart_info(list).then(res=>{
          if (res.data.code == 200) {
            let purchasedList = res.data.data || [];
            let purchasedListIds = [...new Set(purchasedList.map(item=>item.productId))];
            goodsList.forEach(item=>{
              item.purchased = false;
              if(purchasedListIds.includes(item.productId)) {
                item.purchased = true;
              }
            })
            callback(goodsList);
          }
        })
李嘉林 committed
533
      } else {
534
        callback(goodsList);
李嘉林 committed
535
      }
李嘉林 committed
536
    },
李嘉林 committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
    // 收藏状态
    collect(goodsList,callback) {
      let { collectFlag } = this.data.datas.componentData;
      let list = goodsList.map(item => item.productId);
      if(collectFlag) {
        // if(!this.render) return;
        goodsApi.batch_query_collect_count(list).then(res=>{
          if (res.data.code == 200) {
            let collectFlagList = res.data.data || [];
            let collectFlagListIds = [...new Set(collectFlagList.map(item=>item.productId))];
            goodsList.forEach(item=>{
              item.collectFlag = false;
              if(collectFlagListIds.includes(item.productId)) {
                item.collectFlag = true;
              }
            })
            callback(goodsList);
          }
        })
      } else {
        callback(goodsList);
      }
    },
560 561 562
    // 触发图片加载
    lazyloading(){
      var that = this
563
      let storageDatasList = this.getStorageSync('storageDatasList') || []
侯体倬 committed
564 565
      const tempItem = storageDatasList[that.data.datasIndex];
      let style = tempItem ? tempItem.style : "";
李嘉林 committed
566
      if (!style) return;
567
      let type = ''
李嘉林 committed
568
      if(style == 'list' || style == 'rowList'){
569 570 571 572 573 574
        type = 'goods-item'
      }else{
        return
      }
     
      let windowHeight =  wx.getSystemInfoSync().windowHeight
575
      let pageGoodsList =  this.getStorageSync('pageGoodsList') || []
576

577
      let loadingFlag =  this.getStorageSync('loadingFlag')
578 579 580 581 582
      // 如果所有的商品都加载完成直接return
      if (loadingFlag[that.data.datasIndex]) {
        return
      }

583
      let ids = this.getStorageSync('ids')[that.data.datasIndex]
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
      if (ids.length == that.data.pageGoodsList[that.data.datasIndex].length &&
        that.data.pageGoodsList[that.data.datasIndex][that.data.pageGoodsList[that.data.datasIndex].length -1].loadState == true
        ) {
        return
      }
      wx.createSelectorQuery().selectAll(`.goodsListItemIndex${that.data.datasIndex}>>>.${type}`).boundingClientRect(function(rects){
        for (let index = 0; index < rects.length; index++) {
          if (rects[index].top == 0 && rects[index].bottom == 0 && rects[index].left == 0 && rects[index].right == 0) {
            break
          }
          if (rects[index].top < windowHeight) {
            pageGoodsList[that.data.datasIndex][index].loadState = true
          }
        }
        that.setData({
          pageGoodsList,
        })
        // that.pageGoodsList = pageGoodsList
602
        that.setStorageSync('pageGoodsList',pageGoodsList)
603 604 605 606 607 608 609



        // 如果当前分页倒数第一张加载完成直接 打开loadingFlag开关并加载下一页数据
        if (that.data.pageGoodsList[that.data.datasIndex][that.data.pageGoodsList[that.data.datasIndex].length -1].loadState == true) {
          loadingFlag[that.data.datasIndex] = true
          that.setData({
610
            loadingFlag,
611
          })
612
          that.setStorageSync('loadingFlag',loadingFlag)
613 614 615 616 617 618

        }
      
      }).exec();

    },
李嘉林 committed
619 620 621 622
    getSaleTime(val) {
      return new Date(val.replace(/-/g, "/")).getTime() - new Date().getTime();
    },
    getItemNum() {
李嘉林 committed
623 624 625 626 627
      if(this.data.datas.componentData['goodsSource'] == 'classify') {
        return this.data.classificationLoadNum
      }
      // 瀑布流模式默认查6条
      if(this.data.datas.componentData.style == "waterfall" && this.data.datas.componentData["goodsSource"] == "specifyFilter"){
李嘉林 committed
628
        return 10;
李嘉林 committed
629
      }
李嘉林 committed
630 631 632
      //数量
      if (
        this.data.datas.componentData.style === "list" &&
hxx committed
633 634
        this.data.datas.componentData["goodsSource"] != "assign" &&
        this.data.datas.componentData['goodsSource'] != "intelligenceRec"
李嘉林 committed
635 636 637 638
      ) {
        //网格模式
        if (
          this.data.datas.componentData.rowNum *
李嘉林 committed
639
          this.data.datas.componentData.columnNum >=
李嘉林 committed
640 641 642 643 644 645 646 647 648 649
          this.data.datas.componentData.goodsList.length
        ) {
          return this.data.datas.componentData.goodsList.length;
        } else {
          return (
            this.data.datas.componentData.rowNum *
            this.data.datas.componentData.columnNum
          );
        }
      } else {
李嘉林 committed
650
        return 10;
李嘉林 committed
651 652 653
      }
    },
    showRowNum() {
李嘉林 committed
654
      return (
李嘉林 committed
655
        this.data.datas.componentData.moreShow == false &&
李嘉林 committed
656
        this.data.datas.componentData.style == "waterfall" &&
李嘉林 committed
657 658 659
        this.data.datas.componentData.goodsSource == "classify"
      );
    },
李嘉林 committed
660 661 662 663 664 665 666 667 668 669 670 671 672
    filtermark(newlist, marketingTagList) {
      let list = [];
      if (newlist.length <= 0) return;
      if (marketingTagList.length > 0) {
        marketingTagList.forEach((item, index) => {
          newlist.forEach((item1, index1) => {
            if (item1 == item.key) {
              list.push(item);
            }
          });
        });
      }
      return list;
673 674 675 676 677 678 679 680 681 682
    },
    showVipPrice(item, index) {
      // 索引 0 显示价格 1显示名称
      let showFlag = false;
      let vipPrice = item["minPriceAfterRecommendedCardPriceTable"];
      if (vipPrice && Number(vipPrice) < Number(item["minPrice"])) {
        showFlag = true;
      }
      return showFlag;
    },
李嘉林 committed
683
    showVipTag(item, index) {
684 685 686 687
      // 索引 0 显示价格 1显示名称
      let showFlag = false;
      let vipPrice = item["minPriceAfterRecommendedCardPriceTable"];
      let showTag = item["recommendedCardMinPricePriceTableName"];
李嘉林 committed
688
      if (vipPrice && showTag && Number(vipPrice) <= Number(item["minPrice"])) {
689 690 691
        showFlag = true;
      }
      return showFlag;
李嘉林 committed
692 693
    },
    getScroll(el) {
694 695
      //! 如果不是当前tab页return不执行滚动加载
      if (this.data.datasIndex != this.data.goodsListIndex) return;
李嘉林 committed
696 697
      // 是指定分类且不显示查看更多的瀑布流组件滚动加载
      let { goodsSource, moreShow, style } = this.data.datas.componentData;
698
      this.lazyloading()
李嘉林 committed
699
      if (
李嘉林 committed
700
        (goodsSource == "classify" || goodsSource == "specifyFilter") &&
李嘉林 committed
701
        moreShow == false
李嘉林 committed
702
      ) {
李嘉林 committed
703 704 705 706 707
        if (style == "waterfall") {
          this.selectComponent("#waterfallFlow").getScroll(el);
        } else if (style == "rowList") {
          this.getScrollEl(el);
        }
李嘉林 committed
708 709
      }
    },
李嘉林 committed
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
    getScrollEl(el) {
      let { finished } = this.data;
      let _this = this;
      _this
        .createSelectorQuery()
        .select("#goods-rowList")
        .boundingClientRect(function(res) {
          if (res) {
            let scrollTop = parseInt(el.scrollTop);
            let domHeight = parseInt(res.height);
            // 窗口高度+滚动高度等于 = 元素整体高度 -(预留一段距离加载) 触发父组件查询接口
            if (
              scrollTop + _this.data.clientHeight >= domHeight - 150 &&
              finished == false
            ) {
              _this.onLoad();
            }
          }
        })
        .exec();
    },
李嘉林 committed
731 732
    // 分页加载
    onLoad() {
李嘉林 committed
733 734
      this.getProductList(1, 2);
    },
侯体倬 committed
735
    viewMore(e) {
李嘉林 committed
736 737 738 739 740 741
      let {
        goodsType,
        style,
        categoryName,
        categoryId
      } = this.data.datas.componentData;
李嘉林 committed
742 743
      let linkVal = "";
      if (goodsType != 1) {
李嘉林 committed
744
        linkVal = `/goods/commodityMenu?categoryName=${categoryName}&categoryId=${categoryId}`;
李嘉林 committed
745 746 747
      } else {
        linkVal = `/pointShop/productList?categoryName=${categoryName}&categoryId=${categoryId}`;
      }
侯体倬 committed
748
      app.trackCpn(e, this.data.datas.componentName, 'ViewMore查看更多')
李嘉林 committed
749 750
      $themeToLink({
        type: 1,
李嘉林 committed
751
        link: linkVal
李嘉林 committed
752
      });
753 754 755 756 757 758
    },
    setStorageSync(key, val) {
      return wx.setStorageSync(`${this.data.storageKey}_${key}`,val)
    },
    getStorageSync(key) {
      return wx.getStorageSync(`${this.data.storageKey}_${key}`)
759
    },
李嘉林 committed
760
  }
李嘉林 committed
761 762
};

李嘉林 committed
763
Component(componentOptions);