contactPerson.jsx 9.9 KB

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