
import React from 'react';
import { Button, Popconfirm } from 'antd'
import {message} from "antd/lib/index";
import FormPage from '../../components/FormPage'
import { ConfirmButton } from '@woowalker/feui'

//投料方案
export default {

  btnFeed:({record,close,loadData,custom,getSelectedRecords,dispatch})=> {
    const isReturn=record.FEEDING_OP_STATUS!==0&&record.FEEDING_OP_STATUS!==1;
    const closeF=()=>{
      close();
      loadData();
    };
    const regClick= async function () {
      await dispatch({
        type: 'custom/save',
        payload: {
          ['emFeedProposalClick'+(record ? record.ID : '')]: true,
          emFeedProposalSelectIds: record.ID,
        },
      });
    };
    const data={
      id: record ? record.ID : '',
      close: closeF,
      emFeedProposalClick: custom.emFeedProposalClick,
      ids: custom.emFeedProposalSelectIds,
    };
    return {
      content: <FormPage formCode={'EM008'} data={data}/>,
      click: regClick,
      isReturn
    }
  },
  checkRowClass:({record})=>{
    return record.VIR_HAS_PRODUCT_PROPOSAL?null:'danger';
  },
  colRemainFeed:({record})=>{
    return record.QTY- record.FEEDED_QTY;
  },
  btnConfirmFeedingComplete:({record,close,loadData,login,btn,dispatch})=> {
    let enable=record.FEEDING_OP_STATUS!==0&&record.FEEDING_OP_STATUS!==1;
    const confirm=()=>{
      if(enable)return;
      const json={Keyword:record.ID};
      dispatch({
        type: 'WOPdtOrder/confirmFeedingComplete',
        payload:json,
        onComplete: (ret) => {
          if(ret) {
            message.success('执行成功');
            loadData();
          }
        }
      })
    };
    return  {
      content: <ConfirmButton isConfirm={true} confirmTitle="是否确定指定完成?" onClick={confirm} type={btn.CSS} icon={btn.ICON} title={btn.LABEL} size="small" disabled={enable}/>
    };
  },
  btnBatchConfirmFeedingComplete:({record,loadData,login,dispatch,btn,getSelectedRowKeys,clearSelectedRowKeys, getSelectedRecords})=> {
    const selectRecords=getSelectedRecords();
    const selectedRowKeys=getSelectedRowKeys();
    const confirm=()=>{
      let isError=false;
      const tmpSelectedRowKeys=[];
      if(selectRecords){
        selectRecords.forEach(t=>{
          let enable=t.FEEDING_OP_STATUS!==0&&t.FEEDING_OP_STATUS!==1;
          if(!enable){
            message.error(t.CODE+ '该外部生产订单单号无法执行,请核实！');
            isError=true;
            return;
          }
          tmpSelectedRowKeys.push(t.ID);
        });
      }
      if(tmpSelectedRowKeys==null||tmpSelectedRowKeys.length==0){
        message.error('请选择记录');
        return;
      }
      if(isError)
        return;

      const json={Keyword:tmpSelectedRowKeys.join(',')};
      dispatch({
        type: 'WOPdtOrder/confirmFeedingComplete',
        payload:json,
        onComplete: (ret) => {
          if(ret) {
            message.success('执行成功');
            loadData();
          }
        }
      })
    };
    return {

      content: <ConfirmButton isConfirm={true} confirmTitle="是否确认指定完成?" onClick={confirm}
                              type={btn.CSS} icon={btn.ICON} disabled={!selectedRowKeys.length} key='btnConfirm' title={btn.LABEL}/>
    };
  },
  colProductSplitArea:({record})=>{
    if(record.Nav_Product&&record.Nav_Product.SPLIT_QTY)
    return (record.QTY* record.Nav_Product.SPLIT_WIDTH* record.Nav_Product.SPLIT_LENGTH /record.Nav_Product.SPLIT_QTY/1000000).toFixed(2);
  },
}
