
import { Button, Popconfirm } from 'antd'
import FormPage from '../../components/FormPage';
import { initFilter } from "../../utils/common";
import { message } from "antd/lib/index";

//用户列表页
export default {
  btnEdit: ({ record, close, loadData, login, dispatch, btn }) => {
    const closeF = () => {
      close();
      loadData();
    };

    const data = {
      id: (record ? record.ID : ''),
      isEdit: true,
      close: closeF,
    };

    let isReturn = (record && !record.IS_CONFIRM)
    return {
      content: <FormPage formCode={'MM018'} data={data} />,
      isReturn: !isReturn
    }
  },
  btnConfirm: ({ record, loadData, login, dispatch, btn }) => {
    const confirm = () => {
      const json = { Keyword: (record ? record.ID : ''), OrgId: login.OrgId };
      dispatch({
        type: 'reworkPdtOrder/ReworkConfirm',
        payload: json,
        onComplete: (ret) => {
          if (ret) {
            message.success('执行成功');
            loadData();
          }
        }
      })
    };

    let disabled = record && !record.IS_CONFIRM;

    return {
      content: <Button type={'default'} key={record ? (record.ID + btn.ID) : btn.ID} disabled={!disabled} icon={btn.ICON} size="small" title={'确认返工'} onClick={() => confirm()} ></Button>
    };
  },
  btnView: ({ record, close, loadData, login, dispatch }) => {
    const closeF = () => {
      close();
    };

    const data = {
      id: (record ? record.ID : ''),
      isReview: true,
      close: closeF,
    };

    return {
      content: <FormPage formCode={'MM018'} data={data} />
    }
  },
  btnCancle: ({ record, loadData, login, dispatch, btn }) => {
    const confirm = () => {
      const json = { Keyword: (record ? record.ID : ''), OrgId: login.OrgId };
      dispatch({
        type: 'reworkPdtOrder/CancelRework',
        payload: json,
        onComplete: (ret) => {
          if (ret) {
            message.success('执行成功');
            loadData();
          }
        }
      })
    };

    let disabled = (record && record.IS_CONFIRM) && (record && record.Nav_ReworkPdtOrder && record.Nav_ReworkPdtOrder.REWORK_STATUS === 0)

    return {
      content: <Button type={'default'} key={record ? (record.ID + btn.ID) : btn.ID} disabled={!disabled} icon={btn.ICON} size="small" title={'撤销返工'} onClick={() => confirm()} ></Button>
    };
  }
}
