// pages/addTrainers/components/index.js
import api from '../../api/api'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    visible:{
      value:false,
      type:Boolean
    }
  },

  /**
   * 组件的初始数据
   */

  data: {
    visible:false,
    param:{
      "id": "20221216145803",
      "version":1,
      "content": {
        "pageSize":20,
        "pageNumber":1,
        "where":{
          "condition":""
        }
      }
    },
    list:[]
  },
  lifetimes:{
    attached () {
      this.listData()
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    async listData () {
      const res = await api._post(this.data.param)
  
      if (res.data.length > 0) {
        this.setData({
          list:this.data.list.concat(res.data)
        })
      } else {
        wx.showToast({
          title: '没有更多了!',
          duration: 2000,
          icon: 'none'
        })
      }
    },
    onSubmit (data) {
      this.data.param.content.where.condition = data.detail.value
      this.data.list = []
      this.data.param.content.pageNumber = 1
      this.listData()
    },
    onClear() {
      this.data.param.content.where.condition = ''
      this.data.list = []
      this.data.param.content.pageNumber = 1
      this.listData()
    },
    onClick (data) {
      let item = data.currentTarget.dataset.item
      this.setData({
        visible:false
      })
      this.triggerEvent('select',item)
    },
    onPullDownRefresh() {
      this.data.list = []
      this.data.param.content.pageNumber = 1
      this.listData()
    },
    onReachBottom() {
      this.data.param.content.pageNumber ++
      this.listData()
    },
  }
})
