index.jsx 19.3 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4
/* 追踪工单
 * @Author: Li Hanlin
 * @Date: 2022-12-02 11:41:03
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
5
 * @Last Modified time: 2023-01-18 17:45:01
TZW's avatar
TZW committed
6
 */
wuhao's avatar
wuhao committed
7

TZW's avatar
TZW committed
8 9 10 11 12 13 14 15
import * as React from 'react';
import { useState, useMemo, useRef } from 'react';
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
import { useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
TZW's avatar
TZW committed
16 17 18
import Addform from '@/components/Addform';
import { Menu, Dropdown, Button, message } from 'antd';
import InitForm from '@/components/InitForm';
TZW's avatar
TZW committed
19
import Detail from '@/components/RepaireDetail/Detail';
TZW's avatar
TZW committed
20 21
function Failure(props) {
  const actionRef = useRef(),
TZW's avatar
TZW committed
22
    containderef = useRef(),
TZW's avatar
TZW committed
23 24
    formRef = useRef();
  const [drawer, setdrawer] = useState({
wuhao's avatar
wuhao committed
25
      open: false,
TZW's avatar
TZW committed
26 27
    }),
    [activeTabKey, setactiveTabKey] = useState('1');
wuhao's avatar
wuhao committed
28

TZW's avatar
TZW committed
29 30 31 32 33 34 35 36 37 38 39 40 41
  const { run, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    },
  });

TZW's avatar
TZW committed
42 43
  // 重新指派
  const Reassig = () => {
TZW's avatar
TZW committed
44
    return (
TZW's avatar
TZW committed
45 46 47 48
      <>
        <InitForm
          fields={[
            {
TZW's avatar
TZW committed
49
              title: '最新追踪人员',
TZW's avatar
TZW committed
50
              dataIndex: 'newRepairUserName',
TZW's avatar
TZW committed
51
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
52 53
              fieldProps: { disabled: true },
              key: 'newRepairUserName',
TZW's avatar
TZW committed
54 55 56 57 58
            },
            {
              title: '追踪人员',
              dataIndex: 'trackAssistList',
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
59 60 61 62
              fieldProps: {
                placeholder: '请选择',
                mode: 'multiple',
              },
TZW's avatar
TZW committed
63 64 65 66 67 68 69 70 71 72
              key: 'trackAssistList',
              valueType: 'select',
              options: {
                path: '/repair/umTrackOrder/selectionAgain',
                params: { id: drawer?.item.id },
              },
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
73
              trackAssistList: vals?.trackAssistList.map((it) => ({ assistUserId: it })),
TZW's avatar
TZW committed
74 75 76
              id: drawer?.item?.id,
            };
            let res = await doFetch({
TZW's avatar
TZW committed
77
              url: '/repair/umTrackOrder/againTrack',
TZW's avatar
TZW committed
78 79 80
              params,
            });
            if (res.code === '0000') {
TZW's avatar
TZW committed
81
              message.success('重新指派成功!');
TZW's avatar
TZW committed
82 83 84 85 86 87 88
              setdrawer((s) => ({
                ...s,
                open: false,
              }));
              actionRef.current.reload();
            }
          }}
TZW's avatar
TZW committed
89
          defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
90
          {...drawer}
TZW's avatar
TZW committed
91 92 93 94 95 96 97 98 99 100 101 102 103
        />
      </>
    );
  };

  // 追踪
  const TrackForm = () => {
    return (
      <>
        <InitForm
          fields={[
            {
              title: '计划追踪日期',
TZW's avatar
TZW committed
104 105
              dataIndex: 'planTrackTime',
              formItemProps: { rules: [{ required: false, message: '此项为必填项' }] },
TZW's avatar
TZW committed
106
              key: 'nextTrackDate',
TZW's avatar
TZW committed
107 108
              fieldProps: {
                disabled: true,
TZW's avatar
TZW committed
109 110 111
              },
            },
            {
TZW's avatar
TZW committed
112 113 114
              title: '追踪结果',
              dataIndex: 'trackResult',
              valueType: 'radio',
TZW's avatar
TZW committed
115
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
116 117 118 119 120 121 122 123 124 125 126 127
              options: [
                {
                  value: '1',
                  label: '正常',
                },
                {
                  value: '2',
                  label: '异常',
                },
              ],
              colProps: { span: 24 },
              key: 'trackResult',
TZW's avatar
TZW committed
128 129
            },
            {
TZW's avatar
TZW committed
130 131 132
              title: '是否完成追踪',
              dataIndex: 'isFinishTrack',
              valueType: 'radio',
TZW's avatar
TZW committed
133
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
134 135 136 137 138 139 140 141 142 143 144 145
              colProps: { span: 24 },
              key: 'isFinishTrack',
              options: [
                {
                  value: '1',
                  label: '是',
                },
                {
                  value: '2',
                  label: '否',
                },
              ],
TZW's avatar
TZW committed
146 147
            },
            {
TZW's avatar
TZW committed
148 149 150
              title: '追踪周期',
              dataIndex: 'trackCycle',
              key: 'trackCycle',
TZW's avatar
TZW committed
151 152 153
              fieldProps: {
                disabled: true,
              },
TZW's avatar
TZW committed
154 155
            },
            {
TZW's avatar
TZW committed
156 157 158
              title: '追踪内容',
              dataIndex: 'trackContents',
              key: 'trackContents',
TZW's avatar
TZW committed
159
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
160 161 162 163 164
              valueType: 'textarea',
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
165
              trackTraceinfo: { ...vals, planTrackTime: vals.nextTrackDate },
TZW's avatar
TZW committed
166 167
              id: drawer?.item?.id,
            };
TZW's avatar
TZW committed
168 169 170
            delete params.trackTraceinfo.nextTrackDate;
            //console.log(params);

TZW's avatar
TZW committed
171
            let res = await doFetch({
TZW's avatar
TZW committed
172
              url: '/repair/umTrackOrder/trackById',
TZW's avatar
TZW committed
173 174 175
              params,
            });
            if (res.code === '0000') {
TZW's avatar
TZW committed
176
              message.success('成功完成追踪!');
TZW's avatar
TZW committed
177 178 179 180 181 182 183
              setdrawer((s) => ({
                ...s,
                open: false,
              }));
              actionRef.current.reload();
            }
          }}
TZW's avatar
TZW committed
184
          {...drawer}
TZW's avatar
TZW committed
185
          defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
186 187 188 189 190
        />
      </>
    );
  };

TZW's avatar
TZW committed
191 192
  // 验证
  const CheckForm = () => {
TZW's avatar
TZW committed
193 194 195 196 197
    return (
      <>
        <InitForm
          fields={[
            {
TZW's avatar
TZW committed
198 199
              title: '追踪人员',
              dataIndex: 'trackerName',
TZW's avatar
TZW committed
200
              formItemProps: { rules: [{ required: false, message: '此项为必填项' }] },
TZW's avatar
TZW committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214 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 245 246
              key: 'trackerName',
              fieldProps: {
                placeholder: '请选择',
                disabled: true,
              },
            },
            {
              title: '计划追踪日期',
              dataIndex: 'planTrackTime',
              key: 'planTrackTime',
              fieldProps: {
                placeholder: '请选择',
                disabled: true,
              },
            },
            {
              title: '实际追踪日期',
              dataIndex: 'actualTrackTime',
              fieldProps: {
                placeholder: '请选择',
                disabled: true,
              },
              key: 'actualTrackTime',
            },
            {
              title: '追踪结果',
              dataIndex: 'trackResults',
              fieldProps: {
                placeholder: '请选择',
                disabled: true,
              },
              key: 'trackResults',
            },
            {
              title: '追踪内容',
              dataIndex: 'trackContents',
              key: 'trackContents',
              fieldProps: {
                placeholder: '请选择',
                disabled: true,
              },
            },
            {
              title: '验证结果',
              dataIndex: 'reviewerResult',
              valueType: 'radio',
TZW's avatar
TZW committed
247
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
248 249 250 251 252 253 254 255 256 257 258
              options: [
                {
                  value: 1,
                  label: '通过',
                },
                {
                  value: 2,
                  label: '不通过',
                },
              ],
              key: 'reviewerResult',
TZW's avatar
TZW committed
259 260
            },
            {
TZW's avatar
TZW committed
261
              title: '备注',
TZW's avatar
TZW committed
262
              dataIndex: 'remark',
TZW's avatar
TZW committed
263
              valueType: 'textarea',
TZW's avatar
TZW committed
264
              formItemProps: { rules: [{ required: false, message: '此项为必填项' }] },
TZW's avatar
TZW committed
265
              key: 'remark',
TZW's avatar
TZW committed
266 267 268 269
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
270 271 272 273
              trackProcess: {
                reviewerResult: vals.reviewerResult,
                remark: vals.remark,
              },
TZW's avatar
TZW committed
274 275 276
              id: drawer?.item?.id,
            };
            let res = await doFetch({
TZW's avatar
TZW committed
277
              url: '/repair/umTrackOrder/verification',
TZW's avatar
TZW committed
278 279 280
              params,
            });
            if (res.code === '0000') {
TZW's avatar
TZW committed
281
              message.success('验证成功!');
TZW's avatar
TZW committed
282 283 284 285 286 287 288
              setdrawer((s) => ({
                ...s,
                open: false,
              }));
              actionRef.current.reload();
            }
          }}
TZW's avatar
TZW committed
289
          defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
290
          {...drawer}
TZW's avatar
TZW committed
291 292
        />
      </>
TZW's avatar
TZW committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
    );
  };

  const remove = (text, row, _, action) => {
    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
317 318 319 320 321 322 323 324
  // 更多
  const more = (text, row, _, action) => {
    const menu = (
      <Menu
        items={[
          {
            label:
              row?.status == 0 || row?.status == 1 ? (
TZW's avatar
TZW committed
325
                <PremButton
TZW's avatar
TZW committed
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
                  btn={{
                    onClick: async () => {
                      let params = {
                        id: row?.id,
                      };
                      let res = await doFetch({
                        url: '/repair/umTrackOrder/orderReceiving',
                        params,
                      });
                      if (res.code === '0000') {
                        message.success('接单成功!');
                        setdrawer((s) => ({
                          ...s,
                          open: false,
                        }));
                        actionRef.current.reload();
                      }
                    },
TZW's avatar
TZW committed
344 345 346
                  }}
                >
                  接单
TZW's avatar
TZW committed
347
                </PremButton>
TZW's avatar
TZW committed
348
              ) : (
TZW's avatar
TZW committed
349
                <PremButton
TZW's avatar
TZW committed
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
                  btn={{
                    onClick: async () => {
                      let params = {
                        id: row?.id,
                      };
                      let res = await doFetch({
                        url: '/repair/umTrackOrder/dispatchById',
                        params,
                      });
                      if (res.code === '0000') {
                        message.success('派单成功!');
                        setdrawer((s) => ({
                          ...s,
                          open: false,
                        }));
                        actionRef.current.reload();
                      }
                    },
TZW's avatar
TZW committed
368 369 370
                  }}
                >
                  派单
TZW's avatar
TZW committed
371
                </PremButton>
TZW's avatar
TZW committed
372 373 374 375 376 377
              ),
            key: '0',
            // disabled: true,
          },
          {
            label: (
TZW's avatar
TZW committed
378
              <PremButton
TZW's avatar
TZW committed
379 380 381 382 383 384 385 386 387 388 389 390 391
                btn={{
                  onClick: () => {
                    setdrawer((s) => ({
                      ...s,
                      open: true,
                      type: 'track',
                      item: { ...row, trackCycle: String(row?.trackCycle) },
                      // detailpath: '/repair/umTrackTraceinfo/queryByTrackOrderId',
                      // params: { trackOrderId: row?.id },
                      val: 'only',
                      title: '追踪信息',
                    }));
                  },
TZW's avatar
TZW committed
392 393
                }}
              >
TZW's avatar
TZW committed
394
                追踪
TZW's avatar
TZW committed
395
              </PremButton>
TZW's avatar
TZW committed
396 397 398
            ),
            key: '1',
          },
TZW's avatar
TZW committed
399 400
          {
            label: (
TZW's avatar
TZW committed
401
              <PremButton
TZW's avatar
TZW committed
402 403 404 405 406 407 408 409 410 411 412 413 414
                btn={{
                  onClick: () => {
                    setdrawer((s) => ({
                      ...s,
                      open: true,
                      val: 'only',
                      title: '验证',
                      item: row,
                      detailpath: '/repair/umTrackTraceinfo/queryByTrackOrderId',
                      params: { trackOrderId: row?.id },
                      type: 'check',
                    }));
                  },
TZW's avatar
TZW committed
415 416 417
                }}
              >
                验证
TZW's avatar
TZW committed
418
              </PremButton>
TZW's avatar
TZW committed
419 420 421
            ),
            key: '2',
          },
TZW's avatar
TZW committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
        ]}
      />
    );
    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
438
    if (row?.status == 1 || row?.status == 2) {
TZW's avatar
TZW committed
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
      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
457
    } else if (row?.status == 3) {
TZW's avatar
TZW committed
458 459 460 461
      return (
        <PremButton
          btn={{
            size: 'small',
TZW's avatar
TZW committed
462 463 464
            onClick: () => {
              setdrawer((s) => ({
                ...s,
TZW's avatar
TZW committed
465 466 467 468
                item: {
                  ...row,
                  trackAssistList: row?.trackAssistList ? row?.trackAssistList : [],
                },
TZW's avatar
TZW committed
469 470 471 472
                type: 'Reassig',
                open: true,
                val: 'only',
              }));
TZW's avatar
TZW committed
473
              //console.log(drawer);
TZW's avatar
TZW committed
474
            },
TZW's avatar
TZW committed
475 476 477 478 479 480 481 482
          }}
        >
          重新指派
        </PremButton>
      );
    }
  };

TZW's avatar
TZW committed
483 484
  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.columns;
TZW's avatar
TZW committed
485
    //console.log(defcolumn);
TZW's avatar
TZW committed
486
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
TZW's avatar
TZW committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508

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

TZW's avatar
TZW committed
511 512 513 514
  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [activeTabKey]);
wuhao's avatar
wuhao committed
515

TZW's avatar
TZW committed
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
  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: 'nextTrackDate',
          key: 'nextTrackDate',
        },
        {
          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',
        },
        {
          title: '下次追踪日期',
          dataIndex: 'nextTrackDate',
          key: 'nextTrackDate',
        },
      ];
    }
  }, [activeTabKey]);

TZW's avatar
TZW committed
601 602 603
  const selectType = (type) => {
    switch (type) {
      case 'add':
TZW's avatar
TZW committed
604
        return (
TZW's avatar
TZW committed
605 606 607 608 609 610
          <Addform
            url={'/repair/umTrackOrder/save'}
            setdrawer={setdrawer}
            actionRef={actionRef}
            drawer={drawer}
          />
TZW's avatar
TZW committed
611
        );
TZW's avatar
TZW committed
612 613 614 615
      case 'track':
        return <TrackForm />;
      case 'check':
        return <CheckForm />;
TZW's avatar
TZW committed
616 617
      case 'Reassig':
        return <Reassig />;
TZW's avatar
TZW committed
618 619 620 621 622 623 624 625 626 627 628 629
      case 'detail':
        return (
          <Detail
            title="追踪单号"
            titleno={drawer?.item?.taskOrderNo}
            detailpath="/repair/umTrackOperation/queryOperationList"
            params={{ trackOrderId: drawer?.item?.id }}
            baseRow={drawer?.item}
            basecolumns={basecolumns}
            type="zzgd"
          />
        );
TZW's avatar
TZW committed
630 631 632 633 634
      default:
        break;
    }
  };
  return (
TZW's avatar
TZW committed
635
    <div style={{ position: 'relative' }} ref={containderef}>
TZW's avatar
TZW committed
636
      <AutoTable
TZW's avatar
TZW committed
637
        pagetitle={<h3 className="page-title">追踪工单</h3>}
TZW's avatar
TZW committed
638 639 640 641
        columns={columns}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        actionRef={actionRef}
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
642
        resizeable={false}
TZW's avatar
TZW committed
643 644
        addconfig={{
          // access: 'sysDepartment_save',
TZW's avatar
TZW committed
645
          name: '新建追踪工单',
TZW's avatar
TZW committed
646 647 648
          btn: {
            disabled: false,
            type: 'primary',
wuhao's avatar
wuhao committed
649 650 651 652
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
TZW's avatar
TZW committed
653 654 655
                item: {
                  isShutdown: 1,
                },
TZW's avatar
TZW committed
656
                title: '新建追踪工单',
TZW's avatar
TZW committed
657 658
                val: 'only',
                type: 'add',
wuhao's avatar
wuhao committed
659 660
              }));
            },
TZW's avatar
TZW committed
661 662 663 664 665 666 667 668
          },
        }}
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
      />
wuhao's avatar
wuhao committed
669

TZW's avatar
TZW committed
670 671 672 673 674 675 676 677 678 679 680
      <DrawerPro
        fields={columns}
        detailpath={pathconfig?.detail || null}
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        onClose={() => {
          setdrawer((s) => ({
            ...s,
TZW's avatar
TZW committed
681

TZW's avatar
TZW committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
            open: false,
          }));
        }}
        {...drawer}
        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>
    </div>
  );
}
wuhao's avatar
wuhao committed
699

TZW's avatar
TZW committed
700
export default Failure;