index.jsx 16.8 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: 2022-12-08 14:03:22
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';
wuhao's avatar
wuhao committed
19

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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  const { run, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    },
  });

  const detail = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          type: 'link',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
              title: '详情',
              val: 'detail',
              title: '详细信息',
            }));
          },
        }}
      >
        详情
      </PremButton>
    );
  };

TZW's avatar
TZW committed
65 66
  // 重新指派
  const Reassig = () => {
TZW's avatar
TZW committed
67
    return (
TZW's avatar
TZW committed
68 69 70 71
      <>
        <InitForm
          fields={[
            {
TZW's avatar
TZW committed
72
              title: '最新追踪人员',
TZW's avatar
TZW committed
73
              dataIndex: 'newRepairUserName',
TZW's avatar
TZW committed
74
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
75 76
              fieldProps: { disabled: true },
              key: 'newRepairUserName',
TZW's avatar
TZW committed
77 78 79 80 81
            },
            {
              title: '追踪人员',
              dataIndex: 'trackAssistList',
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
82 83 84 85
              fieldProps: {
                placeholder: '请选择',
                mode: 'multiple',
              },
TZW's avatar
TZW committed
86 87 88 89 90 91 92 93 94 95
              key: 'trackAssistList',
              valueType: 'select',
              options: {
                path: '/repair/umTrackOrder/selectionAgain',
                params: { id: drawer?.item.id },
              },
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
96
              trackAssistList: vals?.trackAssistList.map((it) => ({ assistUserId: it })),
TZW's avatar
TZW committed
97 98 99
              id: drawer?.item?.id,
            };
            let res = await doFetch({
TZW's avatar
TZW committed
100
              url: '/repair/umTrackOrder/againTrack',
TZW's avatar
TZW committed
101 102 103
              params,
            });
            if (res.code === '0000') {
TZW's avatar
TZW committed
104
              message.success('重新指派成功!');
TZW's avatar
TZW committed
105 106 107 108 109 110 111
              setdrawer((s) => ({
                ...s,
                open: false,
              }));
              actionRef.current.reload();
            }
          }}
TZW's avatar
TZW committed
112
          defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
113
          {...drawer}
TZW's avatar
TZW committed
114 115 116 117 118 119 120 121 122 123 124 125 126
        />
      </>
    );
  };

  // 追踪
  const TrackForm = () => {
    return (
      <>
        <InitForm
          fields={[
            {
              title: '计划追踪日期',
TZW's avatar
TZW committed
127 128
              dataIndex: 'planTrackTime',
              formItemProps: { rules: [{ required: false, message: '此项为必填项' }] },
TZW's avatar
TZW committed
129
              key: 'nextTrackDate',
TZW's avatar
TZW committed
130 131
              fieldProps: {
                disabled: true,
TZW's avatar
TZW committed
132 133 134
              },
            },
            {
TZW's avatar
TZW committed
135 136 137
              title: '追踪结果',
              dataIndex: 'trackResult',
              valueType: 'radio',
TZW's avatar
TZW committed
138
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
139 140 141 142 143 144 145 146 147 148 149 150
              options: [
                {
                  value: '1',
                  label: '正常',
                },
                {
                  value: '2',
                  label: '异常',
                },
              ],
              colProps: { span: 24 },
              key: 'trackResult',
TZW's avatar
TZW committed
151 152
            },
            {
TZW's avatar
TZW committed
153 154 155
              title: '是否完成追踪',
              dataIndex: 'isFinishTrack',
              valueType: 'radio',
TZW's avatar
TZW committed
156
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
157 158 159 160 161 162 163 164 165 166 167 168
              colProps: { span: 24 },
              key: 'isFinishTrack',
              options: [
                {
                  value: '1',
                  label: '是',
                },
                {
                  value: '2',
                  label: '否',
                },
              ],
TZW's avatar
TZW committed
169 170
            },
            {
TZW's avatar
TZW committed
171 172 173
              title: '追踪周期',
              dataIndex: 'trackCycle',
              key: 'trackCycle',
TZW's avatar
TZW committed
174 175 176
              fieldProps: {
                disabled: true,
              },
TZW's avatar
TZW committed
177 178
            },
            {
TZW's avatar
TZW committed
179 180 181
              title: '追踪内容',
              dataIndex: 'trackContents',
              key: 'trackContents',
TZW's avatar
TZW committed
182
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
183 184 185 186 187
              valueType: 'textarea',
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
188
              trackTraceinfo: { ...vals, planTrackTime: vals.nextTrackDate },
TZW's avatar
TZW committed
189 190
              id: drawer?.item?.id,
            };
TZW's avatar
TZW committed
191 192 193
            delete params.trackTraceinfo.nextTrackDate;
            //console.log(params);

TZW's avatar
TZW committed
194
            let res = await doFetch({
TZW's avatar
TZW committed
195
              url: '/repair/umTrackOrder/trackById',
TZW's avatar
TZW committed
196 197 198
              params,
            });
            if (res.code === '0000') {
TZW's avatar
TZW committed
199
              message.success('成功完成追踪!');
TZW's avatar
TZW committed
200 201 202 203 204 205 206
              setdrawer((s) => ({
                ...s,
                open: false,
              }));
              actionRef.current.reload();
            }
          }}
TZW's avatar
TZW committed
207
          {...drawer}
TZW's avatar
TZW committed
208
          defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
209 210 211 212 213
        />
      </>
    );
  };

TZW's avatar
TZW committed
214 215
  // 验证
  const CheckForm = () => {
TZW's avatar
TZW committed
216 217 218 219 220
    return (
      <>
        <InitForm
          fields={[
            {
TZW's avatar
TZW committed
221 222
              title: '追踪人员',
              dataIndex: 'trackerName',
TZW's avatar
TZW committed
223
              formItemProps: { rules: [{ required: false, message: '此项为必填项' }] },
TZW's avatar
TZW committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
              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
270
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
271 272 273 274 275 276 277 278 279 280 281
              options: [
                {
                  value: 1,
                  label: '通过',
                },
                {
                  value: 2,
                  label: '不通过',
                },
              ],
              key: 'reviewerResult',
TZW's avatar
TZW committed
282 283
            },
            {
TZW's avatar
TZW committed
284
              title: '备注',
TZW's avatar
TZW committed
285
              dataIndex: 'remark',
TZW's avatar
TZW committed
286
              valueType: 'textarea',
TZW's avatar
TZW committed
287
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
288
              key: 'remark',
TZW's avatar
TZW committed
289 290 291 292
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
293 294 295 296
              trackProcess: {
                reviewerResult: vals.reviewerResult,
                remark: vals.remark,
              },
TZW's avatar
TZW committed
297 298 299
              id: drawer?.item?.id,
            };
            let res = await doFetch({
TZW's avatar
TZW committed
300
              url: '/repair/umTrackOrder/verification',
TZW's avatar
TZW committed
301 302 303
              params,
            });
            if (res.code === '0000') {
TZW's avatar
TZW committed
304
              message.success('验证成功!');
TZW's avatar
TZW committed
305 306 307 308 309 310 311
              setdrawer((s) => ({
                ...s,
                open: false,
              }));
              actionRef.current.reload();
            }
          }}
TZW's avatar
TZW committed
312
          defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
313
          {...drawer}
TZW's avatar
TZW committed
314 315
        />
      </>
TZW's avatar
TZW committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
    );
  };

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

TZW's avatar
TZW committed
498 499
  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.columns;
TZW's avatar
TZW committed
500
    //console.log(defcolumn);
TZW's avatar
TZW committed
501
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
TZW's avatar
TZW committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523

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

TZW's avatar
TZW committed
526 527 528 529
  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [activeTabKey]);
wuhao's avatar
wuhao committed
530

TZW's avatar
TZW committed
531 532 533
  const selectType = (type) => {
    switch (type) {
      case 'add':
TZW's avatar
TZW committed
534 535 536
        return (
          <Addform url={'/repair/umTrackOrder/save'} setdrawer={setdrawer} actionRef={actionRef} />
        );
TZW's avatar
TZW committed
537 538 539 540
      case 'track':
        return <TrackForm />;
      case 'check':
        return <CheckForm />;
TZW's avatar
TZW committed
541 542
      case 'Reassig':
        return <Reassig />;
TZW's avatar
TZW committed
543 544 545 546 547
      default:
        break;
    }
  };
  return (
TZW's avatar
TZW committed
548
    <div style={{ position: 'relative' }} ref={containderef}>
TZW's avatar
TZW committed
549
      <AutoTable
TZW's avatar
TZW committed
550
        pagetitle={<h3 className="page-title">追踪工单</h3>}
TZW's avatar
TZW committed
551 552 553 554
        columns={columns}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        actionRef={actionRef}
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
555
        resizeable={false}
TZW's avatar
TZW committed
556 557 558 559 560
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
            type: 'primary',
wuhao's avatar
wuhao committed
561 562 563 564
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
TZW's avatar
TZW committed
565 566 567
                item: {
                  isShutdown: 1,
                },
TZW's avatar
TZW committed
568
                title: '新建追踪工单',
TZW's avatar
TZW committed
569 570
                val: 'only',
                type: 'add',
wuhao's avatar
wuhao committed
571 572
              }));
            },
TZW's avatar
TZW committed
573 574 575 576 577 578 579 580
          },
        }}
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
      />
wuhao's avatar
wuhao committed
581

TZW's avatar
TZW committed
582 583 584 585 586 587 588 589 590 591 592
      <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
593

TZW's avatar
TZW committed
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
            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
611

TZW's avatar
TZW committed
612
export default Failure;