index.jsx 14.7 KB
Newer Older
1
import * as React from 'react';
左玲玲's avatar
左玲玲 committed
2
import { useState, useMemo, useRef } from 'react';
TZW's avatar
TZW committed
3
import { message, Popconfirm, Switch } from 'antd';
左玲玲's avatar
左玲玲 committed
4
import DrawerPro from '@/components/DrawerPro';
左玲玲's avatar
左玲玲 committed
5
import DetailPro from '@/components/DetailPro';
左玲玲's avatar
左玲玲 committed
6
import AutoTable from '@/components/AutoTable';
左玲玲's avatar
左玲玲 committed
7
import AutoTables from '@/components/AutoTable/mtable';
左玲玲's avatar
左玲玲 committed
8 9 10 11
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
import { useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
左玲玲's avatar
左玲玲 committed
12 13
import dayjs from 'dayjs';
import InitForm from '@/components/InitForm';
左玲玲's avatar
左玲玲 committed
14
function Plan(props) {
TZW's avatar
TZW committed
15
  let actionRef = useRef(),
左玲玲's avatar
左玲玲 committed
16 17
    formRef = useRef();
  const [drawer, setdrawer] = useState({
TZW's avatar
TZW committed
18 19
      open: false,
    }),
左玲玲's avatar
左玲玲 committed
20 21
    [activeTabKey, setactiveTabKey] = useState(1);

左玲玲's avatar
左玲玲 committed
22
  const { run, loading, runAsync } = useRequest(doFetch, {
左玲玲's avatar
左玲玲 committed
23 24 25 26 27 28
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
29
          open: false,
左玲玲's avatar
左玲玲 committed
30 31 32 33
        }));
      }
    },
  });
34

左玲玲's avatar
左玲玲 committed
35 36 37 38 39 40 41
  const detail = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          type: 'link',
          onClick: () => {
42 43
            setdrawer((s) => ({
              ...s,
左玲玲's avatar
左玲玲 committed
44 45 46 47 48
              open: true,
              item: row,
              title: '详情',
              val: 'detail',
              title: '详细信息',
49
            }));
左玲玲's avatar
左玲玲 committed
50 51 52 53 54 55 56
          },
        }}
      >
        详情
      </PremButton>
    );
  };
57

左玲玲's avatar
左玲玲 committed
58
  const editDate = (text, row, _, action) => {
左玲玲's avatar
左玲玲 committed
59 60 61 62 63 64 65 66 67
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
左玲玲's avatar
左玲玲 committed
68 69
              title: '调整日期',
              val: 'detailaddon',
TZW's avatar
TZW committed
70
              id: row?.id,
左玲玲's avatar
左玲玲 committed
71 72 73 74
            }));
          },
        }}
      >
左玲玲's avatar
左玲玲 committed
75
        调整日期
左玲玲's avatar
左玲玲 committed
76 77 78
      </PremButton>
    );
  };
79

左玲玲's avatar
左玲玲 committed
80 81 82 83 84 85 86
  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: '是否删除?',
          okText: '确认',
          cancelText: '取消',
左玲玲's avatar
左玲玲 committed
87 88
          onConfirm: async () => {
            await runAsync({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
左玲玲's avatar
左玲玲 committed
89 90 91 92 93 94 95 96 97 98 99
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };
左玲玲's avatar
左玲玲 committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  const close = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: '是否关单?',
          okText: '确认',
          cancelText: '取消',
          onConfirm: async () => {
            await runAsync({ url: '/check/umEquipmentCheckPlan/shut', params: { id: row?.id } });
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        关单
      </PremButton>
    );
  };
120

左玲玲's avatar
左玲玲 committed
121
  const columns = useMemo(() => {
左玲玲's avatar
左玲玲 committed
122 123
    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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 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
    return activeTabKey == 1
      ? defcolumn.concat([
          {
            title: '启用/停用',
            dataIndex: 'checkEnable',
            key: 'checkEnable',
            hideInForm: true,
            hideInSearch: true,
            valueType: 'switch',
            render: (text, row, _, action) => {
              //"1停用  2启用 *"
              return row.checkEnable == 1 ? (
                <Popconfirm
                  title="是否开启或停用?"
                  onConfirm={async () => {
                    if (row.checkEnable == 1) {
                      await runAsync({
                        url: '/check/umEquipmentCheckPlan/enable',
                        params: { id: row.id, checkEnable: 2 },
                      });
                    }
                  }}
                  okText="确定"
                  cancelText="取消"
                  disabled={!(row.status == 1 || (row.status == 2 && row.checkLoop == 2))}
                >
                  <Switch
                    checked={row.checkEnable == 1 ? true : false}
                    checkedChildren="开启"
                    unCheckedChildren="停用"
                    defaultChecked={false}
                    disabled={!(row.status == 1 || (row.status == 2 && row.checkLoop == 2))}
                  />
                </Popconfirm>
              ) : (
                <Switch
                  checked={row.checkEnable == 1 ? true : false}
                  checkedChildren="开启"
                  unCheckedChildren="停用"
                  defaultChecked={false}
                  disabled={!(row.status == 1 || (row.status == 2 && row.checkLoop == 2))}
                  onChange={(checked) => {
                    if (checked) {
                      setdrawer((s) => ({
                        ...s,
                        open: true,
                        item: row,
                        title: '启用点检计划',
                        val: 'detailaddon',
                        type: 'delay',
                        id: row?.id,
                      }));
                    }
                  }}
                />
              );
            },
            hideInDescriptions: true,
          },
          {
            title: '操作',
            valueType: 'option',
            width: 150,
            render: (text, row, _, action) => [
              (row.status == 1 || (row.status == 2 && row.checkLoop == 2)) &&
                editDate(text, row, _, action),
              row.status == 2 && close(text, row, _, action),
              defpath?.enabledelete && row.status == 1 && remove(text, row, _, action),
            ],
          },
        ])
      : defcolumn;
左玲玲's avatar
左玲玲 committed
196
  }, [activeTabKey]);
197

左玲玲's avatar
左玲玲 committed
198 199 200 201 202
  const editDateColumns = useMemo(() => {
    const disabledDate = (current) => {
      if (drawer?.item?.status == 1) {
        return current && current < dayjs().endOf('day');
      } else {
TZW's avatar
TZW committed
203 204 205 206
        if (
          dayjs(drawer?.item?.planCheckDate).endOf('day').valueOf() >=
          dayjs().endOf('day').valueOf()
        ) {
左玲玲's avatar
左玲玲 committed
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 240 241 242 243 244 245 246 247 248 249 250 251 252
          return current && current <= dayjs(drawer?.item?.planCheckDate).endOf('day');
        } else {
          return current && current < dayjs().endOf('day');
        }
      }
    };
    return [
      {
        title: '基础信息',
        valueType: 'split',
        hideInForm: true,
      },
      {
        title: '点检计划单号',
        dataIndex: 'checkNo',
        key: 'checkNo',
        hideInForm: true,
      },
      {
        title: '设备编号',
        dataIndex: 'equipmentNo',
        key: 'equipmentNo',
        hideInForm: true,
      },
      {
        title: '设备名称',
        dataIndex: 'equipmentName',
        key: 'equipmentName',
        hideInForm: true,
      },
      {
        title: '点检类型',
        dataIndex: 'checkTypeName',
        key: 'checkType',
        hideInForm: true,
      },
      {
        title: '下次点检日期',
        dataIndex: 'planCheckDate',
        key: 'planCheckDateList',
        hideInForm: true,
      },
      {
        title: '计划类型',
        dataIndex: 'checkLoopName',
        key: 'checkLoop',
TZW's avatar
TZW committed
253
        hideInForm: true,
左玲玲's avatar
左玲玲 committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
      },
      {
        title: '调整信息',
        valueType: 'split',
        hideInForm: true,
      },
      {
        title: '下次点检日期',
        dataIndex: 'planCheckDate',
        key: 'planCheckDate',
        formItemProps: {
          rules: [
            {
              required: true,
              message: '此项为必填项',
            },
          ],
        },
        fieldProps: {
          disabledDate,
        },
        valueType: 'date',
        hideInSearch: true,
TZW's avatar
TZW committed
277
        hideInDescriptions: true,
左玲玲's avatar
左玲玲 committed
278 279 280 281 282 283 284 285 286 287 288 289
      },
      {
        title: '周期(天)',
        dataIndex: 'checkCycle',
        key: 'checkCycle',
        hideInSearch: true,
        hideInDescriptions: true,
        valueType: 'digit',
        hideInForm: drawer?.item?.checkLoop == 2 ? false : true,
        precision: 0,
      },
    ];
左玲玲's avatar
左玲玲 committed
290
  }, [drawer?.item]);
左玲玲's avatar
左玲玲 committed
291

左玲玲's avatar
左玲玲 committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
  const detailsColumns = useMemo(() => {
    const columnsc = [
      {
        title: '点检项目',
        dataIndex: 'checkItem',
        key: 'checkItem',
        hideInForm: true,
      },
      {
        title: '部位',
        dataIndex: 'checkPosition',
        key: 'checkPosition',
        hideInForm: true,
      },
      {
        title: '点检方法',
        dataIndex: 'checkWay',
        key: 'checkWay',
        hideInForm: true,
      },
    ];
TZW's avatar
TZW committed
313
    if (drawer?.val == 'detail') {
左玲玲's avatar
左玲玲 committed
314 315 316 317 318 319 320 321 322 323 324 325
      return [
        {
          title: '计划信息',
          valueType: 'split',
        },
        {
          title: '点检计划单号',
          dataIndex: 'checkNo',
          key: 'checkNo',
        },
        {
          title: '创建时间',
TZW's avatar
TZW committed
326 327
          dataIndex: 'createTime',
          key: 'createTime',
左玲玲's avatar
左玲玲 committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
        },
        {
          title: '状态',
          dataIndex: 'statusName',
          key: 'statusName',
        },
        {
          title: '启用/停用',
          dataIndex: 'checkEnableName',
          key: 'checkEnableName',
        },
        {
          title: '下次点检日期',
          dataIndex: 'planCheckDate',
          key: 'planCheckDate',
TZW's avatar
TZW committed
343
          span: activeTabKey == 1 ? 2 : 1,
左玲玲's avatar
左玲玲 committed
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
        },
        {
          title: '关单日期',
          dataIndex: 'endDate',
          key: 'endDate',
          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: 'checkTypeName',
          key: 'checkTypeName',
        },
        {
          title: '计划类型',
          dataIndex: 'checkLoopName',
          key: 'checkLoopName',
        },
        {
          title: '周期(天)',
          dataIndex: 'checkCycle',
          key: 'checkCycle',
TZW's avatar
TZW committed
394
          span: activeTabKey == 1 ? 2 : 2,
左玲玲's avatar
左玲玲 committed
395 396 397 398 399 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
        },
        {
          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?.itemList}
              />
            );
          },
        },
        {
          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,
        },
TZW's avatar
TZW committed
438
      ];
左玲玲's avatar
左玲玲 committed
439 440
    }
  }, [drawer?.val, activeTabKey, drawer?.item?.id]);
左玲玲's avatar
左玲玲 committed
441 442 443 444
  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [activeTabKey]);
左玲玲's avatar
左玲玲 committed
445 446 447 448 449 450 451
  const waitTime = (time) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(true);
      }, time);
    });
  };
左玲玲's avatar
左玲玲 committed
452 453 454
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
TZW committed
455
        pagetitle={<h3 className="page-title">点检计划</h3>}
左玲玲's avatar
左玲玲 committed
456 457 458 459 460 461 462
        columns={columns}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        actionRef={actionRef}
        pageextra={pathconfig?.enableadd ? 'add' : null}
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
左玲玲's avatar
左玲玲 committed
463
            type: 'primary',
左玲玲's avatar
左玲玲 committed
464 465
            disabled: false,
            onClick: () => {
466 467
              setdrawer((s) => ({
                ...s,
左玲玲's avatar
左玲玲 committed
468 469 470 471
                open: true,
                item: null,
                title: '新增',
                val: 'add',
472
              }));
左玲玲's avatar
左玲玲 committed
473 474 475 476 477 478 479 480 481 482 483
            },
          },
        }}
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
      />

      <DrawerPro
TZW's avatar
TZW committed
484 485 486 487 488 489 490
        fields={
          drawer?.val == 'detailaddon'
            ? editDateColumns
            : drawer?.val == 'detail'
            ? detailsColumns
            : columns
        }
左玲玲's avatar
左玲玲 committed
491 492 493 494 495 496 497 498 499 500 501 502
        detailpath={pathconfig?.detail || null}
        defaultFormValue={drawer?.item}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            open: false,
          }));
        }}
        {...drawer}
左玲玲's avatar
左玲玲 committed
503 504
        onFinish={async (vals) => {
          let params = JSON.parse(JSON.stringify(vals));
TZW's avatar
TZW committed
505
          params.paramList = params?.paramList?.map((it) => {
左玲玲's avatar
左玲玲 committed
506 507
            return {
              equipmentId: it.id,
TZW's avatar
TZW committed
508 509
              checkPlanDate: it.checkPlanDate,
            };
左玲玲's avatar
左玲玲 committed
510
          });
TZW's avatar
TZW committed
511
          let flag = params.paramList?.some((it) => !it.checkPlanDate);
左玲玲's avatar
左玲玲 committed
512
          if (flag) {
TZW's avatar
TZW committed
513
            message.warning('下次点检日期必填!');
左玲玲's avatar
左玲玲 committed
514 515
            return;
          }
左玲玲's avatar
左玲玲 committed
516
          if (drawer?.val == 'add') {
左玲玲's avatar
左玲玲 committed
517
            await runAsync({ url: pathconfig?.add || '/add', params: { ...params } });
左玲玲's avatar
左玲玲 committed
518
          } else if (drawer?.val == 'edit') {
TZW's avatar
TZW committed
519 520 521 522
            await runAsync({
              url: pathconfig?.edit || '/edit',
              params: { ...params, id: drawer?.item?.id },
            });
左玲玲's avatar
左玲玲 committed
523 524
          }
        }}
左玲玲's avatar
左玲玲 committed
525 526 527 528 529
      >
        <InitForm
          fields={editDateColumns}
          defaultFormValue={{ checkCycle: drawer?.item?.checkCycle }}
          onFinish={async (vals) => {
TZW's avatar
TZW committed
530 531 532 533 534 535 536
            await runAsync({
              url:
                drawer?.type == 'delay'
                  ? '/check/umEquipmentCheckPlan/enable'
                  : '/check/umEquipmentCheckPlan/adjustDate',
              params: { ...vals, id: drawer?.item?.id, checkEnable: 1 },
            });
左玲玲's avatar
左玲玲 committed
537 538 539
          }}
        />
      </DrawerPro>
左玲玲's avatar
左玲玲 committed
540 541 542
    </div>
  );
}
543

左玲玲's avatar
左玲玲 committed
544
export default Plan;