// nova-tourism/pages/my/merchant/good/good-list/index.js
let Parse = getApp().Parse;
const company = getApp().globalData.company
const uid = Parse.User.current()?.id
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodList:[]
  },

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

  async refersh(){
    let merchant = wx.getStorageSync('merchant')

    if (!merchant) {
      wx.showToast({
        title: '商户有误',
        icon: 'error'
      })
      setTimeout(() => {
        wx.reLaunch({
          url: `/nova-tourism/pages/index/index`
        })
      }, 1000);
      return
    }
    this.getGoods()
  },

  /**获取商品 */
  async getGoods() {
    let {goodList}=this.data
    let store = wx.getStorageSync('store')
    let query = new Parse.Query('ShopGoods')
    query.equalTo('company', company)
    query.notEqualTo('isDeleted', true)
    query.equalTo('shopStore',store?.objectId)
    query.ascending('top')
    query.limit(15)
    query.skip(goodList?.length||0)
    let d = await query.find()
    let list = d?.map(item=>item.toJSON())
    console.log(list)
    this.setData({
      goodList:[...goodList,...(list||[])]
    })
  },
  /** 跳转*/
  tourl(e) {
    const url = e.currentTarget.dataset.url
    wx.navigateTo({
      url: `${url}` // 目标页面的路径
    });
  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.getGoods()
  },

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

  }
})