detail.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import {
  4. Form, Button, Input, Select, Spin, Table,
  5. message, DatePicker, Tabs, TreeSelect
  6. } from 'antd';
  7. import moment from 'moment';
  8. import { ShowModal } from "@/tools";
  9. import { ChooseList } from "../../order/orderNew/chooseList";
  10. const { TabPane } = Tabs
  11. const { RangePicker } = DatePicker
  12. const OutboundDetail = Form.create()(React.createClass({
  13. getInitialState() {
  14. return {
  15. searchValues: {}, // 列表筛选条件
  16. loading: false, //加载动画
  17. changeList: undefined, // 更改后的表格显示数据
  18. dataSource: [], // 列表数据
  19. teamList: [], // 团队列表
  20. pagination: {
  21. defaultCurrent: 1,
  22. defaultPageSize: 10,
  23. showQuickJumper: true,
  24. pageSize: 10,
  25. onChange: function (page) {
  26. this.loadData(page);
  27. }.bind(this),
  28. showTotal: function (total) {
  29. return '共' + total + '条数据';
  30. }
  31. },
  32. columns: [
  33. {
  34. title: '姓名',
  35. dataIndex: 'name',
  36. key: 'name',
  37. },
  38. {
  39. title: '所属团队',
  40. dataIndex: 'teamName',
  41. key: 'teamName',
  42. },
  43. {
  44. title: '拨出次数',
  45. dataIndex: 'callSum',
  46. key: 'callSum',
  47. },
  48. {
  49. title: '接通次数',
  50. dataIndex: 'connectSum',
  51. key: 'connectSum',
  52. },
  53. {
  54. title: '有效次数',
  55. dataIndex: 'validSum',
  56. key: 'validSum',
  57. },
  58. {
  59. title: '时长',
  60. dataIndex: 'callDurationSum',
  61. key: 'callDurationSum',
  62. render: (text, record) => {
  63. return (
  64. <div>
  65. {this.isTime(text)}
  66. </div>
  67. )
  68. }
  69. },
  70. {
  71. title: '时间',
  72. dataIndex: 'dayDate',
  73. key: 'dayDate',
  74. },
  75. ],
  76. visible: "",
  77. };
  78. },
  79. componentWillMount() {
  80. this.salesTeam();
  81. let params = this.getParametersFromCookies();
  82. if (params.teamId) {
  83. const { searchValues } = this.state
  84. let obj = {
  85. teamId: Number(params.teamId),
  86. startTime: params.startTime,
  87. endTime: params.endTime,
  88. }
  89. this.setState({
  90. searchValues: Object.assign(searchValues, obj),
  91. }, () => {
  92. this.loadData();
  93. });
  94. } else {
  95. this.loadData();
  96. }
  97. },
  98. getParametersFromCookies() {
  99. let params = {};
  100. let ca = document.cookie.split(';');
  101. for (let i = 0; i < ca.length; i++) {
  102. let c = ca[i];
  103. while (c.charAt(0) === ' ') c = c.substring(1, c.length);
  104. let eqPos = c.indexOf('=');
  105. if (eqPos > -1) {
  106. let paramName = c.substring(0, eqPos);
  107. let paramValue = decodeURIComponent(c.substring(eqPos + 1));
  108. params[paramName] = paramValue;
  109. }
  110. }
  111. return params;
  112. },
  113. // 列表接口
  114. loadData(pageNo) {
  115. const { searchValues, pagination } = this.state;
  116. this.setState({
  117. loading: true,
  118. });
  119. let datas = Object.assign(searchValues, {
  120. pageNo: pageNo || 1,
  121. pageSize: pagination.pageSize,
  122. });
  123. $.ajax({
  124. method: "get",
  125. dataType: "json",
  126. crossDomain: false,
  127. url: globalConfig.context + "/api/admin/userOutbound/listCallDay",
  128. data: datas,
  129. success: function (data) {
  130. ShowModal(this);
  131. this.setState({
  132. loading: false,
  133. });
  134. let theArr = [];
  135. if (data.error && data.error.length === 0) {
  136. if (data.data) {
  137. pagination.current = data.data.pageNo;
  138. pagination.total = data.data.totalCount;
  139. if (data.data && data.data.list && !data.data.list.length) {
  140. pagination.current = 0
  141. pagination.total = 0
  142. };
  143. this.setState({
  144. dataSource: data.data.list,
  145. pagination: this.state.pagination,
  146. pageNo: data.data.pageNo,
  147. });
  148. }
  149. } else {
  150. message.warning(data.error[0].message);
  151. }
  152. }.bind(this),
  153. }).always(
  154. function () {
  155. this.setState({
  156. loading: false,
  157. });
  158. }.bind(this)
  159. );
  160. },
  161. // 团队
  162. salesTeam() {
  163. this.setState({
  164. loading: true
  165. });
  166. $.ajax({
  167. method: "get",
  168. dataType: "json",
  169. crossDomain: false,
  170. url: globalConfig.context + "/api/admin/salesTeam/lvlList",
  171. data: {},
  172. success: function (data) {
  173. this.setState({
  174. loading: false,
  175. });
  176. if (data.error && data.error.length === 0) {
  177. let list = data.data
  178. this.setState({
  179. teamList: list ? this.handleTreeData(list) : []
  180. });
  181. } else {
  182. message.warning(data.error[0].message);
  183. }
  184. }.bind(this),
  185. }).always(function () {
  186. this.setState({
  187. loading: false
  188. });
  189. }.bind(this));
  190. },
  191. // 树状默认数据处理
  192. handleTreeData(treeData) {
  193. let nodeDta = [];
  194. treeData.map(item => {
  195. let treeObj = {};
  196. treeObj.key = item.id
  197. treeObj.id = item.id
  198. treeObj.value = item.id
  199. treeObj.label = item.name
  200. treeObj.title = item.name
  201. treeObj.lvl = item.lvl
  202. item.list ? treeObj.children = this.handleTreeData(item.list) : null;
  203. nodeDta.push(treeObj)
  204. })
  205. return nodeDta
  206. },
  207. search() {
  208. this.loadData();
  209. },
  210. reset() {
  211. this.setState({
  212. searchValues: {}
  213. }, () => {
  214. this.loadData();
  215. })
  216. },
  217. changeList(arr) {
  218. const newArr = [];
  219. this.state.columns.forEach(item => {
  220. arr.forEach(val => {
  221. if (val === item.title) {
  222. newArr.push(item);
  223. }
  224. });
  225. });
  226. this.setState({
  227. changeList: newArr
  228. });
  229. },
  230. isTime(second) {
  231. let time = "0秒"
  232. if (second > 3600) {
  233. time = moment.utc(second * 1000).format('h小时m分s秒')
  234. } else if (second > 60) {
  235. time = moment.utc(second * 1000).format('m分s秒')
  236. } else if (second > 0) {
  237. time = moment.utc(second * 1000).format('s秒')
  238. }
  239. return time
  240. },
  241. render() {
  242. const { searchValues, teamList } = this.state
  243. return (
  244. <div className="user-content">
  245. <div className="content-title">
  246. <Tabs defaultActiveKey="1" onChange={this.callback} className="test">
  247. <TabPane tab="搜索" key="1">
  248. <div className="user-search" style={{ paddingBottom: 10 }}>
  249. <Input
  250. placeholder="请输入姓名"
  251. style={{ width: "180px" }}
  252. value={searchValues["name"]
  253. ? searchValues["name"]
  254. : ""}
  255. onChange={e => {
  256. searchValues["name"] = e.target.value;
  257. this.setState({
  258. searchValues: searchValues,
  259. });
  260. }}
  261. />
  262. <TreeSelect
  263. style={{ width: 180 }}
  264. value={searchValues["teamId"]
  265. ? searchValues["teamId"]
  266. : undefined}
  267. dropdownStyle={{ maxHeight: 300, overflow: 'auto' }}
  268. treeData={teamList}
  269. placeholder="请选择团队"
  270. showSearch
  271. treeNodeFilterProp="title"
  272. onChange={(e) => {
  273. searchValues["teamId"] = e;
  274. this.setState({
  275. searchValues,
  276. });
  277. }}
  278. />
  279. <Select
  280. placeholder="有效次数"
  281. style={{ width: 180 }}
  282. value={searchValues["quantityType"]
  283. ? searchValues["quantityType"]
  284. : undefined}
  285. onChange={e => {
  286. searchValues["quantityType"] = e;
  287. this.setState({
  288. searchValues,
  289. });
  290. }}
  291. >
  292. <Select.Option value={1}>10次以下</Select.Option>
  293. <Select.Option value={2}>10-20次</Select.Option>
  294. <Select.Option value={3}>20-50次</Select.Option>
  295. <Select.Option value={4}>50次以上</Select.Option>
  296. </Select>
  297. <RangePicker
  298. style={{ width: 300 }}
  299. value={[
  300. searchValues["startTime"] ? moment(searchValues["startTime"]) : null,
  301. searchValues["endTime"] ? moment(searchValues["endTime"]) : null,
  302. ]}
  303. onChange={(data, dataString) => {
  304. searchValues["startTime"] = dataString[0];
  305. searchValues["endTime"] = dataString[1];
  306. this.setState({
  307. searchValues,
  308. });
  309. }}
  310. />
  311. <Button
  312. type="primary"
  313. onClick={this.search}
  314. style={{ margin: "0 10px" }}
  315. >搜索</Button>
  316. <Button onClick={this.reset}>重置</Button>
  317. </div>
  318. </TabPane>
  319. <TabPane tab="更改表格显示数据" key="2">
  320. <div style={{ marginLeft: 10 }}>
  321. <ChooseList
  322. columns={this.state.columns}
  323. changeFn={this.changeList}
  324. changeList={this.state.changeList}
  325. top={55}
  326. margin={11}
  327. />
  328. </div>
  329. </TabPane>
  330. </Tabs>
  331. <div className="patent-table">
  332. <Spin spinning={this.state.loading}>
  333. <Table
  334. bordered
  335. columns={
  336. this.state.changeList
  337. ? this.state.changeList
  338. : this.state.columns
  339. }
  340. dataSource={this.state.dataSource}
  341. pagination={this.state.pagination}
  342. />
  343. </Spin>
  344. </div>
  345. </div>
  346. </div>
  347. );
  348. }
  349. }));
  350. export default OutboundDetail;