index.jsx 7.8 KB

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