followDetail.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. import React from 'react'
  2. import ajax from 'jquery/src/ajax/xhr.js';
  3. import $ from 'jquery/src/ajax';
  4. import {Modal,Form,layout,Radio,Button,Input,Spin,Table,Select,Popconfirm,message} from 'antd';
  5. import {intentionalService,newFollow,customerStatus} from '@/dataDic.js';
  6. import {getCompanyIntention} from '@/tools.js';
  7. const FormItem =Form.Item;
  8. import AddContact from './followDetail/addContact.jsx';
  9. import BusName from './followDetail/businessName.jsx';
  10. const FollowDetail = React.createClass({
  11. getInitialState(){
  12. return{
  13. visitModul:false,
  14. loading:false,
  15. data:[],
  16. businessName:'',
  17. projectName:'',
  18. busModul:false,
  19. intentionList:[{
  20. title: '业务名称',
  21. dataIndex: 'businessGlossoryId',
  22. width:120,
  23. key: 'businessGlossoryId',
  24. render: (text, record, index) => {
  25. return (
  26. <div>
  27. {!record.id?<Select placeholder="选择业务名称" value={record.businessGlossoryId} onChange={(e) => { record.businessGlossoryId = e; this.setState({ data: this.state.data }); }}>
  28. {
  29. this.props.categoryArr.map(function (item) {
  30. return <Select.Option key={item.value} >{item.key}</Select.Option>
  31. })
  32. }
  33. </Select>:
  34. <span>{record.businessVarietiesName}</span>}
  35. </div>
  36. )
  37. }
  38. },
  39. {
  40. title: '项目名称',
  41. dataIndex: 'businessName',
  42. key:'businessName',
  43. width:120,
  44. render:(text,record,index)=>{
  45. return(
  46. <div>
  47. {!record.id?<div>
  48. <Button onClick={(e)=>{e.stopPropagation(),this.businessFn(record,index)}} type="small">{record.projectName}</Button>
  49. </div>:
  50. <span>{record.businessProjectName}</span>
  51. }
  52. </div>
  53. )
  54. }
  55. },
  56. {
  57. title: '最新进度',
  58. width:120,
  59. dataIndex: 'followSituation',
  60. key: 'followSituation',
  61. render: (text, record, index) => {
  62. if(text == 5 && !record.isEdit) {
  63. return (
  64. newFollow.map(function (item) {
  65. if(item.value == text) {
  66. return item.key
  67. }
  68. })
  69. )
  70. }else {
  71. return <Select placeholder="选择最新进度" value={record.followSituation} onChange={(e) => { record.followSituation = e; record.isEdit=true; this.setState({ data: this.state.data }); }}>
  72. {
  73. newFollow.map(function (item) {
  74. return <Select.Option key={item.value} >{item.key}</Select.Option>
  75. })
  76. }
  77. </Select>
  78. }
  79. }
  80. }, {
  81. title: '最新状态',
  82. width:120,
  83. dataIndex: 'customerStatus',
  84. key: 'customerStatus',
  85. render: (text, record, index) => {
  86. if(record.followSituation == 5 && !record.isEdit) {
  87. return (
  88. customerStatus.map(function (item) {
  89. if(item.value == text) {
  90. return item.key
  91. }
  92. })
  93. )
  94. }else {
  95. return <Select value={record.customerStatus} placeholder="选择最新状态" onChange={(e) => { record.customerStatus = e; this.setState({ data: this.state.data }); }}>
  96. {
  97. customerStatus.map(function (item) {
  98. return <Select.Option key={item.value} >{item.key}</Select.Option>
  99. })
  100. }
  101. </Select>
  102. }
  103. }
  104. }, {
  105. title: '跟进说明',
  106. width:120,
  107. dataIndex: 'remarks',
  108. key: 'remarks',
  109. render: (text, record, index) => {
  110. if(record.followSituation == 5 && !record.isEdit) {
  111. return (
  112. text
  113. )
  114. }else {
  115. return <Input value={record.remarks} placeholder="跟进说明"
  116. onChange={(e) => { record.remarks = e.target.value; this.setState({ data: this.state.data }); }}
  117. />
  118. }
  119. }
  120. }, {
  121. title: '操作',
  122. width:120,
  123. dataIndex: 'rrr',
  124. key: 'rrr',
  125. render: (text, record, index) => {
  126. return <div>
  127. {!record.id&&<Popconfirm title="是否删除?" onConfirm={(e)=>{this.intentionDelet(record,index)}} okText="删除" cancelText="不删除">
  128. <Button style={{marginRight:'10px',color:'#ffffff',background:'#f00',border:'none'}}>删除</Button>
  129. </Popconfirm>}
  130. </div>
  131. }
  132. }
  133. ],
  134. }
  135. },
  136. //选择子项目
  137. businessFn(record,index){
  138. if(!record.businessGlossoryId){
  139. message.warn('请先选择业务名称!');
  140. return;
  141. }
  142. this.setState({
  143. businessId:record.businessGlossoryId,
  144. busModul:true,
  145. index:index,
  146. addcontactModul:false
  147. })
  148. },
  149. closeBus(datas,e,s){
  150. this.state.addcontactModul=e;
  151. this.state.busModul=false;
  152. if(s){
  153. this.state.data[this.state.index].businessName=datas.id;
  154. this.state.data[this.state.index].projectName=datas.name;
  155. this.setState({
  156. busModul:false,
  157. data:this.state.data
  158. })
  159. }
  160. },
  161. //拜访意向服务列表单个删除
  162. intentionDelet(e, index) {
  163. let deteluserBusinessList = (this.state.data).splice(index, 1)
  164. this.setState({
  165. selectedRowKeys: [],
  166. });
  167. },
  168. //拜访modul函数
  169. visitOk(e) {
  170. this.setState({
  171. addcontactModul:false,
  172. visitModul: false
  173. });
  174. },
  175. visitCancel(e) {
  176. this.setState({
  177. addcontactModul:false,
  178. visitModul: false
  179. });
  180. this.props.closeDesc(false,false)
  181. },
  182. //获取联系人下拉框
  183. getNewWoman(ids) {
  184. this.state.data = []
  185. $.ajax({
  186. method: "get",
  187. dataType: "json",
  188. crossDomain: false,
  189. url: globalConfig.context + "/api/admin/customer/findCustomerContacts",
  190. data: {
  191. uid: ids,
  192. },
  193. success: function(data) {
  194. let theArr = [];
  195. let thedata = data.data;
  196. if(!thedata) {
  197. if(data.error && data.error.length) {
  198. message.warning(data.error[0].message);
  199. };
  200. thedata = {};
  201. };
  202. var telNum = [];
  203. var contactIds = [];
  204. thedata.map(function(item, index) {
  205. contactIds.push(thedata[index].id);
  206. telNum.push(thedata[index].mobile);
  207. });
  208. for(let item in data.data) {
  209. let theData = data.data[item];
  210. theArr.push(
  211. <Select.Option value={item} key={theData.name}>{theData.name}</Select.Option>
  212. );
  213. };
  214. this.setState({
  215. contactsIdArr: thedata,
  216. telNum: telNum,
  217. orderStatusOption: theArr,
  218. });
  219. }.bind(this),
  220. }).always(function() {
  221. this.setState({
  222. deletId: ids,
  223. loading: false
  224. });
  225. }.bind(this));
  226. },
  227. //刷新新增拜访记录刷新
  228. deletelist(e) {
  229. this.setState({
  230. loading:true
  231. });
  232. $.ajax({
  233. method: "get",
  234. dataType: "json",
  235. url: globalConfig.context + '/api/admin/customer/toAddFollowOnHistory',
  236. data: {
  237. uid: e,
  238. },
  239. success: function(data) {
  240. let listArr = [];
  241. let thedata = data.data;
  242. if(!thedata) {
  243. if(data.error && data.error.length) {
  244. message.warning(data.error[0].message);
  245. };
  246. thedata = {};
  247. };
  248. for(let i = 0; i < data.data.userBusinessList.length; i++) {
  249. let thisdata = data.data.userBusinessList[i];
  250. listArr.push({
  251. id: thisdata.businessId,
  252. businessName:thisdata.businessProjectId,
  253. businessGlossoryId:i,
  254. businessVarietiesName:thisdata.businessVarietiesName,
  255. businessProjectName:thisdata.businessProjectName,
  256. followSituation: String(thisdata.followSituation),
  257. customerStatus: String(thisdata.customerStatus),
  258. remarks: thisdata.remarks,
  259. });
  260. };
  261. this.setState({
  262. contacts: thedata.contacts,
  263. uid: thedata.uid,
  264. data: listArr,
  265. followTime: thedata.followTime,
  266. remarks: thedata.remarks,
  267. });
  268. }.bind(this),
  269. }).always(function() {
  270. this.setState({
  271. loading: false
  272. });
  273. }.bind(this));
  274. },
  275. //当选择联系人的列表变化时,则执行
  276. hundleName(e) {
  277. let changNub = this.state.telNum[e];
  278. this.setState({
  279. nub: this.state.telNum[e],
  280. lastName: e,
  281. });
  282. },
  283. //点击添加联系人
  284. newContacts() {
  285. this.setState({
  286. busModul:false,
  287. uids: this.state.uid,
  288. addcontactModul: true
  289. });
  290. },
  291. //页面刷新
  292. closeFollow(e, s) {
  293. this.state.addcontactModul=false;
  294. this.state.visitModul = true;
  295. if(s) {
  296. this.getNewWoman(this.props.followData.id);
  297. this.deletelist(this.props.followData.id)
  298. };
  299. },
  300. //详情保存
  301. visitSubmit(e){
  302. e.preventDefault();
  303. let GlossoryId=false;
  304. this.state.data.map(function(item) {
  305. if(!item.followSituation||!item.customerStatus||!item.businessName) {
  306. GlossoryId = true
  307. }
  308. })
  309. if(this.state.contactType == undefined) {
  310. message.warning('请选择拜访方式')
  311. return false;
  312. };
  313. if(this.state.lastName == undefined) {
  314. message.warning('请选择联系人')
  315. return false;
  316. }
  317. if(this.state.data.length&&GlossoryId) {
  318. message.warning("项目名称/最新进度/最新状态不能为空!")
  319. return false;
  320. };
  321. let dataList=this.state.data,
  322. idsList=[];
  323. dataList.map((item,index) => {
  324. idsList.push({
  325. businessId:item.id||'',
  326. businessProjectId:item.businessName,
  327. customerStatus:item.customerStatus,
  328. followSituation:item.followSituation,
  329. remarks:item.remarks||''
  330. })
  331. })
  332. this.setState({
  333. loading: true
  334. });
  335. let contactsId = '';
  336. let conts = this.state.lastName;
  337. contactsId = this.state.contactsIdArr[conts].id;
  338. //新增
  339. $.ajax({
  340. method: "post",
  341. dataType: "json",
  342. url: globalConfig.context + '/api/admin/customer/addFollow',
  343. data: {
  344. userBusinessList: JSON.stringify(idsList),
  345. uid: this.state.uid,
  346. ocbId: contactsId,
  347. contactType: this.state.contactType,
  348. result: this.state.result,
  349. followTime: this.state.followTime,
  350. }
  351. }).done(function(data) {
  352. this.setState({
  353. loading: false
  354. });
  355. if(!data.error.length) {
  356. message.success('保存成功!');
  357. this.props.closeDesc(false,true)
  358. this.visitCancel();
  359. } else {
  360. message.warning(data.error[0].message);
  361. }
  362. }.bind(this));
  363. },
  364. //添加新业务
  365. addNew(){
  366. this.state.data.push({
  367. isEdit: true,
  368. projectName:'选择',
  369. businessName:'',
  370. customerStatus: undefined,
  371. businessGlossoryId: undefined,
  372. followSituation: undefined,
  373. remarks: '',
  374. });
  375. this.setState({
  376. addcontactModul:false,
  377. data: this.state.data
  378. })
  379. },
  380. componentWillReceiveProps(nextProps) {
  381. if (nextProps.visitModul && nextProps.followData.id) {
  382. this.setState({
  383. result: '',
  384. contactType: undefined,
  385. visitModul: true,
  386. loading: true,
  387. lastName:undefined,
  388. nub:'',
  389. busModul:false,
  390. addcontactModul:false,
  391. })
  392. this.getNewWoman(nextProps.followData.id);
  393. this.deletelist(nextProps.followData.id)
  394. };
  395. },
  396. render() {
  397. const formItemLayout = {
  398. labelCol: { span: 8 },
  399. wrapperCol: { span: 14 },
  400. };
  401. return(
  402. <div>
  403. <Modal
  404. className="customeDetails"
  405. footer=''
  406. title="客户跟进详情"
  407. width='1000px'
  408. visible={this.state.visitModul}
  409. onOk={this.visitOk}
  410. onCancel={this.visitCancel}
  411. >
  412. <Form layout="horizontal" id="demand-form" onSubmit={this.visitSubmit}>
  413. <Spin spinning={this.state.loading}>
  414. <div className="clearfix">
  415. <FormItem
  416. labelCol={{ span: 4 }}
  417. wrapperCol={{ span: 20 }}
  418. label="跟进方式" >
  419. <Radio.Group value={this.state.contactType} onChange={(e) => {
  420. this.setState({ contactType: e.target.value })
  421. }}>
  422. <Radio value={0}>外出</Radio>
  423. <Radio value={1}>电话</Radio>
  424. <Radio value={2}>QQ</Radio>
  425. <Radio value={3}>微信</Radio>
  426. <Radio value={4}>邮箱</Radio>
  427. </Radio.Group>
  428. <span className="mandatory">*</span>
  429. </FormItem>
  430. <div className="clearfix">
  431. {this.state.contacts?<span></span>:
  432. <FormItem className="half-item"
  433. {...formItemLayout}
  434. label="联系人"
  435. >
  436. <Select placeholder="选择联系人" style={{ width: 140 }}
  437. value={this.state.lastName}
  438. onChange={this.hundleName}>
  439. {this.state.orderStatusOption}
  440. </Select>
  441. <span className="mandatory">*</span>
  442. </FormItem>
  443. }
  444. <FormItem className="half-item"
  445. {...formItemLayout}
  446. >
  447. <Button type="primary" onClick={this.newContacts} style={{marginLeft:'100px'}}>添加新联系人</Button>
  448. </FormItem>
  449. <FormItem className="half-item"
  450. {...formItemLayout}
  451. label="联系电话"
  452. >
  453. <span>{this.state.nub}</span>
  454. </FormItem>
  455. <FormItem className="half-item"
  456. {...formItemLayout}
  457. label="跟进时间"
  458. >
  459. <span>{this.state.followTime}</span>
  460. </FormItem>
  461. </div>
  462. <div className="clearfix">
  463. <FormItem
  464. labelCol={{ span: 4 }}
  465. wrapperCol={{ span: 16 }}
  466. label="跟进备注" >
  467. <Input type="textarea" rows={4} value={this.state.result}
  468. onChange={(e)=>{this.setState({result:e.target.value})}}/>
  469. </FormItem>
  470. </div>
  471. <div className="clearfix">
  472. <div style={{fontSize:'18px',marginLeft:'100px',marginTop:'15px',marginBottom:'10px'}}>业务意向<Button onClick={this.addNew} style={{marginLeft:'420px',background:'green',color:'#ffffff'}}>添加新业务</Button></div>
  473. <div className="clearfix" >
  474. <Spin spinning={this.state.loading}>
  475. <Table
  476. rowKey={record => record.id}
  477. pagination={false}
  478. columns={this.state.intentionList}
  479. dataSource={this.state.data}
  480. />
  481. </Spin>
  482. </div>
  483. </div>
  484. </div>
  485. <FormItem wrapperCol={{ span: 12, offset: 6 }}>
  486. <Button type="primary" size="large" htmlType="submit" style={{marginRight:'150px',marginTop:'20px'}}>保存</Button>
  487. <Button size="large" onClick={this.visitCancel}>取消</Button>
  488. </FormItem>
  489. </Spin>
  490. </Form>
  491. </Modal>
  492. <AddContact
  493. addcontactModul={this.state.addcontactModul}
  494. uids={this.state.uids}
  495. closeFollow={this.closeFollow}
  496. />
  497. <BusName
  498. businessId={this.state.businessId}
  499. mid={this.props.followData.id}
  500. busModul={this.state.busModul}
  501. closeBus={this.closeBus}
  502. />
  503. </div>
  504. )
  505. }
  506. })
  507. export default FollowDetail;