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

  /**
   * 页面的初始数据
   */
  data: {
    param: {
      "id": "20220920083901",
      "content": {
        nocache: true,
        "pageSize": 20,
        "pageNumber": 1,
        "where": {
          "condition": "",
          type: 9
        }
      }
    },
    list: []
  },
  async listData() {
    const res = await api._post(this.data.param)
    console.log(res)
    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
    let form = getApp().globalData.formData
    let index = form.data.formLayoutData.formInfo.findIndex(v => v.label == '经销商');
    if (index == -1) {
      form.data.formLayoutData.formInfo.unshift({
        label: '经销商', //标题
        type: 'cell', //表单类型 text,upload,picker,datepicker
        id: 'enterprisename', //表单id
        placeholder: '', //设置文本框默认提示
        inputValue: item.enterprisename,
        data: [], //填充表单的数据 例如下拉框
        role: {
          type: 'reg',
        },
        force: false, //是否必输入
      })
    } else {
      form.data.formLayoutData.formInfo[index].inputValue = item.enterprisename;
    }
    form.data.formLayoutData.formInfo.forEach(e => {
      if (e.id === 'sys_enterpriseid') {
        e.inputValue = item.sys_enterpriseid
      }
    })
    form.setData({
      formLayoutData: form.data.formLayoutData
    })

    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  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() {

  }
})