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

//销售订单
export default {
  checkMrp:({record,close,loadData,login,btn,dispatch})=> {
    let isReturn=false;
    if(record.ORDER_STATUS!=0||record.CONFIRM_STATUS==1)
      isReturn=true;
    else{
      if(record.Nav_Details){
        record.Nav_Details.map(t=>{
          if(t.MRP_STATUS==2){
            isReturn=true;
          }
        });
      }
    }

    return {
      isReturn:isReturn,
    }
  },
  btnImport:({record,close,loadData,custom,dispatch})=> {
    const closeF=()=>{
      loadData();
    };
    const regClick=async function (){
      await dispatch({
        type: 'custom/save',
        payload: {
          orderImportClick:true
        },
      });
    };
    const data={
      close:closeF,
      orderImportClick:custom.orderImportClick
    };
    return {
      content: <FormPage formCode={'SO013'} data={data}/>,
      click: regClick
    }
  },
  revert :({record,close,loadData,getLoadParam,login,btn,dispatch})=>{
    let val = initQueryFilter(login.OrgId, 1, 100, "NUM", 0);
    let isReturn=false;
    if(record.ORDER_STATUS!=0||record.CONFIRM_STATUS==1)
      isReturn=true;
    else{
      if(record.Nav_Details){
        record.Nav_Details.map(t=>{
          if(t.MRP_STATUS==2){
            isReturn=true;
          }
        });
      }
    }
    val["Keyword"] = record.ID;
    const confirmRevert=()=> {
      dispatch({
        type: 'app/getDataByPost',
        payload: val,
        url: "SO/Order/Revert",
        onComplete: (ret) => {
          if (ret) {
            message.success("执行成功");
            loadData();
          }
        }
      });
    };

    return {
      content: <ConfirmButton isConfirm={true} confirmTitle="是否确定撤销?" onClick={confirmRevert} type={'danger'} icon={'rollback'} size="small" title={'撤销'} disabled={isReturn} />,
      isReturn:isReturn
    }
  },
  btnConfirm :({record,close,loadData,getLoadParam,login,btn,dispatch})=>{
    let isReturn=false;
    if(record.ORDER_STATUS!=0||record.CONFIRM_STATUS==1)
      isReturn=true;
    else{
      if(record.Nav_Details){
        record.Nav_Details.map(t=>{
          if(t.MRP_STATUS==2){
            isReturn=true;
          }
        });
      }
    }
    const confirm=()=> {
      let json = initFilter(login.OrgId, record.ID);
      dispatch({
        type: 'SOOrder/confirm',
        payload: json,
        onComplete: (ret) => {
          if (ret) {
            message.success("执行成功");
            loadData();
          }
        }
      });
    };
    return {
      content: <ConfirmButton isConfirm={true} confirmTitle="是否确认?" onClick={confirm} type={btn.CSS} icon={btn.ICON} size="small" title={btn.LABEL}  disabled={isReturn}/>,
      isReturn:isReturn
    }
  },


}
