followDetail.jsx 15 KB

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