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

//SAP报工结果
export default {
  btnBook:({record,close,loadData,login,btn,dispatch})=> {
    let isReturn=record.BOOKING_STATUS!==2;
    const confirm=()=>{
      if(isReturn)return;
      const json={OrgId:login.OrgId, Keyword:record.ID,Parameter1:login.userId};
      dispatch({
        type: 'app/getDataByPost',
        url:"MM/SapBookingLog/Booking",
        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={isReturn}/>,
    };
  },

  btnBatchBook:({record,close,loadData,login,btn,dispatch,getSelectedRecords})=> {
    const selectRecords=getSelectedRecords();
    let ids=[];
    if(selectRecords){
      selectRecords.forEach(item => {
        if(item.BOOKING_STATUS!==2)return;
        ids.push(item.ID);
      });
    }
    const confirm=()=>{
      if(!ids.length)return;
      const json={OrgId:login.OrgId,Keyword:ids.join(','),Parameter1:login.userId};
      dispatch({
        type: 'app/getDataByPost',
        url:"MM/SapBookingLog/Booking",
        payload:json,
        onComplete: (ret) => {
          if(ret) {
            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={!ids.length} title={btn.LABEL} />,
    };
  },
}
