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

//流程审核
export default {
  btnPermit:({record,close,loadData,login,dispatch})=> {
    const closeF=()=>{
      close();
      loadData();
    };
    const regClick= async function () {
      await dispatch({
        type: 'custom/save',
        payload: {
          ['flowPermitEdit'+(record? record.ID:'')]:true
        },
      });
    };
    const data={
      id:(record? record.ID:''),
      close:closeF,
      flowPermitEdit:login.flowPermitEdit
    };
    return {
      content: <FormPage formCode={'PF009'} data={data}/>,
      click: regClick
    }
  },
  onLoadParam:({loadParam,login})=> {
    loadParam['Keyword'] = login.userId;
  },
  btnBatchPermit:({loadData,login,record,dispatch,btn,getSelectedRowKeys,clearSelectedRowKeys})=>{
    const selectedRowKeys=getSelectedRowKeys();
    const confirm=()=>{
      const tmpSelectedRowKeys=getSelectedRowKeys();
      if(tmpSelectedRowKeys==null||tmpSelectedRowKeys.length==0){
        message.error('请选择审核通过记录');
        return;
      }
      const json={Ids:tmpSelectedRowKeys.join(','),
        UserId:login.userId,
        UserName:login.user.NAME
      };
      dispatch({
        type: 'PFFlow/passFlowByBatch',
        payload:json,
        onComplete: (ret) => {
          if(ret) {
            message.success('执行成功');
            clearSelectedRowKeys();
            loadData();
          }
        }
      })
    };

    return {
      content: <ConfirmButton isConfirm={true} confirmTitle="是否确定审批通过?" onClick={confirm} key={record ? (record.ID + btn.ID) : btn.ID}
                     type={btn.CSS} icon={btn.ICON} disabled={!selectedRowKeys.length} title={btn.LABEL}/>
    };
  }

}
