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

//MRP运算
export default {
  btnBatchMrp:({record,close,loadData,login,getSelectedRecords,dispatch})=> {
    const closeF=()=>{
      close();
      loadData();
    };
    const regClick=async function (){
      var selectRecords=getSelectedRecords();
      let isError=false;
      let ids=[];
      if(selectRecords){
        let productId='';
        selectRecords.map(item=>{
          if(item.MRP_STATUS==2)return;
          if(productId=='')
          {
            productId= item.PRODUCT_ID.toString().toUpperCase();
          }
          else if(productId!= item.PRODUCT_ID.toString().toUpperCase())
          {
            message.error('请选择相同的产品进行MRP');
            isError=true;
          }
          ids.push(item.ID);
        });
      };
      if(!ids||ids.length==0){
        message.error('请选择有效的销售订单明细记录');
      }
      else if(!isError&&ids){
        await dispatch({
          type: 'custom/save',
          payload: {
            ['mrpClick'+(record? record.ID:'')]:true,
            mrpSelectIds:ids.join(',')
          },
        });
      }
      return {
        isReturn:isError
      }
    };
    const data={
      id:(record? record.ID:''),
      close:closeF,
      mrpClick:login.mrpClick,
      ids:login.mrpSelectIds,
    };
    return {
      content: <FormPage formCode={'SO004'} data={data}/>,
      click: regClick,
    }
  },
  btnMrp:({record,close,loadData,login,getSelectedRecords,dispatch})=> {
    const isReturn=record.MRP_STATUS==2;
    const closeF=()=>{
      close();
      loadData();
    };
    const regClick= async function () {
      await dispatch({
        type: 'custom/save',
        payload: {
          ['mrpClick'+(record? record.ID:'')]: true,
          mrpSelectIds: record.ID,
        },
      });
    };
    const data={
      id:(record? record.ID:''),
      close:closeF,
      mrpClick:login.mrpClick,
      ids:login.mrpSelectIds,
    };
    return {
      content: <FormPage formCode={'SO004'} data={data}/>,
      click: regClick,
      isReturn
    }
  }

}
