index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import React, { useEffect, useState } from 'react';
  2. import { FilterTable, FormItem } from 'wptpc-design';
  3. import { message, Divider, Modal, Popconfirm } from 'antd';
  4. import { fetchApiGet } from '@/apis';
  5. import { addItem, editItem, delItem } from './services';
  6. import {dc} from "@/conf/config";
  7. let localrefresh = null;
  8. export default function EventManage() {
  9. const apiUrl = `${dc}/ts/web/get-event-list`;
  10. const [visible, setVisible] = useState(false);
  11. const [confirmLoading, setConfirmLoading] = useState(false);
  12. const [formParams, setFormParams] = useState({});
  13. const [typeNum, setTypeNum] = useState({}); // 编辑3 添加4
  14. const add = (e, record, index) => {
  15. setFormParams({});
  16. setTypeNum(2);
  17. setVisible(true);
  18. };
  19. //
  20. const edit = text => {
  21. setFormParams(text);
  22. setTypeNum(3);
  23. setVisible(true);
  24. };
  25. const confirm = (e, text) => {
  26. delItem({ id: text.id }).then(res => {
  27. if (res && res.code === 0) {
  28. message.success(res.msg);
  29. localrefresh();
  30. }
  31. });
  32. };
  33. const onParamsChange = (key, value) => {
  34. setFormParams({ ...formParams, [key]: value });
  35. };
  36. const handleOk = () => {
  37. if (
  38. // !formParams.eventName ||
  39. Object.keys(formParams).length < typeNum ||
  40. formParams.eventName?.length < 2 ||
  41. // !formParams.eventType ||
  42. formParams.eventType?.length < 2
  43. // !formParams.remarks ||
  44. // formParams.remarks?.length < 2
  45. ) {
  46. message.warning('字段全部必填,2-20个字符');
  47. return;
  48. }
  49. setConfirmLoading(true);
  50. if (typeNum === 2) {
  51. addItem(formParams).then(res => {
  52. if (res && res.code === 0) {
  53. message.success(res.msg);
  54. localrefresh();
  55. }
  56. });
  57. } else {
  58. editItem(formParams).then(res => {
  59. if (res && res.code === 0) {
  60. message.success(res.msg);
  61. localrefresh();
  62. }
  63. });
  64. }
  65. localrefresh();
  66. setVisible(false);
  67. setConfirmLoading(false);
  68. };
  69. const filterSetting = {
  70. beforeSearchFunc: params => {},
  71. hasClearBtn: false,
  72. perWidthUnit: 240,
  73. formFields: [
  74. {
  75. label: '事件标识:',
  76. key: 'eventType',
  77. type: 'input',
  78. },
  79. // {
  80. // label: '事件名称:',
  81. // key: 'userinfoId',
  82. // type: 'input',
  83. // },
  84. ],
  85. };
  86. const tableColumns = [
  87. {
  88. title: 'ID',
  89. dataIndex: 'id',
  90. },
  91. {
  92. title: '事件标识',
  93. dataIndex: 'eventType',
  94. },
  95. {
  96. title: '事件名称',
  97. dataIndex: 'eventName',
  98. },
  99. {
  100. title: '备注',
  101. dataIndex: 'remarks',
  102. },
  103. {
  104. title: '操作',
  105. dataIndex: 'time',
  106. render: (e, text, index) => {
  107. return (
  108. <span key={index}>
  109. <a
  110. onClick={() => {
  111. edit(text);
  112. }}
  113. >
  114. 编辑
  115. </a>
  116. <Divider type="vertical" />
  117. <Popconfirm
  118. title="确定删除该任务吗?"
  119. onConfirm={() => {
  120. confirm(e, text);
  121. }}
  122. // onCancel={cancel}
  123. okText="Yes"
  124. cancelText="No"
  125. >
  126. <a>删除</a>
  127. </Popconfirm>
  128. </span>
  129. );
  130. },
  131. },
  132. ];
  133. const tableSetting = {
  134. getRefresh: refresh => {
  135. localrefresh = refresh;
  136. },
  137. columnConfig: tableColumns,
  138. rowKey: 'id',
  139. batchBtns: [{ label: '添加', enabled: true, onClick: add, type: 'primary' }],
  140. };
  141. const formSetting = [
  142. {
  143. label: '事件标识',
  144. isRequired: true,
  145. type: 'input',
  146. key: 'eventType',
  147. maxLength: 50,
  148. placeholder: '2-50个字符',
  149. disabled: typeNum === 3,
  150. },
  151. {
  152. label: '事件名称',
  153. isRequired: true,
  154. type: 'input',
  155. key: 'eventName',
  156. maxLength: 50,
  157. placeholder: '2-50个字符',
  158. },
  159. {
  160. label: '备注',
  161. // isRequired: true,
  162. type: 'input',
  163. key: 'remarks',
  164. // maxLength: 50,
  165. // placeholder: '2-20个字符',
  166. },
  167. ];
  168. let getCheck = null;
  169. return (
  170. <>
  171. <FilterTable
  172. fetchApi={fetchApiGet}
  173. fetctWhenMount={true}
  174. filterSetting={filterSetting}
  175. tableSetting={tableSetting}
  176. apiUrl={apiUrl}
  177. />
  178. <Modal
  179. title="编辑"
  180. visible={visible}
  181. onOk={handleOk}
  182. confirmLoading={confirmLoading}
  183. onCancel={() => {
  184. setVisible(false);
  185. }}
  186. >
  187. <FormItem
  188. formSetting={formSetting}
  189. params={formParams}
  190. onChange={onParamsChange}
  191. getCheck={cb => (getCheck = cb)}
  192. />
  193. </Modal>
  194. </>
  195. );
  196. }