
import { Progress,Button,Input} from 'antd'
import {message} from "antd/lib/index";
import {extendRule, initQueryFilter} from "../../utils/common";
import DropDownPagination from "../../components/common/DropDownPaginationEx"
import moment from 'moment';
//用户列表页
export default {

//自动分配
  BantchAutoAssign:({getSelectedRowKeys,login,loadData,getLoadParam,dispatch,clearSelectedRowKeys})=>{
    const tmpLoadParam= getLoadParam();
    const customs=tmpLoadParam&&tmpLoadParam.data&& tmpLoadParam.data.customs?tmpLoadParam.data.customs:[];
    let val = initQueryFilter(login.OrgId, 1, 100, "NUM", 0);
    if(customs){
        customs.forEach(item => {
          val[item.key]=item.value;
        });
    }
    if(!val["Parameter3"])
    {
      message.error("请选择中心");
      return;
    }
    if(!val["Parameter4"])
    {
      message.error("请选择计划任务");
      return;
    }
    val["Keyword"]=1;
    dispatch({
      type: 'app/getDataByPost',
      payload: val,
      url:"PM/Assign/BantchAuto",
      onComplete: (ret) => {
        if (ret) {
          if(tmpLoadParam&&tmpLoadParam.data&&tmpLoadParam.data.func){
            tmpLoadParam.data.func.forEach((item,i)=>{
              if(typeof item==="function")
                item();
            })
          }

        }
      }
    });

  },
//手工分配
BantchAssign:({getSelectedRowKeys,login,loadData,getLoadParam,dispatch,clearSelectedRowKeys})=>{
  const tmpLoadParam= getLoadParam();
  const customs=tmpLoadParam&&tmpLoadParam.data&& tmpLoadParam.data.customs?tmpLoadParam.data.customs:[];
  let val = initQueryFilter(login.OrgId, 1, 100, "NUM", 0);

  if(customs){
    customs.forEach(item => {
      val[item.key]=item.value;
    });
  }
  if(!val["Parameter3"])
  {
    message.error("请选择中心");
    return;
  }
  if(!val["Parameter4"])
  {
    message.error("请选择计划任务");
    return;
  }
  val["Keyword"]=0;
  dispatch({
    type: 'app/getDataByPost',
    payload: val,
    url:"PM/Assign/BantchAuto",
    onComplete: (ret) => {
      if (ret) {
        if(tmpLoadParam&&tmpLoadParam.data&&tmpLoadParam.data.func){
          tmpLoadParam.data.func.forEach((item,i)=>{
            if(typeof item==="function")
              item();
          })
        }

      }
    }
  });

},
  colTaskShow:({record,close,loadData,getLoadParam,login,btn,dispatch})=>{

      return <div>
        <span>
          {record.Nav_PlanTask.CODE}
        </span>
        <div>
          <Progress
            size="small"
            //format={percent => record.Nav_PlanTask.ASSIGN_QTY + '/' + record.Nav_PlanTask.QTY }
            percent={(record.Nav_PlanTask.ASSIGN_QTY*100/record.Nav_PlanTask.QTY).toFixed(1)}
          />
        </div>
      </div>
  },
  colTask:({record,close,loadData,getLoadParam,login,btn,dispatch})=>{

    return <div>
        <span>
          {record.CODE}
        </span>
      <div>
        <Progress
          size="small"
          //format={percent => record.Nav_PlanTask.ASSIGN_QTY + '/' + record.Nav_PlanTask.QTY }
          percent={(record.ASSIGN_QTY*100/record.QTY).toFixed(1)}
        />
      </div>
    </div>
  },
  colUnAssign:({record,close,loadData,getLoadParam,login,btn,dispatch})=>{
    let unassign=record.Nav_PlanTask.CAN_ASSIGN_QTY;

    const change=(e)=>{

      var qty=unassign+record.QTY;
      let val = {
        "Keyword":record.ID,
        "Parameter1": qty,
        "OrgId":record.ORG_ID,
      };
      dispatch({
        type: 'app/getDataByPost',
        payload: val,
        url:"PM/Assign/Change",
        onlyData:false,
        onComplete: (ret) => {
          if(ret.IsSuccessful&&ret.Data)
          {
            const param= getLoadParam();
            if(param&&param.data&&param.data.func){
              param.data.func.forEach((item,i)=>{
                if(typeof item==="function")
                  item();
              });
            }
          }else{
            message.error(ret.ErrorMessage);
          }
        }
      })
    };
    return unassign>0?<div>
        <span>
          {unassign}
        </span>
      <Button type={'default'} icon={'right'} size="small" title={'全部分配'} onClick={change}/>
    </div>:<span>0</span>
        },
  colRemark:({record,loadData,onRefreshTableData,getLoadParam,login,btn,dispatch, width})=>{


    const onBlur=(e)=>{

      var remark=e.target.value;
      if(!remark&&!record.REMARK)
        return;
      if(remark!==record.REMARK){
        const json={
          Keyword:record.ID,
          Parameter1:remark
        } 
        dispatch({
          type: 'app/getDataByPost',
          payload: json,
          url:"PM/Plan/UpdateRemark",
          onlyData:false,
          onComplete: (ret) => {
            if(ret.IsSuccessful&&ret.Data)
            {
              loadData();
            }else{
              message.error(ret.ErrorMessage);
            }
          }
        })
      }

    };
    return <Input defaultValue={record.REMARK} style={{ width: width > 0 && width }} onBlur={onBlur}/>
  },
colSpitSize:({record})=>{
    if(record.Nav_PdtOrder&&record.Nav_PdtOrder.Nav_MrpOrderWork&&record.Nav_PdtOrder.Nav_MrpOrderWork.Nav_MrpOrderEmProposal)
      return record.Nav_PdtOrder.Nav_MrpOrderWork.Nav_MrpOrderEmProposal.LENGTH+"*"+record.Nav_PdtOrder.Nav_MrpOrderWork.Nav_MrpOrderEmProposal.WIDTH;
  }
}
