index.tsx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. import {
  2. Button,
  3. Cascader,
  4. Form,
  5. Input,
  6. InputNumber,
  7. message,
  8. Modal,
  9. Select,
  10. } from "antd";
  11. import React, { useRef, useState } from "react";
  12. import styles from "./index.module.scss";
  13. import classNames from "classnames";
  14. import "./index.css";
  15. import { useSelector } from "react-redux";
  16. import { RootState } from "@/store";
  17. const { Option } = Select;
  18. type Props = {
  19. id: any;
  20. colsePage: any;
  21. };
  22. function ObjectAdd({ id, colsePage }: Props) {
  23. // 没有通过校验
  24. const onFinishFailed = () => {
  25. return message.warning("有表单不符号规则!");
  26. };
  27. // 通过校验之后发送请求
  28. const onFinish = async (values: any) => {
  29. console.log("具体质量的单位", danweiValue);
  30. console.log("--点击确定存到仓库", values);
  31. };
  32. // 选择商品信息还是附近(默认商品信息)
  33. const [titSelect, setTitSelect] = useState("tit1");
  34. // 从仓库中获取各下拉数据
  35. const options1 = useSelector(
  36. (state: RootState) => state.loginStore.selectAll["藏品编号名称"]
  37. );
  38. const options2 = useSelector(
  39. (state: RootState) => state.loginStore.selectAll["年代"]
  40. );
  41. const options3 = useSelector(
  42. (state: RootState) => state.loginStore.selectAll["质地"]
  43. );
  44. const options4 = useSelector(
  45. (state: RootState) => state.loginStore.selectAll["文物类别"]
  46. );
  47. const options5 = useSelector(
  48. (state: RootState) => state.loginStore.selectAll["文物级别"]
  49. );
  50. const options6 = useSelector(
  51. (state: RootState) => state.loginStore.selectAll["质量范围"]
  52. );
  53. const options7 = useSelector(
  54. (state: RootState) => state.loginStore.selectAll["完残程度"]
  55. );
  56. const options8 = useSelector(
  57. (state: RootState) => state.loginStore.selectAll["保存状态"]
  58. );
  59. // 单位选择
  60. const [danweiValue, setDanweiValue] = useState("kg");
  61. // 设置表单初始数据(区分编辑和新增)
  62. const defaultData = useRef<any>(null);
  63. if (id) {
  64. defaultData.current = {
  65. name1: "编辑",
  66. name3: "索书号",
  67. name5: ["其他"],
  68. };
  69. } else {
  70. defaultData.current = {
  71. name3: options1[0].name ? options1[0].name : null,
  72. name5: ["地质年代", "显生宙", "新生代", "第四纪"],
  73. name6: ["单一质地", "有机质", "竹"],
  74. name8: options4[0].name ? options4[0].name : null,
  75. name10: options5[0].name ? options5[0].name : null,
  76. name15: options6[0].name ? options6[0].name : null,
  77. name17: options7[0].name ? options7[0].name : null,
  78. };
  79. }
  80. return (
  81. <div className={styles.ObjectAdd}>
  82. <Modal
  83. wrapClassName="ObjectAdd"
  84. destroyOnClose
  85. open={true}
  86. title={id ? "编辑藏品" : "添加藏品"}
  87. footer={
  88. [] // 设置footer为空,去掉 取消 确定默认按钮
  89. }
  90. >
  91. {/* 商品信息和附件切换 */}
  92. <div className="ObjectAddTit">
  93. <div
  94. onClick={() => setTitSelect("tit1")}
  95. className={classNames(titSelect === "tit1" ? "active" : "")}
  96. >
  97. 商品信息
  98. </div>
  99. <div
  100. onClick={() => setTitSelect("tit2")}
  101. className={classNames(
  102. "ObjectAddTitTow",
  103. titSelect === "tit2" ? "active" : ""
  104. )}
  105. >
  106. 附件
  107. </div>
  108. </div>
  109. <Form
  110. name="basic"
  111. onFinish={onFinish}
  112. onFinishFailed={onFinishFailed}
  113. autoComplete="off"
  114. initialValues={defaultData.current}
  115. >
  116. <div className="formRow">
  117. <Form.Item
  118. label="藏品名称"
  119. name="name1"
  120. rules={[{ required: true, message: "不能为空!" }]}
  121. >
  122. <Input maxLength={50} showCount placeholder="请输入" />
  123. </Form.Item>
  124. <Form.Item label="原名" name="name2">
  125. <Input maxLength={50} showCount placeholder="请输入" />
  126. </Form.Item>
  127. </div>
  128. <div className="formRow">
  129. <div className="bs">*</div>
  130. <Form.Item label="藏品编号名称" name="name3">
  131. <Select
  132. placeholder="请选择"
  133. options={options1.map((v: any) => ({
  134. label: v.name,
  135. value: v.name,
  136. }))}
  137. />
  138. </Form.Item>
  139. <Form.Item label="藏品编号" name="name4">
  140. <Input maxLength={50} showCount placeholder="请输入" />
  141. </Form.Item>
  142. </div>
  143. <div className="formRow">
  144. <div className="bs bs2">*</div>
  145. <div className="bs bs3">*</div>
  146. <Form.Item label="年代" name="name5">
  147. <Cascader
  148. allowClear={false}
  149. fieldNames={{
  150. label: "name",
  151. value: "name",
  152. children: "children",
  153. }}
  154. options={options2}
  155. placeholder="请选择"
  156. />
  157. </Form.Item>
  158. <Form.Item label="文物质地" name="name6">
  159. <Cascader
  160. allowClear={false}
  161. fieldNames={{
  162. label: "name",
  163. value: "name",
  164. children: "children",
  165. }}
  166. options={options3}
  167. placeholder="请选择"
  168. />
  169. </Form.Item>
  170. </div>
  171. <div className="formRow">
  172. <div className="bs bs3">*</div>
  173. <Form.Item label="具体年代" name="name7">
  174. <Input maxLength={50} showCount placeholder="请输入" />
  175. </Form.Item>
  176. <Form.Item label="文物类别" name="name8">
  177. <Select
  178. placeholder="请选择"
  179. options={options4.map((v: any) => ({
  180. label: v.name,
  181. value: v.name,
  182. }))}
  183. />
  184. </Form.Item>
  185. </div>
  186. <div className="formRow">
  187. <div className="bs bs3">*</div>
  188. <Form.Item
  189. rules={[{ required: true, message: "不能为空!" }]}
  190. label="实际数量"
  191. name="name9"
  192. >
  193. <InputNumber maxLength={8} placeholder="请输入数字" />
  194. </Form.Item>
  195. <Form.Item label="文物级别" name="name10">
  196. <Select
  197. placeholder="请选择"
  198. options={options5.map((v: any) => ({
  199. label: v.name,
  200. value: v.name,
  201. }))}
  202. />
  203. </Form.Item>
  204. </div>
  205. <div className="formRow formRowThree">
  206. <Form.Item
  207. rules={[{ required: true, message: "不能为空!" }]}
  208. label="外形尺寸"
  209. name="name11"
  210. >
  211. <InputNumber maxLength={8} placeholder="通长" addonAfter="cm" />
  212. </Form.Item>
  213. <Form.Item
  214. rules={[{ required: true, message: "不能为空!" }]}
  215. label=""
  216. name="name12"
  217. >
  218. <InputNumber maxLength={8} placeholder="通宽" addonAfter="cm" />
  219. </Form.Item>
  220. <Form.Item
  221. className="formRowThreeRow"
  222. rules={[{ required: true, message: "不能为空!" }]}
  223. label=""
  224. name="name13"
  225. >
  226. <InputNumber maxLength={8} placeholder="通高" addonAfter="cm" />
  227. </Form.Item>
  228. </div>
  229. <div className="formRow formRowFull">
  230. <Form.Item
  231. label="具体尺寸"
  232. name="name14"
  233. rules={[{ required: true, message: "不能为空!" }]}
  234. >
  235. <Input maxLength={50} showCount placeholder="请输入" />
  236. </Form.Item>
  237. </div>
  238. <div className="formRow">
  239. <div className="bs bs4">*</div>
  240. <Form.Item label="质量范围" name="name15">
  241. <Select
  242. placeholder="请选择"
  243. options={options6.map((v: any) => ({
  244. label: v.name,
  245. value: v.name,
  246. }))}
  247. />
  248. </Form.Item>
  249. <Form.Item className="formRowSelec" label="具体质量" name="name16">
  250. <InputNumber
  251. maxLength={8}
  252. placeholder="请输入"
  253. addonAfter={
  254. <Select
  255. value={danweiValue}
  256. onChange={(val) => setDanweiValue(val)}
  257. >
  258. <Option value="kg">kg</Option>
  259. <Option value="g">g</Option>
  260. </Select>
  261. }
  262. />
  263. {/* <div className="formRowSelecSon">
  264. </div> */}
  265. </Form.Item>
  266. </div>
  267. <div className="formRow">
  268. <div className="bs bs4">*</div>
  269. <Form.Item label="完残程度" name="name17">
  270. <Select
  271. placeholder="请选择"
  272. options={options7.map((v: any) => ({
  273. label: v.name,
  274. value: v.name,
  275. }))}
  276. />
  277. </Form.Item>
  278. <Form.Item label="保存状态" name="name18">
  279. <Select
  280. placeholder="请选择"
  281. options={options8.map((v: any) => ({
  282. label: v.name,
  283. value: v.name,
  284. }))}
  285. />
  286. </Form.Item>
  287. </div>
  288. <br />
  289. <Form.Item wrapperCol={{ offset: 20 }}>
  290. <Button onClick={colsePage}>取消</Button>
  291. &emsp;
  292. <Button type="primary" htmlType="submit">
  293. 确定
  294. </Button>
  295. </Form.Item>
  296. </Form>
  297. </Modal>
  298. </div>
  299. );
  300. }
  301. const MemoObjectAdd = React.memo(ObjectAdd);
  302. export default MemoObjectAdd;