import React, { useEffect, useRef, useReducer } from "react"; import { Button, Tooltip, Row, Divider, Drawer, Table, Col, Steps, Card, } from "antd"; import AutoTable from "@/components/AutoTable"; import getPrem from "@/utils/getPrem"; //权限判断fn import { useRequest } from "umi"; import defaultFields from "./fields"; import { doFetch } from "@/utils/doFetch"; import Details from "@/components/Details"; import { gongyiDetail } from "@/utils/detailTotalCard"; import Coltext from "@/components/Coltext"; import InitForm from "@/components/InitForm"; import styles from "./index.less"; import { PlusSquareOutlined, MinusSquareOutlined, MinusCircleOutlined, ArrowDownOutlined, ArrowUpOutlined, } from "@ant-design/icons"; const { Step } = Steps; const initState = { vs: false, fields: {}, iftype: {}, curitem: {}, detail: { dataSource: {}, totalCard: [], }, visible: false, process: [], rightSelectedRows: [], current: 0, stepData: [ { processLineStepProcedureList: [], stepSort: 0, }, ], detailStepData: [], }, otherBasic = { workingProcedureNames: "步骤工序", }; function reducer(state, action) { let { type } = action, newState = {}; switch (type) { case "add": newState = { ...state, vs: true, iftype: { title: "新增工艺路线", val: type, }, fields: { ...action.fields }, }; break; case "edit": newState = { ...state, vs: true, iftype: { title: "编辑工艺路线", val: type, }, fields: { ...action.fields }, curitem: action.curitem, }; break; case "design": newState = { ...state, vs: true, iftype: { title: "工艺设计", val: type, }, fields: {}, curitem: action.curitem, process: action.process, stepData: action.stepData, }; break; case "see": newState = { ...state, detail: { dataSource: action.dataSource, totalCard: [...gongyiDetail], }, detailStepData: action.detailStepData, visible: true, }; break; case "changeProcess": newState = { ...state, process: action.process, }; break; case "changeRightSelect": newState = { ...state, rightSelectedRows: action.rightSelectedRows, }; break; case "changeCurrent": newState = { ...state, current: action.current, }; break; case "changeStep": newState = { ...state, stepData: action.stepData, }; break; case "close": newState = { vs: false, fields: {}, iftype: {}, curitem: {}, detail: { dataSource: {}, totalCard: [], }, visible: false, process: [], rightSelectedRows: [], current: 0, stepData: [ { processLineStepProcedureList: [], stepSort: 0, }, ], detailStepData: [], }; break; } return newState; } const Gongyi = (props) => { let actionRef = useRef(), ChildRef = null; function reload() { actionRef?.current?.reload(); ChildRef?.onRefresh(); } const { run, loading } = useRequest(doFetch, { manual: true, formatResult: (res) => res, onSuccess: (result, params) => { if (result.code == "0000") { reload(); dispatch({ type: "close" }); } }, }), [state, dispatch] = useReducer(reducer, initState), { vs, fields, iftype, curitem, detail, visible, process, rightSelectedRows, current, stepData, detailStepData, } = state, columns = [ { title: "工艺路线编号", dataIndex: "processLineCode", key: "processLineCode", }, { title: "工艺路线名称", dataIndex: "processLineName", key: "processLineName", render: (_, row) => { return ( { doFetch({ url: "/ngic-workmanship/pmProcessLine/queryDetailById", params: { id: row.id }, }).then((res) => { if (res.code == "0000") { let dataSource = res?.data?.data ?? {}; dispatch({ type: "see", dataSource, detailStepData: dataSource?.processLineStepDtoList ?? [], }); } }); }} > {row.processLineName} ); }, }, { title: "所属工厂", dataIndex: "factoryName", key: "factoryName", }, { title: "所属车间", dataIndex: "shopName", key: "shopName", }, { title: "工艺路线类型", dataIndex: "processLineTypeName", key: "processLineTypeName", options: [ { label: "常规", value: 1, }, { label: "返工", value: 2, }, ], valueType: "select", formItemProps: { name: "processLineType", }, }, { title: "能力", dataIndex: "capacity", key: "capacity", search: false, }, { title: "描述", dataIndex: "remark", key: "remark", search: false, }, { title: "操作", dataIndex: "option_dataindex", key: "option_dataindex", valueType: "option", width: 255, render: (text, row, _, action) => extraAction(text, row, _, action), }, ], columnsc = [ { title: "工序编号", dataIndex: "workingProcedureCode", key: "workingProcedureCode", search: false, ellipsis: true, }, { title: "工序名称", dataIndex: "workingProcedureName", key: "workingProcedureName", search: false, ellipsis: true, }, { title: "工序类型", dataIndex: "workingProcedureTypeName", key: "workingProcedureTypeName", search: false, ellipsis: true, }, { title: "采集方式", dataIndex: "collectionModeName", key: "collectionModeName", search: false, ellipsis: true, }, ]; function extraAction(text, record, _, action) { return [ getPrem("sysDepartment_save", action, "修改", () => { doFetch({ url: "/ngic-workmanship/pmProcessLine/queryDetailById", params: { id: record.id }, }).then((res) => { if (res.code == "0000") { let data = res?.data?.data ?? {}; for (let i in defaultFields) { defaultFields[i].value = record[i]; if (i == "factoryId" || i == "shopId") { if (data?.processLineStepDtoList?.length > 0) { defaultFields[i].disabled = true; } else { defaultFields[i].disabled = false; } } } let newData = data?.processLineStepDtoList?.map((it) => { let itemProcessLineStepProcedure = it.processLineStepProcedureList.map((item) => { return item.workingProcedureName; }); return itemProcessLineStepProcedure.join(","); }) ?? [], workingProcedureNames = newData.join("—>"); dispatch({ type: "edit", fields: defaultFields, curitem: { ...data, workingProcedureNames }, }); } }); }), getPrem("sysDepartment_save", action, "工艺设计", () => { let all = async () => { let detail = await doFetch({ url: "/ngic-workmanship/pmProcessLine/queryDetailById", params: { id: record.id }, }), table = await doFetch({ url: "/ngic-workmanship/workingProcedure/querySelectedList", params: { shopId: record.shopId, processLineId: record.id }, }); return { detailData: detail?.data?.data ?? {}, tableData: table?.data?.dataList ?? [], }; }; all().then((res) => { let data = res?.detailData ?? {}; dispatch({ type: "design", curitem: record, process: res?.tableData, stepData: data?.processLineStepDtoList ?? [ { processLineStepProcedureList: [], stepSort: 0, }, ], }); }); }), getPrem("sysDepartment_deleteById", action, "删除", null, { title: "确认删除该工艺路线?", onConfirm: () => { run({ url: "/ngic-workmanship/pmProcessLine/deleteById", params: { id: record.id }, }); }, }), ]; } let saveData = (values, fn) => { let params, url; if (iftype.val == "design") { let processLineStepList = []; stepData?.map((it) => { if (it.processLineStepProcedureList.length > 0) { let el = { stepSort: it.stepSort, lineStepProcedureList: it.processLineStepProcedureList.map( (item) => item.id ), }; processLineStepList.push(el); } }); for (let i = 0; i < processLineStepList.length; i++) { processLineStepList[i].stepSort = i; } url = "/ngic-workmanship/pmProcessLineStep/save"; params = { processLineId: curitem.id, processLineStepList, }; } else { let newfields = JSON.parse(JSON.stringify(values)), difrid = iftype.val == "edit" ? { id: curitem.id } : {}; url = "/ngic-workmanship/pmProcessLine/save"; params = { ...newfields, ...difrid, }; } run({ url, params }); }; let extrarender = [ , ]; return (
(ChildRef = node)} > {vs && iftype.val == "design" && (
工序
it.id), onChange: (selectedRowKeys, selectedRows) => { dispatch({ type: "changeRightSelect", rightSelectedRows: selectedRows, }); }, }} rowKey="id" scroll={{ y: 700, }} /> )} dispatch({ type: "close" })} footer={false} destroyOnClose={true} width={"100%"} style={{ position: "absolute" }} getContainer={false} maskClosable={false} > {iftype.val == "edit" && ( <> {Object.keys(otherBasic).map((it) => { return ( ); })} )} {iftype.val == "design" ? (
{ dispatch({ type: "changeCurrent", current: c }); }} > {stepData?.map((it, i) => { return (
{`步骤${i + 1}`}
{it?.processLineStepProcedureList?.length == 0 && ( )} {i != 0 && it?.processLineStepProcedureList?.length != 0 && ( )} {i != stepData.length - 1 && it?.processLineStepProcedureList?.length != 0 && ( )}
} description={ it?.processLineStepProcedureList && (
{it?.processLineStepProcedureList?.map( (item, j) => { return (
工序编号: {item.workingProcedureCode}
工序名称: {item.workingProcedureName}
); } )} ) } /> ); })} ) : ( { saveData(values, fn); }} onChange={(changedValues, allValues) => {}} submitting={loading || !vs} > )}
dispatch({ type: "close" })} footer={false} destroyOnClose={true} width={"100%"} bottomNode={
{detailStepData?.map((it, i) => { return (
{`步骤${i + 1}`}
} description={ it?.processLineStepProcedureList && (
{it?.processLineStepProcedureList?.map( (item, j) => { return (
工序编号: {item.workingProcedureCode}
工序名称: {item.workingProcedureName}
); } )} ) } /> ); })} } {...detail} > ); }; export default Gongyi;