index.jsx 15.7 KB
Newer Older
TZW's avatar
TZW committed
1
/* 外协工单
TZW's avatar
TZW committed
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-06 14:21:36
TZW's avatar
TZW committed
6 7
 */

wuhao's avatar
wuhao committed
8 9 10 11 12 13
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';
TZW's avatar
TZW committed
14 15
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';
wuhao's avatar
wuhao committed
20

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

  const detail = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          type: 'link',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
TZW's avatar
TZW committed
52
              open: true,
wuhao's avatar
wuhao committed
53 54 55
              item: row,
              title: '详情',
              val: 'detail',
TZW's avatar
TZW committed
56
              title: '详细信息',
wuhao's avatar
wuhao committed
57 58 59 60 61 62 63 64 65
            }));
          },
        }}
      >
        详情
      </PremButton>
    );
  };

TZW's avatar
TZW committed
66 67
  // 完成外协
  const CompleteOuts = () => {
wuhao's avatar
wuhao committed
68
    return (
TZW's avatar
TZW committed
69 70 71 72 73 74 75 76 77 78 79 80 81 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
      <>
        <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',
              // valueType: 'number',
            },
            {
              title: '外协费用',
              dataIndex: 'otherUnitsCost',
              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
          fields={[
            {
              title: '最新外协人员',
TZW's avatar
TZW committed
146
              dataIndex: 'newRepairUserName',
TZW's avatar
TZW committed
147
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
148 149
              fieldProps: { disabled: true },
              key: 'newRepairUserName',
TZW's avatar
TZW committed
150 151 152 153 154 155 156 157 158
            },
            {
              title: '外协人员',
              dataIndex: 'otherUnitsAssistList',
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              key: 'otherUnitsAssistList',
              valueType: 'select',
              options: {
                path: '/repair/umOtherUnitsOrder/selectionAgain',
TZW's avatar
TZW committed
159
                params: { id: drawer?.item.id },
TZW's avatar
TZW committed
160 161 162 163 164
              },
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
165
              otherUnitsAssistList: vals?.otherUnitsAssistList.map((it) => ({ assistUserId: it })),
TZW's avatar
TZW committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
              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
183 184 185
    );
  };

TZW's avatar
TZW committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
  // 外协派单
  const Wxpd = () => {
    const columns = [
      {
        title: '外协人员',
        dataIndex: 'otherUnitsAssistList',
        key: 'otherUnitsAssistList',
        valueType: 'select',
        options: { path: '/repair/umOtherUnitsOrder/selection', params: { id: drawer?.item.id } },
        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
225 226 227 228
  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
TZW's avatar
TZW committed
229
          title: '是否删除?',
wuhao's avatar
wuhao committed
230 231 232
          okText: '确认',
          cancelText: '取消',
          onConfirm: () => {
TZW's avatar
TZW committed
233
            run({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
wuhao's avatar
wuhao committed
234 235 236 237 238 239 240 241 242 243 244 245
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };

TZW's avatar
TZW committed
246 247 248 249 250 251 252 253
  // 更多
  const more = (text, row, _, action) => {
    const menu = (
      <Menu
        items={[
          {
            label:
              row?.status == 0 || row?.status == 1 ? (
TZW's avatar
TZW committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
                <PremButton
                  btn={{
                    onClick: async () => {
                      let params = {
                        id: row?.id,
                      };
                      let res = await doFetch({
                        url: '/repair/umOtherUnitsOrder/orderReceiving',
                        params,
                      });
                      if (res.code === '0000') {
                        message.success('接单成功!');
                        setdrawer((s) => ({
                          ...s,
                          open: false,
                        }));
                        actionRef.current.reload();
                      }
                    },
TZW's avatar
TZW committed
273 274 275
                  }}
                >
                  接单
TZW's avatar
TZW committed
276
                </PremButton>
TZW's avatar
TZW committed
277
              ) : (
TZW's avatar
TZW committed
278 279 280 281 282 283 284 285 286 287 288 289
                <PremButton
                  btn={{
                    onClick: async () => {
                      setdrawer((s) => ({
                        ...s,
                        open: true,
                        type: 'wxpd',
                        item: row,
                        val: 'only',
                        title: '派单',
                      }));
                    },
TZW's avatar
TZW committed
290 291 292
                  }}
                >
                  派单
TZW's avatar
TZW committed
293
                </PremButton>
TZW's avatar
TZW committed
294 295 296 297 298 299
              ),
            key: '0',
            // disabled: true,
          },
          {
            label: (
TZW's avatar
TZW committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313
              <PremButton
                btn={{
                  onClick: () => {
                    setdrawer((s) => ({
                      ...s,
                      open: true,
                      type: 'comouts',
                      item: {
                        id: row.id,
                      },
                      val: 'only',
                      title: '完成外协',
                    }));
                  },
TZW's avatar
TZW committed
314 315 316
                }}
              >
                完成外协
TZW's avatar
TZW committed
317
              </PremButton>
TZW's avatar
TZW committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
            ),
            key: '1',
          },
        ]}
      />
    );
    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
337
    if (row?.status == 1 || row?.status == 2) {
TZW's avatar
TZW committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
      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
356
    } else {
TZW's avatar
TZW committed
357 358 359 360
      return (
        <PremButton
          btn={{
            size: 'small',
TZW's avatar
TZW committed
361 362 363 364 365 366 367 368 369 370 371 372
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                item: {
                  ...row,
                  trackAssistList: row?.trackAssistList ? row?.trackAssistList : [],
                },
                title: '重新指派',
                type: 'Reassig',
                open: true,
              }));
            },
TZW's avatar
TZW committed
373 374 375 376 377 378 379 380
          }}
        >
          重新指派
        </PremButton>
      );
    }
  };

wuhao's avatar
wuhao committed
381
  const columns = useMemo(() => {
TZW's avatar
TZW committed
382
    let defcolumn = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.columns;
TZW's avatar
TZW committed
383
    //console.log(defcolumn);
TZW's avatar
TZW committed
384
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
TZW's avatar
TZW committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406

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

TZW's avatar
TZW committed
409 410 411 412 413
  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [activeTabKey]);

TZW's avatar
TZW committed
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 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
  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
489 490 491
  const selectType = (type) => {
    switch (type) {
      case 'add':
TZW's avatar
TZW committed
492 493 494 495 496 497 498
        return (
          <Addform
            url={'/repair/umOtherUnitsOrder/save'}
            setdrawer={setdrawer}
            actionRef={actionRef}
          />
        );
TZW's avatar
TZW committed
499 500 501 502
      case 'comouts':
        return <CompleteOuts />;
      case 'Reassig':
        return <Reassig />;
TZW's avatar
TZW committed
503 504
      case 'wxpd':
        return <Wxpd />;
TZW's avatar
TZW committed
505 506 507 508 509 510 511 512 513 514 515 516
      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
517 518 519 520
      default:
        break;
    }
  };
wuhao's avatar
wuhao committed
521
  return (
TZW's avatar
TZW committed
522
    <div style={{ position: 'relative' }} ref={containderef}>
wuhao's avatar
wuhao committed
523
      <AutoTable
TZW's avatar
TZW committed
524
        pagetitle={<h3 className="page-title">外协工单</h3>}
wuhao's avatar
wuhao committed
525
        columns={columns}
TZW's avatar
TZW committed
526
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
wuhao's avatar
wuhao committed
527
        actionRef={actionRef}
TZW's avatar
TZW committed
528
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
529
        resizeable={false}
wuhao's avatar
wuhao committed
530 531
        addconfig={{
          // access: 'sysDepartment_save',
TZW's avatar
TZW committed
532
          name: '新建外协工单',
wuhao's avatar
wuhao committed
533 534
          btn: {
            disabled: false,
TZW's avatar
TZW committed
535
            type: 'primary',
wuhao's avatar
wuhao committed
536 537 538
            onClick: () => {
              setdrawer((s) => ({
                ...s,
TZW's avatar
TZW committed
539
                open: true,
TZW's avatar
TZW committed
540 541 542 543
                item: {
                  isShutdown: 1,
                },
                title: '新建外协工单',
TZW's avatar
TZW committed
544 545
                val: 'only',
                type: 'add',
wuhao's avatar
wuhao committed
546 547 548 549
              }));
            },
          },
        }}
TZW's avatar
TZW committed
550 551 552 553 554
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
wuhao's avatar
wuhao committed
555 556 557 558
      />

      <DrawerPro
        fields={columns}
TZW's avatar
TZW committed
559 560 561
        detailpath={pathconfig?.detail || null}
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
wuhao's avatar
wuhao committed
562 563 564 565 566 567
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        onClose={() => {
          setdrawer((s) => ({
            ...s,
TZW's avatar
TZW committed
568

TZW's avatar
TZW committed
569
            open: false,
wuhao's avatar
wuhao committed
570 571 572
          }));
        }}
        {...drawer}
TZW's avatar
TZW committed
573 574 575 576 577 578 579 580 581 582
        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
583 584 585 586
    </div>
  );
}

TZW's avatar
TZW committed
587
export default Failure;