index.jsx 11 KB

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