index.jsx 7.3 KB

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