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

//MRP单编辑
export default {
  btnBatchFrozen:({record,loadData,login,dispatch,btn,getSelectedRowKeys,clearSelectedRowKeys, getSelectedRecords, getLoadParam, btnCustomParams})=> {
    let confirmTitle = '是否确认冻结?';
    let api = 'WoJobFrozen/jobFrozen';
    if(btnCustomParams.isFrozen == "false")
    {
      confirmTitle = '是否确认解冻?';
      api = 'WoJobFrozen/jobUnFrozen';
    }



    const selectRecords=getSelectedRecords();
    const selectedRowKeys=getSelectedRowKeys();
    let enable=true;

    const confirm=()=>{
      const tmpSelectedRowKeys=[];
      if(selectRecords){
        selectRecords.forEach(t=>{
          if(
            (t.IS_FROZEN === 1 && btnCustomParams.isFrozen === "true") ||
            (t.IS_FROZEN === 0 && btnCustomParams.isFrozen === "false")
          ){
            message.error(t.CODE+ '该工单无法执行,请核实！');
            enable=false;
            return;
          }
          tmpSelectedRowKeys.push(t.ID);
        });
        if(!enable)
          return;
      }
      const json={Keyword:tmpSelectedRowKeys.join(',')};
      dispatch({
        type: api,
        payload:json,
        onComplete: (ret) => {
          if(ret) {
            message.success('执行成功');
            loadData();
          }
        }
      })
    };
    return {
      content:<ConfirmButton isConfirm={true} confirmTitle={confirmTitle} onClick={confirm} key={record ? (record.ID + btn.ID) : btn.ID}
                     type={btn.CSS} icon={btn.ICON}   disabled={!selectedRowKeys.length} title={btn.LABEL}/>
    };
  },
  btnSkipedMes:({record,loadData,login,dispatch,btn,getSelectedRowKeys,clearSelectedRowKeys, getSelectedRecords, getLoadParam, btnCustomParams})=> {
    let isReturn = record.IS_SKIPED_MES;
    let toReturn= record.IS_SKIPED_MES?false:true;
    let confirmTitle = '是否确认排除MES?';
    let api = 'WoJobFrozen/jobSkipedMes';
    if(isReturn)
    {
      confirmTitle = '是否确认加入MES?';
     
    }
    


   
    const confirm=()=>{
      
      
      const json={Keyword:record.ID,Parameter1:toReturn};
      dispatch({
        type: api,
        payload:json,
        onComplete: (ret) => {
          if(ret) {
            message.success('执行成功');
            loadData();
          }
        }
      })
    };
    return {
      content:<ConfirmButton isConfirm={true} confirmTitle={confirmTitle} onClick={confirm}
                     type="primary" icon={toReturn?"minus":"plus"} title={toReturn?"排除MES":"加入MES"} size="small" />,
    };
  }
}
