Modal.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { iUserInfo } from '@/types/setting'
  2. import consts from '@/utils/consts'
  3. import { EyeInvisibleOutlined, EyeTwoTone } from '@ant-design/icons'
  4. import { Button, Form, Input, Modal, Select } from 'antd'
  5. import React, { useEffect, useState } from 'react'
  6. import { apiAccountDelete } from '../api'
  7. import styles from '../index.module.scss'
  8. import PswModal from './PswModal'
  9. const { Option } = Select
  10. export interface iUserModal {
  11. visible: boolean
  12. loading: boolean
  13. userInfo: iUserInfo
  14. onCreate: (values: any) => void
  15. onCancel: () => void
  16. initData: () => void
  17. }
  18. const userModal:React.FC<iUserModal> = ({ visible, loading, onCreate, onCancel, userInfo, initData }) => {
  19. const [ form ] = Form.useForm()
  20. const [ delLoading, setDelLoading ] = useState<boolean>(false)
  21. const [ showPswModal, setShowPswModal ] = useState<boolean>(false)
  22. useEffect(() => {
  23. form.setFieldsValue(userInfo)
  24. }, [ visible ])
  25. const delBtnHandler = async () => {
  26. setDelLoading(true)
  27. const { code = -1 } = await apiAccountDelete(userInfo.id)
  28. if (code === consts.RET_CODE.SUCCESS) {
  29. onCancel()
  30. initData()
  31. }
  32. setDelLoading(false)
  33. }
  34. return (
  35. <>
  36. <Modal
  37. getContainer={false}
  38. visible={visible}
  39. title={userInfo.id ? '编辑账号' : '新增账号'}
  40. onCancel={onCancel}
  41. footer={
  42. <div>
  43. {
  44. userInfo.id ?
  45. <>
  46. <Button size="small" danger onClick={() => delBtnHandler()} loading={delLoading}>删除账号</Button>
  47. <Button size="small" type="primary" ghost onClick={() => {
  48. onCancel()
  49. setShowPswModal(true)
  50. }}>修改账号/密码</Button>
  51. </>
  52. : ''
  53. }
  54. <Button size="small" className={styles.grayBtn} onClick={() => onCancel()}>关闭</Button>
  55. <Button size="small" type="primary" loading={loading} onClick={() => {
  56. form.validateFields().then(values => {
  57. form.resetFields()
  58. onCreate(values)
  59. })
  60. }}>{userInfo.id ? '提交修改' : '确认添加'}</Button>
  61. </div>
  62. }
  63. >
  64. <Form
  65. form={form}
  66. layout="vertical"
  67. className={styles.FormContent}
  68. >
  69. {
  70. userInfo.id ?
  71. <Form.Item name="id" hidden>
  72. <Input></Input>
  73. </Form.Item>
  74. : ''
  75. }
  76. <Form.Item name="accountGroup" label="账号组" rules={[ { required: true, message: '请选择账号组' } ]}>
  77. <Select
  78. showSearch
  79. placeholder="请选择"
  80. size="small"
  81. optionFilterProp="children"
  82. filterOption={(input, option) => option?.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}>
  83. <Option value={1}>建设单位</Option>
  84. <Option value={2}>监理单位</Option>
  85. <Option value={3}>施工单位</Option>
  86. <Option value={4}>设计单位</Option>
  87. </Select>
  88. </Form.Item>
  89. <Form.Item name="account" label="登录账号" rules={[ { required: true, message: '请输入登录账号' } ]}>
  90. <Input size="small" placeholder="支持英文数字组合" disabled={userInfo.id ? true : false}></Input>
  91. </Form.Item>
  92. {
  93. !userInfo.id ?
  94. <Form.Item name="password" label="登录密码" rules={[ { required: true, message: '请输入登录密码' } ]}>
  95. <Input.Password
  96. placeholder="密码支持英文数字及符号"
  97. addonAfter={<span>随机密码</span>}
  98. iconRender={visible => (visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />)}
  99. />
  100. </Form.Item>
  101. : ''
  102. }
  103. <Form.Item name="name" label="姓名" rules={[ { required: true, message: '请输入姓名' } ]}>
  104. <Input size="small"></Input>
  105. </Form.Item>
  106. <Form.Item name="company" label="单位名称" rules={[ { required: true, message: '请输入单位名称' } ]}>
  107. <Input size="small"></Input>
  108. </Form.Item>
  109. <Form.Item name="position" label="职位名称" rules={[ { required: true, message: '请输入职位名称' } ]}>
  110. <Input size="small"></Input>
  111. </Form.Item>
  112. <Form.Item name="mobile" label="手机" rules={[ { required: true, message: '请输入手机号码' } ]}>
  113. <Input size="small"></Input>
  114. </Form.Item>
  115. <Form.Item name="telephone" label="电话">
  116. <Input size="small" placeholder="格式000-0000000"></Input>
  117. </Form.Item>
  118. </Form>
  119. </Modal>
  120. <PswModal visible={showPswModal} onCancel={() => setShowPswModal(false)} userInfo={userInfo}></PswModal>
  121. </>
  122. )
  123. }
  124. export default userModal