index.js 7.02 KB
Newer Older
程智春 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// static/nativeComponents/MerchantsList/index.js
let app = getApp()
const { indexApi } = app;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    datas: {
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    showList : true,
    toLoad : true,
    query : {
      pageNum: 0,
      pageSize: 10,
      shopTagIds: [],
      mallFlag: 1,
李嘉林 committed
25 26
      sortColumn: 0,
      sortType: 1,
程智春 committed
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
    },
    WaterfallFlowList : [],
    skeletonLoading: true,
    loading: false,
    finished: false,
    clientHeight : 0,
    WaterfallFlowListL : [],
    WaterfallFlowListR : []
  },
  ready(){
    let _this = this;
    let { clientHeight } = this.data;
    wx.getSystemInfo({
      success: function (res) {
        let clientHeight = parseInt(res.windowHeight);
        _this.setData({ clientHeight });
      }
    });
    this.init()
  },

  /**
   * 组件的方法列表
   */
  methods: {
    init(){
      this.loadHandle(1);
    },
    loadHandle(val){
      if (this.data.toLoad == false) return;
      this.setData({
        toLoad: false
      })
      if(val == 1){
        this.setData({
          ['query.pageNum'] : 1,
          WaterfallFlowList : []
        })
      }else{
        this.setData({
          ['query.pageNum']: this.data.query.pageNum + 1
        })
      }
      this.setData({
        ['query.shopTagIds']: this.data.datas.componentData.selectMerchants == 0 ? [] : this.data.datas.componentData.selectLabelList,
李嘉林 committed
72 73
        "query.sortColumn": this.data.datas.componentData.sortType,
        "query.sortType": this.data.datas.componentData.sortType == 0?1:0,
程智春 committed
74 75 76 77 78 79 80 81 82 83
      })
      indexApi.get_multi_merchant_by_tags(this.data.query).then(res => {
        this.setData({
          toLoad : true,
          skeletonLoading : false,
          loading : false
        })
        if(res.data.code == '200'){
          let list = res.data.data
          if(list == null || list.length == 0){
李嘉林 committed
84
            if(this.data.query.pageNum == 1){
程智春 committed
85 86 87
              this.setData({
                showList: false
              })
李嘉林 committed
88
              console.log('------change1')
程智春 committed
89 90 91 92 93 94 95 96
            }
          }else{
            list.forEach((item,index) => {
              item.logoUrl = item.logoUrl ? app.DFSImg(item.logoUrl,300,300,1) : app.DFSImg("");
            })
            if (val == 1){

              if (this.data.datas.componentData.layoutType == 0){
侯体倬 committed
97

程智春 committed
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
                this.setData({
                  WaterfallFlowListL: [],
                  WaterfallFlowListR: []
                })
                let  WaterfallFlowListL = []
                let WaterfallFlowListR = []
                list.forEach((item, index) => {
                  if (index % 2 == 0) {
                    WaterfallFlowListL.push(item)
                  } else {
                    WaterfallFlowListR.push(item)
                  }
                })
                this.setData({
                  'WaterfallFlowListL[0]': WaterfallFlowListL,
                  'WaterfallFlowListR[0]': WaterfallFlowListR
                })
              }else{
                  this.setData({
                    'WaterfallFlowList[0]': list
                  })
              }
            }else{
              if (this.data.datas.componentData.layoutType == 0) {
                let WaterfallFlowListL = []
                let WaterfallFlowListR = []

                  list.forEach((item,index) => {
                    if (index % 2 == 0) {
                      WaterfallFlowListL.push(item)
                    } else {
                      WaterfallFlowListR.push(item)
                    }
                  })
                this.setData({
                  ['WaterfallFlowListL[' + this.data.WaterfallFlowListL.length + ']']: WaterfallFlowListL,
                  ['WaterfallFlowListR[' + this.data.WaterfallFlowListR.length + ']']: WaterfallFlowListR
                })
              } else {
                this.setData({
                  ['WaterfallFlowList[' + this.data.WaterfallFlowList.length + ']']: list
                })
              }
侯体倬 committed
141

程智春 committed
142 143
            }
            if (this.data.WaterfallFlowList.length <= 0) {
李嘉林 committed
144 145 146 147
              this.setData({
                showList : false
              })
              console.log('------change2')
程智春 committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
            }
          }
          if (list == null || list.length < 10) {
              this.setData({
                finished : true
              })
            } else {
              this.setData({
                finished: false
              })
            }

          console.log(this.data.WaterfallFlowList,'this.data.WaterfallFlowList')
        }else{
          this.setData({
            finished : true,
            showList : false
          })
李嘉林 committed
166
          console.log('------change3')
程智春 committed
167 168 169 170 171 172 173
        }

      })

    },
    getScroll(el) {
      let _this = this
程智春 committed
174 175 176
      let query = wx.createSelectorQuery().in(this)
      let { windowHeight } = wx.getSystemInfoSync()
      query.select("#ItemModule0").boundingClientRect(function(res){
程智春 committed
177
        if(res){
程智春 committed
178 179 180
          // let scrollTop = parseInt(el.scrollTop);
          // let domHeight = parseInt(res.height);
          if (res.top < windowHeight && res.top + res.height > 0 && _this.data.finished == false) {
侯体倬 committed
181

程智春 committed
182 183
            _this.loadHandle(2);
          }
程智春 committed
184 185 186 187 188 189 190
          // if (
          //   scrollTop + _this.data.clientHeight >= domHeight - 150 &&
          //   _this.data.finished == false
          // ) {
          //   console.log(scrollTop + _this.data.clientHeight, '44444444444')
          //   _this.loadHandle(2);
          // }
程智春 committed
191 192 193
        }
      }).exec()

程智春 committed
194
      query.select("#ItemModule1").boundingClientRect(function (res) {
程智春 committed
195
        if (res) {
程智春 committed
196 197 198
          // let scrollTop = parseInt(el.scrollTop);
          // let domHeight = parseInt(res.height);
          if (res.top < windowHeight && res.top + res.height > 0 && _this.data.finished == false) {
程智春 committed
199 200
            _this.loadHandle(2);
          }
程智春 committed
201 202 203 204 205 206 207
          // if (
          //   scrollTop + _this.data.clientHeight >= domHeight - 150 &&
          //   _this.data.finished == false
          // ) {
          //   console.log(scrollTop + _this.data.clientHeight, '44444444444')
          //   _this.loadHandle(2);
          // }
程智春 committed
208 209
        }
      }).exec()
侯体倬 committed
210

程智春 committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224
      // wx.createSelectorQuery().in(this).select("#ItemModule1").boundingClientRect(function(res){
      //   if (res) {

      //     let scrollTop = parseInt(el.scrollTop);
      //     let domHeight = parseInt(res.height);
      //     // 窗口高度+滚动高度等于 = 元素整体高度 -(预留一段距离加载) 触发父组件查询接口
      //     if (
      //       scrollTop + _this.data.clientHeight >= domHeight - 150 &&
      //       _this.data.finished == false
      //     ) {
      //       _this.loadHandle(2);
      //     }
      //   }
      // }).exec()
程智春 committed
225 226 227 228 229 230 231 232 233
    },
    scrolltolower(){
      if(this.data.finished == false){
        this.loadHandle(2)
      }
    },
    itemClick(e){
      let item = e.currentTarget.dataset.item
      console.log(item)
侯体倬 committed
234
      app.trackCpn(e, this.data.datas.componentName, item)
程智春 committed
235 236 237 238 239 240 241
      app.$themeToLink({
        type: 1,
        link: `/merchantsDetail/${ item.boundOrgId }`
      })
    }
  }
})