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

//MRP单编辑
export default {
  btnEdit:({record,close,loadData,login,btn,dispatch})=> {
    let isShow=record.CONFIRM_STATUS==1||record.ORDER_STATUS==1;
    const closeF=()=>{
      close();
      loadData();
    };
    const regClick=async function (){
      await dispatch({
        type: 'custom/save',
        payload: {
          ['mrpEditPage'+(record? record.ID:'')]:true
        },
      });
    };
    const data={
      id:(record? record.ID:''),
      close:closeF,
      mrpEditPage:login.mrpEditPage,
      isShow:isShow,
    };
    if(isShow){
      btn.LABEL="查看";
      btn.ICON='eye';
    }
    else{
      btn.LABEL="编辑";
      btn.ICON='edit';
    }

    return {
      content: <FormPage formCode={'SO006'} data={data}/>,
      click: regClick,
    }
  },
  btnCancel:({record,close,loadData,login,btn,dispatch})=> {
    let isReturn=record.CONFIRM_STATUS==1||record.ORDER_STATUS==1;
    const confirm=()=>{
      //dispatch()
      const json={Keyword:record.ID};
      dispatch({
        type: 'SOMrpEdit/cancelMrp',
        payload:json,
        onComplete: () => {
          message.success('执行成功');
          loadData();
        }
      })
    };
    return {
      content:<ConfirmButton isConfirm={true} confirmTitle="是否确定撤销?" onClick={confirm} key={record ? (record.ID + btn.ID) : btn.ID}
                             type={btn.CSS} icon={btn.ICON}   disabled={isReturn} size={record?'small':null} title={btn.LABEL}/>,
    };
  },
  btnMrpConfirm:({record,close,loadData,login,btn,dispatch})=> {
    let enable=record.CONFIRM_STATUS==0&&record.IS_CONFIRM_ENABLE;
    const confirm=()=>{
      const json={Keyword:record.ID};
      dispatch({
        type: 'SOMrpEdit/mrpConfirm',
        payload:json,
        onComplete: () => {
          message.success('执行成功');
          loadData();
        }
      })
    };
    return {
      content:<ConfirmButton isConfirm={true} confirmTitle="是否确定确认生产?" onClick={confirm} key={record ? (record.ID + btn.ID) : btn.ID}
                             type={btn.CSS} icon={btn.ICON}   disabled={!enable} size={record?'small':null} title={btn.LABEL}/>,
    };
  }


}
