index.jsx 13.2 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:35:09
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';
wuhao's avatar
wuhao committed
19

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

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

TZW's avatar
TZW committed
65 66
  // 完成外协
  const CompleteOuts = () => {
wuhao's avatar
wuhao committed
67
    return (
TZW's avatar
TZW committed
68 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
      <>
        <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
145
              dataIndex: 'newRepairUserName',
TZW's avatar
TZW committed
146
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
TZW's avatar
TZW committed
147 148
              fieldProps: { disabled: true },
              key: 'newRepairUserName',
TZW's avatar
TZW committed
149 150 151 152 153 154 155 156 157
            },
            {
              title: '外协人员',
              dataIndex: 'otherUnitsAssistList',
              formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
              key: 'otherUnitsAssistList',
              valueType: 'select',
              options: {
                path: '/repair/umOtherUnitsOrder/selectionAgain',
TZW's avatar
TZW committed
158
                params: { id: drawer?.item.id },
TZW's avatar
TZW committed
159 160 161 162 163
              },
            },
          ]}
          onFinish={async (vals) => {
            let params = {
TZW's avatar
TZW committed
164
              otherUnitsAssistList: vals?.otherUnitsAssistList.map((it) => ({ assistUserId: it })),
TZW's avatar
TZW committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
              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
182 183 184
    );
  };

TZW's avatar
TZW committed
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
  // 外协派单
  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
224 225 226 227
  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
TZW's avatar
TZW committed
228
          title: '是否删除?',
wuhao's avatar
wuhao committed
229 230 231
          okText: '确认',
          cancelText: '取消',
          onConfirm: () => {
TZW's avatar
TZW committed
232
            run({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
wuhao's avatar
wuhao committed
233 234 235 236 237 238 239 240 241 242 243 244
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };

TZW's avatar
TZW committed
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 270 271 272 273 274 275 276
  // 更多
  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({
                      url: '/repair/umOtherUnitsOrder/orderReceiving',
                      params,
                    });
                    if (res.code === '0000') {
                      message.success('接单成功!');
                      setdrawer((s) => ({
                        ...s,
                        open: false,
                      }));
                      actionRef.current.reload();
                    }
                  }}
                >
                  接单
                </a>
              ) : (
                <a
                  onClick={async () => {
TZW's avatar
TZW committed
277 278 279 280 281 282 283 284
                    setdrawer((s) => ({
                      ...s,
                      open: true,
                      type: 'wxpd',
                      item: row,
                      val: 'only',
                      title: '派单',
                    }));
TZW's avatar
TZW committed
285 286 287 288 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
                  }}
                >
                  派单
                </a>
              ),
            key: '0',
            // disabled: true,
          },
          {
            label: (
              <a
                onClick={() => {
                  setdrawer((s) => ({
                    ...s,
                    open: true,
                    type: 'comouts',
                    item: {
                      id: row.id,
                    },
                    val: 'only',
                    title: '完成外协',
                  }));
                }}
              >
                完成外协
              </a>
            ),
            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
330
    if (row?.status == 1 || row?.status == 2) {
TZW's avatar
TZW committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
      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
349
    } else {
TZW's avatar
TZW committed
350 351 352 353
      return (
        <PremButton
          btn={{
            size: 'small',
TZW's avatar
TZW committed
354 355 356 357 358 359 360 361 362 363 364 365
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                item: {
                  ...row,
                  trackAssistList: row?.trackAssistList ? row?.trackAssistList : [],
                },
                title: '重新指派',
                type: 'Reassig',
                open: true,
              }));
            },
TZW's avatar
TZW committed
366 367 368 369 370 371 372 373
          }}
        >
          重新指派
        </PremButton>
      );
    }
  };

wuhao's avatar
wuhao committed
374
  const columns = useMemo(() => {
TZW's avatar
TZW committed
375
    let defcolumn = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.columns;
TZW's avatar
TZW committed
376
    //console.log(defcolumn);
TZW's avatar
TZW committed
377
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
TZW's avatar
TZW committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399

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

TZW's avatar
TZW committed
402 403 404 405 406 407 408 409
  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [activeTabKey]);

  const selectType = (type) => {
    switch (type) {
      case 'add':
TZW's avatar
TZW committed
410 411 412 413 414 415 416
        return (
          <Addform
            url={'/repair/umOtherUnitsOrder/save'}
            setdrawer={setdrawer}
            actionRef={actionRef}
          />
        );
TZW's avatar
TZW committed
417 418 419 420
      case 'comouts':
        return <CompleteOuts />;
      case 'Reassig':
        return <Reassig />;
TZW's avatar
TZW committed
421 422
      case 'wxpd':
        return <Wxpd />;
TZW's avatar
TZW committed
423 424 425 426
      default:
        break;
    }
  };
wuhao's avatar
wuhao committed
427
  return (
TZW's avatar
TZW committed
428
    <div style={{ position: 'relative' }} ref={containderef}>
wuhao's avatar
wuhao committed
429
      <AutoTable
TZW's avatar
TZW committed
430
        pagetitle={<h3 className="page-title">外协工单</h3>}
wuhao's avatar
wuhao committed
431
        columns={columns}
TZW's avatar
TZW committed
432
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
wuhao's avatar
wuhao committed
433
        actionRef={actionRef}
TZW's avatar
TZW committed
434
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
435
        resizeable={false}
wuhao's avatar
wuhao committed
436 437 438 439
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
TZW's avatar
TZW committed
440
            type: 'primary',
wuhao's avatar
wuhao committed
441 442 443
            onClick: () => {
              setdrawer((s) => ({
                ...s,
TZW's avatar
TZW committed
444
                open: true,
TZW's avatar
TZW committed
445 446 447 448
                item: {
                  isShutdown: 1,
                },
                title: '新建外协工单',
TZW's avatar
TZW committed
449 450
                val: 'only',
                type: 'add',
wuhao's avatar
wuhao committed
451 452 453 454
              }));
            },
          },
        }}
TZW's avatar
TZW committed
455 456 457 458 459
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
wuhao's avatar
wuhao committed
460 461 462 463
      />

      <DrawerPro
        fields={columns}
TZW's avatar
TZW committed
464 465 466
        detailpath={pathconfig?.detail || null}
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
wuhao's avatar
wuhao committed
467 468 469 470 471 472
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        onClose={() => {
          setdrawer((s) => ({
            ...s,
TZW's avatar
TZW committed
473

TZW's avatar
TZW committed
474
            open: false,
wuhao's avatar
wuhao committed
475 476 477
          }));
        }}
        {...drawer}
TZW's avatar
TZW committed
478 479 480 481 482 483 484 485 486 487
        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
488 489 490 491
    </div>
  );
}

TZW's avatar
TZW committed
492
export default Failure;