index.jsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import React,{Component} from "react";
  2. import {Button, Input, message, Modal, Popconfirm, Spin, Table, Tooltip} from "antd";
  3. import './index.less';
  4. import $ from "jquery/src/ajax";
  5. class EnterpriseNameChange extends Component{
  6. constructor(props) {
  7. super(props);
  8. this.state={
  9. visible:false,
  10. enterpriseName:'',
  11. loading:false,
  12. colunmn: [
  13. {
  14. title: "操作人名称",
  15. dataIndex: "adminName",
  16. key: "adminName",
  17. },
  18. {
  19. title: "客户名称",
  20. dataIndex: "name",
  21. key: "name",
  22. width:150,
  23. render:(text)=>{
  24. return (
  25. <Tooltip title={text}>
  26. <div style={{
  27. maxWidth:'150px',
  28. overflow:'hidden',
  29. textOverflow: "ellipsis",
  30. whiteSpace:'nowrap',
  31. }}>{text}</div>
  32. </Tooltip>
  33. )
  34. }
  35. },
  36. {
  37. title: "操作时间",
  38. dataIndex: "createTimes",
  39. key: "createTimes",
  40. },
  41. ],
  42. dataSource:[]
  43. }
  44. this.onCancel = this.onCancel.bind(this);
  45. this.onOk = this.onOk.bind(this);
  46. }
  47. onCancel(){
  48. this.setState({
  49. visible:false,
  50. loading:false,
  51. })
  52. }
  53. onOk(){
  54. if(!this.state.enterpriseName){
  55. message.warning('请输入企业名称');
  56. return;
  57. }
  58. this.setState({
  59. loading: true
  60. });
  61. $.ajax({
  62. url: globalConfig.context + "/api/admin/customer/updateUserName",
  63. method: "post",
  64. data: {
  65. uid:this.props.enterpriseId,
  66. userName:this.state.enterpriseName
  67. }
  68. }).done(
  69. function(data) {
  70. this.setState({
  71. loading: false
  72. });
  73. if (data.error.length === 0) {
  74. message.success("恭喜您,更名成功!");
  75. this.setState({
  76. visible:false
  77. })
  78. this.props.onChangeSuccess(this.state.enterpriseName);
  79. }else{
  80. message.warning(data.error[0].message);
  81. }
  82. }.bind(this)
  83. )
  84. }
  85. loadData() {
  86. this.setState({
  87. loading: true
  88. });
  89. $.ajax({
  90. method: "get",
  91. dataType: "json",
  92. crossDomain: false,
  93. url: globalConfig.context + "/api/admin/customer/listUserName",
  94. data: {
  95. uid: this.props.enterpriseId,
  96. },
  97. success: function (data) {
  98. if (data.error.length || data.data.list == "") {
  99. if (data.error && data.error.length) {
  100. message.warning(data.error[0].message);
  101. }
  102. } else {
  103. this.setState({
  104. initialName:data.data[0] ? data.data[0].name : ''
  105. })
  106. data.data.splice(0,1);
  107. this.setState({
  108. dataSource: data.data,
  109. });
  110. }
  111. }.bind(this),
  112. }).always(
  113. function () {
  114. this.setState({
  115. loading: false,
  116. });
  117. }.bind(this)
  118. );
  119. }
  120. render() {
  121. return (
  122. <span className='enterpriseNameChange'>
  123. <Button
  124. type="primary"
  125. disabled={this.props.disabled}
  126. loading={this.state.loading}
  127. style={this.props.style}
  128. onClick={()=>{
  129. if(this.props.type === 'journal'){
  130. this.loadData();
  131. }
  132. this.setState({
  133. visible:true
  134. })
  135. }}>
  136. {this.props.type === 'journal' ? '更名日志': this.props.type === 'modify' ? '企业更名': ''}
  137. </Button>
  138. <Modal
  139. footer={null}
  140. maskClosable={false}
  141. width={this.props.type === 'journal' ? '1000px': this.props.type === 'modify' ? '300px': ''}
  142. title={this.props.type === 'journal' ? '更名日志': this.props.type === 'modify' ? '企业更名': ''}
  143. visible={this.state.visible}
  144. onCancel={this.onCancel}>
  145. <div>
  146. {this.props.type === 'modify' ?
  147. <div className='enterpriseNameContent'>
  148. <div className='enterpriseNameItem'>
  149. <div className='enterpriseNameTitle'>更名前:</div>
  150. <div className='enterpriseNameValue'>{this.props.enterpriseName}</div>
  151. </div>
  152. <div className='enterpriseNameItem'>
  153. <div className='enterpriseNameTitle'>更名后:</div>
  154. <div className='enterpriseNameValue'>
  155. <Input
  156. value={this.state.enterpriseName}
  157. onChange={(e) => {
  158. this.setState({
  159. enterpriseName: e.target.value
  160. })
  161. }} />
  162. </div>
  163. </div>
  164. </div> : this.props.type === 'journal' ?
  165. <div>
  166. {this.state.initialName ? <div style={{paddingBottom:'20px'}}>
  167. 初始客户名称:{this.state.initialName}
  168. </div> : null}
  169. <Spin spinning={this.state.loading} >
  170. <Table
  171. columns={this.state.colunmn}
  172. dataSource={this.state.dataSource}
  173. pagination={false}
  174. scroll={{ x: "max-content", y: 0 }}
  175. bordered
  176. size="small"
  177. />
  178. </Spin>
  179. </div> : null
  180. }
  181. {
  182. this.props.type === 'modify' ?
  183. <Popconfirm placement="top" title="确定要修改吗?" onConfirm={(e)=>{
  184. e.stopPropagation();
  185. this.onOk();
  186. }} okText="确定" cancelText="取消">
  187. <Button type='primary' onClick={this.handleCancel}>
  188. 确定修改
  189. </Button>
  190. </Popconfirm> : null
  191. }
  192. </div>
  193. </Modal>
  194. </span>
  195. )
  196. }
  197. }
  198. export default EnterpriseNameChange;