// pages/agent/billCanUseProduct/index.vue.js
import api from '../api/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    param:{
      "id": "20220923140602",
      "version":1,
      "content": {
        "pageSize":20,
        "pageNumber":1,
        "where":{
          "condition":"",
          "isservice":1
        }
      }
    },
    value:'',
    list:[],
    selection:[]
  },
  search (data) {
    this.data.param.content.where.condition = data.detail.value
    this.data.list = []
    this.data.param.content.pageNumber = 1

    this.listData()
  },
  clear () {
    this.data.param.content.where.condition = ''
    this.data.list = []
    this.data.param.content.pageNumber = 1
  },
  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'
      })
    }
  },
  handleGroupChange(event) {
    this.setData({
      selection: event.detail.value,
    });
  },
  refresh () {
    this.setData({
      selection:[]
    })
  },
  onConfirm () {
    let pages = getCurrentPages();

    let prePage = pages[pages.length - 2];
    let arr = []
    this.data.selection.forEach(e => {
      this.data.list.forEach(item=>{
        if (e == item.itemid) {
          arr.push(item)
        }
      })
    });
    prePage.getAdd(arr)

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

    this.listData()
  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.data.list = []
    this.data.param.content.pageNumber = 1
    this.listData()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.data.param.content.pageNumber ++
    this.listData()
  },

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

  }
})