index.jsx 17.7 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4
/* 保养计划
 * @Author: Li Hanlin
 * @Date: 2023-01-16 15:35:00
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
5
 * @Last Modified time: 2023-02-16 17:45:48
TZW's avatar
TZW committed
6 7
 */

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

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

TZW's avatar
TZW committed
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 editDateColumns = useMemo(() => {
    const disabledDateOfDay = (current) => {
      // Can not select days before today and today
      return current && current < dayjs().endOf('day');
    };
    const disabledDateOfMonth = (current) => {
      // Can not select days before today and today
      return current && current < dayjs().startOf('month');
    };
    const disabledDate = (current) => {
      if (drawer?.item?.status == 1) {
        return current && current < dayjs().endOf('day');
      } else {
        if (
          dayjs(drawer?.item?.planCheckDate).endOf('day').valueOf() >=
          dayjs().endOf('day').valueOf()
        ) {
          return current && current <= dayjs(drawer?.item?.planCheckDate).endOf('day');
        } else {
          return current && current < dayjs().endOf('day');
        }
      }
    };
    return [
TZW's avatar
TZW committed
65 66 67 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
      {
        title: '计划信息',
        valueType: 'split',
        hideInForm: true,
      },
      {
        title: '保养计划单号',
        dataIndex: 'maintainNo',
        key: 'maintainNo',
        hideInForm: true,
      },
      {
        title: '设备编号',
        dataIndex: 'equipmentNo',
        key: 'equipmentNo',
        hideInForm: true,
      },
      {
        title: '设备名称',
        dataIndex: 'equipmentName',
        key: 'equipmentName',
        hideInForm: true,
      },
      {
        title: '保养类型',
        dataIndex: 'maintainTypeName',
        key: 'maintainTypeName',
        hideInForm: true,
      },
      {
        title: '下次保养日期',
        dataIndex: 'nextMaintainDate',
        key: 'nextMaintainDate',
        hideInForm: true,
      },
      {
        title: '调整信息',
        valueType: 'split',
        hideInForm: true,
      },
TZW's avatar
TZW committed
105 106
      {
        title: '保养频次',
TZW's avatar
TZW committed
107
        hideInDescriptions: true,
TZW's avatar
TZW committed
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
        dataIndex: 'maintainFrequencyName',
        key: 'maintainFrequency',
        fieldProps: {
          disabled: true,
        },
        formItemProps: {
          rules: [
            {
              required: true,
              message: '此项为必填项',
            },
          ],
        },
        valueType: 'select',
        mode: 'radio',
        options: [
          {
            label: '周',
            value: 0,
          },
          {
            label: '月度',
            value: 1,
          },
          {
            label: '季度',
            value: 2,
          },
          {
            label: '半年',
            value: 3,
          },
          {
TZW's avatar
TZW committed
141
            label: '年度',
TZW's avatar
TZW committed
142 143 144 145 146 147 148
            value: 4,
          },
        ],
      },
      {
        title: '计划类型',
        dataIndex: 'isCycle',
TZW's avatar
TZW committed
149
        hideInDescriptions: true,
TZW's avatar
TZW committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 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
        key: 'isCycle',
        fieldProps: {
          disabled: true,
        },
        valueType: 'select',
        mode: 'radio',
        options: [
          {
            label: '单次',
            value: 1,
          },
          {
            label: '周期',
            value: 2,
          },
        ],
      },
      {
        title: '下次保养日期',
        dataIndex: 'nextMaintainDate',
        key: 'nextMaintainDate',
        formItemProps: {
          rules: [
            {
              required: true,
              message: '此项为必填项',
            },
          ],
        },
        fieldProps: {
          disabledDate: disabledDateOfDay,
        },
        valueType: 'date',
        hideInSearch: true,
        hideInDescriptions: true,
        hideInForm: {
          maintainFrequency: {
            reverse: [0],
          },
        },
      },
      {
        title: '下次保养日期',
        dataIndex: 'nextMaintainDate',
        key: 'nextMaintainDate',
        formItemProps: {
          rules: [
            {
              required: true,
              message: '此项为必填项',
            },
          ],
        },
        fieldProps: {
          disabledDate: disabledDateOfMonth,
        },
        valueType: 'dateMonth',
        hideInForm: {
          maintainFrequency: [0],
        },
        hideInSearch: true,
        hideInDescriptions: true,
      },
    ];
  }, [drawer?.item]);

TZW's avatar
TZW committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
  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
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 270 271 272
  const detailsColumns = useMemo(() => {
    const columnsc = [
      {
        title: '保养项目',
        dataIndex: 'maintainItemName',
        key: 'maintainItemName',
        hideInForm: true,
      },
      {
        title: '部位',
        dataIndex: 'maintainPosition',
        key: 'maintainPosition',
        hideInForm: true,
      },
      {
        title: '保养方法',
        dataIndex: 'maintainWay',
        key: 'maintainWay',
        hideInForm: true,
      },
    ];
    if (drawer?.val == 'detail') {
      return [
        {
          title: '计划信息',
          valueType: 'split',
        },
        {
          title: '保养计划单号',
          dataIndex: 'maintainNo',
          key: 'maintainNo',
        },
        {
          title: '创建时间',
TZW's avatar
TZW committed
273 274
          dataIndex: 'createTime',
          key: 'createTime',
TZW's avatar
TZW committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
        },
        {
          title: '状态',
          dataIndex: 'maintainStatus',
          key: 'maintainStatus',
          render: (_, row) => {
            return row?.maintainStatus == 1 ? '未开始' : '执行中';
          },
        },
        {
          title: '启用/停用',
          dataIndex: 'isStopStatusName',
          key: 'isStopStatusName',
        },
        {
          title: '下次保养日期',
          dataIndex: 'nextMaintainDate',
          key: 'nextMaintainDate',
          span: activeTabKey == 1 ? 2 : 1,
        },
        {
          title: '关单日期',
TZW's avatar
TZW committed
297 298
          dataIndex: 'customsTime',
          key: 'customsTime',
TZW's avatar
TZW committed
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 330 331 332 333 334
          hideInDescriptions: activeTabKey == 1 ? true : false,
        },
        {
          title: '基本信息',
          valueType: 'split',
        },
        {
          title: '设备编号',
          dataIndex: 'equipmentNo',
          key: 'equipmentNo',
        },
        {
          title: '设备名称',
          dataIndex: 'equipmentName',
          key: 'equipmentName',
        },
        {
          title: '设备型号',
          dataIndex: 'equipmentModelName',
          key: 'equipmentModelName',
        },
        {
          title: '工厂名称',
          dataIndex: 'factoryName',
          key: 'factoryName',
        },
        {
          title: '车间名称',
          dataIndex: 'shopName',
          key: 'shopName',
        },
        {
          title: '保养类型',
          dataIndex: 'maintainTypeName',
          key: 'maintainTypeName',
        },
TZW's avatar
TZW committed
335 336 337 338 339
        {
          title: '保养频次',
          dataIndex: 'maintainFrequencyName',
          key: 'maintainFrequencyName',
        },
TZW's avatar
TZW committed
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
        {
          title: '计划类型',
          dataIndex: 'isCycle',
          key: 'isCycle',
          span: activeTabKey == 1 ? 3 : 3,
          render: (_, row) => {
            return row?.isCycle == 1 ? '单次' : '周期';
          },
        },
        {
          title: '保养项目',
          valueType: 'split',
        },
        {
          dataIndex: 'itemList',
          key: 'itemList',
          valueType: 'formList',
          colProps: {
            span: 24,
          },
          columns,
          span: 24,
          render: (text, row) => {
            return (
              <AutoTables
                columns={columnsc?.map((it) => ({
                  ...it,
                  hideInSearch: true,
                }))}
                dataSource={row?.maintainItemList}
              />
            );
          },
        },
        {
          title: '关单信息',
          valueType: 'split',
          hideInDescriptions: drawer?.item?.status != 3 ? true : false,
        },
        {
          title: '关单人员',
          dataIndex: 'shutUserName',
          key: 'shutUserName',
          hideInDescriptions: drawer?.item?.status != 3 ? true : false,
        },
        {
          title: '强制关单时间',
          dataIndex: 'shutTime',
          key: 'shutTime',
          hideInDescriptions: drawer?.item?.status != 3 ? true : false,
        },
      ];
    }
  }, [drawer?.val, activeTabKey, drawer?.item?.id]);

TZW's avatar
TZW committed
395
  const close = (text, row, _, action) => {
TZW's avatar
TZW committed
396 397
    return (
      <PremButton
TZW's avatar
TZW committed
398 399 400 401 402
        pop={{
          title: '是否关单?',
          okText: '确认',
          cancelText: '取消',
          onConfirm: async () => {
TZW's avatar
TZW committed
403 404 405 406
            await runAsync({
              url: '/maintain/umMaintainPlan/customsDeclaration',
              params: { id: row?.id },
            });
TZW's avatar
TZW committed
407 408
          },
        }}
TZW's avatar
TZW committed
409 410
        btn={{
          size: 'small',
TZW's avatar
TZW committed
411
          type: 'danger',
TZW's avatar
TZW committed
412 413
        }}
      >
TZW's avatar
TZW committed
414
        关单
TZW's avatar
TZW committed
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
      </PremButton>
    );
  };

  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
440 441 442 443 444 445 446 447 448 449 450 451 452
  const editDate = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
              title: '调整日期',
              val: 'detailaddon',
              id: row?.id,
TZW's avatar
TZW committed
453
              from: 'tz',
TZW's avatar
TZW committed
454 455 456 457 458 459 460 461 462
            }));
          },
        }}
      >
        调整日期
      </PremButton>
    );
  };

TZW's avatar
TZW committed
463 464 465
  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.columns;
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
TZW's avatar
TZW committed
466 467
    return activeTabKey == 1
      ? defcolumn.concat([
TZW's avatar
TZW committed
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
          {
            title: '启用/停用',
            dataIndex: 'isStopStatus',
            key: 'isStopStatus',
            hideInForm: true,
            hideInSearch: true,
            valueType: 'switch',
            render: (text, row, _, action) => {
              //"1停用  2启用 *"
              return row.isStopStatus == 1 ? (
                <Popconfirm
                  title="是否开启或停用?"
                  onConfirm={async () => {
                    if (row.isStopStatus == 1) {
                      await runAsync({
                        url: '/maintain/umMaintainPlan/enableDeactivate',
                        params: { id: row.id, isStopFlag: 2 },
                      });
                    }
                  }}
                  okText="确定"
                  cancelText="取消"
                  disabled={
                    !(row.maintainStatus == 1 || (row.maintainStatus == 2 && row.isCycle == 2))
TZW's avatar
TZW committed
492
                  }
TZW's avatar
TZW committed
493 494 495 496 497 498 499 500 501 502 503 504
                >
                  <Switch
                    checked={row.isStopStatus == 1 ? true : false}
                    checkedChildren="开启"
                    unCheckedChildren="停用"
                    defaultChecked={false}
                    disabled={
                      !(row.maintainStatus == 1 || (row.maintainStatus == 2 && row.isCycle == 2))
                    }
                  />
                </Popconfirm>
              ) : (
TZW's avatar
TZW committed
505 506 507 508 509 510 511 512
                <Switch
                  checked={row.isStopStatus == 1 ? true : false}
                  checkedChildren="开启"
                  unCheckedChildren="停用"
                  defaultChecked={false}
                  disabled={
                    !(row.maintainStatus == 1 || (row.maintainStatus == 2 && row.isCycle == 2))
                  }
TZW's avatar
TZW committed
513 514 515 516 517 518
                  onChange={(checked) => {
                    if (checked) {
                      setdrawer((s) => ({
                        ...s,
                        open: true,
                        item: row,
TZW's avatar
TZW committed
519
                        title: '启用保养计划',
TZW's avatar
TZW committed
520 521 522 523 524 525
                        val: 'detailaddon',
                        id: row?.id,
                        from: 'tq',
                      }));
                    }
                  }}
TZW's avatar
TZW committed
526
                />
TZW's avatar
TZW committed
527 528 529
              );
            },
            hideInDescriptions: true,
TZW's avatar
TZW committed
530
          },
TZW's avatar
TZW committed
531 532 533 534 535 536 537 538 539 540 541 542
          {
            title: '操作',
            valueType: 'option',
            width: 150,
            render: (text, row, _, action) => [
              (row.maintainStatus == 1 || (row.maintainStatus == 2 && row.isCycle == 2)) &&
                editDate(text, row, _, action),
              row.maintainStatus == 2 && close(text, row, _, action),
              defpath?.enabledelete && row.maintainStatus == 1 && remove(text, row, _, action),
            ],
          },
        ])
TZW's avatar
TZW committed
543
      : defcolumn;
TZW's avatar
TZW committed
544
  }, [activeTabKey]);
TZW's avatar
TZW committed
545

TZW's avatar
TZW committed
546 547 548 549
  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [activeTabKey]);
TZW's avatar
TZW committed
550

TZW's avatar
TZW committed
551 552 553 554 555 556 557 558 559 560 561 562 563
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
        pagetitle={<h3 className="page-title">保养计划</h3>}
        columns={columns}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        actionRef={actionRef}
        pageextra={pathconfig?.enableadd ? 'add' : null}
        resizeable={false}
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
TZW's avatar
TZW committed
564
            type: 'primary',
TZW's avatar
TZW committed
565 566 567 568
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
TZW's avatar
TZW committed
569 570 571
                item: null,
                title: '新增',
                val: 'add',
TZW's avatar
TZW committed
572 573
              }));
            },
TZW's avatar
TZW committed
574 575 576 577 578 579 580 581
          },
        }}
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
      />
TZW's avatar
TZW committed
582

TZW's avatar
TZW committed
583
      <DrawerPro
TZW's avatar
TZW committed
584 585 586 587
        fields={
          drawer?.val == 'detailaddon'
            ? editDateColumns
            : drawer?.val == 'detail'
TZW's avatar
TZW committed
588 589
            ? detailsColumns
            : columns
TZW's avatar
TZW committed
590
        }
TZW's avatar
TZW committed
591
        detailpath={pathconfig?.detail || null}
TZW's avatar
TZW committed
592 593 594 595 596 597 598
        onValuesChange={(changedValues, allValues) => {
          if (Object.keys(changedValues)[0] == 'maintainFrequency') {
            formRef?.current?.setFieldsValue({
              paramList: [],
            });
          }
        }}
TZW's avatar
TZW committed
599
        // detailData={drawer?.item}
TZW's avatar
TZW committed
600 601 602 603 604 605 606 607 608 609 610
        defaultFormValue={drawer?.item}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            open: false,
          }));
        }}
        {...drawer}
TZW's avatar
TZW committed
611
        onFinish={async (vals) => {
TZW's avatar
TZW committed
612 613 614 615 616
          let flag = vals.paramList?.some((it) => !it.nextMaintainDate);
          if (flag) {
            message.warning('下次保养日期必填!');
            return;
          }
TZW's avatar
TZW committed
617 618 619 620 621 622 623 624
          let params = JSON.parse(JSON.stringify(vals));
          params.equipmentList = vals?.paramList?.map((it) => {
            return {
              id: it.id,
              nextMaintainDate: it.nextMaintainDate,
            };
          });
          delete params.paramList;
TZW's avatar
TZW committed
625

TZW's avatar
TZW committed
626
          if (drawer?.val == 'add') {
TZW's avatar
TZW committed
627
            await runAsync({ url: pathconfig?.add || '/add', params: { ...params } });
TZW's avatar
TZW committed
628
          } else if (drawer?.val == 'edit') {
TZW's avatar
TZW committed
629 630 631 632
            await runAsync({
              url: pathconfig?.edit || '/edit',
              params: { ...params, id: drawer?.item?.id },
            });
TZW's avatar
TZW committed
633 634
          }
        }}
TZW's avatar
TZW committed
635 636 637 638 639 640 641 642 643 644
      >
        <InitForm
          fields={editDateColumns}
          defaultFormValue={{
            isCycle: drawer?.item?.isCycle,
            maintainFrequency: drawer?.item?.maintainFrequency,
          }}
          onFinish={async (vals) => {
            delete vals.isCycle;
            delete vals.maintainFrequency;
TZW's avatar
TZW committed
645 646
            if (drawer?.from == 'tq') {
              vals.isStopFlag = 1;
TZW's avatar
TZW committed
647 648 649 650 651 652 653 654 655
              await runAsync({
                url: '/maintain/umMaintainPlan/enableDeactivate',
                params: { ...vals, id: drawer?.item?.id },
              });
            } else {
              await runAsync({
                url: '/maintain/umMaintainPlan/adjustDate',
                params: { ...vals, id: drawer?.item?.id },
              });
TZW's avatar
TZW committed
656
            }
TZW's avatar
TZW committed
657 658 659
          }}
        />
      </DrawerPro>
TZW's avatar
TZW committed
660 661 662
    </div>
  );
}
TZW's avatar
TZW committed
663

TZW's avatar
TZW committed
664
export default Plan;