index.jsx 16.5 KB
Newer Older
TZW's avatar
TZW committed
1
/* eslint-disable react-hooks/exhaustive-deps */
TZW's avatar
TZW committed
2
/* 外协工单
TZW's avatar
TZW committed
3 4 5
 * @Author: Li Hanlin
 * @Date: 2022-12-02 11:41:03
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
6
 * @Last Modified time: 2023-02-08 14:50:40
TZW's avatar
TZW committed
7 8
 */

wuhao's avatar
wuhao committed
9
import * as React from 'react';
TZW's avatar
TZW committed
10
import { useState, useMemo, useRef, useEffect } from 'react';
wuhao's avatar
wuhao committed
11 12 13 14
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
TZW's avatar
TZW committed
15 16
import { useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
TZW's avatar
TZW committed
17 18 19
import Addform from '@/components/Addform';
import { Menu, Dropdown, Button, message } from 'antd';
import InitForm from '@/components/InitForm';
TZW's avatar
TZW committed
20
import Detail from '@/components/RepaireDetail/Detail';
TZW's avatar
TZW committed
21
import { useModel } from '@umijs/max';
TZW's avatar
TZW committed
22
function Failure(props) {
TZW's avatar
TZW committed
23
  const { initialState, setInitialState } = useModel('@@initialState');
wuhao's avatar
wuhao committed
24
  const actionRef = useRef(),
TZW's avatar
TZW committed
25
    containderef = useRef(),
wuhao's avatar
wuhao committed
26 27
    formRef = useRef();
  const [drawer, setdrawer] = useState({
TZW's avatar
TZW committed
28
      open: false,
TZW's avatar
TZW committed
29
      SpecName: null,
TZW's avatar
TZW committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43
    }),
    [activeTabKey, setactiveTabKey] = useState('1');

  const { run, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    },
wuhao's avatar
wuhao committed
44 45
  });

TZW's avatar
TZW committed
46 47 48 49 50 51 52 53 54 55 56
  useEffect(async () => {
    let res = await doFetch({
      url: '/base/pmBaseBusinessData/queryBySpecName',
      params: { businessSpecName: 'TRANSFER_ORDER_DISTRIBUTE' },
    });
    setdrawer((s) => ({
      ...s,
      SpecName: res?.data?.data,
    }));
  }, []);

wuhao's avatar
wuhao committed
57 58 59 60 61 62 63 64 65
  const detail = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          type: 'link',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
TZW's avatar
TZW committed
66
              open: true,
wuhao's avatar
wuhao committed
67 68 69
              item: row,
              title: '详情',
              val: 'detail',
TZW's avatar
TZW committed
70
              title: '详细信息',
wuhao's avatar
wuhao committed
71 72 73 74 75 76 77 78 79
            }));
          },
        }}
      >
        详情
      </PremButton>
    );
  };

TZW's avatar
TZW committed
80 81
  // 完成外协
  const CompleteOuts = () => {
wuhao's avatar
wuhao committed
82
    return (
TZW's avatar
TZW committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
      <>
        <InitForm
          fields={[
            {
              title: '外协单位',
              dataIndex: 'otherUnitsId',
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              key: 'otherUnitsId',
              valueType: 'select',
              options: {
                path: '/asset/equipmentSupplier/query/selection',
                params: {},
              },
            },
            {
              title: '故障原因',
              dataIndex: 'causeFailure',
              valueType: 'textarea',
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              key: 'causeFailure',
            },
            {
              title: '维修内容',
              dataIndex: 'repairContent',
              valueType: 'textarea',
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              key: 'repairContent',
            },
            {
              title: '外协时长',
              dataIndex: 'otherUnitsHours',
              key: 'otherUnitsHours',
TZW's avatar
TZW committed
115
              valueType: 'digit',
TZW's avatar
TZW committed
116
              precision: 3,
TZW's avatar
TZW committed
117 118 119 120
            },
            {
              title: '外协费用',
              dataIndex: 'otherUnitsCost',
TZW's avatar
TZW committed
121
              valueType: 'digit',
TZW's avatar
TZW committed
122
              precision: 3,
TZW's avatar
TZW committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
              key: 'otherUnitsCost',
            },
            {
              title: '备注',
              dataIndex: 'remark',
              key: 'remark',
              valueType: 'textarea',
            },
          ]}
          onFinish={async (vals) => {
            let params = {
              otherUnitsFinish: vals,
              id: drawer?.item?.id,
            };
            let res = await doFetch({
              url: '/repair/umOtherUnitsOrder/finishOtherUnits',
              params,
            });
            if (res.code === '0000') {
              message.success('成功完成外协!');
              setdrawer((s) => ({
                ...s,
                open: false,
              }));
              actionRef.current.reload();
            }
          }}
        />
      </>
    );
  };

  // 重新指派
  const Reassig = () => {
    return (
      <>
        <InitForm
TZW's avatar
TZW committed
160
          defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
161 162 163
          fields={[
            {
              title: '最新外协人员',
TZW's avatar
TZW committed
164
              dataIndex: 'newRepairUserName',
TZW's avatar
TZW committed
165
              formItemProps: { rules: [{ required: false, message: '此项为必填项' }] },
TZW's avatar
TZW committed
166 167
              fieldProps: { disabled: true },
              key: 'newRepairUserName',
TZW's avatar
TZW committed
168 169 170 171 172 173 174 175 176
            },
            {
              title: '外协人员',
              dataIndex: 'otherUnitsAssistList',
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              key: 'otherUnitsAssistList',
              valueType: 'select',
              options: {
                path: '/repair/umOtherUnitsOrder/selectionAgain',
TZW's avatar
TZW committed
177
                params: { id: drawer?.item.id, permission: 'umOtherUnitsOrder:finishOtherUnits' },
TZW's avatar
TZW committed
178 179 180 181 182
              },
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
183
              otherUnitsAssistList: [{ assistUserId: vals?.otherUnitsAssistList }],
TZW's avatar
TZW committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
              id: drawer?.item?.id,
            };
            let res = await doFetch({
              url: '/repair/umOtherUnitsOrder/againOtherUnits',
              params,
            });
            if (res.code === '0000') {
              message.success('重新外协成功!');
              setdrawer((s) => ({
                ...s,
                open: false,
              }));
              actionRef.current.reload();
            }
          }}
        />
      </>
wuhao's avatar
wuhao committed
201 202 203
    );
  };

TZW's avatar
TZW committed
204 205 206 207 208 209 210 211
  // 外协派单
  const Wxpd = () => {
    const columns = [
      {
        title: '外协人员',
        dataIndex: 'otherUnitsAssistList',
        key: 'otherUnitsAssistList',
        valueType: 'select',
TZW's avatar
TZW committed
212 213 214 215
        options: {
          path: '/repair/umOtherUnitsOrder/selection',
          params: { id: drawer?.item.id, permission: 'umOtherUnitsOrder:finishOtherUnits' },
        },
TZW's avatar
TZW committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      },
    ];
    return (
      <>
        <InitForm
          fields={columns}
          onFinish={async (vals) => {
            let params = {
              otherUnitsAssistList: [{ assistUserId: vals?.otherUnitsAssistList }],
              id: drawer?.item.id,
            };
            let res = await doFetch({
              url: '/repair/umOtherUnitsOrder/dispatchById',
              params,
            });
            if (res.code === '0000') {
              message.success('派单成功!');
              setdrawer((s) => ({
                ...s,
                open: false,
              }));
              actionRef.current.reload();
            }
          }}
        />
      </>
    );
  };

wuhao's avatar
wuhao committed
246 247 248 249
  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
TZW's avatar
TZW committed
250
          title: '是否删除?',
wuhao's avatar
wuhao committed
251 252 253
          okText: '确认',
          cancelText: '取消',
          onConfirm: () => {
TZW's avatar
TZW committed
254
            run({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
wuhao's avatar
wuhao committed
255 256 257 258 259 260 261 262 263 264 265 266
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };

TZW's avatar
TZW committed
267 268
  // 更多
  const more = (text, row, _, action) => {
TZW's avatar
TZW committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
    let menulist = [];
    if (row?.status == '1') {
      menulist = [
        {
          label: (
            <PremButton
              btn={{
                onClick: async () => {
                  let params = {
                    id: row?.id,
                  };
                  let res = await doFetch({
                    url: '/repair/umOtherUnitsOrder/orderReceiving',
                    params,
                  });
                  if (res.code === '0000') {
                    message.success('接单成功!');
TZW's avatar
TZW committed
286 287
                    setdrawer((s) => ({
                      ...s,
TZW's avatar
TZW committed
288
                      open: false,
TZW's avatar
TZW committed
289
                    }));
TZW's avatar
TZW committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
                    actionRef.current.reload();
                  }
                },
              }}
            >
              接单
            </PremButton>
          ),
          key: '0',
        },
      ];
    } else if (row?.status == '3') {
      menulist = [
        {
          label: (
            <PremButton
              btn={{
                onClick: () => {
                  setdrawer((s) => ({
                    ...s,
                    open: true,
                    type: 'comouts',
                    item: {
                      id: row.id,
                    },
                    val: 'only',
                    title: '完成外协',
                  }));
                },
              }}
            >
              完成外协
            </PremButton>
          ),
          key: '1',
        },
      ];
    } else if (row?.status == '2') {
      menulist = [
        {
          label: (
            <PremButton
              btn={{
                onClick: async () => {
                  setdrawer((s) => ({
                    ...s,
                    open: true,
                    type: 'wxpd',
                    item: row,
                    val: 'only',
                    title: '派单',
                  }));
                },
              }}
            >
              派单
            </PremButton>
          ),
          key: '0',
        },
      ];
    }

    const menu = <Menu items={menulist} />;
TZW's avatar
TZW committed
354 355 356 357 358 359 360 361 362 363 364 365 366
    return (
      <Dropdown
        overlay={menu}
        trigger={['click']}
        arrow={true}
        getPopupContainer={() => containderef.current}
      >
        <Button size="small">更多</Button>
      </Dropdown>
    );
  };
  // 未完成按钮
  const unfinishBtn = (text, row, _, action) => {
TZW's avatar
TZW committed
367
    if (row?.status == 1 || row?.status == 2) {
TZW's avatar
TZW committed
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
      return (
        <PremButton
          pop={{
            title: '是否删除?',
            okText: '确认',
            cancelText: '取消',
            onConfirm: () => {
              run({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
            },
          }}
          btn={{
            size: 'small',
            type: 'danger',
          }}
        >
          删除
        </PremButton>
      );
TZW's avatar
TZW committed
386
    } else {
TZW's avatar
TZW committed
387 388 389 390
      return (
        <PremButton
          btn={{
            size: 'small',
TZW's avatar
TZW committed
391 392 393 394 395 396 397 398 399 400
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                item: {
                  ...row,
                  trackAssistList: row?.trackAssistList ? row?.trackAssistList : [],
                },
                title: '重新指派',
                type: 'Reassig',
                open: true,
TZW's avatar
TZW committed
401
                val: 'only',
TZW's avatar
TZW committed
402 403
              }));
            },
TZW's avatar
TZW committed
404 405 406 407 408 409 410 411
          }}
        >
          重新指派
        </PremButton>
      );
    }
  };

wuhao's avatar
wuhao committed
412
  const columns = useMemo(() => {
TZW's avatar
TZW committed
413 414 415
    let defcolumn = getcolumns(setdrawer, drawer?.SpecName?.businessData).filter(
      (it) => it.key == activeTabKey,
    )[0]?.columns;
TZW's avatar
TZW committed
416
    //console.log(defcolumn);
TZW's avatar
TZW committed
417 418 419 420
    let defpath =
      getcolumns(setdrawer, drawer?.SpecName?.businessData).filter(
        (it) => it.key == activeTabKey,
      )[0]?.pathconfig ?? {};
TZW's avatar
TZW committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

    if (activeTabKey == '1') {
      return defcolumn.concat({
        title: '操作',
        valueType: 'option',
        width: 150,
        render: (text, row, _, action) => {
          return [more(text, row, _, action)];
        },
      });
    } else if (activeTabKey == '2') {
      return defcolumn.concat({
        title: '操作',
        valueType: 'option',
        width: 150,
        render: (text, row, _, action) => {
          return [unfinishBtn(text, row, _, action)];
        },
      });
    } else if (activeTabKey == '3') {
      return defcolumn;
    }
TZW's avatar
TZW committed
443
  }, [activeTabKey]);
wuhao's avatar
wuhao committed
444

TZW's avatar
TZW committed
445 446 447 448 449
  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [activeTabKey]);

TZW's avatar
TZW committed
450 451 452 453 454 455 456 457 458 459
  const basecolumns = useMemo(() => {
    if (activeTabKey == 3) {
      return [
        {
          title: '创建人',
          dataIndex: 'createUserName',
          key: 'createUserName',
        },
        {
          title: '创建时间',
TZW's avatar
TZW committed
460 461
          dataIndex: 'createTimes',
          key: 'createTimes',
TZW's avatar
TZW committed
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
        },
        {
          title: '工单状态',
          dataIndex: 'statusName',
          key: 'statusName',
        },
        {
          title: '来源工单',
          dataIndex: 'dataSourcesNo',
          key: 'dataSourcesNo',
        },
        {
          title: '来源类型',
          dataIndex: 'dataSourcesName',
          key: 'dataSourcesName',
        },
        {
          title: '最新外协人员',
          dataIndex: 'newRepairUserName',
          key: 'newRepairUserName',
        },
        {
          title: '关单时间',
          dataIndex: 'repairCloseTime',
          key: 'repairCloseTime',
        },
      ];
    } else {
      return [
        {
          title: '创建人',
          dataIndex: 'createUserName',
          key: 'createUserName',
        },
        {
          title: '创建时间',
TZW's avatar
TZW committed
498 499
          dataIndex: 'createTimes',
          key: 'createTimes',
TZW's avatar
TZW committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
        },
        {
          title: '工单状态',
          dataIndex: 'statusName',
          key: 'statusName',
        },
        {
          title: '来源工单',
          dataIndex: 'dataSourcesNo',
          key: 'dataSourcesNo',
        },
        {
          title: '来源类型',
          dataIndex: 'dataSourcesName',
          key: 'dataSourcesName',
        },
        {
          title: '最新外协人员',
          dataIndex: 'newRepairUserName',
          key: 'newRepairUserName',
        },
      ];
    }
  }, [activeTabKey]);

TZW's avatar
TZW committed
525 526 527
  const selectType = (type) => {
    switch (type) {
      case 'add':
TZW's avatar
TZW committed
528 529 530 531 532
        return (
          <Addform
            url={'/repair/umOtherUnitsOrder/save'}
            setdrawer={setdrawer}
            actionRef={actionRef}
TZW's avatar
TZW committed
533
            drawer={drawer}
TZW's avatar
TZW committed
534 535
          />
        );
TZW's avatar
TZW committed
536 537 538 539
      case 'comouts':
        return <CompleteOuts />;
      case 'Reassig':
        return <Reassig />;
TZW's avatar
TZW committed
540 541
      case 'wxpd':
        return <Wxpd />;
TZW's avatar
TZW committed
542 543 544 545 546 547 548 549 550 551 552 553
      case 'detail':
        return (
          <Detail
            title="外协单号"
            titleno={drawer?.item.repairNo}
            detailpath="/repair/umOtherUnitsOperation/queryOperationList"
            params={{ otherUnitsOrderId: drawer?.item.id }}
            baseRow={drawer?.item}
            basecolumns={basecolumns}
            type="wgd"
          />
        );
TZW's avatar
TZW committed
554 555 556 557
      default:
        break;
    }
  };
wuhao's avatar
wuhao committed
558
  return (
TZW's avatar
TZW committed
559
    <div style={{ position: 'relative' }} ref={containderef}>
wuhao's avatar
wuhao committed
560
      <AutoTable
TZW's avatar
TZW committed
561
        pagetitle={<h3 className="page-title">外协工单</h3>}
wuhao's avatar
wuhao committed
562
        columns={columns}
TZW's avatar
TZW committed
563
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
wuhao's avatar
wuhao committed
564
        actionRef={actionRef}
TZW's avatar
TZW committed
565
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
566
        resizeable={false}
wuhao's avatar
wuhao committed
567 568
        addconfig={{
          // access: 'sysDepartment_save',
TZW's avatar
TZW committed
569
          name: '新建外协工单',
wuhao's avatar
wuhao committed
570 571
          btn: {
            disabled: false,
TZW's avatar
TZW committed
572
            type: 'primary',
wuhao's avatar
wuhao committed
573 574 575
            onClick: () => {
              setdrawer((s) => ({
                ...s,
TZW's avatar
TZW committed
576
                open: true,
TZW's avatar
TZW committed
577 578 579 580
                item: {
                  isShutdown: 1,
                },
                title: '新建外协工单',
TZW's avatar
TZW committed
581 582
                val: 'only',
                type: 'add',
wuhao's avatar
wuhao committed
583 584 585 586
              }));
            },
          },
        }}
TZW's avatar
TZW committed
587
        tabList={getcolumns()}
TZW's avatar
TZW committed
588
        extraparams={activeTabKey == 1 ? { newUserId: initialState?.currentUser?.id } : null}
TZW's avatar
TZW committed
589 590 591 592
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
wuhao's avatar
wuhao committed
593 594 595 596
      />

      <DrawerPro
        fields={columns}
TZW's avatar
TZW committed
597 598 599
        detailpath={pathconfig?.detail || null}
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
wuhao's avatar
wuhao committed
600 601 602 603 604 605
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        onClose={() => {
          setdrawer((s) => ({
            ...s,
TZW's avatar
TZW committed
606

TZW's avatar
TZW committed
607
            open: false,
wuhao's avatar
wuhao committed
608 609 610
          }));
        }}
        {...drawer}
TZW's avatar
TZW committed
611 612 613 614 615 616 617 618 619 620
        onFinish={(vals) => {
          if (drawer?.val == 'add') {
            run({ url: pathconfig?.add || '/add', params: { ...vals } });
          } else if (drawer?.val == 'edit') {
            run({ url: pathconfig?.edit || '/edit', params: { ...vals, id: drawer?.item?.id } });
          }
        }}
      >
        {selectType(drawer?.type)}
      </DrawerPro>
wuhao's avatar
wuhao committed
621 622 623 624
    </div>
  );
}

TZW's avatar
TZW committed
625
export default Failure;