index.jsx 17 KB

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