index.jsx 9.88 KB
Newer Older
wangjing2's avatar
wangjing2 committed
1 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 32 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 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 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 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
import React, { useState, useEffect, useMemo, useRef } from 'react';
import DrawerPro from '@/components/DrawerPro';
import PremButton from '@/components/PremButton';
import AutoTable from '@/components/AutoTable';
import DetailPro from '@/components/DetailPro';
import useKeepAlive from "@/components/useKeepAlive";
import getcolumns from "./columns";
import { doFetch } from '@/utils/doFetch';
import _ from "lodash";
import { useRequest, useDebounceFn } from 'ahooks';
const columnsa = [
  {
    title: "物料编号-名称",
    dataIndex: "name",
    key: "name",
    render: (_, row) => {
      return (
        <span className='table-cell'>{row?.materialCode}-{row?.materialName}</span>
      );
    },
  },
  {
    title: "工单号",
    dataIndex: "jobNo",
    key: "jobNo",
  },
  {
    title: "入库数量",
    dataIndex: "inStoreNum",
    key: "inStoreNum",
  },
  {
    title: "库存单位",
    dataIndex: "productionUnitName",
    key: "productionUnitName",
  },
  {
    title: "未上架数量",
    dataIndex: "notUploadNum",
    key: "notUploadNum",
  }
],
  columnsb = [
    {
      title: "库位名称",
      dataIndex: "storePositionName",
      key: "storePositionName",
    },
    {
      title: "计划数量",
      dataIndex: "planNum",
      key: "planNum",
    },
    {
      title: "上架数量",
      dataIndex: "inStoreNum",
      key: "inStoreNum",
    },
    {
      title: "状态",
      dataIndex: "statusName",
      key: "statusName",
    },
  ];
function Instoreapplication() {
  let actionRef = useRef(), formRef = useRef();
  const { loading, run } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    }
  });
  const debounceFn = useDebounceFn(
    async (changedValues) => {
      for (let i in changedValues) {
        if (i === 'trayCode') {
          if (changedValues[i]) {
            let stations = await doFetch({ url: '/ta_wms_auth/sysStation/queryLyPositionForFitOut', params: { trayNo: changedValues[i] } }),
              tables = await doFetch({ url: '/ta_wms_workmanship/wmsInStoreApplyDetail/queryListForProduct', params: { trayCode: changedValues[i] } });
            formRef?.current?.setFieldsValue({ sourceAreaPosition: stations?.data?.data?.stationName });
            setdrawer(s => {
              return {
                ...s,
                item: {
                  ...s.item,
                  sourceAreaPosition: stations?.data?.data?.stationName,
                  materiallist: tables?.data?.dataList ?? [],
                  stations: stations?.data?.data
                }

              }
            });
          } else {
            formRef?.current?.setFieldsValue({ sourceAreaPosition: '' });
            setdrawer(s => {
              return {
                ...s,
                item: {
                  ...s.item,
                  sourceAreaPosition: '',
                  materiallist: [],
                  stations: {}
                }

              }
            });
          }
        }
      }
    },
    {
      wait: 500,
    },
  );
  const [drawer, setdrawer] = useState({
    open: false,
  }),
    [tabKey, setTabKey] = useState('1');
  const tabList = useMemo(() => {
    return getcolumns();
  }, [tabKey]);
  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer).filter((it) => it.key == tabKey)[0]?.columns ?? [];
    return tabKey === '2' ? defcolumn : defcolumn.concat({
      title: "操作",
      valueType: "option",
      width: 80,
      render: (text, row, _, action) => rightExtra(text, row, _, action),
    });
  }, [tabKey]),
    dom = useMemo(() => {
      const renderType = {
        'detailaddon': <div>
          <div className='splittitle' style={{ borderWidth: 1, marginBottom: 16 }}>物料信息</div>
          <AutoTable
            columns={columnsa}
            withCard={false}
            pagination={false}
            expandable={{
              expandedRowRender: (record) => (
                <AutoTable
                  withCard={false}
                  pagination={false}
                  className="expandableTable"
                  columns={columnsb}
                  dataSource={record?.uploadList ?? []}
                />
              )
            }}
            dataSource={drawer?.item?.detailList ?? []}
            defaultExpandAllRows
            style={{ marginBottom: 16 }}
          />
          {
            tabKey === '2' && <DetailPro
              fields={[
                { title: "强制关单信息", valueType: "split" },
                { title: "关单人员", dataIndex: "closeUserName" },
                { title: "关单时间", dataIndex: "closeTime" },
              ]}
              detailData={drawer?.item}
            />
          }
        </div>,
        'add': <div>
          <div className='splittitle' style={{ borderWidth: 1, marginBottom: 16 }}>物料信息</div>
          <AutoTable
            columns={columnsa.filter(it => it.key != 'notUploadNum')}
            withCard={false}
            pagination={false}
            dataSource={drawer?.item?.materiallist ?? []}
            rowKey='jobNo'
          />
          <PremButton
            btn={{
              type: 'primary',
              style: { marginTop: 16 },
              onClick: () => {
                formRef?.current?.validateFields().then(val => {
                  let objs = _.pick(drawer?.item?.materiallist?.[0], ['jobNo', 'materialId', 'materialCode', 'materialName', 'productModel', 'factoryNo', 'inStoreNum', 'productionUnitName']);
                  let params = {
                    inStoreNo: val.inStoreNo,
                    trayCode: val.trayCode,
                    sourcePositionId: drawer?.item?.stations?.id,
                    detailList: [
                      {
                        ...objs
                      }
                    ]
                  };
                  run({ url: '/ta_wms_workmanship/wmsInStoreProduct/saveProductInFromPc', params })
                })
              },
              loading: loading
            }}
          >提交</PremButton>
        </div>
      };
      return renderType[drawer?.val];
    }, [tabKey, drawer?.val, drawer?.item,loading])
  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == tabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [tabKey]);
  const rightExtra = (text, row, _, action) => {
    return [
      (row.inStoreStatus === 0 || row.inStoreStatus === 1) && <PremButton
        key="delete"
        pop={{
          title: "是否关闭该入库单?",
          okText: "确认",
          cancelText: "取消",
          onConfirm: () => {
            run({
              url: "/ta_wms_workmanship/wmsInStoreProduct/closeProductIn",
              params: { id: row.id },
            });
          },
        }}
        btn={{
          size: "small",
          danger: true,
        }}
      >
        关单
      </PremButton>,
    ];
  };



  return <div>
    <AutoTable
      pagetitle='装配入库'
      columns={columns}
      path={drawer?.open ? null : pathconfig?.list}
      actionRef={actionRef}
      resizeable={false}
      tabList={tabList}
      tabKey={tabKey}
      onTabChange={(key) => {
        setTabKey(key);
      }}
      pageextra={tabKey == '1' ? 'add' : null}
      addconfig={{
        // access: 'sysDepartment_save',
        name: '新增',
        btn: {
          type: 'primary',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              title: '新增',
              val: 'add',
              item: {
                inStoreTypeName: '生产入库单',
                sourceAreaName: '装配区',
                targetAreaName: '成品缓存区'
              },
              fields: [
                {
                  title: "入库单号",
                  dataIndex: "inStoreNo",
                  key: "inStoreNo"
                },
                {
                  title: "托盘号",
                  dataIndex: "trayCode",
                  key: "trayCode",
                  formItemProps: { rules: [{ required: true, message: '此项为必填项' }] }
                },
                {
                  title: "入库类型",
                  dataIndex: "inStoreTypeName",
                  key: "inStoreTypeName",
                  fieldProps: {
                    disabled: true
                  }
                },
                {
                  title: "来源区域",
                  dataIndex: "sourceAreaName",
                  key: "sourceAreaName",
                  fieldProps: {
                    disabled: true
                  }
                },
                {
                  title: "来源位置",
                  dataIndex: "sourceAreaPosition",
                  key: "sourceAreaPosition",
                  fieldProps: {
                    disabled: true
                  }
                },
                {
                  title: "目标区域",
                  dataIndex: "targetAreaName",
                  key: "targetAreaName",
                  fieldProps: {
                    disabled: true
                  }
                },
              ]
            }));
          },
        },
      }}
    />
    <DrawerPro
      {...drawer}
      fields={drawer?.val === 'add' ? drawer?.fields : columns}
      detailData={drawer?.item}
      defaultFormValue={drawer?.item}
      placement="right"
      onClose={() => {
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }}
      onValuesChange={(changedValues, allValues) => {
        debounceFn.run(changedValues)
      }}
      childrenposition={drawer.val === 'add' ? 'bottom' : null}
      submitter={false}
      formRef={formRef}
    >
      {dom}
    </DrawerPro>
  </div>
}

export default useKeepAlive(Instoreapplication);