index.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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. };
  119. // 处理WebSocket错误事件
  120. this.webSocket.onerror = (error) => {
  121. console.error('WebSocket出错了', error);
  122. };
  123. }
  124. onOk() {
  125. this.setState({
  126. status: true
  127. })
  128. this.callNumber()
  129. }
  130. // 公共库-默认联系人
  131. getDefaultMobile() {
  132. const { uid } = this.props
  133. $.ajax({
  134. method: "get",
  135. dataType: "json",
  136. crossDomain: false,
  137. url: globalConfig.context + "/api/admin/userOutbound/getDefaultMobile",
  138. data: {
  139. uid,
  140. }
  141. }).done(function (data) {
  142. if (!data.error.length) {
  143. if (data.data) {
  144. let mobile = data.data.mobile
  145. this.setState({
  146. pVisible: true,
  147. mobile,
  148. })
  149. } else {
  150. message.warning("暂无查询到联系人号码~")
  151. }
  152. } else {
  153. message.warning(data.error[0].message);
  154. };
  155. }.bind(this));
  156. }
  157. // 私有-客户联系方式列表
  158. findCustomerContacts() {
  159. const { uid } = this.props
  160. $.ajax({
  161. method: "get",
  162. dataType: "json",
  163. crossDomain: false,
  164. url: globalConfig.context + "/api/admin/customer/findCustomerContacts",
  165. data: {
  166. uid,
  167. }
  168. }).done(function (data) {
  169. if (!data.error.length) {
  170. let list = data.data || [];
  171. let mobile = "";
  172. if (list && list.length > 0) {
  173. for (var i = 0; i < list.length; i++) {
  174. if (list[i].major == 1) {
  175. mobile = list[i].mobile
  176. }
  177. }
  178. }
  179. this.setState({
  180. pVisible: true,
  181. mobile: mobile,
  182. uList: list,
  183. })
  184. } else {
  185. message.warning(data.error[0].message);
  186. };
  187. }.bind(this));
  188. }
  189. // 转移列表
  190. agentList() {
  191. $.ajax({
  192. method: "get",
  193. dataType: "json",
  194. crossDomain: false,
  195. url: globalConfig.context + "/api/admin/userOutbound/agentList",
  196. data: {}
  197. }).done(function (data) {
  198. if (!data.error.length) {
  199. let newList = data.data || []
  200. this.setState({
  201. transAgent: newList[0].callNo,
  202. tList: newList
  203. })
  204. } else {
  205. message.warning(data.error[0].message);
  206. };
  207. }.bind(this));
  208. }
  209. // 呼叫
  210. callNumber() {
  211. const { uid } = this.props
  212. const { mobile } = this.state
  213. $.ajax({
  214. method: "post",
  215. dataType: "json",
  216. crossDomain: false,
  217. url: globalConfig.context + "/api/admin/userOutbound/callNumber",
  218. data: {
  219. uid,
  220. callee: mobile,
  221. }
  222. }).done(function (data) {
  223. if (!data.error.length) {
  224. this.setState({
  225. pVisible: false
  226. })
  227. message.success(data.data)
  228. } else {
  229. message.warning(data.error[0].message);
  230. };
  231. }.bind(this));
  232. }
  233. // 呼叫转移
  234. blindTransferByAgent() {
  235. const { transAgent } = this.state
  236. const _this = this
  237. $.ajax({
  238. method: "post",
  239. dataType: "json",
  240. crossDomain: false,
  241. url: globalConfig.context + "/api/admin/userOutbound/blindTransferByAgent",
  242. data: {
  243. transAgent,
  244. }
  245. }).done(function (data) {
  246. if (!data.error.length) {
  247. _this.setState({
  248. tVisible: false
  249. })
  250. message.success(data.data)
  251. } else {
  252. message.warning(data.error[0].message);
  253. };
  254. }.bind(this));
  255. }
  256. // 通话记录
  257. userCallList(pageNo) {
  258. const { pagination } = this.state;
  259. const { uid } = this.props
  260. this.setState({
  261. loading: true,
  262. });
  263. $.ajax({
  264. method: "get",
  265. dataType: "json",
  266. crossDomain: false,
  267. url: globalConfig.context + "/api/admin/userOutbound/userCallList",
  268. data: {
  269. uid,
  270. pageNo: pageNo || 1,
  271. pageSize: pagination.pageSize,
  272. },
  273. success: function (data) {
  274. this.setState({
  275. loading: false,
  276. });
  277. if (data.error && data.error.length === 0) {
  278. if (data.data.page.list) {
  279. pagination.current = data.data.page.pageNo;
  280. pagination.total = data.data.page.totalCount;
  281. if (data.data.page && data.data.page.list && !data.data.page.list.length) {
  282. pagination.current = 0;
  283. pagination.total = 0;
  284. }
  285. this.setState({
  286. dataSource: data.data.page.list,
  287. pagination: this.state.pagination,
  288. pageNo: data.data.pageNo,
  289. info: data.data.sum
  290. });
  291. } else {
  292. this.setState({
  293. dataSource: data.data,
  294. pagination: false,
  295. });
  296. }
  297. } else {
  298. message.warning(data.error[0].message);
  299. }
  300. }.bind(this),
  301. }).always(
  302. function () {
  303. this.setState({
  304. loading: false,
  305. });
  306. }.bind(this)
  307. );
  308. }
  309. render() {
  310. const { status, pVisible, rVisible, tVisible, transAgent, tList, mobile, uList } = this.state
  311. const { type, } = this.props
  312. return (
  313. <span>
  314. {type != "history" &&
  315. <Button
  316. style={{ background: !status ? "green" : "red", border: 0 }}
  317. type="primary"
  318. loading={pVisible}
  319. onClick={() => {
  320. if (status) {
  321. return
  322. }
  323. this.getWebSocket();
  324. type == "public"
  325. ? this.getDefaultMobile()
  326. : this.findCustomerContacts()
  327. }}
  328. >{!pVisible && <Icon type="phone" />} {!status ? '呼叫' : '正在通话中'}</Button>}
  329. {type == "private" && status &&
  330. <Button
  331. style={{ background: "green", border: 0, marginLeft: 20 }}
  332. type="primary"
  333. onClick={() => {
  334. this.agentList();
  335. this.setState({ tVisible: true })
  336. }}
  337. ><Icon type="phone" /> 呼叫转移</Button>}
  338. <Button
  339. style={{ background: "green", border: 0, marginLeft: 20 }}
  340. type="primary"
  341. onClick={() => {
  342. this.userCallList();
  343. this.setState({ rVisible: true })
  344. }}
  345. ><Icon type="phone" /> 历史记录</Button>
  346. <Modal
  347. title="联系人电话"
  348. width={420}
  349. visible={pVisible}
  350. maskClosable={false}
  351. okText="呼叫"
  352. onOk={this.onOk}
  353. onCancel={() => {
  354. this.setState({
  355. pVisible: false
  356. })
  357. }}
  358. >
  359. <div className="contacts">
  360. <Select
  361. style={{ width: 200 }}
  362. value={mobile}
  363. onChange={e => {
  364. this.setState({
  365. mobile: e
  366. })
  367. }}
  368. >
  369. {
  370. uList.map(item =>
  371. <Select.Option value={item.mobile} key={item.id}>{item.mobile}</Select.Option>
  372. )
  373. }
  374. </Select>
  375. </div>
  376. </Modal>
  377. <Modal
  378. title="呼叫转移"
  379. width={420}
  380. visible={tVisible}
  381. maskClosable={false}
  382. okText="呼叫转移"
  383. onOk={this.blindTransferByAgent}
  384. onCancel={() => {
  385. this.setState({
  386. tVisible: false
  387. })
  388. }}
  389. >
  390. <div className="contacts">
  391. <Select
  392. style={{ width: 200 }}
  393. value={transAgent}
  394. onChange={(e) => {
  395. this.setState({
  396. transAgent: e
  397. })
  398. }}
  399. >
  400. {
  401. tList.map(item =>
  402. <Select.Option value={item.callNo} key={item.id}>{item.name}</Select.Option>
  403. )
  404. }
  405. </Select>
  406. </div>
  407. </Modal>
  408. <Modal
  409. title="历史记录"
  410. width={600}
  411. visible={rVisible}
  412. maskClosable={false}
  413. onCancel={() => {
  414. this.setState({
  415. rVisible: false
  416. })
  417. }}
  418. footer={null}
  419. >
  420. <div>
  421. <div style={{ marginBottom: 5 }}>公司名称:{this.state.info.name}</div>
  422. <div style={{ marginBottom: 10 }}>累计通话次数:{this.state.info.callCount}次&nbsp;&nbsp;&nbsp;&nbsp;通话时长:{this.isTime(this.state.info.callDuration)}</div>
  423. <Spin spinning={this.state.loading}>
  424. <Table
  425. size="middle"
  426. columns={this.state.columns}
  427. dataSource={this.state.dataSource}
  428. pagination={this.state.pagination}
  429. />
  430. </Spin>
  431. </div>
  432. </Modal>
  433. </span>
  434. );
  435. }
  436. }
  437. export default Outbound;