index.jsx 8.86 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4
/* 接单平台
 * @Author: Li Hanlin
 * @Date: 2022-12-05 10:13:42
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
5
 * @Last Modified time: 2022-12-08 13:47:55
TZW's avatar
TZW committed
6 7
 */

wuhao's avatar
wuhao committed
8
import * as React from 'react';
TZW's avatar
TZW committed
9 10 11 12 13 14 15
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';
import { useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
TZW's avatar
TZW committed
16
import OrderHandle from './RepairOrderHandle';
TZW's avatar
TZW committed
17
import { message } from 'antd';
wuhao's avatar
wuhao committed
18

TZW's avatar
TZW committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
function Platform(props) {
  const actionRef = useRef(),
    formRef = useRef();
  const [drawer, setdrawer] = useState({
      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,
wuhao's avatar
wuhao committed
34
          open: false,
TZW's avatar
TZW committed
35 36 37 38
        }));
      }
    },
  });
wuhao's avatar
wuhao committed
39

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

TZW's avatar
TZW committed
63
  // 接单按钮
TZW's avatar
TZW committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  const receiveBtn = (text, row, _, action, activeTab) => {
    if (row?.status == 0 || row?.status == 1) {
      if (activeTab == '2') {
        // 追踪
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: async () => {
                debugger;
                // setdrawer((s) => ({
                //   ...s,
                //   type: null,
                // }));
TZW's avatar
TZW committed
79
                //console.log('zzjd');
TZW's avatar
TZW committed
80 81 82 83 84 85 86 87 88 89 90
                let params = {
                  id: row?.id,
                };
                let res = await doFetch({
                  url: '/repair/umTrackOrder/orderReceiving',
                  params,
                });
                if (res.code === '0000') {
                  message.success('操作成功!');
                  setdrawer((s) => ({
                    ...s,
TZW's avatar
TZW committed
91
                    open: false,
TZW's avatar
TZW committed
92 93 94 95 96 97
                  }));
                  actionRef.current.reload();
                }
              },
            }}
          >
TZW's avatar
TZW committed
98
            接单
TZW's avatar
TZW committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
          </PremButton>
        );
      } else if (activeTab == '3') {
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: async () => {
                let params = {
                  ...vals,
                  id,
                };
                let res = await doFetch({
                  url: '/repair/umOtherUnitsOrder/orderReceiving',
                  params,
                });
                if (res.code === '0000') {
                  message.success('操作成功!');
                  setdrawer((s) => ({
                    ...s,
TZW's avatar
TZW committed
120
                    open: false,
TZW's avatar
TZW committed
121 122 123 124 125 126
                  }));
                  actionRef.current.reload();
                }
              },
            }}
          >
TZW's avatar
TZW committed
127
            接单
TZW's avatar
TZW committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
          </PremButton>
        );
      } else if (activeTab == '1') {
        // 维修
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: () => {
                setdrawer((s) => ({
                  ...s,
                  open: true,
                  item: row,
                  title: '接单',
                  val: 'only',
                  type: 'wxjd',
                }));
              },
            }}
          >
TZW's avatar
TZW committed
149
            接单
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 216 217 218 219
          </PremButton>
        );
      }
    } else {
      if (activeTab == '2') {
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: () => {
                setdrawer((s) => ({
                  ...s,
                  open: true,
                  item: row,
                  title: '派单',
                  type: 'zzpd',
                  val: 'only',
                }));
              },
            }}
          >
            派单
          </PremButton>
        );
      } else if (activeTab == '1') {
        // 维修
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: () => {
                setdrawer((s) => ({
                  ...s,
                  open: true,
                  item: row,
                  title: '派单',
                  type: 'wxpd',
                  val: 'only',
                }));
              },
            }}
          >
            派单
          </PremButton>
        );
      } else if (activeTab == '3') {
        return (
          <PremButton
            btn={{
              size: 'small',
              type: 'primary',
              onClick: () => {
                setdrawer((s) => ({
                  ...s,
                  open: true,
                  item: row,
                  title: '派单',
                  type: 'wpd',
                  val: 'only',
                }));
              },
            }}
          >
            派单
          </PremButton>
        );
      }
    }
TZW's avatar
TZW committed
220
  };
wuhao's avatar
wuhao committed
221

TZW's avatar
TZW committed
222 223 224
  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
225
    let actions = {
TZW's avatar
TZW committed
226 227 228
      title: '操作',
      valueType: 'option',
      width: 150,
TZW's avatar
TZW committed
229 230 231
      render: (text, row, _, action) => receiveBtn(text, row, _, action, activeTabKey),
    };
    return defcolumn.concat(actions);
TZW's avatar
TZW committed
232
  }, [activeTabKey]);
wuhao's avatar
wuhao committed
233

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

TZW's avatar
TZW committed
239 240
  function selectType(type) {
    switch (type) {
TZW's avatar
TZW committed
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
      case 'wxjd':
        return (
          <OrderHandle
            type="wxjd"
            id={drawer?.item.id}
            url={'/repair/umRepairOrder/orderReceiving'}
            actionRef={actionRef}
            setdrawer={setdrawer}
          />
        );
      case 'wxpd':
        return (
          <OrderHandle
            type="wxpd"
            actionRef={actionRef}
            setdrawer={setdrawer}
            id={drawer?.item.id}
            url={'/repair/umRepairOrder/dispatchById'}
          />
        );
      case 'zzpd':
        return (
          <OrderHandle
            type="zzpd"
            actionRef={actionRef}
            setdrawer={setdrawer}
            id={drawer?.item.id}
            url={'/repair/umTrackOrder/dispatchById'}
          />
        );
      case 'wpd':
        return (
          <OrderHandle
            type="wpd"
            setdrawer={setdrawer}
            actionRef={actionRef}
            id={drawer?.item.id}
            url={'/repair/umOtherUnitsOrder/dispatchById'}
          />
        );
TZW's avatar
TZW committed
281 282 283 284
      default:
        break;
    }
  }
TZW's avatar
TZW committed
285 286 287 288 289 290 291
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
        pagetitle={<h3 className="page-title">接单平台</h3>}
        columns={columns}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        actionRef={actionRef}
TZW's avatar
TZW committed
292 293
        // pageextra={pathconfig?.enableadd ? 'add' : null}
        resizeable={false}
TZW's avatar
TZW committed
294 295 296 297 298
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
            onClick: () => {
wuhao's avatar
wuhao committed
299 300
              setdrawer((s) => ({
                ...s,
TZW's avatar
TZW committed
301 302 303 304
                open: true,
                item: null,
                title: '新增',
                val: 'add',
wuhao's avatar
wuhao committed
305
              }));
TZW's avatar
TZW committed
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
            },
          },
        }}
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
      />

      <DrawerPro
        fields={columns}
        detailpath={pathconfig?.detail || null}
        detailData={drawer?.item}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        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 } });
          }
        }}
TZW's avatar
TZW committed
337 338 339
      >
        {selectType(drawer?.type)}
      </DrawerPro>
TZW's avatar
TZW committed
340 341 342
    </div>
  );
}
wuhao's avatar
wuhao committed
343

TZW's avatar
TZW committed
344
export default Platform;