BasicInfo.jsx 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import React, { useState, useRef, useEffect } from 'react';
  2. import { Form, Input, Popconfirm, Select, Button, Modal, InputNumber, message, Col, Row, Card } from 'antd';
  3. import { PlusOutlined } from '@ant-design/icons';
  4. import { saveInvoiceFill, updateInvoiceFill, getInvoiceFillDetail } from '@/services/invoiceFill'
  5. import { saveInvoiceItemTpl, getInvoiceItemTplList, deleteInvoiceItemTpl } from '@/services/invoiceItemTpl'
  6. import { history } from 'umi';
  7. import PageTable from '@/components/PageTable';
  8. const FormItem = Form.Item;
  9. const { Option } = Select;
  10. const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
  11. const goBack = () => {
  12. history.goBack();
  13. };
  14. export default (props) => {
  15. const { invoiceId } = props
  16. const [form] = Form.useForm();
  17. const [loading, setLoading] = useState(false);
  18. const [formModel] = Form.useForm();
  19. const [editModal, setEditModal] = useState(false);
  20. const [modelLoading, setModelLoading] = useState(false);
  21. const actionRef = useRef();
  22. //保存班级
  23. const onSubmit = (data) => {
  24. var newData = { ...data };
  25. setLoading(true);
  26. if (invoiceId) {
  27. updateInvoiceFill(invoiceId, newData)
  28. .then(() => {
  29. setLoading(false);
  30. message.success('数据更新成功');
  31. goBack();
  32. })
  33. .catch((err) => {
  34. setLoading(false);
  35. message.error(err.message || err);
  36. });
  37. } else {
  38. saveInvoiceFill(newData)
  39. .then((res) => {
  40. setLoading(false);
  41. message.success('数据保存成功');
  42. history.replace(`./edit.jsx?id=${res.invoiceId}`);
  43. })
  44. .catch((err) => {
  45. setLoading(false);
  46. message.error(err.message || err);
  47. });
  48. }
  49. };
  50. //报销项目弹窗保存
  51. const Submit = (val) => {
  52. setModelLoading(true);
  53. saveInvoiceItemTpl(val, invoiceId).then(res => {
  54. message.success('添加成功')
  55. setModelLoading(false)
  56. actionRef.current.reload()
  57. onCancel();
  58. }).catch((err) => {
  59. setModelLoading(false);
  60. message.error(err.message || err);
  61. });
  62. }
  63. // 弹窗关闭
  64. const onCancel = () => {
  65. setEditModal(false);
  66. formModel.resetFields()
  67. }
  68. //弹起弹窗
  69. const showModel = () => {
  70. setEditModal(true);
  71. }
  72. //删除报销项目
  73. const handleDelete = (invoiceItemTplId) => {
  74. deleteInvoiceItemTpl(invoiceItemTplId).then(res => {
  75. message.success('删除成功')
  76. actionRef.current.reload()
  77. }).catch((err) => {
  78. message.error(err.message || err);
  79. });
  80. }
  81. const actions = () => [
  82. <Button key="add" type="primary" icon={<PlusOutlined />} onClick={showModel}>
  83. 新增报销项目
  84. </Button>,
  85. ];
  86. useEffect(() => {
  87. if (invoiceId) {
  88. getInvoiceFillDetail(invoiceId).then((res) => {
  89. form.setFieldsValue(res)
  90. }).catch((err) => {
  91. message.error(err.message || err);
  92. });
  93. }
  94. }, [invoiceId])
  95. const columns = [
  96. {
  97. title: '报销项目名称',
  98. dataIndex: 'name',
  99. key: 'name',
  100. },
  101. {
  102. title: '开票金额',
  103. dataIndex: 'charge',
  104. key: 'charge',
  105. },
  106. {
  107. title: '操作',
  108. valueType: 'option',
  109. render: (_, record) => [
  110. <Popconfirm
  111. key={2}
  112. title="您是否确认删除 ?"
  113. onConfirm={() => handleDelete(record.invoiceItemTplId)}
  114. okText="确定"
  115. cancelText="取消"
  116. >
  117. <Button style={{ padding: 0 }} type="link">
  118. 删除
  119. </Button>
  120. </Popconfirm>,
  121. ],
  122. },
  123. ];
  124. return (
  125. <>
  126. <Row>
  127. <Col span={12}>
  128. <Form {...formItemLayout} onFinish={onSubmit} form={form}>
  129. <FormItem label="班级名称" name="name" rules={[{ required: true, message: '请输入班级名称' }]}>
  130. <Input placeholder="请输入班级名称" style={{ width: '350px' }} />
  131. </FormItem>
  132. <FormItem label="状态" name="status" rules={[{ required: true, message: '请选择' }]}>
  133. <Select placeholder="请选择发布状态" style={{ width: '350px' }}>
  134. <Option value={1}>发布</Option>
  135. <Option value={0}>未发布</Option>
  136. </Select>
  137. </FormItem>
  138. <FormItem label=" " colon={false}>
  139. <Button type="default" onClick={goBack}>
  140. 返回
  141. </Button>
  142. <Button type="primary" loading={loading} htmlType="submit" style={{ marginLeft: '4em' }}>
  143. 保存
  144. </Button>
  145. </FormItem>
  146. </Form>
  147. </Col>
  148. {
  149. invoiceId &&
  150. <Col span={12}>
  151. 报销项目
  152. <PageTable
  153. request={getInvoiceItemTplList}
  154. toolBarRender={actions}
  155. actionRef={actionRef}
  156. columns={columns}
  157. rowKey="invoiceItemTplId"
  158. options={false}
  159. search={false}
  160. params={{ invoiceId }}
  161. />
  162. </Col>
  163. }
  164. </Row>
  165. <Modal
  166. forceRender
  167. title='报销项目新增'
  168. visible={editModal}
  169. onCancel={onCancel}
  170. keyboard={false}
  171. maskClosable={false}
  172. destroyOnClose={true}
  173. footer={null}
  174. >
  175. <Form {...formItemLayout} onFinish={Submit} form={formModel}>
  176. <FormItem label="报销项目名称" name="name" rules={[{ required: true, message: '请输入' }]}>
  177. <Input placeholder="请输入" />
  178. </FormItem>
  179. <FormItem label="报销金额" name="charge" rules={[{ required: true, message: '请输入' }]}>
  180. <InputNumber min={0} placeholder="请输入" style={{ width: '100%' }} />
  181. </FormItem>
  182. <FormItem label=" " colon={false}>
  183. <Button type="default" onClick={onCancel}>
  184. 取消
  185. </Button>
  186. <Button
  187. type="primary"
  188. loading={modelLoading}
  189. htmlType="Submit"
  190. style={{ marginLeft: '4em' }}
  191. >
  192. 确认
  193. </Button>
  194. </FormItem>
  195. </Form>
  196. </Modal>
  197. </>
  198. )
  199. }