index.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. import React, { Component } from "react";
  2. import {
  3. Form,
  4. Button,
  5. DatePicker,
  6. Input,
  7. message,
  8. Select,
  9. Spin,
  10. Table,
  11. Tabs,
  12. AutoComplete,
  13. } from "antd";
  14. import { ShowModal } from "@/tools";
  15. import { ChooseList } from "../../manageCenter/order/orderNew/chooseList";
  16. import $ from "jquery/src/ajax";
  17. import moment from "moment";
  18. import AutoCompleteSearch from "./autoCompleteSearch";
  19. import Cascaders from "../cascaders"
  20. const { TabPane } = Tabs;
  21. const { RangePicker, MonthPicker } = DatePicker;
  22. const FormItem = Form.Item;
  23. class TabelContent extends Component {
  24. constructor(props) {
  25. super(props);
  26. this.state = {
  27. changeList: undefined,
  28. dataSource: [],
  29. pagination: {
  30. defaultCurrent: 1,
  31. defaultPageSize: 10,
  32. showQuickJumper: true,
  33. pageSize: 10,
  34. onChange: function (page) {
  35. this.loadData(page);
  36. }.bind(this),
  37. showTotal: function (total) {
  38. return "共" + total + "条数据";
  39. },
  40. },
  41. searchValues: this.props.searchConfig || {},
  42. contactsOption: [],
  43. departmentLoading: false,
  44. };
  45. this.loadData = this.loadData.bind(this);
  46. this.resetAll = this.resetAll.bind(this);
  47. this.exportExec = this.exportExec.bind(this);
  48. this.selectSuperId = this.selectSuperId.bind(this);
  49. this.onRefresh = this.onRefresh.bind(this);
  50. this.changeList = this.changeList.bind(this);
  51. this.autoCompleteSearchRef = {};
  52. }
  53. loadData(pageNo) {
  54. this.setState({
  55. loading: true,
  56. });
  57. let searchInfor = {
  58. pageNo: pageNo || 1,
  59. pageSize: this.state.pagination.pageSize,
  60. };
  61. if (this.props.query) {
  62. let obj = JSON.parse(JSON.stringify(this.props.query));
  63. searchInfor = Object.assign(searchInfor, obj);
  64. }
  65. if (Object.keys(this.state.searchValues).length > 0) {
  66. let obj1 = JSON.parse(JSON.stringify(this.state.searchValues));
  67. searchInfor = Object.assign(searchInfor, obj1);
  68. for (let i in searchInfor) {
  69. if (searchInfor[i] == "" && i == "startTime") {
  70. delete searchInfor.startTime;
  71. } else if (searchInfor[i] == "" && i == "endTime") {
  72. delete searchInfor.endTime;
  73. }
  74. }
  75. }
  76. $.ajax({
  77. method: "get",
  78. dataType: "json",
  79. crossDomain: false,
  80. url: globalConfig.context + this.props.tabelApi,
  81. data: searchInfor,
  82. success: function (data) {
  83. ShowModal(this);
  84. this.setState({
  85. loading: false,
  86. });
  87. if (data.error && data.error.length === 0) {
  88. this.props.searchOperation && this.props.searchOperation(searchInfor);
  89. if (data.data.list) {
  90. this.state.pagination.current = data.data.pageNo;
  91. this.state.pagination.total = data.data.totalCount;
  92. if (data.data && data.data.list && !data.data.list.length) {
  93. this.state.pagination.current = 0;
  94. this.state.pagination.total = 0;
  95. }
  96. this.setState({
  97. dataSource: this.props.dataProcessing
  98. ? this.props.dataProcessing(data)
  99. : data.data.list,
  100. pagination: this.state.pagination,
  101. pageNo: data.data.pageNo,
  102. });
  103. } else {
  104. this.setState({
  105. dataSource: this.props.dataProcessing
  106. ? this.props.dataProcessing(data)
  107. : data.data,
  108. pagination: false,
  109. });
  110. }
  111. } else {
  112. message.warning(data.error[0].message);
  113. }
  114. }.bind(this),
  115. }).always(
  116. function () {
  117. this.setState({
  118. loading: false,
  119. });
  120. }.bind(this)
  121. );
  122. }
  123. exportExec() {
  124. // debugger
  125. // console.log(this.props.exportApi);
  126. message.config({
  127. duration: 20,
  128. });
  129. let loading = message.loading("下载中...");
  130. this.setState({
  131. exportPendingLoading: true,
  132. });
  133. let data = {
  134. province: this.props.query.province
  135. };
  136. let obj1 = JSON.parse(JSON.stringify(this.state.searchValues));
  137. // console.log(obj1);
  138. data = Object.assign(data, obj1);
  139. if (this.props.exportExecProcessing) {
  140. data = this.props.exportExecProcessing(data);
  141. }
  142. // console.log(data);
  143. $.ajax({
  144. method: "get",
  145. dataType: "json",
  146. crossDomain: false,
  147. url: this.props.exportApi,
  148. data,
  149. success: function (data) {
  150. if (data.error.length === 0) {
  151. this.download(data.data);
  152. } else {
  153. message.warning(data.error[0].message);
  154. }
  155. }.bind(this),
  156. }).always(
  157. function () {
  158. loading();
  159. this.setState({
  160. exportPendingLoading: false,
  161. });
  162. }.bind(this)
  163. );
  164. }
  165. download(fileName) {
  166. window.location.href =
  167. globalConfig.context + "/open/download?fileName=" + fileName;
  168. }
  169. //获取上级组织
  170. selectSuperId() {
  171. this.setState({
  172. departmentLoading: true,
  173. });
  174. $.ajax({
  175. method: "get",
  176. dataType: "json",
  177. crossDomain: false,
  178. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  179. data: {},
  180. success: function (data) {
  181. let theArr = [];
  182. if (data.error && data.error.length === 0) {
  183. for (let i = 0; i < data.data.length; i++) {
  184. let theData = data.data[i];
  185. theArr.push({
  186. value: theData.id,
  187. label: theData.name,
  188. });
  189. }
  190. this.setState({
  191. contactsOption: theArr,
  192. });
  193. } else {
  194. message.warning(data.error[0].message);
  195. }
  196. }.bind(this),
  197. }).always(
  198. function () {
  199. this.setState({
  200. departmentLoading: false,
  201. });
  202. }.bind(this)
  203. );
  204. }
  205. componentDidMount() {
  206. this.loadData();
  207. if (this.props.searchList) {
  208. let arr = this.props.searchList.filter(
  209. (v) => v.type === "departmentSelect"
  210. );
  211. let arr1 = this.props.searchList.filter((v) => v.defaultValue);
  212. if (arr.length > 0) {
  213. // this.selectSuperId();
  214. }
  215. if (arr1.length > 0) {
  216. for (let i of arr1) {
  217. this.state.searchValues[i.dataKey] = i.defaultValue;
  218. }
  219. }
  220. }
  221. }
  222. resetAll() {
  223. for (let i of Object.keys(this.autoCompleteSearchRef)) {
  224. this.autoCompleteSearchRef[i].onReset();
  225. }
  226. let obj = this.props.query || {};
  227. this.setState(
  228. {
  229. searchValues: JSON.parse(JSON.stringify(obj)),
  230. },
  231. () => {
  232. this.Cascaders.empty();
  233. this.loadData();
  234. }
  235. );
  236. }
  237. //刷新页面
  238. onRefresh(lv) {
  239. if (lv) {
  240. this.loadData();
  241. } else {
  242. this.loadData(this.state.pageNo);
  243. }
  244. }
  245. changeList(arr) {
  246. const newArr = [];
  247. this.props.columns.forEach((item) => {
  248. arr.forEach((val) => {
  249. if (val === item.title) {
  250. newArr.push(item);
  251. }
  252. });
  253. });
  254. this.setState({
  255. changeList: newArr,
  256. });
  257. }
  258. render() {
  259. const { searchValues } = this.state;
  260. // console.log(this.props.searchList);
  261. return (
  262. <div>
  263. <Tabs defaultActiveKey="1" className="test">
  264. {this.props.searchList && (
  265. <TabPane tab="搜索" key="1">
  266. <div className="user-search" style={{ paddingTop: 10, paddingLeft: 10 }}>
  267. <Form layout="inline">
  268. {(this.props.searchList || []).map((v, k) => {
  269. return v.type === "text" ? (
  270. <FormItem label={v.title} key={k}>
  271. <Input
  272. placeholder={v.placeholder}
  273. value={
  274. searchValues[v.dataKey]
  275. ? searchValues[v.dataKey]
  276. : v.defaultValue || undefined
  277. }
  278. style={
  279. v.style ? v.style : { width: 150, }
  280. }
  281. onChange={(e) => {
  282. searchValues[v.dataKey] = e.target.value;
  283. this.setState({
  284. searchValues: searchValues,
  285. });
  286. }}
  287. />
  288. </FormItem>
  289. ) : v.type === "autoComplete" ? (
  290. <FormItem
  291. label={v.title}
  292. style={{ marginTop: "-8px" }}
  293. key={k}
  294. >
  295. <AutoCompleteSearch
  296. ref={(ref) => {
  297. (this.autoCompleteSearchRef[v.dataKey] = ref)
  298. }
  299. }
  300. value={searchValues[v.dataKey]}
  301. onSelect={(value, title) => {
  302. searchValues[v.dataKey] = value;
  303. searchValues["aName"] = title;
  304. if (v.dataTitle) {
  305. searchValues[v.dataTitle] = title;
  306. }
  307. this.setState({
  308. searchValues: searchValues,
  309. });
  310. }}
  311. config={v}
  312. />
  313. </FormItem>
  314. ) : v.type === "select" || v.type === "departmentSelect" ? (
  315. <FormItem
  316. label={v.title}
  317. style={{ marginTop: "-8px" }}
  318. key={k}
  319. >
  320. <Spin spinning={this.state.departmentLoading}>
  321. {
  322. <Select
  323. placeholder={v.placeholder}
  324. style={
  325. v.style
  326. ? v.style
  327. : { width: 200, }
  328. }
  329. value={
  330. searchValues[v.dataKey]
  331. ? searchValues[v.dataKey]
  332. : v.defaultValue || undefined
  333. }
  334. onChange={(e) => {
  335. searchValues[v.dataKey] = String(e);
  336. if (v.type === "departmentSelect") {
  337. let arr = this.state.contactsOption.filter(
  338. (v) => String(v.value) === String(e)
  339. );
  340. searchValues["depName"] = arr[0].label;
  341. }
  342. this.setState({
  343. searchValues: searchValues,
  344. });
  345. }}
  346. >
  347. {v.selectOptionList
  348. ? v.selectOptionList()
  349. : (v.type === "departmentSelect"
  350. ? this.state.contactsOption
  351. : v.selectList
  352. ? typeof v.selectList === "function"
  353. ? v.selectList()
  354. : v.selectList
  355. : []
  356. ).map((v) => (
  357. <Select.Option
  358. key={v.value}
  359. value={v.value}
  360. >
  361. {v.label}
  362. </Select.Option>
  363. ))}
  364. </Select>
  365. }
  366. </Spin>
  367. </FormItem>
  368. ) : v.type === "times" ? (
  369. <FormItem label={v.title} key={k}>
  370. {v.format === "YYYY/MM" ? (
  371. <MonthPicker
  372. value={
  373. searchValues[v.dataKey]
  374. ? moment(searchValues[v.dataKey])
  375. : null
  376. }
  377. style={{ marginTop: "2px" }}
  378. onChange={(data, dataString) => {
  379. searchValues[v.dataKey] = String(dataString);
  380. this.setState({
  381. searchValues: searchValues,
  382. });
  383. }}
  384. />
  385. ) : (
  386. <RangePicker
  387. style={{ marginTop: "2px" }}
  388. value={[
  389. searchValues[v.dataKey[0]]
  390. ? moment(searchValues[v.dataKey[0]])
  391. : null,
  392. searchValues[v.dataKey[1]]
  393. ? moment(searchValues[v.dataKey[1]])
  394. : null,
  395. ]}
  396. onChange={(data, dataString) => {
  397. searchValues[v.dataKey[0]] = String(
  398. dataString[0]
  399. );
  400. searchValues[v.dataKey[1]] = String(
  401. dataString[1]
  402. );
  403. this.setState({
  404. searchValues: searchValues,
  405. });
  406. }}
  407. />
  408. )}
  409. </FormItem>
  410. ) : v.type === "types" ? (
  411. <FormItem
  412. label={v.title}
  413. key={k}
  414. style={{ bottom: "8px" }}
  415. >
  416. <Select
  417. placeholder={v.placeholder}
  418. style={
  419. v.style ? v.style : { width: 200, }
  420. }
  421. value={
  422. searchValues[v.dataKey]
  423. ? searchValues[v.dataKey]
  424. : v.defaultValue || undefined
  425. }
  426. onChange={(e) => {
  427. searchValues[v.dataKey] = String(e);
  428. // searchValues["statusName"] = arr[0].label;
  429. this.setState({
  430. searchValues: searchValues,
  431. });
  432. }}
  433. >
  434. <Option value="1">已完成法务/已回款</Option>
  435. <Option value="2">已完成法务/已诉讼</Option>
  436. <Option value="3">已完成法务/已坏账处理</Option>
  437. </Select>
  438. </FormItem>
  439. ) : v.type === "newDepartmentSelect" ? (
  440. <FormItem
  441. label={v.title}
  442. key={k}
  443. >
  444. <Cascaders
  445. ref={node => this.Cascaders = node}
  446. placeholder="请选择订单部门"
  447. id="id"
  448. name="name"
  449. children="list"
  450. height={28}
  451. onSel={(e) => {
  452. searchValues["deps"] = JSON.stringify(e);
  453. this.setState({
  454. searchValues: searchValues,
  455. });
  456. }}
  457. />
  458. </FormItem>
  459. ) : null;
  460. })}
  461. <Button
  462. type="primary"
  463. onClick={() => {
  464. this.loadData();
  465. }}
  466. style={{ marginRight: "10px", marginBottom: "10px" }}
  467. >
  468. 搜索
  469. </Button>
  470. <Button
  471. onClick={this.resetAll}
  472. style={{ marginRight: "10px", marginBottom: "10px" }}
  473. >
  474. 重置
  475. </Button>
  476. </Form>
  477. </div>
  478. </TabPane>
  479. )}
  480. <TabPane tab="更改表格显示数据" key="2">
  481. <div style={{ marginLeft: 10 }}>
  482. <ChooseList
  483. columns={this.props.columns}
  484. changeFn={this.changeList}
  485. changeList={this.state.changeList}
  486. top={55}
  487. margin={11}
  488. />
  489. </div>
  490. </TabPane>
  491. {this.props.exportApi ? (
  492. <TabPane tab="导出" key="3">
  493. <div style={{ float: "left" }}>
  494. <Button
  495. loading={this.state.exportPendingLoading}
  496. onClick={this.exportExec}
  497. style={{ margin: 10 }}
  498. >
  499. 导出excel
  500. </Button>
  501. </div>
  502. </TabPane>
  503. ) : ''}
  504. </Tabs>
  505. <div className="patent-table">
  506. <Spin spinning={this.state.loading}>
  507. <Table
  508. bordered
  509. size="middle"
  510. scroll={this.props.scroll}
  511. columns={
  512. this.state.changeList != undefined
  513. ? this.state.changeList
  514. : this.props.columns
  515. }
  516. onRowClick={this.props.onRowClick ? this.props.onRowClick : () => { }}
  517. dataSource={this.state.dataSource}
  518. pagination={this.state.pagination}
  519. />
  520. </Spin>
  521. </div>
  522. </div>
  523. );
  524. }
  525. }
  526. export default TabelContent;