inforChange.jsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. import React,{Component} from "react";
  2. import {AutoComplete, Button, Cascader, message, Modal, Popconfirm, Select, Spin, Table, Tag, Tooltip} from "antd";
  3. import { areaSelect,getProvince } from '@/NewDicProvinceList';
  4. import $ from "jquery/src/ajax";
  5. import TextArea from "antd/es/input/TextArea";
  6. class InforChange extends Component{
  7. constructor(props) {
  8. super(props);
  9. this.state={
  10. visible:false,
  11. changeType:0,
  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. inputVisible:false,
  43. inputValue:'',
  44. dataArrar:[],
  45. cooperationProjects:[],
  46. locationProvince:props.data.locationProvince,
  47. businessScope:props.data.businessScope,
  48. intendedProject:props.data.intendedProject
  49. }
  50. this.onChange = this.onChange.bind(this);
  51. this.onCancel = this.onCancel.bind(this);
  52. this.loadData = this.loadData.bind(this);
  53. this.onOk = this.onOk.bind(this);
  54. this.showInput = this.showInput.bind(this);
  55. this.handleInputConfirm = this.handleInputConfirm.bind(this);
  56. this.handleClose = this.handleClose.bind(this);
  57. this.handleCloseCooperation = this.handleCloseCooperation.bind(this);
  58. this.supervisor = this.supervisor.bind(this);
  59. this.onSelect = this.onSelect.bind(this);
  60. }
  61. onChange(type){
  62. this.setState({
  63. visible:true,
  64. changeType:type,
  65. })
  66. }
  67. onCancel(){
  68. this.setState({
  69. visible:false,
  70. loading:false,
  71. changeType:0,
  72. dataArrar:[]
  73. })
  74. }
  75. loadData() {
  76. this.setState({
  77. loading: true
  78. });
  79. $.ajax({
  80. method: "get",
  81. dataType: "json",
  82. crossDomain: false,
  83. url: globalConfig.context + "/api/admin/customer/listUserName",
  84. data: {
  85. uid: this.props.enterpriseId,
  86. },
  87. success: function (data) {
  88. if (data.error.length || data.data.list == "") {
  89. if (data.error && data.error.length) {
  90. message.warning(data.error[0].message);
  91. }
  92. } else {
  93. this.setState({
  94. initialName:data.data[0] ? data.data[0].name : ''
  95. })
  96. data.data.splice(0,1);
  97. this.setState({
  98. dataSource: data.data,
  99. });
  100. }
  101. }.bind(this),
  102. }).always(
  103. function () {
  104. this.setState({
  105. loading: false,
  106. });
  107. }.bind(this)
  108. );
  109. }
  110. onOk(){
  111. const {dataArrar} = this.state;
  112. if(this.state.changeType=== 0 && dataArrar.length === 0){
  113. message.warning('请输入省-市-区');
  114. return;
  115. }
  116. if(this.state.changeType=== 1 && dataArrar.length === 0){
  117. message.warning('请输入企业主管产品/服务');
  118. return;
  119. }
  120. if(this.state.changeType=== 2 && dataArrar.length === 0){
  121. message.warning('请输入意向合作项目');
  122. return;
  123. }
  124. this.setState({
  125. loading: true
  126. });
  127. let data ={
  128. uid:this.props.enterpriseId,
  129. }
  130. if(this.state.changeType=== 0){
  131. data.province = dataArrar[0] || undefined;
  132. data.city = dataArrar[1] || undefined;
  133. data.area = dataArrar[2] || undefined;
  134. }
  135. if(this.state.changeType=== 1){
  136. data.businessScope = dataArrar.join(',')
  137. }
  138. if(this.state.changeType=== 2){
  139. let arr = [];
  140. for(let i of dataArrar){
  141. arr.push(i.label)
  142. }
  143. data.intendedProject = arr.join(',')
  144. }
  145. $.ajax({
  146. url: globalConfig.context + "/api/admin/customer/updateUserDate",
  147. method: "post",
  148. data: data
  149. }).done(
  150. function(data) {
  151. this.setState({
  152. loading: false
  153. });
  154. if (data.error.length === 0) {
  155. message.success("恭喜您,更改成功!");
  156. if(this.state.changeType=== 0){
  157. this.setState({
  158. locationProvince:getProvince(dataArrar[0],dataArrar[1],dataArrar[2])
  159. })
  160. }
  161. if(this.state.changeType=== 1){
  162. this.setState({
  163. businessScope:dataArrar.join(',')
  164. })
  165. }
  166. if(this.state.changeType=== 2){
  167. let arr = [];
  168. for(let i of dataArrar){
  169. arr.push(i.label)
  170. }
  171. this.setState({
  172. intendedProject:arr.join(',')
  173. })
  174. }
  175. this.onCancel();
  176. }else{
  177. message.warning(data.error[0].message);
  178. }
  179. }.bind(this)
  180. )
  181. }
  182. showInput(){
  183. let str = this.state.dataArrar.join('/')
  184. this.setState({
  185. inputVisible: true,
  186. inputValue: str
  187. });
  188. }
  189. handleInputConfirm(){
  190. let inputValue = this.state.inputValue;
  191. let arr = inputValue.split('/');
  192. let lv = true;
  193. for(let i of arr){
  194. if(i.length > 16){
  195. message.warning('单个标签字数不能超过16个字符')
  196. lv = false;
  197. return;
  198. }
  199. }
  200. if(lv){
  201. arr = Array.from(new Set(arr));
  202. arr = arr.filter(v=>v);
  203. this.setState({
  204. dataArrar:arr,
  205. inputVisible: false,
  206. inputValue: '',
  207. });
  208. }
  209. }
  210. handleClose(removedTag){
  211. let dataArrar = this.state.dataArrar.filter(tag => {return tag !== removedTag});
  212. this.setState({ dataArrar });
  213. }
  214. handleCloseCooperation(removedTag){
  215. let dataArrar = this.state.dataArrar.filter(tag => {return tag.value !== removedTag.value});
  216. this.setState({ dataArrar });
  217. }
  218. supervisor(value) {
  219. $.ajax({
  220. method: "get",
  221. dataType: "json",
  222. crossDomain: false,
  223. url: globalConfig.context + '/api/admin/order/getBusinessProjectByName',
  224. data: {
  225. businessName: value
  226. },
  227. success: function (data) {
  228. let thedata = data.data;
  229. if (data.error.length === 0) {
  230. this.setState({
  231. cooperationProjects: thedata,
  232. });
  233. }else{
  234. message.warning(data.error[0].message);
  235. }
  236. }.bind(this),
  237. }).always(
  238. function () {
  239. }.bind(this)
  240. );
  241. }
  242. onSelect(value){
  243. let arr = this.state.cooperationProjects.filter(v=>v.id === value);
  244. let arr1 = this.state.dataArrar.filter(v=>v.value === value);
  245. if(arr.length > 0){
  246. if(arr1.length > 0){
  247. message.warning('选项已存在');
  248. }else{
  249. this.state.dataArrar.push({
  250. label: arr[0].bname,
  251. value: arr[0].id,
  252. })
  253. this.setState({
  254. dataArrar:this.state.dataArrar
  255. })
  256. }
  257. }
  258. }
  259. render() {
  260. return (
  261. <div style={{
  262. fontSize: 14,
  263. fontWeight: "bold",
  264. marginTop: 20,
  265. }}>
  266. <div style={{
  267. display:'flex',
  268. alignItems:'center',
  269. paddingBottom:'5px'
  270. }}>
  271. <div style={{width:'123px'}}>省-市-区:</div>
  272. <div>
  273. {
  274. this.state.locationProvince
  275. }
  276. </div>
  277. {this.props.type === 'modify' && <Button style={{marginLeft:'5px'}} type="primary" onClick={(e)=>{e.stopPropagation();this.onChange(0)}}>修改</Button>}
  278. </div>
  279. <div style={{
  280. display:'flex',
  281. alignItems:'center',
  282. paddingBottom:'5px'
  283. }}>
  284. <div style={{width:'123px'}}>企业主营产品/服务:</div>
  285. <div>
  286. {
  287. this.state.businessScope
  288. }
  289. </div>
  290. {this.props.type === 'modify' && <Button style={{marginLeft:'5px'}} type="primary" onClick={(e)=>{e.stopPropagation();this.onChange(1)}}>修改</Button>}
  291. </div>
  292. <div style={{
  293. display:'flex',
  294. alignItems:'center',
  295. paddingBottom:'5px'
  296. }}>
  297. <div style={{width:'123px'}}>意向合作项目:</div>
  298. <div>
  299. {
  300. this.state.intendedProject
  301. }
  302. </div>
  303. {this.props.type === 'modify' && <Button style={{marginLeft:'5px'}} type="primary" onClick={(e)=>{e.stopPropagation();this.onChange(2)}}>修改</Button>}
  304. </div>
  305. <Modal
  306. footer={null}
  307. maskClosable={false}
  308. width={this.props.type === 'journal' ? '1000px': this.props.type === 'modify' ? (this.state.changeType === 0 ? '300px' : '800px'): ''}
  309. title={this.props.type === 'journal' ? '操作日志': this.props.type === 'modify' ? '信息修改': ''}
  310. visible={this.state.visible}
  311. onCancel={this.onCancel}>
  312. <div>
  313. {this.props.type === 'modify' ?
  314. <div className='enterpriseNameContent'>
  315. <div className='enterpriseNameItem'>
  316. <div className='enterpriseNameTitle'>
  317. {
  318. this.state.changeType === 0 ? '省-市-区' :
  319. this.state.changeType === 1 ? '企业主管产品/服务' :
  320. this.state.changeType === 2 ? '意向合作项目' : ''
  321. }
  322. :
  323. </div>
  324. <div className='enterpriseNameValue'>
  325. {
  326. this.state.changeType === 0 ? this.state.locationProvince :
  327. this.state.changeType === 1 ? this.state.businessScope :
  328. this.state.changeType === 2 ? this.state.intendedProject : ''
  329. }
  330. </div>
  331. </div>
  332. <div className='enterpriseNameItem'>
  333. <div className='enterpriseNameTitle'>更改:</div>
  334. <div className='enterpriseNameValue'>
  335. {
  336. this.state.changeType === 0 ? <Cascader
  337. options={areaSelect()}
  338. placeholder="选择城市"
  339. onChange={(e, pre) => {
  340. this.setState({
  341. dataArrar:e
  342. })
  343. }}
  344. /> :
  345. this.state.changeType === 1 ?
  346. <div>
  347. <div>
  348. {this.state.dataArrar.map((tag) => {
  349. const isLongTag = tag.length > 20;
  350. const tagElem = (
  351. <Tag closable key={tag} afterClose={() => this.handleClose(tag)}>
  352. {isLongTag ? `${tag.slice(0, 20)}...` : tag}
  353. </Tag>
  354. );
  355. return isLongTag ? <Tooltip title={tag} key={tag}>{tagElem}</Tooltip> : tagElem;
  356. })}
  357. {
  358. !this.state.inputVisible &&
  359. <Button
  360. size="small"
  361. type="primary"
  362. onClick={this.showInput}>
  363. + 新增主营产品
  364. </Button>
  365. }
  366. </div>
  367. {this.state.inputVisible && (<div>
  368. <TextArea
  369. style={{width:'300px',height:'100px'}}
  370. value={this.state.inputValue}
  371. onChange={(e)=>{
  372. this.setState({
  373. inputValue: e.target.value
  374. })
  375. }}/>
  376. <div style={{color:'#f00'}}>提示:请用 / 符号隔开关键字</div>
  377. <div>
  378. <Button
  379. size="small"
  380. type="primary"
  381. onClick={this.handleInputConfirm}>
  382. 确定
  383. </Button>
  384. <Button
  385. size="small"
  386. style={{marginLeft:'5px'}}
  387. onClick={()=>{
  388. this.setState({
  389. inputVisible: false,
  390. inputValue: ''
  391. })
  392. }}>
  393. 取消
  394. </Button>
  395. </div>
  396. </div>)}
  397. </div>
  398. :
  399. this.state.changeType === 2 ?
  400. <div>
  401. <div style={{paddingBottom: this.state.dataArrar.length === 0 ? 0 : '10px'}}>
  402. {this.state.dataArrar.map((tag, index) => {
  403. const isLongTag = tag.label.length > 20;
  404. const tagElem = (
  405. <Tag closable key={tag.label} afterClose={() => this.handleCloseCooperation(tag)}>
  406. {isLongTag ? `${tag.label.slice(0, 20)}...` : tag.label}
  407. </Tag>
  408. );
  409. return isLongTag ? <Tooltip title={tag.label} key={tag.label}>{tagElem}</Tooltip> : tagElem;
  410. })}
  411. </div>
  412. <div>
  413. <AutoComplete
  414. style={{ width: 200 }}
  415. onSearch={this.supervisor}
  416. onSelect={this.onSelect}
  417. placeholder="请输入关键字"
  418. >
  419. {
  420. this.state.cooperationProjects.map(function (item) {
  421. return <Select.Option key={item.id} value={item.id}>{item.bname}</Select.Option>
  422. })
  423. }
  424. </AutoComplete>
  425. </div>
  426. </div>
  427. : ''
  428. }
  429. </div>
  430. </div>
  431. </div> : this.props.type === 'journal' ?
  432. <div>
  433. <Spin spinning={this.state.loading} >
  434. <Table
  435. columns={this.state.colunmn}
  436. dataSource={this.state.dataSource}
  437. pagination={false}
  438. scroll={{ x: "max-content", y: 0 }}
  439. bordered
  440. size="small"
  441. />
  442. </Spin>
  443. </div> : null
  444. }
  445. {
  446. this.props.type === 'modify' ?
  447. <Popconfirm placement="top" title="确定要修改吗?" onConfirm={(e)=>{
  448. e.stopPropagation();
  449. this.onOk();
  450. }} okText="确定" cancelText="取消">
  451. <Button type='primary'>
  452. 确定修改
  453. </Button>
  454. </Popconfirm> : null
  455. }
  456. </div>
  457. </Modal>
  458. </div>
  459. )
  460. }
  461. }
  462. export default InforChange;