index.js 3.25 KB
Newer Older
hxx committed
1
const app = getApp();
李嘉林 committed
2
const { goodsApi, DFSImg, $themeToLink } = app;
hxx committed
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

Component({
  behaviors: [],
  properties: {
    datas : {
      type : Object
    }
  },
  data: {
    rankingInfoA: {},
    rankingInfoB: {},
    rankingList: [],
    rankingListA: [],
    rankingListB: []
  },
  ready() {
    this.setData({ rankingInfoA: this.data.datas.componentData.rankingInfoA });
    this.setData({ rankingInfoB: this.data.datas.componentData.rankingInfoB });
    this.getRankingList();
  },
  observers: {
    rankingListA() {
      this.notifyRankingList()
    },
    rankingListB() {
      this.notifyRankingList()
    }
  },
  methods: {
    handleItemClick(e) {
      const item = e.currentTarget.dataset.item;
      $themeToLink({
        type: 1,
        link: `/goods/${item.productId}?terminalProductId=${item.terminalProductId}`
      });
    },
    notifyRankingList() {
      const rankingInfoA = this.data.rankingInfoA;
      const rankingInfoB = this.data.rankingInfoB;
      if (rankingInfoA.checked && rankingInfoB.checked) {
        const listA = this.data.rankingListA.slice(0, 2);
        const listB = this.data.rankingListB.slice(0, 2);
        this.setData({ rankingList: listA.concat(listB) });
      } else if (rankingInfoA.checked) {
        this.setData({ rankingList: this.data.rankingListA })
      } else if (rankingInfoB.checked) {
        this.setData({ rankingList: this.data.rankingListB });
      }
    },
    
    async getRankingList() {
      const rankingInfoA = this.data.rankingInfoA;
      const rankingInfoB = this.data.rankingInfoB;
      // 开启两个榜单
      if (rankingInfoA.checked) {
        this.getProductInfo(0, rankingInfoA.filter);
      }
      if (rankingInfoB.checked) {
        this.getProductInfo(1, rankingInfoB.filter);
      }
    },
    
    async getProductInfo(type, id) {
      const data = {
        categoryIncludeChild: true,
        categoryId: id,
        page: 1, // 当前页
        rows: 4,
        sortColumn: this.goodsSort,
        sortType: 1,
        whetherShowSoldOutGoods: false, //查询销售数量
        whetherQueryCollectCount: false, //查询收藏数
        whetherUseVirtualSalesQty: false, //是否使用虚拟销售数量
        whetherUseVirtualCollectCount: false, //是否使用虚拟收藏人数
        whetherFindDistributionCommission: 0, //是否查询商品佣金(0:不查询,1:展示,为空不查佣金)
        whetherFindRecommendedCardFlag: 0, //是否查询会员价  1是  0否
        whetherShowGoodsDefaultTagFlag: 0, //是否展示营销标签  1是  0否
        whetherFindMultiShopFlag:1, //是否查询多商户   //商城使用
        whetherFindMultiSonShopFlag:1, //是否查询多商户   //多主题使用
        brandIdList: [],
        categoryIdList: [],
        whetherQueryGoodsAttributeFlag: 0,
        whetherToEnableQuickPurchase: 0,
      }
      const res = await goodsApi.queryProductInfo(data);
      if (res.data.code == 200) {
李嘉林 committed
89 90 91
        res.data.data.list && res.data.data.list.forEach(item => {
          item.productImgUrl = DFSImg(item.productImgUrl);
        })
hxx committed
92 93 94 95 96 97 98 99 100
        if (!type) {
          this.setData({ rankingListA: res.data.data.list || [] });
        } else {
          this.setData({ rankingListB: res.data.data.list || [] });
        }
      }
    }
  },
});