index.jsx 11.3 KB
Newer Older
TZW's avatar
TZW committed
1
/* 维修工单
TZW's avatar
TZW committed
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 17:52: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';
wuhao's avatar
wuhao committed
14 15
import { useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
TZW's avatar
TZW committed
16
import { Dropdown, Menu, Button } from 'antd';
TZW's avatar
TZW committed
17
import InitForm from '@/components/InitForm';
wuhao's avatar
wuhao committed
18

TZW's avatar
TZW committed
19
function Failure(props) {
wuhao's avatar
wuhao committed
20 21 22
  const actionRef = useRef(),
    formRef = useRef();
  const [drawer, setdrawer] = useState({
TZW's avatar
TZW committed
23 24 25
      open: false,
    }),
    [activeTabKey, setactiveTabKey] = useState('1');
wuhao's avatar
wuhao committed
26 27 28 29 30 31 32 33 34 35 36 37

  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
38 39 40 41 42 43 44 45 46 47 48
  });

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

  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
wuhao's avatar
wuhao committed
71
              open: true,
wuhao's avatar
wuhao committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
              item: row,
              title: '编辑',
              val: 'edit',
            }));
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
wuhao's avatar
wuhao committed
88
          title: '是否删除?',
wuhao's avatar
wuhao committed
89 90 91
          okText: '确认',
          cancelText: '取消',
          onConfirm: () => {
wuhao's avatar
wuhao committed
92
            run({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
wuhao's avatar
wuhao committed
93 94 95 96 97 98 99 100 101 102 103 104
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };

TZW's avatar
TZW committed
105
  // 更多
TZW's avatar
TZW committed
106 107 108 109 110 111 112 113
  const more = (text, row, _, action) => {
    const menu = (
      <Menu
        items={[
          {
            label: (
              <a
                onClick={() => {
TZW's avatar
TZW committed
114
                  setdrawer((s) => ({
TZW's avatar
TZW committed
115
                    ...s,
TZW's avatar
TZW committed
116
                    open: true,
TZW's avatar
TZW committed
117 118 119 120 121 122 123
                    type: 'editChildEquipment',
                    item: {
                      id: row.id,
                    },
                    val: 'only',
                    title: '编辑子设备',
                    // onFinish: async (vals) => {
TZW's avatar
TZW committed
124
                    //   //console.log(1);
TZW's avatar
TZW committed
125 126 127 128 129 130 131 132 133 134
                    //   let params = {
                    //     ...vals,
                    //     id: row.id,
                    //   };
                    //   let res = await doFetch({
                    //     url: urlParams.save,
                    //     params,
                    //   });
                    //   if (res.code === '0000') {
                    //     message.success('新增成功!');
TZW's avatar
TZW committed
135
                    //     setdrawer((s) => ({
TZW's avatar
TZW committed
136
                    //       ...s,
TZW's avatar
TZW committed
137
                    //       open: false,
TZW's avatar
TZW committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
                    //     }));
                    //     actionRef.current.reload();
                    //   }
                    // },
                  }));
                }}
              >
                接单/派单
              </a>
            ),
            key: '0',
          },
          {
            label: (
              <a
                onClick={() => {
TZW's avatar
TZW committed
154
                  setdrawer((s) => ({
TZW's avatar
TZW committed
155
                    ...s,
TZW's avatar
TZW committed
156 157
                    open: true,
                    type: 'wcwx',
TZW's avatar
TZW committed
158 159 160 161
                    item: {
                      id: row.id,
                    },
                    val: 'only',
TZW's avatar
TZW committed
162
                    title: '完成维修',
TZW's avatar
TZW committed
163
                    // onFinish: async (vals) => {
TZW's avatar
TZW committed
164
                    //   //console.log(1);
TZW's avatar
TZW committed
165 166 167 168 169 170 171 172 173 174
                    //   let params = {
                    //     ...vals,
                    //     id: row.id,
                    //   };
                    //   let res = await doFetch({
                    //     url: urlParams.save,
                    //     params,
                    //   });
                    //   if (res.code === '0000') {
                    //     message.success('新增成功!');
TZW's avatar
TZW committed
175
                    //     setdrawer((s) => ({
TZW's avatar
TZW committed
176
                    //       ...s,
TZW's avatar
TZW committed
177
                    //       open: false,
TZW's avatar
TZW committed
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
                    //     }));
                    //     actionRef.current.reload();
                    //   }
                    // },
                  }));
                }}
              >
                完成维修
              </a>
            ),
            key: '1',
          },
          {
            label: <a>转追踪</a>,
            key: '2',
          },
          {
            label: <a>转外协</a>,
            key: '3',
          },
          {
            label: <a>转单</a>,
            key: '4',
          },
          {
            label: <a>退单</a>,
            key: '5',
          },
          {
            label: <a>效果验证</a>,
            key: '6',
          },
          {
            label: <a>追踪审核</a>,
            key: '7',
          },
          {
            label: <a>外协审核</a>,
            key: '8',
          },
          {
            label: <a>退单审核</a>,
            key: '9',
          },
        ]}
      />
    );
    return (
      <Dropdown
        overlay={menu}
        trigger={['click']}
        arrow={true}
        getPopupContainer={() => containderef.current}
      >
        <Button size="small">更多</Button>
      </Dropdown>
    );
  };

TZW's avatar
TZW committed
237 238 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 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 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
  // ++++++下拉菜单+++++++
  // 接单
  const Recevive = () => {};
  // 完成维修
  const Finishrepair = () => {
    const columns = [
      {
        title: '故障类型',
        dataIndex: 'faultSettingId',
        key: 'faultSettingId',
        valueType: 'select',
        options: {
          path: '/repair/umFaultSetting/selected/queryList',
          params: {
            equipmentId: drawer?.item.id,
          },
        },
      },
      {
        title: '故障名称',
        dataIndex: 'faultDetailId',
        key: 'faultDetailId',
        valueType: 'select',
        options: {
          path: '/repair/umFaultSettingDetail/selected/queryList',
          linkParams: {
            faultSettingId: '',
          },
        },
      },
      {
        title: '故障原因',
        dataIndex: 'faultDescription',
        key: 'faultDescription',
        valueType: 'textarea',
        formItemProps: {
          rules: [
            {
              required: true,
              message: '此项为必填项',
            },
          ],
        },
      },
      {
        title: '开始维修时间',
        dataIndex: 'equipmentId',
        key: 'equipmentId',
        fieldProps: {
          disabled: true,
        },
      },
      {
        title: '维修类型',
        dataIndex: 'equipmentId',
        key: 'equipmentId',
        valueType: 'select',
        options: { path: '/asset/equipment/selection/user/shop', params: {} },
        formItemProps: {
          rules: [
            {
              required: true,
              message: '此项为必填项',
            },
          ],
        },
      },
      {
        title: '是否停机维修',
        dataIndex: 'isShutdown',
        key: 'isShutdown',
        valueType: 'radio',
        options: [
          {
            value: 1,
            label: '是',
          },
          {
            value: 2,
            label: '否',
          },
        ],
        formItemProps: {
          rules: [
            {
              required: true,
              message: '此项为必填项',
            },
          ],
        },
      },
      {
        title: '维修内容',
        dataIndex: 'repairContent',
        key: 'repairContent',
        valueType: 'textarea',
        formItemProps: {
          rules: [
            {
              required: true,
              message: '此项为必填项',
            },
          ],
        },
      },
      {
        title: '协助维修人员',
        dataIndex: 'repairAssistList',
        key: 'repairAssistList',
        valueType: 'select',
        options: { path: '/repair/umRepairOrder/selection', params: { id: drawer?.item.id } },
        fieldProps: {
          placeholder: '请选择',
          showSearch: true,
          mode: 'multiple',
        },
      },
    ];
    return (
      <>
        <InitForm
          fields={columns}
          onFinish={(vals) => {
            console.log(vals);
          }}
          {...drawer}
        />
      </>
    );
  };

  const selectType = {
    jd: <Recevive />,
    wcwx: <Finishrepair />,
  };

wuhao's avatar
wuhao committed
373
  const columns = useMemo(() => {
TZW's avatar
TZW committed
374 375
    let defcolumn = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.columns;
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
wuhao's avatar
wuhao committed
376 377 378 379
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 150,
TZW's avatar
TZW committed
380
      render: (text, row, _, action) => [more(text, row, _, action)],
wuhao's avatar
wuhao committed
381
    });
TZW's avatar
TZW committed
382 383 384 385 386 387
  }, [activeTabKey]);

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

TZW's avatar
TZW committed
389
  const containderef = useRef();
wuhao's avatar
wuhao committed
390
  return (
TZW's avatar
TZW committed
391
    <div style={{ position: 'relative' }} ref={containderef}>
wuhao's avatar
wuhao committed
392
      <AutoTable
TZW's avatar
TZW committed
393
        pagetitle={<h3 className="page-title">维修工单</h3>}
wuhao's avatar
wuhao committed
394
        columns={columns}
wuhao's avatar
wuhao committed
395
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
TZW's avatar
TZW committed
396
        actionRef={actionRef}
wuhao's avatar
wuhao committed
397
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
398
        resizeable={false}
wuhao's avatar
wuhao committed
399 400 401 402
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
TZW's avatar
TZW committed
403
            type: 'primary',
wuhao's avatar
wuhao committed
404 405 406
            onClick: () => {
              setdrawer((s) => ({
                ...s,
wuhao's avatar
wuhao committed
407
                open: true,
wuhao's avatar
wuhao committed
408 409
                item: null,
                title: '新增',
TZW's avatar
TZW committed
410 411
                val: 'only',
                type: 'add',
wuhao's avatar
wuhao committed
412 413 414 415
              }));
            },
          },
        }}
TZW's avatar
TZW committed
416 417 418 419 420
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
wuhao's avatar
wuhao committed
421 422 423 424
      />

      <DrawerPro
        fields={columns}
wuhao's avatar
wuhao committed
425 426 427
        detailpath={pathconfig?.detail || null}
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
428 429 430
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
wuhao's avatar
wuhao committed
431 432 433
        onClose={() => {
          setdrawer((s) => ({
            ...s,
wuhao's avatar
wuhao committed
434
            open: false,
wuhao's avatar
wuhao committed
435 436 437
          }));
        }}
        {...drawer}
wuhao's avatar
wuhao committed
438 439 440 441 442 443 444
        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
445
      >
TZW's avatar
TZW committed
446
        {selectType[drawer?.type]}
TZW's avatar
TZW committed
447
      </DrawerPro>
wuhao's avatar
wuhao committed
448 449 450 451
    </div>
  );
}

TZW's avatar
TZW committed
452
export default Failure;