Blame view

src/pages/product/procure/index.tsx 6.59 KB
1
import ButtonConfirm from '@/components/ButtomConfirm';
2
import { RESPONSE_CODE } from '@/constants/enum';
3
import AddOrUpdate from '@/pages/product/procure/components/AddOrUpdate';
4
5
6
7
8
9
import {
  postProcureBillDelete,
  postProcureBillPage,
  postServiceConstProcureBillAuditStatus,
} from '@/services';
import { enumToSelect } from '@/utils';
10
11
12
import { ProTable, type ActionType } from '@ant-design/pro-components';
import { message } from 'antd';
import { useRef } from 'react';
13
import Audit from './components/Audit';
14
15

export default () => {
16
  const actionRef = useRef<ActionType>();
17
18
  const columns = [
    {
19
20
21
22
23
24
      title: '单号',
      dataIndex: 'id',
      ellipsis: true,
      hideInSearch: true,
    },
    {
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
      title: '创建时间',
      dataIndex: 'createTime',
      ellipsis: true,
      width: 180,
      hideInSearch: true,
    },
    {
      title: '创建人',
      dataIndex: 'createByName',
      ellipsis: true,
      width: 180,
      hideInSearch: true,
    },
    {
      title: '总金额',
40
      dataIndex: 'totalPrice',
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
      ellipsis: true,
      width: 180,
      hideInSearch: true,
    },
    {
      title: '审核状态',
      dataIndex: 'auditStatusText',
      ellipsis: true,
      width: 180,
      hideInSearch: true,
    },
    {
      title: '审核备注',
      dataIndex: 'auditNotes',
      ellipsis: true,
      width: 180,
      hideInSearch: true,
    },
    {
      title: '备注',
      dataIndex: 'notes',
      ellipsis: true,
      width: 180,
      hideInSearch: true,
    },
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
      title: '采购单号',
      dataIndex: 'id',
      ellipsis: true,
      hideInTable: true,
    },
    {
      title: '创建人',
      dataIndex: 'createByNameLike',
      ellipsis: true,
      hideInTable: true,
    },
    {
      title: '创建时间',
      valueType: 'dateTimeRange',
      hideInTable: true,
      search: {
        transform: (value) => {
          if (value) {
            return {
              createTimeGe: value[0],
              createTimeLe: value[1],
            };
          }
        },
      },
    },
    {
      title: '审核状态',
      valueType: 'select',
      key: 'auditStatus',
      dataIndex: 'auditStatus',
      filters: true,
      onFilter: true,
      hideInTable: true,
      request: async () => {
        const res = await postServiceConstProcureBillAuditStatus();
        return enumToSelect(res.data);
      },
    },
    {
107
108
109
110
      title: '操作',
      valueType: 'option',
      key: 'option',
      render: (text, record) => [
111
112
113
114
115
        record.paths?.includes('UPDATE') && (
          <AddOrUpdate
            key="update"
            record={record}
            onfinish={() => {
116
              actionRef.current?.reload();
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
            }}
          />
        ),
        record.paths?.includes('UPDATE') && (
          <ButtonConfirm
            key="delete"
            className="p-0"
            title={'确认删除该记录?'}
            text="删除"
            onConfirm={async () => {
              let res = await postProcureBillDelete({
                query: { id: record.id },
              });
              if (res) {
                message.success(res.message);
                actionRef.current?.reload();
              }
            }}
          />
        ),
        record.paths?.includes('AUDIT') && (
          <Audit
            recordId={record.id}
            onClose={() => {
              actionRef.current?.reload();
            }}
          ></Audit>
        ),
145
146
      ],
    },
147
148
149
150
  ];

  return (
    <ProTable
151
      actionRef={actionRef}
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
      columns={columns}
      request={async (params) => {
        const res = await postProcureBillPage({
          data: {
            ...params,
          },
        });
        if (res.result === RESPONSE_CODE.SUCCESS) {
          return {
            data: res?.data?.data,
            total: res?.data?.total || 0,
          };
        }
        return {
          data: [],
          success: false,
        };
      }}
      rowKey="id"
      pagination={{
        showQuickJumper: true,
      }}
      expandable={{
        expandedRowRender: (record) => (
          <ProTable
            columns={[
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
              {
                title: '商品名称',
                dataIndex: 'productName',
                key: 'productName',
              },
              {
                title: '单位',
                dataIndex: 'productUnitName',
                key: 'productUnitName',
              },
              {
                title: '单价',
                dataIndex: 'productUnitPrice',
                key: 'productUnitPrice',
              },
193
              { title: '数量', dataIndex: 'number', key: 'number' },
194
              { title: '小计', dataIndex: 'totalPrice', key: 'totalPrice' },
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
              {
                title: '附件',
                dataIndex: 'annex',
                key: 'annex',
                render: (_, record) => (
                  <div>
                    {record.annexList?.map((url, index) => {
                      const shortName =
                        url.split('/').pop()?.slice(0, 15) ||
                        `附件 ${index + 1}`;
                      return (
                        <a
                          key={index}
                          href={url}
                          target="_blank"
                          rel="noopener noreferrer"
                          title={url} // 悬停显示完整链接
                          style={{
                            display: 'block',
                            marginBottom: '4px',
                            whiteSpace: 'nowrap',
                            overflow: 'hidden',
                            textOverflow: 'ellipsis',
                            maxWidth: '200px', // 限制显示宽度
                          }}
                        >
                          {shortName.length < url.split('/').pop()?.length
                            ? `${shortName}...`
                            : shortName}
                        </a>
                      );
                    })}
                  </div>
                ),
              },
230
231
232
233
234
235
236
237
238
239
240
              { title: '备注', dataIndex: 'notes', key: 'notes' },
            ]}
            headerTitle={false}
            search={false}
            options={false}
            dataSource={record.procureBillDetailList}
            pagination={false}
          />
        ),
      }}
      dateFormatter="string"
241
      headerTitle="采购管理"
242
243
      options={false}
      toolBarRender={() => [
244
245
246
247
248
        <AddOrUpdate
          key="add"
          record={undefined}
          onfinish={() => actionRef.current?.reload()}
        />,
249
250
251
252
      ]}
    />
  );
};