contactPerson.jsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. import React from "react";
  2. import {
  3. Table,
  4. Button,
  5. Spin,
  6. message,
  7. Popconfirm,
  8. Alert
  9. } from "antd";
  10. import $ from "jquery/src/ajax";
  11. import EnterpriseNameChange from "../../../../../../common/enterpriseNameChange";
  12. import AddContact from "../../followDetail/addContact";
  13. const ContactPerson = React.createClass({
  14. getInitialState() {
  15. return {
  16. loading: false,
  17. addcontactModul:false,
  18. ContactsLists: [
  19. {
  20. title: "姓名",
  21. dataIndex: "name",
  22. key: "name",
  23. render: (text, record, index) => {
  24. if(record.id) return <div>{text}</div>
  25. }
  26. },
  27. {
  28. title: "联系人部门",
  29. dataIndex: "department",
  30. key: "department",
  31. render: (text, record, index) => {
  32. if(record.id) return <div>{text}</div>
  33. }
  34. },
  35. {
  36. title: "联系人职务",
  37. dataIndex: "position",
  38. key: "position",
  39. render: (text, record, index) => {
  40. if(record.id) return <div>{text}</div>
  41. }
  42. },
  43. {
  44. title: "主要联系人",
  45. dataIndex: "major",
  46. width: 100,
  47. key: "major",
  48. render: text => {
  49. return text == 1 ? "是" : "否";
  50. }
  51. },
  52. {
  53. title: "地区",
  54. dataIndex: "cityName",
  55. key: "cityName",
  56. render: (text, record, index) => {
  57. if(record.id) return <div>{text}</div>
  58. }
  59. },
  60. {
  61. title: "手机号码",
  62. dataIndex: "mobile",
  63. key: "mobile",
  64. render: (text, record, index) => {
  65. if(record.id) return <div>{text}</div>
  66. }
  67. },
  68. {
  69. title: "座机",
  70. dataIndex: "fixedTel",
  71. key: "fixedTel",
  72. render: (text, record, index) => {
  73. if(record.id) return <div>{text}</div>
  74. }
  75. },
  76. {
  77. title: "微信",
  78. dataIndex: "wechat",
  79. key: "wechat",
  80. render: (text, record, index) => {
  81. if(record.id) return <div>{text}</div>
  82. }
  83. },
  84. {
  85. title: "联系人QQ",
  86. dataIndex: "qq",
  87. key: "qq",
  88. render: (text, record, index) => {
  89. if(record.id) return <div>{text}</div>
  90. }
  91. },
  92. {
  93. title: "电子邮箱",
  94. dataIndex: "email",
  95. key: "email",
  96. render: (text, record, index) => {
  97. if(record.id) return <div>{text}</div>
  98. }
  99. },
  100. {
  101. title: "更新时间",
  102. dataIndex: "createTimes",
  103. key: "createTimes",
  104. render: (text, record, index) => {
  105. if(record.id) return <div>{text}</div>
  106. }
  107. },
  108. {
  109. title: "跟进人",
  110. dataIndex: "aname",
  111. key: "aname",
  112. render: (text, record, index) => {
  113. if(record.id) return <div>{text}</div>
  114. }
  115. },
  116. {
  117. title: "操作",
  118. dataIndex: "dels",
  119. key: "dels",
  120. render: (text, record, index) => {
  121. return (
  122. <div>
  123. {adminData.isSuperAdmin || !record.id? (
  124. <Popconfirm
  125. title="是否删除?"
  126. onConfirm={e => {
  127. this.confirmDelet(record);
  128. }}
  129. okText="删除"
  130. cancelText="不删除"
  131. >
  132. <Button
  133. style={{
  134. marginRight: "10px",
  135. color: "#ffffff",
  136. background: "#f00",
  137. border: "none"
  138. }}
  139. >
  140. 删除
  141. </Button>
  142. </Popconfirm>
  143. ) : (
  144. ""
  145. )}
  146. {record.major!=1 ? (
  147. <Button
  148. style={{
  149. marginRight: "10px",
  150. color: "#ffffff",
  151. background: "green",
  152. border: "none"
  153. }}
  154. onClick={e => {
  155. e.stopPropagation(), this.mainContact(record);
  156. }}
  157. >
  158. 设为主要联系人
  159. </Button>
  160. ) : (
  161. ""
  162. )}
  163. </div>
  164. );
  165. }
  166. }
  167. ]
  168. };
  169. },
  170. //tab2删除
  171. confirmDelet(e) {
  172. this.setState({
  173. loading: true
  174. });
  175. if (e.id) {
  176. $.ajax({
  177. method: "get",
  178. dataType: "json",
  179. crossDomain: false,
  180. url: globalConfig.context + "/api/admin/customer/deleteOneContact",
  181. data: {
  182. ocbId: e.id //删除的ID
  183. }
  184. }).done(
  185. function(data) {
  186. if (!data.error.length) {
  187. message.success("删除成功!");
  188. this.setState({
  189. loading: false
  190. });
  191. } else {
  192. message.warning(data.error[0].message);
  193. }
  194. this.contactLists();
  195. }.bind(this)
  196. );
  197. } else {
  198. this.contactLists();
  199. }
  200. },
  201. //选择主要联系人
  202. mainContact(record) {
  203. this.setState({
  204. loading: true
  205. });
  206. $.ajax({
  207. method: "get",
  208. dataType: "json",
  209. crossDomain: false,
  210. url: globalConfig.context + "/api/admin/customer/updateMainContact",
  211. data: {
  212. uid:this.props.data.id,
  213. ocbId: record.id
  214. }
  215. }).done(function(data) {
  216. if(!data.error.length) {
  217. message.success('设为主要联系人成功!');
  218. this.setState({
  219. loading: false,
  220. });
  221. } else {
  222. message.warning(data.error[0].message);
  223. };
  224. this.contactLists();
  225. }.bind(this));
  226. this.state.contactList.forEach(item => {
  227. item.major = 0;
  228. });
  229. record.major = 1;
  230. // console.log(record);
  231. this.setState({
  232. contactList: this.state.contactList
  233. });
  234. },
  235. //tab2获取联系人详情
  236. contactLists(ids) {
  237. this.setState({
  238. loading: true
  239. });
  240. $.ajax({
  241. method: "get",
  242. dataType: "json",
  243. crossDomain: false,
  244. url: globalConfig.context + "/api/admin/customer/findCustomerContacts",
  245. data: {
  246. uid: ids || this.props.data.id //名称1
  247. },
  248. success: function(data) {
  249. let theArr = [];
  250. if (data.error.length || data.data.list == "") {
  251. if (data.error && data.error.length) {
  252. message.warning(data.error[0].message);
  253. }
  254. } else {
  255. for (let i = 0; i < data.data.length; i++) {
  256. let thisdata = data.data[i];
  257. theArr.push({
  258. key: i,
  259. id: thisdata.id,
  260. name: thisdata.name,
  261. mobile: thisdata.mobile,
  262. email: thisdata.email,
  263. qq: thisdata.qq,
  264. wechat: thisdata.wechat,
  265. department: thisdata.department,
  266. position: thisdata.position,
  267. major: thisdata.major,
  268. createTimes:thisdata.createTimes,
  269. fixedTel:thisdata.fixedTel,
  270. aname:thisdata.aname,
  271. cityName:thisdata.provinceName+thisdata.cityName+thisdata.areaName
  272. });
  273. }
  274. }
  275. this.setState({
  276. contactList: theArr
  277. });
  278. }.bind(this)
  279. }).always(
  280. function() {
  281. this.setState({
  282. loading: false
  283. });
  284. }.bind(this)
  285. );
  286. },
  287. //新增
  288. //tab2新增联系人
  289. addcontact() {
  290. this.setState({
  291. addcontactModul: true
  292. });
  293. },
  294. componentWillMount() {
  295. this.contactLists(this.props.data.id);
  296. },
  297. detailsModal() {
  298. this.props.closeDetail(false, false);
  299. },
  300. componentWillReceiveProps(nextProps) {
  301. if (nextProps.data.id && nextProps.contactState) {
  302. this.contactLists(nextProps.data.id);
  303. }
  304. },
  305. render() {
  306. return (
  307. <div>
  308. <div className="clearfix">
  309. <Alert message="注:已保存信息不可修改,可新增正确的信息并设置为主要联系人" banner />
  310. <span
  311. style={{
  312. fontSize: 14,
  313. fontWeight: "bold",
  314. marginTop: 20,
  315. display: "inline-block",
  316. }}
  317. >
  318. 公司名称:{this.state.enterpriseName ? this.state.enterpriseName : this.props.name}
  319. <EnterpriseNameChange
  320. type='modify'
  321. changeOtherInfor
  322. style={{marginLeft:'20px'}}
  323. enterpriseId={this.props.data.uid}
  324. enterpriseName={this.props.name}
  325. data={this.props.data}
  326. onChangeSuccess={(value)=>{
  327. this.setState({
  328. enterpriseName:value
  329. })
  330. }}/>
  331. </span>
  332. <Button
  333. className="ContactsList"
  334. type="primary"
  335. onClick={this.addcontact}
  336. >
  337. 新增联系人
  338. </Button>
  339. </div>
  340. <div className="clearfix">
  341. <Spin spinning={this.state.loading}>
  342. <Table
  343. size="middle"
  344. pagination={false}
  345. columns={this.state.ContactsLists}
  346. dataSource={this.state.contactList}
  347. />
  348. </Spin>
  349. </div>
  350. <AddContact
  351. addcontactModul={this.state.addcontactModul}
  352. uids={this.props.data.id}
  353. closeFollow={()=>{
  354. this.setState({
  355. addcontactModul:false
  356. },()=>{
  357. this.contactLists()
  358. })
  359. }}
  360. />
  361. </div>
  362. );
  363. }
  364. });
  365. export default ContactPerson;