
const util = require('../../../../utils/util')
const apiArr = require('../../../../api/water_filter')

// packages/partner/pages/master/master.js
const __staticUrl = require('../../../../config/env.js').static_url
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nav_list:{},
    foot_width:"",
     
    page_num:1,
    page_size:10,
    total:'',
    flag:false,
    MasterList:[],
    admin:""
  },
  creatMaster(){
      wx.navigateTo({
        url: '../creatMaster/creatMaster',
      })
  },
  desc(e){
    console.log(e);
    wx.navigateTo({
        url: `../masterDesc/masterDesc?info_id=${e.currentTarget.dataset.id}`,
    })
  },
  getMasterList(){
    let that = this
    wx.showLoading({
      title: '加载中...',
    })

    util.postUrl4(apiArr.MasterList,{
        page_num:that.data.page_num,
        page_size:that.data.page_size,
        dealer_id:that.data.admin.shop_id
      },res=>{
          wx.hideLoading()
          let flag = false;
          if(res.rows.length == that.data.page_size){
              flag = true
          }else{
              flag = false
          }
          res.rows.forEach(item=>{
            //   item.avatar = util.img_url + item.avatar
              item.avatar = item.avatar.startsWith('http')?item.avatar: util.img_url + item.avatar
          })

          that.setData({
              MasterList:that.data.MasterList.concat(res.rows || []),
              page_num:that.data.page_num + 1,
              flag
          })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    that.setData({
        admin: wx.getStorageSync('admin')
    })
    wx.showShareMenu({
        withShareTicket: true,
        menus: ['shareAppMessage', 'shareTimeline']
    })
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this
    that.setData({
        MasterList:[],
        page_num:1,
        flag:true
    })
    that.getMasterList()

  },

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

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    let that=  this
    that.setData({
        flag:false,
        page_num:1,
        MasterList:[],
    })
    that.getMasterList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let that = this
    if(that.data.flag){
        this.getMasterList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
        title: '人人爱净水',  // 分享卡片标题（必填）
        path: '/pages/water_filter/water_filter',  // 用户点击后跳转的路径（可选，默认当前页）
        imageUrl: (__staticUrl + '/share.png')  // 自定义图片（可选，比例建议 5:4）
    }
},
onShareTimeline() {
    return {
        title: '人人爱净水', // 自定义标题
        query: '', // 自定义页面路径中的参数
        imageUrl: (__staticUrl + '/share.png') // 自定义分享图片路径
    }
},
})