index.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. import React, { Component } from "react";
  2. import { Table, Spin, Button, message, Select, Modal, Icon } from "antd";
  3. import $ from "jquery/src/ajax";
  4. import moment from 'moment';
  5. import "./index.less";
  6. class Outbound extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. loading: false,
  11. pVisible: false,
  12. rVisible: false,
  13. tVisible: false,
  14. status: false,
  15. uList: [],
  16. tList: [],
  17. transAgent: "",
  18. mobile: '',
  19. info: {},
  20. dataSource: [],
  21. pagination: {
  22. defaultCurrent: 1,
  23. defaultPageSize: 10,
  24. showQuickJumper: true,
  25. pageSize: 10,
  26. onChange: function (page) {
  27. this.userCallList(page);
  28. }.bind(this),
  29. showTotal: function (total) {
  30. return '共' + total + '条数据';
  31. }
  32. },
  33. columns: [
  34. {
  35. title: '通话人',
  36. dataIndex: 'adminName',
  37. key: 'adminName',
  38. },
  39. {
  40. title: '联系人',
  41. dataIndex: 'contacts',
  42. key: 'contacts',
  43. },
  44. {
  45. title: '电话(尾号)',
  46. dataIndex: 'mobileLastDigits',
  47. key: 'mobileLastDigits',
  48. width: 100,
  49. },
  50. {
  51. title: '时长',
  52. dataIndex: 'duration',
  53. key: 'duration',
  54. render: (text) => {
  55. return this.isTime(text)
  56. }
  57. },
  58. {
  59. title: '时间',
  60. dataIndex: 'createTime',
  61. key: 'createTime',
  62. },
  63. ],
  64. };
  65. this.onOk = this.onOk.bind(this);
  66. this.blindTransferByAgent = this.blindTransferByAgent.bind(this);
  67. this.webSocket = null;
  68. }
  69. componentDidMount() {
  70. }
  71. componentWillUnmount() {
  72. }
  73. isTime(second) {
  74. let time = "0秒"
  75. if (second > 3600) {
  76. time = moment.utc(second * 1000).format('h小时m分s秒')
  77. } else if (second > 60) {
  78. time = moment.utc(second * 1000).format('m分s秒')
  79. } else {
  80. time = moment.utc(second * 1000).format('s秒')
  81. }
  82. return time
  83. }
  84. getWebSocket() {
  85. const _this = this
  86. if (typeof (WebSocket) == "undefined") {
  87. console.log('\x1b[31m您的浏览器不支持WebSocket\x1b[0m')
  88. } else {
  89. console.log('\x1b[32m您的浏览器支持WebSocket\x1b[0m')
  90. }
  91. // 测试
  92. // this.webSocket = new WebSocket('ws://uat.jishutao.com/webSocketServer');
  93. // 生产
  94. this.webSocket = new WebSocket('wss://bm.jishutao.com/webSocketServer');
  95. // 处理WebSocket打开事件
  96. this.webSocket.onopen = () => {
  97. console.log('WebSocke已打开');
  98. };
  99. // 处理收到消息的事件
  100. this.webSocket.onmessage = (event) => {
  101. const newMessage = event.data;
  102. console.log('WebSocke已连接', newMessage);
  103. _this.setState({
  104. status: false
  105. })
  106. // const newMessage = event.data;
  107. // this.setState((prevState) => ({
  108. // messages: [...prevState.messages, newMessage],
  109. // }));
  110. if (this.webSocket) {
  111. console.log("关闭WebSocket连接")
  112. this.webSocket.close();
  113. }
  114. };
  115. // 处理WebSocket关闭事件
  116. this.webSocket.onclose = () => {
  117. console.log('WebSocket已关闭');
  118. _this.setState({
  119. status: false
  120. })
  121. };
  122. // 处理WebSocket错误事件
  123. this.webSocket.onerror = (error) => {
  124. console.error('WebSocket出错了', error);
  125. _this.setState({
  126. status: false
  127. })
  128. };
  129. }
  130. onOk() {
  131. this.setState({
  132. status: true
  133. })
  134. this.callNumber()
  135. }
  136. // 公共库-默认联系人
  137. getDefaultMobile() {
  138. const { uid } = this.props
  139. $.ajax({
  140. method: "get",
  141. dataType: "json",
  142. crossDomain: false,
  143. url: globalConfig.context + "/api/admin/userOutbound/getDefaultMobile",
  144. data: {
  145. uid,
  146. }
  147. }).done(function (data) {
  148. if (!data.error.length) {
  149. if (data.data) {
  150. let mobile = data.data.mobile
  151. this.setState({
  152. pVisible: true,
  153. mobile,
  154. })
  155. } else {
  156. message.warning("暂无查询到联系人号码~")
  157. }
  158. } else {
  159. message.warning(data.error[0].message);
  160. };
  161. }.bind(this));
  162. }
  163. // 私有-客户联系方式列表
  164. findCustomerContacts() {
  165. const { uid } = this.props
  166. $.ajax({
  167. method: "get",
  168. dataType: "json",
  169. crossDomain: false,
  170. url: globalConfig.context + "/api/admin/customer/findCustomerContacts",
  171. data: {
  172. uid,
  173. }
  174. }).done(function (data) {
  175. if (!data.error.length) {
  176. let list = data.data || [];
  177. let mobile = "";
  178. if (list && list.length > 0) {
  179. for (var i = 0; i < list.length; i++) {
  180. if (list[i].major == 1) {
  181. mobile = list[i].mobile
  182. }
  183. }
  184. }
  185. this.setState({
  186. pVisible: true,
  187. mobile: mobile,
  188. uList: list,
  189. })
  190. } else {
  191. message.warning(data.error[0].message);
  192. };
  193. }.bind(this));
  194. }
  195. // 转移列表
  196. agentList() {
  197. $.ajax({
  198. method: "get",
  199. dataType: "json",
  200. crossDomain: false,
  201. url: globalConfig.context + "/api/admin/userOutbound/agentList",
  202. data: {}
  203. }).done(function (data) {
  204. if (!data.error.length) {
  205. let newList = data.data || []
  206. this.setState({
  207. transAgent: newList[0].callNo,
  208. tList: newList
  209. })
  210. } else {
  211. message.warning(data.error[0].message);
  212. };
  213. }.bind(this));
  214. }
  215. // 呼叫
  216. callNumber() {
  217. const { uid } = this.props
  218. const { mobile } = this.state
  219. $.ajax({
  220. method: "post",
  221. dataType: "json",
  222. crossDomain: false,
  223. url: globalConfig.context + "/api/admin/userOutbound/callNumber",
  224. data: {
  225. uid,
  226. callee: mobile,
  227. }
  228. }).done(function (data) {
  229. if (!data.error.length) {
  230. this.setState({
  231. pVisible: false
  232. })
  233. message.success(data.data)
  234. } else {
  235. message.warning(data.error[0].message);
  236. };
  237. }.bind(this));
  238. }
  239. // 呼叫转移
  240. blindTransferByAgent() {
  241. const { transAgent } = this.state
  242. const _this = this
  243. $.ajax({
  244. method: "post",
  245. dataType: "json",
  246. crossDomain: false,
  247. url: globalConfig.context + "/api/admin/userOutbound/blindTransferByAgent",
  248. data: {
  249. transAgent,
  250. }
  251. }).done(function (data) {
  252. if (!data.error.length) {
  253. _this.setState({
  254. tVisible: false
  255. })
  256. message.success(data.data)
  257. } else {
  258. message.warning(data.error[0].message);
  259. };
  260. }.bind(this));
  261. }
  262. // 通话记录
  263. userCallList(pageNo) {
  264. const { pagination } = this.state;
  265. const { uid } = this.props
  266. this.setState({
  267. loading: true,
  268. });
  269. $.ajax({
  270. method: "get",
  271. dataType: "json",
  272. crossDomain: false,
  273. url: globalConfig.context + "/api/admin/userOutbound/userCallList",
  274. data: {
  275. uid,
  276. pageNo: pageNo || 1,
  277. pageSize: pagination.pageSize,
  278. },
  279. success: function (data) {
  280. this.setState({
  281. loading: false,
  282. });
  283. if (data.error && data.error.length === 0) {
  284. if (data.data.page.list) {
  285. pagination.current = data.data.page.pageNo;
  286. pagination.total = data.data.page.totalCount;
  287. if (data.data.page && data.data.page.list && !data.data.page.list.length) {
  288. pagination.current = 0;
  289. pagination.total = 0;
  290. }
  291. this.setState({
  292. dataSource: data.data.page.list,
  293. pagination: this.state.pagination,
  294. pageNo: data.data.pageNo,
  295. info: data.data.sum
  296. });
  297. } else {
  298. this.setState({
  299. dataSource: data.data,
  300. pagination: false,
  301. });
  302. }
  303. } else {
  304. message.warning(data.error[0].message);
  305. }
  306. }.bind(this),
  307. }).always(
  308. function () {
  309. this.setState({
  310. loading: false,
  311. });
  312. }.bind(this)
  313. );
  314. }
  315. render() {
  316. const { status, pVisible, rVisible, tVisible, transAgent, tList, mobile, uList } = this.state
  317. const { type, } = this.props
  318. // history 只查看呼叫记录
  319. // private 私有呼叫,支持呼叫转移
  320. // public 公共库呼叫
  321. return (
  322. <span>
  323. {type != "history" &&
  324. <Button
  325. style={{ background: !status ? "green" : "red", border: 0 }}
  326. type="primary"
  327. loading={pVisible}
  328. onClick={() => {
  329. if (status) {
  330. return
  331. }
  332. this.getWebSocket();
  333. type == "public"
  334. ? this.getDefaultMobile()
  335. : this.findCustomerContacts()
  336. }}
  337. >{!pVisible && <Icon type="phone" />} {!status ? '呼叫' : '正在通话中'}</Button>}
  338. {type == "private" && status &&
  339. <Button
  340. style={{ background: "green", border: 0, marginLeft: 20 }}
  341. type="primary"
  342. onClick={() => {
  343. this.agentList();
  344. this.setState({ tVisible: true })
  345. }}
  346. ><Icon type="phone" /> 呼叫转移</Button>}
  347. <Button
  348. style={{ background: "green", border: 0, marginLeft: 20 }}
  349. type="primary"
  350. onClick={() => {
  351. this.userCallList();
  352. this.setState({ rVisible: true })
  353. }}
  354. ><Icon type="phone" /> 历史记录</Button>
  355. <Modal
  356. title="联系人电话"
  357. width={420}
  358. visible={pVisible}
  359. maskClosable={false}
  360. okText="呼叫"
  361. onOk={this.onOk}
  362. onCancel={() => {
  363. this.setState({
  364. pVisible: false
  365. })
  366. }}
  367. >
  368. <div className="contacts">
  369. <Select
  370. style={{ width: 200 }}
  371. value={mobile}
  372. onChange={e => {
  373. this.setState({
  374. mobile: e
  375. })
  376. }}
  377. >
  378. {
  379. uList.map(item =>
  380. <Select.Option value={item.mobile} key={item.id}>{item.mobile}</Select.Option>
  381. )
  382. }
  383. </Select>
  384. </div>
  385. </Modal>
  386. <Modal
  387. title="呼叫转移"
  388. width={420}
  389. visible={tVisible}
  390. maskClosable={false}
  391. okText="呼叫转移"
  392. onOk={this.blindTransferByAgent}
  393. onCancel={() => {
  394. this.setState({
  395. tVisible: false
  396. })
  397. }}
  398. >
  399. <div className="contacts">
  400. <Select
  401. style={{ width: 200 }}
  402. value={transAgent}
  403. onChange={(e) => {
  404. this.setState({
  405. transAgent: e
  406. })
  407. }}
  408. >
  409. {
  410. tList.map(item =>
  411. <Select.Option value={item.callNo} key={item.id}>{item.name}</Select.Option>
  412. )
  413. }
  414. </Select>
  415. </div>
  416. </Modal>
  417. <Modal
  418. title="历史记录"
  419. width={600}
  420. visible={rVisible}
  421. maskClosable={false}
  422. onCancel={() => {
  423. this.setState({
  424. rVisible: false
  425. })
  426. }}
  427. footer={null}
  428. >
  429. <div>
  430. <div style={{ marginBottom: 5 }}>公司名称:{this.state.info.name}</div>
  431. <div style={{ marginBottom: 10 }}>累计通话次数:{this.state.info.callCount}次&nbsp;&nbsp;&nbsp;&nbsp;通话时长:{this.isTime(this.state.info.callDuration)}</div>
  432. <Spin spinning={this.state.loading}>
  433. <Table
  434. size="middle"
  435. columns={this.state.columns}
  436. dataSource={this.state.dataSource}
  437. pagination={this.state.pagination}
  438. />
  439. </Spin>
  440. </div>
  441. </Modal>
  442. </span>
  443. );
  444. }
  445. }
  446. export default Outbound;