import XEUtils from 'xe-utils'
import request from '@/utils/request'
import {getSumAdd} from "@/utils/rpkj";

const 作业计划完成量统计=()=>{

  const butClick=()=>{
    作业计划完成量(data.formData).then(res=>{
      data.options.data=res.data
    })
  }

  const footerMethod=({ columns, data })=>{
    return [
      columns.map((column, columnIndex) => {
        if (['total','bclqzl','bcshzl'].includes(column.property)) {
          return getSumAdd(data, column.property)
        }
        if (columnIndex === 1) {
          return '合计'
        }
        return null
      })
    ]
  }

  const data={
    formData:{
      from:XEUtils.toDateString(new Date(),'yyyy/MM/dd'),
      to:XEUtils.toDateString(new Date(),'yyyy/MM/dd'),
      ylbs:'n',
    },
    formItems:[
      { field: 'from', title: '开始日期', span: 4,
        itemRender: {
          name: '$input', props: {type:'date', labelFormat:'yyyy/MM/dd',valueFormat:'yyyy/MM/dd',placeholder: '请选择日期' }
        }
      },
      { field: 'to', title: '结束日期', span: 4 ,
        itemRender: {
          name: '$input', props: {type:'date', labelFormat:'yyyy/MM/dd',valueFormat:'yyyy/MM/dd',placeholder: '请选择日期' }
        }
      },
      {span: 16 ,align:'right',
        itemRender: {
          name: '$button', props: {content:'查询',status:'primary'},events:{click:butClick}
        }
      },
    ],
    options:{
      height:400,
      align:'center',
      border: true,
      resizable: true,
      keepSource:true,
      size:'mini',
      showOverflow: true,
      scrollY:{enable:true},
      editConfig:{trigger: 'click', mode: 'cell', showStatus: true},
      highlightCurrentRow:true,
      showFooter:true,
      footerMethod:footerMethod,
      data:[],
    },
    columns:[
      { type: 'seq', width: 60, title: '序号' },
      { field: 'dc_ch', title: '船号',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: 'total', title: '加工数量',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: 'bclqzl', title: '领取重量',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: 'bcshzl', title: '实耗重量',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
    ]
  }

  return data
}

const 作业计划完成量=(data)=>{
  return request({
    url: "/kban/zyjhwcl",
    method: "post",
    data,
  });
}

export default 作业计划完成量统计
