index.jsx 16.4 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-03 10:40:38
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';
wuhao's avatar
wuhao committed
21

TZW's avatar
TZW committed
22
function Failure(props) {
wuhao's avatar
wuhao committed
23
  const actionRef = useRef(),
TZW's avatar
TZW committed
24
    containderef = useRef(),
wuhao's avatar
wuhao committed
25 26
    formRef = useRef();
  const [drawer, setdrawer] = useState({
TZW's avatar
TZW committed
27
      open: false,
TZW's avatar
TZW committed
28
      SpecName: null,
TZW's avatar
TZW committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42
    }),
    [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
43 44
  });

TZW's avatar
TZW committed
45 46 47 48 49 50 51 52 53 54 55
  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
56 57 58 59 60 61 62 63 64
  const detail = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          type: 'link',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
TZW's avatar
TZW committed
65
              open: true,
wuhao's avatar
wuhao committed
66 67 68
              item: row,
              title: '详情',
              val: 'detail',
TZW's avatar
TZW committed
69
              title: '详细信息',
wuhao's avatar
wuhao committed
70 71 72 73 74 75 76 77 78
            }));
          },
        }}
      >
        详情
      </PremButton>
    );
  };

TZW's avatar
TZW committed
79 80
  // 完成外协
  const CompleteOuts = () => {
wuhao's avatar
wuhao committed
81
    return (
TZW's avatar
TZW committed
82 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
      <>
        <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
114
              valueType: 'digit',
TZW's avatar
TZW committed
115
              precision: 3,
TZW's avatar
TZW committed
116 117 118 119
            },
            {
              title: '外协费用',
              dataIndex: 'otherUnitsCost',
TZW's avatar
TZW committed
120
              valueType: 'digit',
TZW's avatar
TZW committed
121
              precision: 3,
TZW's avatar
TZW committed
122 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
              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
159
          defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
160 161 162
          fields={[
            {
              title: '最新外协人员',
TZW's avatar
TZW committed
163
              dataIndex: 'newRepairUserName',
TZW's avatar
TZW committed
164
              formItemProps: { rules: [{ required: false, message: '此项为必填项' }] },
TZW's avatar
TZW committed
165 166
              fieldProps: { disabled: true },
              key: 'newRepairUserName',
TZW's avatar
TZW committed
167 168 169 170 171 172 173 174 175
            },
            {
              title: '外协人员',
              dataIndex: 'otherUnitsAssistList',
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              key: 'otherUnitsAssistList',
              valueType: 'select',
              options: {
                path: '/repair/umOtherUnitsOrder/selectionAgain',
TZW's avatar
TZW committed
176
                params: { id: drawer?.item.id, permission: 'umOtherUnitsOrder:finishOtherUnits' },
TZW's avatar
TZW committed
177 178 179 180 181
              },
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
182
              otherUnitsAssistList: vals?.otherUnitsAssistList.map((it) => ({ assistUserId: it })),
TZW's avatar
TZW committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
              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
200 201 202
    );
  };

TZW's avatar
TZW committed
203 204 205 206 207 208 209 210
  // 外协派单
  const Wxpd = () => {
    const columns = [
      {
        title: '外协人员',
        dataIndex: 'otherUnitsAssistList',
        key: 'otherUnitsAssistList',
        valueType: 'select',
TZW's avatar
TZW committed
211 212 213 214
        options: {
          path: '/repair/umOtherUnitsOrder/selection',
          params: { id: drawer?.item.id, permission: 'umOtherUnitsOrder:finishOtherUnits' },
        },
TZW's avatar
TZW committed
215 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
        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
245 246 247 248
  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
TZW's avatar
TZW committed
249
          title: '是否删除?',
wuhao's avatar
wuhao committed
250 251 252
          okText: '确认',
          cancelText: '取消',
          onConfirm: () => {
TZW's avatar
TZW committed
253
            run({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
wuhao's avatar
wuhao committed
254 255 256 257 258 259 260 261 262 263 264 265
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };

TZW's avatar
TZW committed
266 267
  // 更多
  const more = (text, row, _, action) => {
TZW's avatar
TZW committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    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
285 286
                    setdrawer((s) => ({
                      ...s,
TZW's avatar
TZW committed
287
                      open: false,
TZW's avatar
TZW committed
288
                    }));
TZW's avatar
TZW committed
289 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
                    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
353 354 355 356 357 358 359 360 361 362 363 364 365
    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
366
    if (row?.status == 1 || row?.status == 2) {
TZW's avatar
TZW committed
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
      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
385
    } else {
TZW's avatar
TZW committed
386 387 388 389
      return (
        <PremButton
          btn={{
            size: 'small',
TZW's avatar
TZW committed
390 391 392 393 394 395 396 397 398 399
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                item: {
                  ...row,
                  trackAssistList: row?.trackAssistList ? row?.trackAssistList : [],
                },
                title: '重新指派',
                type: 'Reassig',
                open: true,
TZW's avatar
TZW committed
400
                val: 'only',
TZW's avatar
TZW committed
401 402
              }));
            },
TZW's avatar
TZW committed
403 404 405 406 407 408 409 410
          }}
        >
          重新指派
        </PremButton>
      );
    }
  };

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

    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
442
  }, [activeTabKey]);
wuhao's avatar
wuhao committed
443

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

TZW's avatar
TZW committed
449 450 451 452 453 454 455 456 457 458 459 460 461 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 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
  const basecolumns = useMemo(() => {
    if (activeTabKey == 3) {
      return [
        {
          title: '创建人',
          dataIndex: 'createUserName',
          key: 'createUserName',
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          key: 'createTime',
        },
        {
          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: '创建时间',
          dataIndex: 'createTime',
          key: 'createTime',
        },
        {
          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
524 525 526
  const selectType = (type) => {
    switch (type) {
      case 'add':
TZW's avatar
TZW committed
527 528 529 530 531
        return (
          <Addform
            url={'/repair/umOtherUnitsOrder/save'}
            setdrawer={setdrawer}
            actionRef={actionRef}
TZW's avatar
TZW committed
532
            drawer={drawer}
TZW's avatar
TZW committed
533 534
          />
        );
TZW's avatar
TZW committed
535 536 537 538
      case 'comouts':
        return <CompleteOuts />;
      case 'Reassig':
        return <Reassig />;
TZW's avatar
TZW committed
539 540
      case 'wxpd':
        return <Wxpd />;
TZW's avatar
TZW committed
541 542 543 544 545 546 547 548 549 550 551 552
      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
553 554 555 556
      default:
        break;
    }
  };
wuhao's avatar
wuhao committed
557
  return (
TZW's avatar
TZW committed
558
    <div style={{ position: 'relative' }} ref={containderef}>
wuhao's avatar
wuhao committed
559
      <AutoTable
TZW's avatar
TZW committed
560
        pagetitle={<h3 className="page-title">外协工单</h3>}
wuhao's avatar
wuhao committed
561
        columns={columns}
TZW's avatar
TZW committed
562
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
wuhao's avatar
wuhao committed
563
        actionRef={actionRef}
TZW's avatar
TZW committed
564
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
565
        resizeable={false}
wuhao's avatar
wuhao committed
566 567
        addconfig={{
          // access: 'sysDepartment_save',
TZW's avatar
TZW committed
568
          name: '新建外协工单',
wuhao's avatar
wuhao committed
569 570
          btn: {
            disabled: false,
TZW's avatar
TZW committed
571
            type: 'primary',
wuhao's avatar
wuhao committed
572 573 574
            onClick: () => {
              setdrawer((s) => ({
                ...s,
TZW's avatar
TZW committed
575
                open: true,
TZW's avatar
TZW committed
576 577 578 579
                item: {
                  isShutdown: 1,
                },
                title: '新建外协工单',
TZW's avatar
TZW committed
580 581
                val: 'only',
                type: 'add',
wuhao's avatar
wuhao committed
582 583 584 585
              }));
            },
          },
        }}
TZW's avatar
TZW committed
586 587 588 589 590
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
wuhao's avatar
wuhao committed
591 592 593 594
      />

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

TZW's avatar
TZW committed
605
            open: false,
wuhao's avatar
wuhao committed
606 607 608
          }));
        }}
        {...drawer}
TZW's avatar
TZW committed
609 610 611 612 613 614 615 616 617 618
        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
619 620 621 622
    </div>
  );
}

TZW's avatar
TZW committed
623
export default Failure;