let leftHeight = 0
let rightHeight = 0
let query = null
Page({

  /**
   * 页面的初始数据
   */
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    txtlist: [
      '这是第一条公告内容',
      '小程序上下滚动效果总结',
      '这是一行上下滚动的文字，文字最好短点，超过一行省略'
    ],
    headerNav: [{
      icon: '',
      name: '供应商',
      path: ''
    },
      {
        icon: '',
        name: '采购指南',
        path: ''
      },
      {
        icon: '',
        name: '收藏',
        path: ''
      },
      {
        icon: '',
        name: '农事天地',
        path: ''
      }
    ],
    category: [{
      name: '全部',
      id: '1'
    },
      {
        name: '分类',
        id: '2'
      },
      {
        name: '分类',
        id: '3'
      },
      {
        name: '分类',
        id: '4'
      },
      {
        name: '分类',
        id: '5'
      },
      {
        name: '分类',
        id: '6'
      }
    ],
    currentCategory: '',
    list: [],
    leftList: [],
    rightList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage () {

  },
  async isLeft () {
    const {
      list,
      leftList,
      rightList
    } = this.data
    query = wx.createSelectorQuery()
    for (const item of list) {
      leftHeight <= rightHeight ? leftList.push(item) : rightList.push(item)
      await this.getBoxHeight(leftList, rightList)
    }
  },
  getBoxHeight (leftList, rightList) {
    return new Promise((resolve, reject) => {
      this.setData({
        leftList,
        rightList
      }, () => {
        query.select('.waterfall-left').boundingClientRect()
        query.select('.waterfall-right').boundingClientRect()
        query.exec((res) => {
          leftHeight = res[0].height
          rightHeight = res[1].height
          resolve()
        })
      })
    })
  }
})
