index.jsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import React, { Component } from "react";
  2. import { Button, Input, message, Modal, Popconfirm, Spin, Table, Tooltip } from "antd";
  3. import InforChange from './inforChange';
  4. import './index.less';
  5. import $ from "jquery/src/ajax";
  6. class EnterpriseNameChange extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. visible: false,
  11. enterpriseName: '',
  12. loading: false,
  13. colunmn: [
  14. {
  15. title: "操作人名称",
  16. dataIndex: "adminName",
  17. key: "adminName",
  18. },
  19. {
  20. title: "客户名称",
  21. dataIndex: "name",
  22. key: "name",
  23. render: (text) => {
  24. return (
  25. <Tooltip title={text}>
  26. <div
  27. // style={{
  28. // maxWidth: '150px',
  29. // overflow: 'hidden',
  30. // textOverflow: "ellipsis",
  31. // whiteSpace: 'nowrap',
  32. // }}
  33. >{text}</div>
  34. </Tooltip>
  35. )
  36. }
  37. },
  38. {
  39. title: "操作时间",
  40. dataIndex: "createTimes",
  41. key: "createTimes",
  42. },
  43. ],
  44. dataSource: []
  45. }
  46. this.onCancel = this.onCancel.bind(this);
  47. this.onOk = this.onOk.bind(this);
  48. }
  49. onCancel() {
  50. this.setState({
  51. visible: false,
  52. loading: false,
  53. })
  54. }
  55. onOk() {
  56. if (!this.state.enterpriseName) {
  57. message.warning('请输入企业名称!');
  58. return;
  59. }
  60. let re = new RegExp("^[\u4e00-\u9fa5]");
  61. if (!re.test(this.state.enterpriseName)) {
  62. message.warning('公司名称必须以汉字开头!')
  63. return
  64. }
  65. if (!re.test(this.state.enterpriseName.charAt(this.state.enterpriseName.length - 1))) {
  66. message.warning('公司名称必须以汉字结尾!')
  67. return
  68. }
  69. if (this.state.enterpriseName.length > 64) {
  70. message.warning('公司名称字数不超过64个!')
  71. return;
  72. };
  73. let regu = /[`~!#$%^&*'_[\]+=<>?:"{}|~!#¥%……&*=-@-!{}|/《》?:“”【】、;;‘’,,.。、\s+]/g;
  74. if (regu.test(this.state.enterpriseName)) {
  75. message.warning('公司名称不能存在特殊符号或空格!')
  76. return false;
  77. }
  78. this.setState({
  79. loading: true
  80. });
  81. $.ajax({
  82. url: globalConfig.context + "/api/admin/customer/updateUserName",
  83. method: "post",
  84. data: {
  85. uid: this.props.enterpriseId,
  86. userName: this.state.enterpriseName
  87. }
  88. }).done(
  89. function (data) {
  90. this.setState({
  91. loading: false
  92. });
  93. if (data.error.length === 0) {
  94. message.success("恭喜您,更名成功!");
  95. this.setState({
  96. visible: false
  97. })
  98. this.props.onChangeSuccess(this.state.enterpriseName);
  99. } else {
  100. message.warning(data.error[0].message);
  101. }
  102. }.bind(this)
  103. )
  104. }
  105. loadData() {
  106. this.setState({
  107. loading: true
  108. });
  109. $.ajax({
  110. method: "get",
  111. dataType: "json",
  112. crossDomain: false,
  113. url: globalConfig.context + "/api/admin/customer/listUserName",
  114. data: {
  115. uid: this.props.enterpriseId,
  116. },
  117. success: function (data) {
  118. if (data.error.length || data.data.list == "") {
  119. if (data.error && data.error.length) {
  120. message.warning(data.error[0].message);
  121. }
  122. } else {
  123. this.setState({
  124. initialName: data.data[0] ? data.data[0].name : ''
  125. })
  126. data.data.splice(0, 1);
  127. this.setState({
  128. dataSource: data.data,
  129. });
  130. }
  131. }.bind(this),
  132. }).always(
  133. function () {
  134. this.setState({
  135. loading: false,
  136. });
  137. }.bind(this)
  138. );
  139. }
  140. render() {
  141. return (
  142. <span className='enterpriseNameChange'>
  143. <Button
  144. type="primary"
  145. disabled={this.props.disabled}
  146. loading={this.state.loading}
  147. style={this.props.style}
  148. onClick={() => {
  149. if (this.props.type === 'journal') {
  150. this.loadData();
  151. }
  152. this.setState({
  153. visible: true
  154. })
  155. }}>
  156. {this.props.type === 'journal' ? '更改日志' : this.props.type === 'modify' ? '企业更名' : ''}
  157. </Button>
  158. {
  159. this.props.changeOtherInfor ?
  160. <InforChange
  161. enterpriseId={this.props.enterpriseId}
  162. type={this.props.type}
  163. data={this.props.data}
  164. onCancel={this.props.onCancel}
  165. /> : null
  166. }
  167. <Modal
  168. footer={null}
  169. maskClosable={false}
  170. width={this.props.type === 'journal' ? '900px' : this.props.type === 'modify' ? '300px' : ''}
  171. title={this.props.type === 'journal' ? '更名日志' : this.props.type === 'modify' ? '企业更名' : ''}
  172. visible={this.state.visible}
  173. onCancel={this.onCancel}>
  174. <div>
  175. {this.props.type === 'modify' ?
  176. <div className='enterpriseNameContent'>
  177. <div className='enterpriseNameItem'>
  178. <div className='enterpriseNameTitle'>更名前:</div>
  179. <div className='enterpriseNameValue'>{this.props.enterpriseName}</div>
  180. </div>
  181. <div className='enterpriseNameItem'>
  182. <div className='enterpriseNameTitle'>更名后:</div>
  183. <div className='enterpriseNameValue'>
  184. <Input
  185. value={this.state.enterpriseName}
  186. onChange={(e) => {
  187. this.setState({
  188. enterpriseName: e.target.value
  189. })
  190. }} />
  191. </div>
  192. </div>
  193. </div> : this.props.type === 'journal' ?
  194. <div>
  195. {this.state.initialName ? <div style={{ paddingBottom: '20px' }}>
  196. 初始客户名称:{this.state.initialName}
  197. </div> : null}
  198. <Spin spinning={this.state.loading} >
  199. <Table
  200. columns={this.state.colunmn}
  201. dataSource={this.state.dataSource}
  202. pagination={false}
  203. scroll={{ x: "max-content", y: 0 }}
  204. bordered
  205. size="small"
  206. />
  207. </Spin>
  208. </div> : null
  209. }
  210. {
  211. this.props.type === 'modify' ?
  212. <Popconfirm
  213. placement="top"
  214. title="确定要修改吗?"
  215. onConfirm={(e) => {
  216. e.stopPropagation();
  217. this.onOk();
  218. }}
  219. okText="确定"
  220. cancelText="取消"
  221. >
  222. <Button type='primary' onClick={this.handleCancel}>
  223. 确定修改
  224. </Button>
  225. </Popconfirm> : null
  226. }
  227. </div>
  228. </Modal>
  229. </span>
  230. )
  231. }
  232. }
  233. export default EnterpriseNameChange;