import {encodeStr} from "@/assets/js/common"
import HeadForm from "../component/HeadForm"
import Tables from "../component/Tables"
import skeleton from '@/views/project/projectList/component/skeleton'
export default {
  components: {
    HeadForm,
    Tables,
    skeleton
  },
  data() {
    return {
      isSkeleton:true,
      encodeStr
    }
  },
  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) || item.value===0) {
          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] || condtion[key]===0) {
          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;
      if(params.companyTypes){
        if(params.companyTypes.length === 0){
          delete params.companyTypes
        }
      }

      if(!params.companyType){
        delete params.companyType
      }
      this.handleQuery(params)
    },
    //分页
    handleCurrentChange(e){
      let params = this.formParams()
      params.pageNum = e
      this.queryParams.pageNum = e
      this.handleQuery(params)
    },
    handleSizeChange(e){

    },
    //排序
    sortChange(e){
      let item = this.forData.find(item => item.prop === e.prop)
      this.queryParams.sort = item[e.order]
      this.handleSearch()
    }
  }
}
