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

const 钢材到货情况统计=()=>{
  const butClick=()=>{
    钢材到货情况统计查询(data.formData).then(res=>{
      res.data.map(item=>{
        const data={
          ...item
        }
        const 到货比例=item.completeTon/item.planTon
        data.到货比例=(到货比例*100).toFixed(0)+'%'
        data.差距=(item.planTon-item.completeTon).toFixed(2)
      })
      data.options.data=res.data
    })
  }

  const countGroup=[]
  countGroup.push('planTon','completeTom')

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

  const data={
    formData:{
      dcCh:'',
      dcPl:'',
    },
    formItems:[
      { field: 'dcCh', title: '船号', span: 4,
        itemRender: {
          name: '$select', props: { options:[],placeholder: '船号' }
        }
      },
      { field: 'dcPl', title: '批量', span: 4,
        itemRender: {
          name: 'input', props: { options:[],placeholder: '批量' }
        }
      },
      {span: 20 ,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:[
      { field: 'dcCh', title: '产品',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: 'plZ', title: '所含批量',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: 'planTon', title: '订货吨位',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: 'completeTon', title: '到货吨位',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: '到货比例', title: '到货比例',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: '使用月份', title: '使用月份',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: 'planDate', title: '计划到货期',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
      { field: '差距', title: '差距/吨',
        filters: [{ data: { checks: [], sVal: '', sMenu: '', fType1: '', fVal1: '', fMode: 'and', fType2: '', fVal2: '' } }],
        filterRender: { name: 'FilterCombination', },
      },
    ]
  }

  return data
}

const 钢材到货情况统计查询=(data)=>{
  return request({
    url: "/钢材到货情况统计/list",
    method: "get",
    data,
  });
}

export default 钢材到货情况统计
