index.jsx 7.23 KB
Newer Older
1
import * as React from 'react';
左玲玲's avatar
左玲玲 committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import { useState, useMemo, useRef } from 'react';
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import AutoTables from '@/components/AutoTable/mtable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
import { useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
function Order(props) {
  const actionRef = useRef(),
    formRef = useRef();
  const [drawer, setdrawer] = useState({
    open: false,
  });
  const pathconfig = useMemo(() => {
    let pathconf = getcolumns(setdrawer)?.pathconfig ?? {};
    return pathconf;
  }, []);
  const { run, loading, runAsync } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    },
  });
32

左玲玲's avatar
左玲玲 committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 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 146
  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>
    );
  };

  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
              title: '编辑',
              val: 'edit',
            }));
          },
        }}
      >
        编辑
      </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>
    );
  };
  const order = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: '是否接单?',
          okText: '确认',
          cancelText: '取消',
          onConfirm: async () => {
            await runAsync({ url: '/check/umEquipmentCheckTask/meet', params: { id: row?.id } });
          },
        }}
        btn={{
          size: 'small',
        }}
      >
        接单
      </PremButton>
    );
  };
  const close = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: '是否关单?',
          okText: '确认',
          cancelText: '取消',
          onConfirm: async () => {
            await runAsync({ url: '/check/umEquipmentCheckTask/shut', params: { id: row?.id } });
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        关单
      </PremButton>
    );
  };

  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer)?.columns;
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 120,
      render: (text, row, _, action) => [
        order(text, row, _, action),
        close(text, row, _, action)
      ],
147
    });
左玲玲's avatar
左玲玲 committed
148
  }, []);
149

左玲玲's avatar
左玲玲 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 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
  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,
      },
    ];
    if (drawer?.val == "detail") {
      return [
        {
          title: '计划信息',
          valueType: 'split',
        },
        {
          title: '点检单号',
          dataIndex: 'taskNo',
          key: 'taskNo',
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          key: 'createTime',
        },
        {
          title: '工单状态',
          dataIndex: 'statusName',
          key: 'statusName',
        },
        {
          title: '点检计划单号',
          dataIndex: 'planNo',
          key: 'planNo',
        },
        {
          title: '基本信息',
          valueType: 'split',
        },
        {
          title: '设备编号',
          dataIndex: 'equipmentNo',
          key: 'equipmentNo',
        },
        {
          title: '设备名称',
          dataIndex: 'equipmentName',
          key: 'equipmentName',
        },
        {
          title: '设备型号',
          dataIndex: 'equipmentModelName',
          key: 'equipmentModelName',
        },
        {
          title: '点检类型',
          dataIndex: 'checkTypeName',
          key: 'checkTypeName',
        },
        {
          title: '点检截止日期',
          dataIndex: 'checkCloseDate',
          key: 'checkCloseDate',
          span: 2
        },
        {
          title: '点检项目',
          dataIndex: 'item',
          key: 'item',
          valueType: 'formList',
          colProps: {
            span: 24,
          },
          columns,
          span: 3,
          render: (text, row) => {
            return (
              <AutoTables
                columns={columnsc?.map((it) => ({
                  ...it,
                  hideInSearch: true,
                }))}
                dataSource={row?.item}
              />
            );
          },
        }
      ]
    }
  }, [drawer?.val, drawer?.item?.id]);
252

左玲玲's avatar
左玲玲 committed
253 254 255 256 257 258 259 260 261 262 263 264 265
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
        pagetitle="点检接单"
        columns={columns}
        actionRef={actionRef}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        pageextra={pathconfig?.enableadd ? 'add' : null}
        resizeable={false}
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
266 267 268 269
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
左玲玲's avatar
左玲玲 committed
270 271 272
                item: null,
                title: '新增',
                val: 'add',
273 274
              }));
            },
左玲玲's avatar
左玲玲 committed
275 276 277
          },
        }}
      />
278

左玲玲's avatar
左玲玲 committed
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
      <DrawerPro
        fields={drawer.val == "detail" ? detailsColumns : columns}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        detailpath={pathconfig?.detail || null}
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
        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 } });
          }
        }}
      />
    </div>
  );
}
305

左玲玲's avatar
左玲玲 committed
306
export default Order;