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

//采购单列表
export default {

  btnShow:({record,close,loadData,login,dispatch})=> {

    const data= {
      rules: [{field: 'InstanceId', operator: 1, value: record.FLOW_ID}],
      onlyFirst:false
    }

    return {
      isReturn:record.FLOW_STATUS==0,
      content: <ListPage formCode={'PO007'} data={data} />}
  },
  btnPermit:({record,close,loadData,login,btn,dispatch})=> {
    let isReturn=record.FLOW_STATUS!=0;
    const confirm=()=>{
      //dispatch()
      const json={Keyword:record.ID,
        Parameter1:login.userId,
        Parameter2:login.user.NAME
      };
      dispatch({
        type: 'POOrderPermitShow/sendFlow',
        payload:json,
        onComplete: (ret) => {
          if(ret) {
            message.success('执行成功');
            loadData();
          }
        }
      })
    };
      if(record.ENABLE_FLOW){
        btn.LABEL="送审";
        btn.ICON="shrink";
      }
      else{
        btn.LABEL="确认";
        btn.ICON="check";
      };

     let result = {
        content:<ConfirmButton isConfirm={true} confirmTitle="是否确定操作?" onClick={confirm} type={'primary'} icon={btn.ICON}  size="small" title={btn.LABEL} disabled={isReturn}/>
      }

    return result;
  },
  checkPermitState:({record,close,loadData,login,btn,dispatch})=> {
    const isReturn=record.FLOW_STATUS!=0;
    return {
      isReturn:isReturn,
    };
  },
}
