import { Button } from 'antd'
import FormPage from '../../components/FormPage'
import ShowOrderQuery from "../../components/CustomPages/WO/ShowOrderQuery";
import config from '../../config';
import ImgPreView from '../../components/common/ImgPreView.js';
import {message} from "antd/lib/index";
import { ConfirmButton } from '@woowalker/feui'
//销售订单
export default {
  showProductOrder:({record, close, loadData, login, btn, dispatch, formId})=> {
    //return {content: <ShowOrderQuery SearchNo={record.PDT_CODE} formCode="WO001"><Button type={btn.CSS} icon={btn.ICON} size="small"/></ShowOrderQuery>}
    return {content: <ShowOrderQuery SearchNo={record.PDT_CODE} formCode="WO001"><ConfirmButton isConfirm={false} type={btn.CSS} icon={btn.ICON} title={btn.LABEL} size="small"/></ShowOrderQuery>}
  },
  btnFlowCard: ({record,close,loadData,custom,btn,dispatch,formId}) => {
    const closeF=()=>{
      loadData();
    };
    const regClick=async function () {
      await dispatch({
        type: 'custom/save',
        payload: {
          ['orderFlowCardClick'+(record ? record.ID : '')]:true
        },
      });
    };
    const data = {
      id:(record ? record.ID : ''),
      close:closeF,
      orderFlowCardClick:custom.orderFlowCardClick,
      getIds:()=>{return (record ? record.ID : '');}
    };
    return {
      content: <FormPage formCode={'WO004'} data={data}/>,
      click: regClick,
      close:closeF,
    }
  },
  btnFlowCardByBatch: ({record,close,loadData,custom,btn,dispatch,getSelectedRecords}) => {
    const closeF=()=>{
      loadData();
    };
    const getIds=()=>{
      var selectRecords=getSelectedRecords();
      let ids=[];
      if(selectRecords){
        selectRecords.forEach(item => {
          ids.push(item.ID);
        });
      }
      return ids.join(',');
    }
    const regClick=async function () {
      const ids = getIds();
      let isError = false;
      if (!ids) {
        message.error('请选择生产订单记录');
        isError = true;
      }
      else if (ids) {
        await dispatch({
          type: 'custom/save',
          payload: {
            ['orderFlowCardClick' + (record ? record.ID : '')]: true,
          },
        });
      }
      return {
        isReturn: isError
      }
    };
    const data = {
      id:(record ? record.ID : ''),
      close:closeF,
      orderFlowCardClick:custom.orderFlowCardClick,
      getIds:getIds,
    };
    return {
      content: <FormPage formCode={'WO004'} data={data}/>,
      click: regClick,
      close:closeF,
    }
  },
  sopView: ({ record,btn }) => {
    let sopData = [];
    if(record.Nav_ImgFile && record.Nav_ImgFile.Nav_Details) {
      record.Nav_ImgFile.Nav_Details.forEach(j => {
        sopData.push(j)
      })
    }

    if(sopData&&sopData.length>0){
      const imgSrc = config.serviceHost('api/PF/File/GetFile?id=' + sopData)?config.serviceHost('api/PF/File/GetFile?id=' + sopData[0].FILE_ID):''
      return {
        content: <ImgPreView source={imgSrc}>
          <Button type='primary' icon={btn.ICON} />
        </ImgPreView>
      }
    }
    //return {content: <div></div>}
  },

}
