From 3fa0c1b14ed70fe78eed15d8a390cafb2a8f41be Mon Sep 17 00:00:00 2001
From: wuhao930406 <1148547900@qq.com>
Date: Fri, 30 Dec 2022 17:09:42 +0800
Subject: [PATCH] asder

---
 config/authRoutes.js                   |  43 ++-
 src/pages/spare/requisition/columns.js |   1 +
 src/pages/spare/spareback/columns.js   | 492 +++++++++++++++++++++++++
 src/pages/spare/spareback/index.jsx    | 228 ++++++++++++
 4 files changed, 747 insertions(+), 17 deletions(-)
 create mode 100644 src/pages/spare/spareback/columns.js
 create mode 100644 src/pages/spare/spareback/index.jsx

diff --git a/config/authRoutes.js b/config/authRoutes.js
index 8bd327d..af813c4 100644
--- a/config/authRoutes.js
+++ b/config/authRoutes.js
@@ -171,24 +171,37 @@ export default [
 				"icon": "",
 				"component": "./spare/outstore"
 			},
-			{
-				"name": "个人库存",
-				"path": "/spare/personalstore",
+      {
+				"name": "出入库记录",
+				"path": "/spare/record",
+				"icon": "",
+				"component": "./spare/record"
+			},
+      {
+				"name": "备件领用",
+				"path": "/spare/requisition",
+				"icon": "",
+				"component": "./spare/requisition"
+			},
+      {
+				"name": "备件回冲",
+				"path": "/spare/spareback",
 				"icon": "",
-				"component": "./spare/personalstore"
+				"component": "./spare/spareback"
 			},
+			// {
+			// 	"name": "个人库存",
+			// 	"path": "/spare/personalstore",
+			// 	"icon": "",
+			// 	"component": "./spare/personalstore"
+			// },
 			{
 				"name": " 线边库存",
 				"path": "/spare/edgestore",
 				"icon": "",
 				"component": "./spare/edgestore"
 			},
-			{
-				"name": "出入库记录",
-				"path": "/spare/record",
-				"icon": "",
-				"component": "./spare/record"
-			},
+
 			{
 				"name": "备件供应商",
 				"path": "/spare/supplier",
@@ -201,12 +214,8 @@ export default [
 				"icon": "",
 				"component": "./spare/setting"
 			},
-			{
-				"name": "备件领用",
-				"path": "/spare/requisition",
-				"icon": "",
-				"component": "./spare/requisition"
-			}
+
+
 		]
 	}
-];
\ No newline at end of file
+];
diff --git a/src/pages/spare/requisition/columns.js b/src/pages/spare/requisition/columns.js
index bf97c0f..0a80715 100644
--- a/src/pages/spare/requisition/columns.js
+++ b/src/pages/spare/requisition/columns.js
@@ -399,6 +399,7 @@ function getcolumns(type) {
           dataIndex: 'cdetails',
           key: 'cdetails',
           valueType: 'split',
+          hideInForm: true,
         },
         {
           title: '审批人',
diff --git a/src/pages/spare/spareback/columns.js b/src/pages/spare/spareback/columns.js
new file mode 100644
index 0000000..75f9f71
--- /dev/null
+++ b/src/pages/spare/spareback/columns.js
@@ -0,0 +1,492 @@
+import AutoTable from '@/components/AutoTable/mtable';
+
+function getcolumns(type) {
+  const columns = [
+    {
+      title: '备件料号',
+      dataIndex: 'sparePartNo',
+      key: 'sparePartNo',
+      editable: false,
+    },
+    {
+      title: '备件名称',
+      dataIndex: 'sparePartName',
+      key: 'sparePartName',
+      editable: false,
+    },
+    {
+      title: '供应商编号',
+      dataIndex: 'supplierNo',
+      key: 'supplierNo',
+      editable: false,
+    },
+    {
+      title: '供应商名称',
+      dataIndex: 'supplierName',
+      key: 'supplierName',
+      editable: false,
+    },
+    {
+      title: '可用库存',
+      dataIndex: 'usedStock',
+      key: 'usedStock',
+      editable: false,
+      hideInSearch: true,
+    },
+    {
+      title: '申请数量',
+      dataIndex: 'operateNum',
+      key: 'operateNum',
+      hideInSearch: true,
+      valueType: 'digit',
+      fieldProps: {
+        precision: 3,
+      },
+      formItemProps: {
+        rules: [
+          {
+            required: true,
+            message: '此项为必填项',
+          },
+        ],
+      },
+    },
+    {
+      title: '库存单位',
+      dataIndex: 'unit',
+      editable: false,
+      hideInSearch: true,
+    },
+  ];
+  return [
+    {
+      tab: '未完成',
+      key: '1',
+      columns: [
+        {
+          title: '回冲单号',
+          dataIndex: 'taskNo',
+          key: 'taskNo',
+        },
+        {
+          title: '申请原因',
+          dataIndex: 'backReasonName',
+          key: 'backReason',
+          valueType: 'select',
+          options: [
+            {
+              label: '回冲入库',
+              value: 1,
+            },
+          ],
+          formItemProps: {
+            rules: [
+              {
+                required: true,
+                message: '此项为必填项',
+              },
+            ],
+          },
+        },
+        {
+          title: '入库仓库',
+          dataIndex: 'inWarehouseName',
+          key: 'inWarehouseId',
+          hideInForm: true,
+        },
+        {
+          title: '出库仓库',
+          dataIndex: 'outWarehouseName',
+          key: 'outWarehouseId',
+          valueType: 'select',
+          options: {
+            path: '/auth/sysShop/getUserShopSelection',
+            params: {},
+          },
+          hideInForm: type == 1,
+          formItemProps: {
+            rules: [
+              {
+                required: true,
+                message: '此项为必填项',
+              },
+            ],
+          },
+        },
+        {
+          title: '备件种类',
+          dataIndex: 'spareTypeNum',
+          key: 'spareTypeNum',
+          hideInForm: true,
+          hideInSearch: true,
+        },
+        {
+          title: '相关单号',
+          dataIndex: 'relationNo',
+          key: 'relationNo',
+        },
+        {
+          title: '创建时间',
+          dataIndex: 'createTime',
+          key: 'createTimeList',
+          hideInForm: true,
+          valueType: 'dateRange',
+          render: (text, row) => {
+            return <span>{row?.createTime}</span>;
+          },
+          hideInForm: true,
+        },
+        {
+          dataIndex: 'remark',
+          valueType: 'textarea',
+          title: '备注',
+          key: 'remark',
+          colProps: {
+            span: 24,
+          },
+          hideInTable: true,
+          hideInSearch: true,
+        },
+        {
+          title: '入库单号',
+          dataIndex: 'inWarehouseTaskNo',
+          key: 'inWarehouseTaskNo',
+          hideInForm: true,
+        },
+        {
+          title: '状态',
+          dataIndex: 'statusName',
+          key: 'status',
+          hideInForm: true,
+          valueType: 'select',
+          options: [
+            {
+              label: '待审批',
+              value: 1,
+            },
+            {
+              label: '出库中',
+              value: 2,
+            },
+          ],
+        },
+        {
+          title: '备件信息',
+          dataIndex: 'details',
+          key: 'details',
+          valueType: 'split',
+        },
+        {
+          title: '备件',
+          dataIndex: 'detailsList',
+          key: 'detailsList',
+          valueType: 'formSelectList',
+          colProps: {
+            span: 24,
+          },
+          columns,
+          span: 12,
+          path: '/sparepart/lineStock/queryByBack',
+          hideInSearch: true,
+          hideInTable: true,
+          formItemProps: {
+            rules: [
+              {
+                required: true,
+                message: '此项为必填项',
+              },
+            ],
+          },
+          rowName: 'sparePartName',
+          linkParams: {
+            outWarehouseId: 'stockId',
+          }, //params 则不联动
+          render: (text, row) => {
+            return (
+              <AutoTable
+                columns={columns?.map((it) => ({
+                  ...it,
+                  hideInSearch: true,
+                }))}
+                dataSource={row?.detailsList}
+              />
+            );
+          },
+        },
+        {
+          title: '审批信息',
+          dataIndex: 'cdetails',
+          key: 'cdetails',
+          valueType: 'split',
+          hideInForm: true,
+        },
+        {
+          title: '审批人',
+          dataIndex: 'approvalUserName',
+          key: 'approvalUserName',
+          hideInTable: true,
+          hideInForm: true,
+          hideInSearch: true,
+        },
+        {
+          title: '审批时间',
+          dataIndex: 'approvalTime',
+          key: 'approvalTime',
+          hideInSearch: true,
+          hideInTable: true,
+          hideInForm: true,
+        },
+        {
+          title: '审批结果',
+          dataIndex: 'approvalResultName',
+          key: 'approvalResultName',
+          hideInSearch: true,
+          hideInTable: true,
+          hideInForm: true,
+        },
+        {
+          title: '审批备注',
+          dataIndex: 'approvalRemark',
+          key: 'approvalRemark',
+          hideInSearch: true,
+          hideInTable: true,
+          hideInForm: true,
+        },
+      ],
+      pathconfig: {
+        enableadd: true,
+        enableedit: true,
+        enabledelete: true,
+        enabledetail: true,
+        add: '/sparepart/spareBackTask/save',
+        edit: '',
+        list: '/sparepart/spareBackTask/queryNoComplete',
+        delete: '/sparepart/spareBackTask/deleteById',
+        detail: '/sparepart/spareBackTask/queryDetails',
+      },
+    },
+    {
+      tab: '已完成',
+      key: '2',
+      columns: [
+        {
+          title: '回冲单号',
+          dataIndex: 'taskNo',
+          key: 'taskNo',
+        },
+        {
+          title: '申请原因',
+          dataIndex: 'backReasonName',
+          key: 'backReason',
+          valueType: 'select',
+          options: [
+            {
+              label: '回冲入库',
+              value: 1,
+            },
+          ],
+          formItemProps: {
+            rules: [
+              {
+                required: true,
+                message: '此项为必填项',
+              },
+            ],
+          },
+        },
+        {
+          title: '入库仓库',
+          dataIndex: 'inWarehouseName',
+          key: 'inWarehouseId',
+          hideInForm: true,
+        },
+        {
+          title: '出库仓库',
+          dataIndex: 'outWarehouseName',
+          key: 'outWarehouseId',
+          valueType: 'select',
+          options: {
+            path: '/auth/sysShop/getUserShopSelection',
+            params: {},
+          },
+          hideInForm: type == 1,
+          formItemProps: {
+            rules: [
+              {
+                required: true,
+                message: '此项为必填项',
+              },
+            ],
+          },
+        },
+        {
+          title: '备件种类',
+          dataIndex: 'spareTypeNum',
+          key: 'spareTypeNum',
+          hideInForm: true,
+          hideInSearch: true,
+        },
+        {
+          title: '相关单号',
+          dataIndex: 'relationNo',
+          key: 'relationNo',
+        },
+        {
+          title: '创建时间',
+          dataIndex: 'createTime',
+          key: 'createTimeList',
+          hideInForm: true,
+          valueType: 'dateRange',
+          render: (text, row) => {
+            return <span>{row?.createTime}</span>;
+          },
+          hideInForm: true,
+        },
+        {
+          title: '完成时间',
+          dataIndex: 'completeTime',
+          key: 'completeTimeList',
+          hideInForm: true,
+          valueType: 'dateRange',
+          render: (text, row) => {
+            return <span>{row?.completeTime}</span>;
+          },
+          hideInForm: true,
+        },
+        {
+          dataIndex: 'remark',
+          valueType: 'textarea',
+          title: '备注',
+          key: 'remark',
+          colProps: {
+            span: 24,
+          },
+          hideInTable: true,
+          hideInSearch: true,
+        },
+        {
+          title: '入库单号',
+          dataIndex: 'inWarehouseTaskNo',
+          key: 'inWarehouseTaskNo',
+          hideInForm: true,
+        },
+        {
+          title: '状态',
+          dataIndex: 'statusName',
+          key: 'status',
+          hideInForm: true,
+          valueType: 'select',
+          options: [
+            {
+              label: '已驳回',
+              value: 3,
+            },
+            {
+              label: '处理失败  ',
+              value: 4,
+            },
+            {
+              label: '已完成',
+              value: 5,
+            },
+          ],
+        },
+        {
+          title: '备件信息',
+          dataIndex: 'details',
+          key: 'details',
+          valueType: 'split',
+          hideInForm: true,
+        },
+        {
+          title: '备件',
+          dataIndex: 'detailsList',
+          key: 'detailsList',
+          valueType: 'formSelectList',
+          colProps: {
+            span: 24,
+          },
+          columns,
+          span: 12,
+          formItemProps: {
+            rules: [
+              {
+                required: true,
+                message: '此项为必填项',
+              },
+            ],
+          },
+          path: '/sparepart/lineStock/queryByBack',
+          hideInSearch: true,
+          hideInTable: true,
+          linkParams: {
+            outWarehouseId: 'stockId',
+          }, //params 则不联动
+          rowName: 'sparePartName',
+          render: (text, row) => {
+            return (
+              <AutoTable
+                columns={columns?.map((it) => ({
+                  ...it,
+                  hideInSearch: true,
+                }))}
+                dataSource={row?.detailsList}
+              />
+            );
+          },
+        },
+        {
+          title: '审批信息',
+          dataIndex: 'cdetails',
+          key: 'cdetails',
+          valueType: 'split',
+          hideInForm: true,
+        },
+        {
+          title: '审批人',
+          dataIndex: 'approvalUserName',
+          key: 'approvalUserName',
+          hideInTable: true,
+          hideInForm: true,
+          hideInSearch: true,
+        },
+        {
+          title: '审批时间',
+          dataIndex: 'approvalTime',
+          key: 'approvalTime',
+          hideInSearch: true,
+          hideInTable: true,
+          hideInForm: true,
+        },
+        {
+          title: '审批结果',
+          dataIndex: 'approvalResultName',
+          key: 'approvalResultName',
+          hideInSearch: true,
+          hideInTable: true,
+          hideInForm: true,
+        },
+        {
+          title: '审批备注',
+          dataIndex: 'approvalRemark',
+          key: 'approvalRemark',
+          hideInSearch: true,
+          hideInTable: true,
+          hideInForm: true,
+        },
+      ],
+      pathconfig: {
+        enableadd: true,
+        enableedit: false,
+        enabledelete: false,
+        enabledetail: true,
+        add: '/sparepart/spareBackTask/save',
+        edit: '',
+        list: '/sparepart/spareBackTask/queryYesComplete',
+        delete: '',
+        detail: '/sparepart/spareBackTask/queryDetails',
+      },
+    },
+  ];
+}
+export default getcolumns;
diff --git a/src/pages/spare/spareback/index.jsx b/src/pages/spare/spareback/index.jsx
new file mode 100644
index 0000000..512f15f
--- /dev/null
+++ b/src/pages/spare/spareback/index.jsx
@@ -0,0 +1,228 @@
+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';
+import { message, Divider } from 'antd';
+
+function Spareback(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') {
+        message.success('操作成功');
+        actionRef?.current?.reload();
+        setdrawer((s) => ({
+          ...s,
+          open: false,
+        }));
+      }
+    },
+  });
+
+  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',
+          disabled: row.status == 2,
+          onClick: () => {
+            setdrawer((s) => ({
+              ...s,
+              open: true,
+              item: row,
+              title: '审批',
+              val: 'detailaddon',
+              addon: (
+                <>
+                  <InitForm
+                    style={{ background: '#f0f0f0', padding: 12, borderTop: '#1890ff solid 1px' }}
+                    fields={[
+                      {
+                        title: '审批结果',
+                        dataIndex: 'approvalResult',
+                        key: 'approvalResult',
+                        formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
+                        valueType: 'radio',
+                        options: [
+                          { label: '通过', value: '1' },
+                          { label: '不通过', value: '2' },
+                        ],
+                      },
+                      {
+                        title: '审批备注',
+                        dataIndex: 'approvalRemark',
+                        key: 'approvalRemark',
+                        valueType: 'textarea',
+                        colProps: { span: 24 },
+                      },
+                    ]}
+                    onFinish={(vals) => {
+                      run({
+                        url: '/sparepart/spareBackTask/approval',
+                        params: { ...vals, id: row?.id },
+                      });
+                    }}
+                  />
+                </>
+              ),
+            }));
+          },
+        }}
+      >
+        审批
+      </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(drawer?.type).filter((it) => it.key == activeTabKey)[0]?.columns;
+    let defpath =
+      getcolumns(drawer?.type).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
+    return defcolumn.concat({
+      title: '操作',
+      valueType: 'option',
+      width: 150,
+      render: (text, row, _, action) => [
+        defpath?.enabledetail && detail(text, row, _, action),
+        defpath?.enableedit && edit(text, row, _, action),
+        defpath?.enabledelete && remove(text, row, _, action),
+      ],
+    });
+  }, [activeTabKey, drawer?.type]);
+
+  const pathconfig = useMemo(() => {
+    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
+    return defpath;
+  }, [activeTabKey]);
+
+  return (
+    <div style={{ position: 'relative' }}>
+      <AutoTable
+        pagetitle="备件回冲"
+        columns={columns}
+        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
+        actionRef={actionRef}
+        pageextra={pathconfig?.enableadd ? 'add' : null}
+        resizeable={false}
+        addconfig={{
+          // access: 'sysDepartment_save',
+          btn: {
+            disabled: false,
+            onClick: async () => {
+              let res = await doFetch({
+                url: '/base/pmBaseBusinessData/querySpareStockType',
+                params: {},
+              });
+              let type = res?.data?.data?.type;
+              setdrawer((s) => ({
+                ...s,
+                open: true,
+                item: null,
+                title: '新增',
+                val: 'add',
+                type,
+              }));
+            },
+          },
+        }}
+        tabList={getcolumns()}
+        activeTabKey={activeTabKey}
+        onTabChange={(key) => {
+          setactiveTabKey(key);
+        }}
+      />
+
+      <DrawerPro
+        fields={columns}
+        detailpath={pathconfig?.detail || null}
+        defaultFormValue={drawer?.item}
+        params={{ id: drawer?.item?.id }}
+        formRef={formRef}
+        placement="right"
+        onClose={() => {
+          setdrawer((s) => ({
+            ...s,
+            open: false,
+          }));
+        }}
+        {...drawer}
+        onFinish={(vals) => {
+          const detailsList = vals?.detailsList?.map?.((it, i) => {
+            return {
+              lineStockId: it?.id,
+              operateNum: it?.operateNum,
+            };
+          });
+          if (drawer?.val == 'add') {
+            run({ url: pathconfig?.add || '/add', params: { ...vals, detailsList } });
+          } else if (drawer?.val == 'edit') {
+            run({
+              url: pathconfig?.edit || '/edit',
+              params: { ...vals, id: drawer?.item?.id, detailsList },
+            });
+          }
+        }}
+      >
+        {drawer?.addon}
+      </DrawerPro>
+    </div>
+  );
+}
+
+export default Spareback;
-- 
2.21.0