index.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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.data.level && this.props.data.level != 0) {
  150. Modal.warning({
  151. title: '系统提示',
  152. content: (
  153. <div>
  154. <p>请先设置客户类型。操作位置:</p>
  155. <p>1.勾选客户名称</p>
  156. <p>2.点击切换至“操作”项</p>
  157. <p>3.选择相应的客户类型即可。</p>
  158. </div>
  159. ),
  160. });
  161. return
  162. }
  163. if (this.props.type === 'journal') {
  164. this.loadData();
  165. }
  166. this.setState({
  167. visible: true
  168. })
  169. }}>
  170. {this.props.type === 'journal' ? '更改日志' : this.props.type === 'modify' ? '企业更名' : ''}
  171. </Button>
  172. {
  173. this.props.changeOtherInfor ?
  174. <InforChange
  175. enterpriseId={this.props.enterpriseId}
  176. type={this.props.type}
  177. data={this.props.data}
  178. onCancel={this.props.onCancel}
  179. /> : null
  180. }
  181. <Modal
  182. footer={null}
  183. maskClosable={false}
  184. width={this.props.type === 'journal' ? '900px' : this.props.type === 'modify' ? '300px' : ''}
  185. title={this.props.type === 'journal' ? '更名日志' : this.props.type === 'modify' ? '企业更名' : ''}
  186. visible={this.state.visible}
  187. onCancel={this.onCancel}>
  188. <div>
  189. {this.props.type === 'modify' ?
  190. <div className='enterpriseNameContent'>
  191. <div className='enterpriseNameItem'>
  192. <div className='enterpriseNameTitle'>更名前:</div>
  193. <div className='enterpriseNameValue'>{this.props.enterpriseName}</div>
  194. </div>
  195. <div className='enterpriseNameItem'>
  196. <div className='enterpriseNameTitle'>更名后:</div>
  197. <div className='enterpriseNameValue'>
  198. <Input
  199. value={this.state.enterpriseName}
  200. onChange={(e) => {
  201. this.setState({
  202. enterpriseName: e.target.value
  203. })
  204. }} />
  205. </div>
  206. </div>
  207. </div> : this.props.type === 'journal' ?
  208. <div>
  209. {this.state.initialName ? <div style={{ paddingBottom: '20px' }}>
  210. 初始客户名称:{this.state.initialName}
  211. </div> : null}
  212. <Spin spinning={this.state.loading} >
  213. <Table
  214. columns={this.state.colunmn}
  215. dataSource={this.state.dataSource}
  216. pagination={false}
  217. scroll={{ x: "max-content", y: 0 }}
  218. bordered
  219. size="small"
  220. />
  221. </Spin>
  222. </div> : null
  223. }
  224. {
  225. this.props.type === 'modify' ?
  226. <Popconfirm
  227. placement="top"
  228. title="确定要修改吗?"
  229. onConfirm={(e) => {
  230. e.stopPropagation();
  231. this.onOk();
  232. }}
  233. okText="确定"
  234. cancelText="取消"
  235. >
  236. <Button type='primary' onClick={this.handleCancel}>
  237. 确定修改
  238. </Button>
  239. </Popconfirm> : null
  240. }
  241. </div>
  242. </Modal>
  243. </span>
  244. )
  245. }
  246. }
  247. export default EnterpriseNameChange;