Commit 9b99e6f514b7fdcee0b63157eb579ca6fb3c8e80

Authored by 曾国涛
1 parent 38661cba

feat: 开票功能开发

src/pages/Invoice/components/InvoiceDetailTable.tsx
1 1 import InvoiceDetailImportModal from '@/pages/Invoice/components/InvoiceDetailImportModal';
2 2 import { InvoiceProjectSelect } from '@/pages/Invoice/components/InvoiceProjectSelect';
3   -import { EditableProTable, ProColumns } from '@ant-design/pro-components';
4   -import { useEffect, useState } from 'react';
  3 +import {
  4 + ActionType,
  5 + EditableProTable,
  6 + ProCard,
  7 + ProColumns,
  8 + ProFormField,
  9 +} from '@ant-design/pro-components';
  10 +import { useEffect, useRef, useState } from 'react';
5 11  
6 12 export default ({ recordId, details, updateDetails, readOnly }) => {
7 13 const [editableKeys, setEditableRowKeys] = useState([]);
8   -
  14 + const [invoiceProject, setInvoiceProject] = useState({});
  15 + const ref = useRef<ActionType>();
9 16 useEffect(() => {
10 17 updateDetails(details);
11 18 }, []);
... ... @@ -17,10 +24,16 @@ export default ({ recordId, details, updateDetails, readOnly }) =&gt; {
17 24 {
18 25 title: '项目名称',
19 26 dataIndex: 'projectName',
  27 + width: 200,
20 28 ellipsis: true,
21 29 readonly: readOnly,
22 30 renderFormItem: () => {
23   - return <InvoiceProjectSelect />;
  31 + return (
  32 + <InvoiceProjectSelect
  33 + setInvoiceProject={setInvoiceProject}
  34 + readOnly={readOnly}
  35 + />
  36 + );
24 37 },
25 38 },
26 39 {
... ... @@ -89,12 +102,13 @@ export default ({ recordId, details, updateDetails, readOnly }) =&gt; {
89 102 <EditableProTable
90 103 headerTitle="可编辑表格"
91 104 columns={columns}
  105 + actionRef={ref}
92 106 rowKey="tid"
93 107 scroll={{
94 108 x: 960,
95 109 }}
96 110 value={details}
97   - onChange={updateDetails}
  111 + controlled={true}
98 112 recordCreatorProps={
99 113 readOnly
100 114 ? false
... ... @@ -118,11 +132,36 @@ export default ({ recordId, details, updateDetails, readOnly }) =&gt; {
118 132 },
119 133  
120 134 onValuesChange: (record, recordList) => {
121   - updateDetails(recordList);
  135 + console.log('reList' + JSON.stringify(recordList));
  136 + console.log(record);
  137 + console.log('ip' + JSON.stringify(invoiceProject));
  138 + //修改recordList中tid为record.tid的元素,将它的specification属性设置为invoiceProject的specification属性
  139 + const records = recordList.map((item) => {
  140 + if (item.tid === record.tid) {
  141 + item.specification = invoiceProject?.specification;
  142 + item.unit = invoiceProject?.unit;
  143 + item.taxRate = invoiceProject?.taxRate * 100;
  144 + }
  145 + return item;
  146 + });
  147 + console.log('res' + JSON.stringify(records));
  148 + updateDetails(records);
122 149 },
123   - onChange: setEditableRowKeys,
124 150 }}
125 151 />
  152 + <ProCard title="表格数据" headerBordered collapsible defaultCollapsed>
  153 + <ProFormField
  154 + ignoreFormItem
  155 + fieldProps={{
  156 + style: {
  157 + width: '100%',
  158 + },
  159 + }}
  160 + mode="read"
  161 + valueType="jsonCode"
  162 + text={JSON.stringify(details)}
  163 + />
  164 + </ProCard>
126 165 </>
127 166 );
128 167 };
... ...
src/pages/Invoice/components/InvoiceProjectSelect.tsx
1 1 import { postServiceConstListInvoiceDetailNames } from '@/services';
2   -import { enumToSelect } from '@/utils';
3   -import { ProFormSelect } from '@ant-design/pro-components';
  2 +import { Select, Tooltip } from 'antd';
  3 +import { useState } from 'react';
4 4  
5   -export const InvoiceProjectSelect = () => {
  5 +export const InvoiceProjectSelect = ({
  6 + readOnly,
  7 + value,
  8 + onChange,
  9 + setInvoiceProject,
  10 +}) => {
  11 + const [options, setOptions] = useState<any[]>([]);
  12 + // 定义防抖函数
  13 + let timeoutId = null;
6 14 const fetchOptions = async (keywords) => {
7   - const res = await postServiceConstListInvoiceDetailNames({
8   - data: {
9   - nameLike: keywords,
10   - },
11   - });
12   - const data = res.data;
13   - console.log('invoiceProject' + JSON.stringify(data));
14   - return enumToSelect(data);
  15 + clearTimeout(timeoutId);
  16 + timeoutId = setTimeout(async () => {
  17 + const res = await postServiceConstListInvoiceDetailNames({
  18 + data: {
  19 + nameLike: keywords,
  20 + },
  21 + });
  22 + const data = res.data;
  23 + console.log('invoiceProject' + JSON.stringify(data));
  24 + setOptions(
  25 + data.map((item) => {
  26 + return {
  27 + label: item.name,
  28 + value: item.id,
  29 + ...item,
  30 + };
  31 + }),
  32 + );
  33 + // 这里可以放置实际的搜索逻辑,比如发起网络请求等
  34 + }, 500); // 设置延迟时间,单位毫秒
15 35 };
16 36  
17   - return (
18   - <ProFormSelect
  37 + return readOnly ? (
  38 + <Tooltip title={value}>{value}</Tooltip>
  39 + ) : (
  40 + <Select
19 41 key="project"
20   - width={500}
  42 + /*readonly={readonly}*/
21 43 showSearch
22   - name="project"
23 44 placeholder="请选择开票项目"
24   - fieldProps={{
25   - filterOption() {
26   - return true;
27   - },
  45 + onChange={(e) => {
  46 + setInvoiceProject(options.find((item) => item.value === e));
  47 + onChange(e);
28 48 }}
29   - debounceTime={1000}
30   - request={async (value, {}) => {
31   - const keywords = value.keywords;
32   - const data = await fetchOptions(keywords);
33   - return data;
  49 + defaultValue={value}
  50 + options={options}
  51 + onSearch={(e) => {
  52 + fetchOptions(e);
34 53 }}
35 54 />
36 55 );
... ...
src/pages/Order/components/InvoicingDrawerForm.tsx
1 1 // import { PlusOutlined } from '@ant-design/icons';
  2 +import { InvoiceProjectSelect } from '@/pages/Invoice/components/InvoiceProjectSelect';
2 3 import {
3 4 postServiceConstInvoiceType,
4 5 postServiceConstInvoicingType,
... ... @@ -164,6 +165,24 @@ export default ({ dataList, mainOrder, setVisible, onClose }) =&gt; {
164 165 headers: { Authorization: localStorage.getItem('token') },
165 166 }}
166 167 />
  168 + <ProFormList
  169 + name="invoiceDetails"
  170 + label="开票明细"
  171 + rules={[
  172 + {
  173 + required: true,
  174 + validator: async (_, value) => {
  175 + console.log(value);
  176 + if (value && value.length > 0) {
  177 + return;
  178 + }
  179 + throw new Error('至少要有一项!');
  180 + },
  181 + },
  182 + ]}
  183 + >
  184 + <InvoiceProjectSelect readOnly={true} />
  185 + </ProFormList>
167 186 <ProFormTextArea
168 187 name="applyInvoicingNotes"
169 188 label="备注"
... ...