index.jsx 13.8 KB
Newer Older
TZW's avatar
TZW committed
1
/* eslint-disable react-hooks/exhaustive-deps */
TZW's avatar
TZW committed
2 3 4 5
/* 接单平台
 * @Author: Li Hanlin
 * @Date: 2022-12-05 10:13:42
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
6
 * @Last Modified time: 2023-01-29 16:25:57
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';
TZW's avatar
TZW committed
11 12 13 14 15 16
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
17
import OrderHandle from './RepairOrderHandle';
TZW's avatar
TZW committed
18
import { message } from 'antd';
TZW's avatar
TZW committed
19
import Detail from '@/components/RepaireDetail/Detail';
TZW's avatar
TZW committed
20 21 22 23 24
function Platform(props) {
  const actionRef = useRef(),
    formRef = useRef();
  const [drawer, setdrawer] = useState({
      open: false,
TZW's avatar
TZW committed
25
      SpecName: null,
TZW's avatar
TZW committed
26 27 28 29 30 31 32 33 34 35
    }),
    [activeTabKey, setactiveTabKey] = useState('1');

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

TZW's avatar
TZW committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  useEffect(async () => {
    let params = {};
    if (activeTabKey == '1') {
      params.businessSpecName = 'ORDER_RECEIVING_DISTRIBUTE';
    } else if (activeTabKey == '2') {
      params.businessSpecName = 'TRACKING_ORDER_DISTRIBUTE';
    } else if (activeTabKey == '3') {
      params.businessSpecName = 'TRANSFER_ORDER_DISTRIBUTE';
    }
    let res = await doFetch({
      url: '/base/pmBaseBusinessData/queryBySpecName',
      params,
    });
    setdrawer((s) => ({
      ...s,
      SpecName: res?.data?.data,
    }));
  }, [activeTabKey]);

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

TZW's avatar
TZW committed
84
  // 接单按钮
TZW's avatar
TZW committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98
  const receiveBtn = (text, row, _, action, activeTab) => {
    if (row?.status == 0 || row?.status == 1) {
      if (activeTab == '2') {
        // 追踪
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: async () => {
                // setdrawer((s) => ({
                //   ...s,
                //   type: null,
                // }));
TZW's avatar
TZW committed
99
                //console.log('zzjd');
TZW's avatar
TZW committed
100 101 102 103 104 105 106 107 108 109 110
                let params = {
                  id: row?.id,
                };
                let res = await doFetch({
                  url: '/repair/umTrackOrder/orderReceiving',
                  params,
                });
                if (res.code === '0000') {
                  message.success('操作成功!');
                  setdrawer((s) => ({
                    ...s,
TZW's avatar
TZW committed
111
                    open: false,
TZW's avatar
TZW committed
112 113 114 115 116 117
                  }));
                  actionRef.current.reload();
                }
              },
            }}
          >
TZW's avatar
TZW committed
118
            接单
TZW's avatar
TZW committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
          </PremButton>
        );
      } else if (activeTab == '3') {
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: async () => {
                let params = {
                  ...vals,
                  id,
                };
                let res = await doFetch({
                  url: '/repair/umOtherUnitsOrder/orderReceiving',
                  params,
                });
                if (res.code === '0000') {
                  message.success('操作成功!');
                  setdrawer((s) => ({
                    ...s,
TZW's avatar
TZW committed
140
                    open: false,
TZW's avatar
TZW committed
141 142 143 144 145 146
                  }));
                  actionRef.current.reload();
                }
              },
            }}
          >
TZW's avatar
TZW committed
147
            接单
TZW's avatar
TZW committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
          </PremButton>
        );
      } else if (activeTab == '1') {
        // 维修
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: () => {
                setdrawer((s) => ({
                  ...s,
                  open: true,
                  item: row,
                  title: '接单',
                  val: 'only',
                  type: 'wxjd',
                }));
              },
            }}
          >
TZW's avatar
TZW committed
169
            接单
TZW's avatar
TZW committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
          </PremButton>
        );
      }
    } else {
      if (activeTab == '2') {
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: () => {
                setdrawer((s) => ({
                  ...s,
                  open: true,
                  item: row,
                  title: '派单',
                  type: 'zzpd',
                  val: 'only',
                }));
              },
            }}
          >
            派单
          </PremButton>
        );
      } else if (activeTab == '1') {
        // 维修
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: () => {
                setdrawer((s) => ({
                  ...s,
                  open: true,
                  item: row,
                  title: '派单',
                  type: 'wxpd',
                  val: 'only',
                }));
              },
            }}
          >
            派单
          </PremButton>
        );
      } else if (activeTab == '3') {
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: () => {
                setdrawer((s) => ({
                  ...s,
                  open: true,
                  item: row,
                  title: '派单',
                  type: 'wpd',
                  val: 'only',
                }));
              },
            }}
          >
            派单
          </PremButton>
        );
      }
    }
TZW's avatar
TZW committed
240
  };
wuhao's avatar
wuhao committed
241

TZW's avatar
TZW committed
242
  const columns = useMemo(() => {
TZW's avatar
TZW committed
243 244 245 246 247 248 249
    let defcolumn = getcolumns(setdrawer, drawer?.SpecName?.businessData).filter(
      (it) => it.key == activeTabKey,
    )[0]?.columns;
    let defpath =
      getcolumns(setdrawer, drawer?.SpecName?.businessData).filter(
        (it) => it.key == activeTabKey,
      )[0]?.pathconfig ?? {};
TZW's avatar
TZW committed
250
    let actions = {
TZW's avatar
TZW committed
251 252 253
      title: '操作',
      valueType: 'option',
      width: 150,
TZW's avatar
TZW committed
254 255 256
      render: (text, row, _, action) => receiveBtn(text, row, _, action, activeTabKey),
    };
    return defcolumn.concat(actions);
TZW's avatar
TZW committed
257
  }, [activeTabKey]);
wuhao's avatar
wuhao committed
258

TZW's avatar
TZW committed
259 260 261 262
  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [activeTabKey]);
wuhao's avatar
wuhao committed
263

TZW's avatar
TZW committed
264 265
  function selectType(type) {
    switch (type) {
TZW's avatar
TZW committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
      case 'wxjd':
        return (
          <OrderHandle
            type="wxjd"
            id={drawer?.item.id}
            url={'/repair/umRepairOrder/orderReceiving'}
            actionRef={actionRef}
            setdrawer={setdrawer}
          />
        );
      case 'wxpd':
        return (
          <OrderHandle
            type="wxpd"
            actionRef={actionRef}
            setdrawer={setdrawer}
            id={drawer?.item.id}
            url={'/repair/umRepairOrder/dispatchById'}
          />
        );
      case 'zzpd':
        return (
          <OrderHandle
            type="zzpd"
            actionRef={actionRef}
            setdrawer={setdrawer}
            id={drawer?.item.id}
            url={'/repair/umTrackOrder/dispatchById'}
          />
        );
      case 'wpd':
        return (
          <OrderHandle
            type="wpd"
            setdrawer={setdrawer}
            actionRef={actionRef}
            id={drawer?.item.id}
            url={'/repair/umOtherUnitsOrder/dispatchById'}
          />
        );
TZW's avatar
TZW committed
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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
      case 'detail_wxgd':
        return (
          <Detail
            title="维修单号"
            titleno={drawer?.item?.repairNo}
            detailpath="/repair/umRepairOperation/queryOperationList"
            params={{ repairOrderId: drawer?.item?.id }}
            baseRow={drawer?.item}
            basecolumns={[
              {
                title: '创建时间',
                dataIndex: 'createTime',
                key: 'createTime',
              },
              {
                title: '工单状态',
                dataIndex: 'statusName',
                key: 'statusName',
              },
              {
                title: '报修单号',
                dataIndex: 'repairNo',
                key: 'repairNo',
              },
              {
                title: '最新维修人员',
                dataIndex: 'newRepairUserName',
                key: 'newRepairUserName',
              },
              {
                title: '关单时间',
                dataIndex: 'repairCloseTime',
                key: 'repairCloseTime',
              },
            ]}
            type="wxgd"
          />
        );
      case 'detail_wgd':
        return (
          <Detail
            title="外协单号"
            titleno={drawer?.item.otherUnitsOrderNo}
            detailpath="/repair/umOtherUnitsOperation/queryOperationList"
            params={{ otherUnitsOrderId: drawer?.item.id }}
            baseRow={drawer?.item}
            basecolumns={[
              {
                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',
              },
            ]}
            type="wgd"
          />
        );
      case 'detail_zzgd':
        return (
          <Detail
            title="追踪单号"
            titleno={drawer?.item?.taskOrderNo}
            detailpath="/repair/umTrackOperation/queryOperationList"
            params={{ trackOrderId: drawer?.item?.id }}
            baseRow={drawer?.item}
TZW's avatar
TZW committed
400 401 402 403 404 405 406 407 408 409 410 411 412 413 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
            basecolumns={[
              {
                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',
              },
            ]}
TZW's avatar
TZW committed
442 443 444
            type="zzgd"
          />
        );
TZW's avatar
TZW committed
445 446 447 448
      default:
        break;
    }
  }
TZW's avatar
TZW committed
449 450 451 452 453 454 455
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
        pagetitle={<h3 className="page-title">接单平台</h3>}
        columns={columns}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        actionRef={actionRef}
TZW's avatar
TZW committed
456 457
        // pageextra={pathconfig?.enableadd ? 'add' : null}
        resizeable={false}
TZW's avatar
TZW committed
458 459 460 461 462
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
            onClick: () => {
wuhao's avatar
wuhao committed
463 464
              setdrawer((s) => ({
                ...s,
TZW's avatar
TZW committed
465 466 467 468
                open: true,
                item: null,
                title: '新增',
                val: 'add',
wuhao's avatar
wuhao committed
469
              }));
TZW's avatar
TZW committed
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
            },
          },
        }}
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
      />

      <DrawerPro
        fields={columns}
        detailpath={pathconfig?.detail || null}
        detailData={drawer?.item}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            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 } });
          }
        }}
TZW's avatar
TZW committed
501 502 503
      >
        {selectType(drawer?.type)}
      </DrawerPro>
TZW's avatar
TZW committed
504 505 506
    </div>
  );
}
wuhao's avatar
wuhao committed
507

TZW's avatar
TZW committed
508
export default Platform;