
import { Button, Popconfirm ,InputNumber} from 'antd'
import {message} from "antd/lib/index";
import {initQueryFilter} from "../../utils/common";

//用户列表页
export default {
  revertPlans :({getSelectedRowKeys,login,loadData,getLoadParam,dispatch,clearSelectedRowKeys,getSelectedRecords})=>{

    var keys=[];
    var records=getSelectedRecords();
    if(records){
      records.forEach((n,i)=>{
        if(n.BATCH_ID!==undefined){
          if(n.BATCH_ID){
            keys.push(n.BATCH_ID);
          }
        }
        else{
          keys.push(n.ID);
        }
      });
    }
    if(!keys){
      message.error("未选择任何行");
    }else{
      let val = initQueryFilter(login.OrgId, 1, 100, "NUM", 0);
      let str=keys.join(",");
      val["Keyword"]=str;
      dispatch({
        type: 'app/getDataByPost',
        payload: val,
        url:"PM/PlanBatch/Revert",
        onComplete: (ret) => {
          if (ret) {
            message.success("执行成功");
            clearSelectedRowKeys();
            loadData();
          }
        }
      });
    }
  },
  revertPlan :({record,close,loadData,getLoadParam,login,btn,dispatch})=>{
      const batchId=record.BATCH_ID!==undefined?record.BATCH_ID:record.ID;
      if(batchId) {
        let val = initQueryFilter(login.OrgId, 1, 100, "NUM", 0);
        val["Keyword"] =batchId;
        dispatch({
          type: 'app/getDataByPost',
          payload: val,
          url: "PM/PlanBatch/Revert",
          onComplete: (ret) => {
            if (ret) {
              message.success("执行成功");
              loadData();
            }
          }
        });
      }
  },
  revertOnePlan :({record,close,loadData,getLoadParam,login,btn,dispatch})=>{

    let val = initQueryFilter(login.OrgId, 1, 100, "NUM", 0);
    val["Keyword"]=record.ID;
    dispatch({
      type: 'app/getDataByPost',
      payload: val,
      url:"PM/PlanBatch/RevertPlan",
      onComplete: (ret) => {
        if (ret) {
          message.success("执行成功");
          loadData();
        }
      }
    });
  },

  preRevertPlans :({getSelectedRowKeys,login,loadData,getLoadParam,dispatch,clearSelectedRowKeys})=>{
    var keys=getSelectedRowKeys();
    if(!keys){
      message.error("未选择任何行");
    }else{
      let val = initQueryFilter(login.OrgId, 1, 100, "NUM", 0);
      let str=keys.join(",");
      val["Keyword"]=str;
      dispatch({
        type: 'app/getDataByPost',
        payload: val,
        url:"PM/PlanBatch/PreRevert",
        onComplete: (ret) => {
          if (ret) {
            message.success("执行成功");
            clearSelectedRowKeys();
            loadData();
          }
        }
      });
    }
  },
  cancelPreRevertPlans :({getSelectedRowKeys,login,loadData,getLoadParam,dispatch,clearSelectedRowKeys})=>{
    var keys=getSelectedRowKeys();
    if(!keys){
      message.error("未选择任何行");
    }else{
      let val = initQueryFilter(login.OrgId, 1, 100, "NUM", 0);
      let str=keys.join(",");
      val["Keyword"]=str;
      dispatch({
        type: 'app/getDataByPost',
        payload: val,
        url:"PM/PlanBatch/CancelPreRevert",
        onComplete: (ret) => {
          if (ret) {
            message.success("执行成功");
            clearSelectedRowKeys();
            loadData();
          }
        }
      });
    }
  },
}
