import HeadForm from "../component/HeadForm"
import Tables from "../component/Tables"
export default {
  components: {
    HeadForm,
    Tables
  },
  data() {
    return {

    }
  },
  mounted() {

  },
  methods: {
    // 设置下拉选项数据源
    setFormData(fieldName, list) {
      this.formData.forEach(item => {
        item.fieldName == fieldName ? item.options =  list : ''
      })
    },
    formParams(){
      let condtion = {}
      let reqData = {}
      this.formData.forEach(item => {
        if(item.value || (item.value && item.value.length)) {
          if(item.fieldName == 'time') {
            condtion[item.startTime] = item.value[0];
            condtion[item.endTime] = item.value[1];
            return
          }
          if(item.fieldName == 'money') {
            condtion[item.startMoney] = item.value[0];
            condtion[item.endMoney] = item.value[1];
            return
          }
          condtion[item.fieldName] = item.value
        }
      })
      Object.keys(condtion).forEach(key => {
        if(condtion[key]) {
          if(Array.isArray(condtion[key]) && condtion[key].length == 0){
            delete condtion[key]
          }
          reqData[key] = condtion[key]
        }
      })
      if(this.queryParams && Object.keys(this.queryParams)) {
        reqData = Object.assign(reqData, this.queryParams)
      }
      return reqData
    },
    //条件
    handleSearch(){
      let params = this.formParams()
      params.pageNum = 1
      this.queryParams.pageNum = 1
      this.handleQuery(params)
    },
    //分页
    handleCurrentChange(e){
      let params = this.formParams()
      params.pageNum = e
      this.queryParams.pageNum = e
      this.handleQuery(params)
    },
    handleSizeChange(e){

    },
    //排序
    sortChange(e){
      console.log(e)
    }
  }
}
