contactPerson.jsx 9.8 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 "../../../../../../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. {/* 禁止管理员删除联系人 */}
  124. {/* {adminData.isSuperAdmin || !record.id? (
  125. <Popconfirm
  126. title="是否删除?"
  127. onConfirm={e => {
  128. this.confirmDelet(record);
  129. }}
  130. okText="删除"
  131. cancelText="不删除"
  132. >
  133. <Button
  134. style={{
  135. marginRight: "10px",
  136. color: "#ffffff",
  137. background: "#f00",
  138. border: "none"
  139. }}
  140. >
  141. 删除
  142. </Button>
  143. </Popconfirm>
  144. ) : (
  145. ""
  146. )} */}
  147. {record.major!=1 ? (
  148. <Button
  149. style={{
  150. marginRight: "10px",
  151. color: "#ffffff",
  152. background: "green",
  153. border: "none"
  154. }}
  155. onClick={e => {
  156. e.stopPropagation(), this.mainContact(record);
  157. }}
  158. >
  159. 设为主要联系人
  160. </Button>
  161. ) : (
  162. ""
  163. )}
  164. </div>
  165. );
  166. }
  167. }
  168. ]
  169. };
  170. },
  171. //tab2删除
  172. confirmDelet(e) {
  173. this.setState({
  174. loading: true
  175. });
  176. if (e.id) {
  177. $.ajax({
  178. method: "get",
  179. dataType: "json",
  180. crossDomain: false,
  181. url: globalConfig.context + "/api/admin/customer/deleteOneContact",
  182. data: {
  183. ocbId: e.id //删除的ID
  184. }
  185. }).done(
  186. function(data) {
  187. if (!data.error.length) {
  188. message.success("删除成功!");
  189. this.setState({
  190. loading: false
  191. });
  192. } else {
  193. message.warning(data.error[0].message);
  194. }
  195. this.contactLists();
  196. }.bind(this)
  197. );
  198. } else {
  199. this.contactLists();
  200. }
  201. },
  202. //选择主要联系人
  203. mainContact(record) {
  204. this.setState({
  205. loading: true
  206. });
  207. $.ajax({
  208. method: "get",
  209. dataType: "json",
  210. crossDomain: false,
  211. url: globalConfig.context + "/api/admin/customer/updateMainContact",
  212. data: {
  213. uid:this.props.data.id,
  214. ocbId: record.id
  215. }
  216. }).done(function(data) {
  217. if(!data.error.length) {
  218. message.success('设为主要联系人成功!');
  219. this.setState({
  220. loading: false,
  221. });
  222. } else {
  223. message.warning(data.error[0].message);
  224. };
  225. this.contactLists();
  226. }.bind(this));
  227. this.state.contactList.forEach(item => {
  228. item.major = 0;
  229. });
  230. record.major = 1;
  231. // console.log(record);
  232. this.setState({
  233. contactList: this.state.contactList
  234. });
  235. },
  236. //tab2获取联系人详情
  237. contactLists(ids) {
  238. this.setState({
  239. loading: true
  240. });
  241. $.ajax({
  242. method: "get",
  243. dataType: "json",
  244. crossDomain: false,
  245. url: globalConfig.context + "/api/admin/customer/findCustomerContacts",
  246. data: {
  247. uid: ids || this.props.data.id //名称1
  248. },
  249. success: function(data) {
  250. let theArr = [];
  251. if (data.error.length || data.data.list == "") {
  252. if (data.error && data.error.length) {
  253. message.warning(data.error[0].message);
  254. }
  255. } else {
  256. for (let i = 0; i < data.data.length; i++) {
  257. let thisdata = data.data[i];
  258. theArr.push({
  259. key: i,
  260. id: thisdata.id,
  261. name: thisdata.name,
  262. mobile: thisdata.mobile,
  263. email: thisdata.email,
  264. qq: thisdata.qq,
  265. wechat: thisdata.wechat,
  266. department: thisdata.department,
  267. position: thisdata.position,
  268. major: thisdata.major,
  269. createTimes:thisdata.createTimes,
  270. fixedTel:thisdata.fixedTel,
  271. aname:thisdata.aname,
  272. cityName:thisdata.provinceName+thisdata.cityName+thisdata.areaName
  273. });
  274. }
  275. }
  276. this.setState({
  277. contactList: theArr
  278. });
  279. }.bind(this)
  280. }).always(
  281. function() {
  282. this.setState({
  283. loading: false
  284. });
  285. }.bind(this)
  286. );
  287. },
  288. //新增
  289. //tab2新增联系人
  290. addcontact() {
  291. this.setState({
  292. addcontactModul: true
  293. });
  294. },
  295. componentWillMount() {
  296. this.contactLists(this.props.data.id);
  297. },
  298. detailsModal() {
  299. this.props.closeDetail(false, false);
  300. },
  301. componentWillReceiveProps(nextProps) {
  302. if (nextProps.data.id && nextProps.contactState) {
  303. this.contactLists(nextProps.data.id);
  304. }
  305. },
  306. render() {
  307. return (
  308. <div>
  309. <div className="clearfix">
  310. <Alert message="注:已保存信息不可修改,可新增正确的信息并设置为主要联系人" banner />
  311. <span
  312. style={{
  313. fontSize: 14,
  314. fontWeight: "bold",
  315. marginTop: 20,
  316. display: "inline-block",
  317. }}
  318. >
  319. 公司名称:{this.state.enterpriseName ? this.state.enterpriseName : this.props.name}
  320. <EnterpriseNameChange
  321. type='modify'
  322. changeOtherInfor
  323. style={{marginLeft:'20px'}}
  324. enterpriseId={this.props.data.uid}
  325. enterpriseName={this.props.name}
  326. data={this.props.data}
  327. onCancel={this.props.onCancel}
  328. onChangeSuccess={(value)=>{
  329. this.setState({
  330. enterpriseName:value
  331. })
  332. }}/>
  333. </span>
  334. <Button
  335. className="ContactsList"
  336. type="primary"
  337. onClick={this.addcontact}
  338. >
  339. 新增联系人
  340. </Button>
  341. </div>
  342. <div className="clearfix">
  343. <Spin spinning={this.state.loading}>
  344. <Table
  345. size="middle"
  346. pagination={false}
  347. columns={this.state.ContactsLists}
  348. dataSource={this.state.contactList}
  349. />
  350. </Spin>
  351. </div>
  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;