index.jsx 7.53 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4 5 6 7 8 9
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';
import { useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
import InitForm from '@/components/InitForm';
TZW's avatar
TZW committed
10
import { message } from 'antd';
TZW's avatar
TZW committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24
function Warning(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 } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
TZW's avatar
TZW committed
25
        message.success('操作成功!', 2);
TZW's avatar
TZW committed
26 27 28 29 30 31 32 33 34
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    },
  });

TZW's avatar
TZW committed
35 36 37 38
  const changeColumns = useMemo(() => {
    const columns = [
      {
        title: '线边库',
TZW's avatar
TZW committed
39 40
        dataIndex: 'stockName',
        key: 'stockName',
TZW's avatar
TZW committed
41 42 43 44
        editable: false,
      },
      {
        title: '备件料号',
TZW's avatar
TZW committed
45 46
        dataIndex: 'sparePartNo',
        key: 'sparePartNo',
TZW's avatar
TZW committed
47
        span: 3,
TZW's avatar
TZW committed
48
        search: false,
TZW's avatar
TZW committed
49 50 51 52 53 54
        editable: false,
      },
      {
        title: '备件名称',
        dataIndex: 'sparePartName',
        key: 'sparePartName',
TZW's avatar
TZW committed
55
        search: false,
TZW's avatar
TZW committed
56 57 58 59 60
        span: 3,
        editable: false,
      },
      {
        title: '供应商编号',
TZW's avatar
TZW committed
61 62
        dataIndex: 'supplierNo',
        key: 'supplierNo',
TZW's avatar
TZW committed
63 64 65 66 67
        span: 3,
        editable: false,
      },
      {
        title: '供应商名称',
TZW's avatar
TZW committed
68 69
        dataIndex: 'supplierName',
        key: 'supplierName',
TZW's avatar
TZW committed
70 71 72 73 74
        span: 3,
        editable: false,
      },
      {
        title: '可用数量',
TZW's avatar
TZW committed
75 76
        dataIndex: 'usedStock',
        key: 'usedStock',
TZW's avatar
TZW committed
77 78 79 80 81 82 83 84 85 86 87
        search: false,
        span: 3,
        editable: false,
      },
      {
        title: (
          <div>
            更换数量 <span style={{ color: 'red' }}>* </span>
          </div>
        ),
        search: false,
TZW's avatar
TZW committed
88 89 90 91 92 93
        dataIndex: 'operateNum',
        valueType: 'digit',
        fieldProps: {
          precision: 3,
        },
        key: 'operateNum',
TZW's avatar
TZW committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107
        span: 3,
        hideInForm: true,
      },
    ];
    return [
      {
        title: (
          <div>
            <span style={{ color: 'red' }}>* </span> 持有寿命件信息
          </div>
        ),
        valueType: 'split',
      },
      {
TZW's avatar
TZW committed
108 109 110 111 112
        title: (
          <span style={{ color: 'rgba(0, 0, 0, 0.)', fontSize: 12, fontWeight: 400 }}>
            注意:无法选择供应商未维护寿命件周期的数据
          </span>
        ),
TZW's avatar
TZW committed
113 114 115 116 117 118 119 120 121 122
        dataIndex: 'supplierList',
        key: 'supplierList',
        valueType: 'formSelectList',
        colProps: {
          span: 24,
        },
        span: 3,
        columns,
        hideInSearch: true,
        hideInTable: true,
TZW's avatar
TZW committed
123 124
        path: '/sparepart/lineStock/queryReplaceStock',
        params: { lifePieceAccountId: drawer?.item?.id },
TZW's avatar
TZW committed
125
        rowName: 'supplierList',
TZW's avatar
TZW committed
126 127 128 129 130 131
        rowSelection: {
          type: 'checkbox',
          getCheckboxProps: (record) => ({
            disabled: record.isAsh == '1',
          }),
        },
TZW's avatar
TZW committed
132 133 134
      },
    ];
  });
TZW's avatar
TZW committed
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
  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,
TZW's avatar
TZW committed
168
              title: '更换寿命件',
TZW's avatar
TZW committed
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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
              val: 'detailaddon',
            }));
          },
        }}
      >
        更换
      </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 columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer)?.columns;
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 150,
      render: (text, row, _, action) => [
        pathconfig?.enabledetail && detail(text, row, _, action),
        pathconfig?.enableedit && edit(text, row, _, action),
        pathconfig?.enabledelete && remove(text, row, _, action),
      ],
    });
  }, []);

  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
        pagetitle={<h3 className="page-title">寿命件台账</h3>}
        columns={columns}
        actionRef={actionRef}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        pageextra={pathconfig?.enableadd ? 'add' : null}
        resizeable={false}
        addconfig={{
          // access: 'sysDepartment_save',
          name: '初始化寿命件',
          btn: {
            disabled: false,
            type: 'primary',
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
                item: null,
                title: '新增',
                val: 'add',
              }));
            },
          },
        }}
      />

      <DrawerPro
        fields={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') {
            const params = { ...vals };
            params.nextReplaceDate = params.nextReplaceDateList;
            delete params.nextReplaceDateList;
            run({ url: pathconfig?.add || '/add', params });
          } else if (drawer?.val == 'edit') {
            run({ url: pathconfig?.edit || '/edit', params: { ...vals, id: drawer?.item?.id } });
          }
        }}
      >
TZW's avatar
TZW committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
        <InitForm
          fields={changeColumns}
          onFinish={(vals) => {
            console.log(vals);
            if (vals.supplierList?.length == 0) {
              return message.warning('请选择线边库存数据');
            }
            const lineStockUseList = vals?.supplierList?.map((it) => {
              return {
                lineStockId: it?.id,
                operateNum: it?.operateNum,
              };
            });
            for (let i of lineStockUseList) {
              if (!i?.operateNum) {
                return message.warning('请输入线边库存更换数量');
              }
            }
            run({
              url: '/sparepart/lifePieceAccount/replace',
              params: { lineStockUseList, id: drawer?.item?.id },
            });
          }}
        />
TZW's avatar
TZW committed
292 293 294 295 296 297
      </DrawerPro>
    </div>
  );
}

export default Warning;