index.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. let obj1 = JSON.parse(JSON.stringify(this.state.searchValues));
  135. // console.log(obj1);
  136. data = Object.assign(data, obj1);
  137. if (this.props.exportExecProcessing) {
  138. data = this.props.exportExecProcessing(data);
  139. }
  140. // console.log(data);
  141. $.ajax({
  142. method: "get",
  143. dataType: "json",
  144. crossDomain: false,
  145. url: this.props.exportApi,
  146. data,
  147. success: function (data) {
  148. if (data.error.length === 0) {
  149. this.download(data.data);
  150. } else {
  151. message.warning(data.error[0].message);
  152. }
  153. }.bind(this),
  154. }).always(
  155. function () {
  156. loading();
  157. this.setState({
  158. exportPendingLoading: false,
  159. });
  160. }.bind(this)
  161. );
  162. }
  163. download(fileName) {
  164. window.location.href =
  165. globalConfig.context + "/open/download?fileName=" + fileName;
  166. }
  167. //获取上级组织
  168. selectSuperId() {
  169. this.setState({
  170. departmentLoading: true,
  171. });
  172. $.ajax({
  173. method: "get",
  174. dataType: "json",
  175. crossDomain: false,
  176. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  177. data: {},
  178. success: function (data) {
  179. let theArr = [];
  180. if (data.error && data.error.length === 0) {
  181. for (let i = 0; i < data.data.length; i++) {
  182. let theData = data.data[i];
  183. theArr.push({
  184. value: theData.id,
  185. label: theData.name,
  186. });
  187. }
  188. this.setState({
  189. contactsOption: theArr,
  190. });
  191. } else {
  192. message.warning(data.error[0].message);
  193. }
  194. }.bind(this),
  195. }).always(
  196. function () {
  197. this.setState({
  198. departmentLoading: false,
  199. });
  200. }.bind(this)
  201. );
  202. }
  203. componentDidMount() {
  204. this.loadData();
  205. if (this.props.searchList) {
  206. let arr = this.props.searchList.filter(
  207. (v) => v.type === "departmentSelect"
  208. );
  209. let arr1 = this.props.searchList.filter((v) => v.defaultValue);
  210. if (arr.length > 0) {
  211. // this.selectSuperId();
  212. }
  213. if (arr1.length > 0) {
  214. for (let i of arr1) {
  215. this.state.searchValues[i.dataKey] = i.defaultValue;
  216. }
  217. }
  218. }
  219. }
  220. resetAll() {
  221. for (let i of Object.keys(this.autoCompleteSearchRef)) {
  222. this.autoCompleteSearchRef[i].onReset();
  223. }
  224. let obj = this.props.query || {};
  225. this.setState(
  226. {
  227. searchValues: JSON.parse(JSON.stringify(obj)),
  228. },
  229. () => {
  230. this.Cascaders.empty();
  231. this.loadData();
  232. }
  233. );
  234. }
  235. //刷新页面
  236. onRefresh(lv) {
  237. if (lv) {
  238. this.loadData();
  239. } else {
  240. this.loadData(this.state.pageNo);
  241. }
  242. }
  243. changeList(arr) {
  244. const newArr = [];
  245. this.props.columns.forEach((item) => {
  246. arr.forEach((val) => {
  247. if (val === item.title) {
  248. newArr.push(item);
  249. }
  250. });
  251. });
  252. this.setState({
  253. changeList: newArr,
  254. });
  255. }
  256. render() {
  257. const { searchValues } = this.state;
  258. // console.log(this.props.searchList);
  259. return (
  260. <div>
  261. <Tabs defaultActiveKey="1" className="test">
  262. {this.props.searchList && (
  263. <TabPane tab="搜索" key="1">
  264. <div className="user-search" style={{ paddingTop: 10, paddingLeft: 10 }}>
  265. <Form layout="inline">
  266. {(this.props.searchList || []).map((v, k) => {
  267. return v.type === "text" ? (
  268. <FormItem label={v.title} key={k}>
  269. <Input
  270. placeholder={v.placeholder}
  271. value={
  272. searchValues[v.dataKey]
  273. ? searchValues[v.dataKey]
  274. : v.defaultValue || undefined
  275. }
  276. style={
  277. v.style ? v.style : { width: 150, }
  278. }
  279. onChange={(e) => {
  280. searchValues[v.dataKey] = e.target.value;
  281. this.setState({
  282. searchValues: searchValues,
  283. });
  284. }}
  285. />
  286. </FormItem>
  287. ) : v.type === "autoComplete" ? (
  288. <FormItem
  289. label={v.title}
  290. style={{ marginTop: "-8px" }}
  291. key={k}
  292. >
  293. <AutoCompleteSearch
  294. ref={(ref) => {
  295. (this.autoCompleteSearchRef[v.dataKey] = ref)
  296. }
  297. }
  298. value={searchValues[v.dataKey]}
  299. onSelect={(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, }
  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={{ 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={{ 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, }
  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. ) : v.type === "newDepartmentSelect" ? (
  438. <FormItem
  439. label={v.title}
  440. key={k}
  441. >
  442. <Cascaders
  443. ref={node => this.Cascaders = node}
  444. placeholder="请选择订单部门"
  445. id="id"
  446. name="name"
  447. children="list"
  448. height={28}
  449. onSel={(e) => {
  450. searchValues["deps"] = JSON.stringify(e);
  451. this.setState({
  452. searchValues: searchValues,
  453. });
  454. }}
  455. />
  456. </FormItem>
  457. ) : null;
  458. })}
  459. <Button
  460. type="primary"
  461. onClick={() => {
  462. this.loadData();
  463. }}
  464. style={{ marginRight: "10px", marginBottom: "10px" }}
  465. >
  466. 搜索
  467. </Button>
  468. <Button
  469. onClick={this.resetAll}
  470. style={{ marginRight: "10px", marginBottom: "10px" }}
  471. >
  472. 重置
  473. </Button>
  474. </Form>
  475. </div>
  476. </TabPane>
  477. )}
  478. <TabPane tab="更改表格显示数据" key="2">
  479. <div style={{ marginLeft: 10 }}>
  480. <ChooseList
  481. columns={this.props.columns}
  482. changeFn={this.changeList}
  483. changeList={this.state.changeList}
  484. top={55}
  485. margin={11}
  486. />
  487. </div>
  488. </TabPane>
  489. {this.props.exportApi ? (
  490. <TabPane tab="导出" key="3">
  491. <div style={{ float: "left" }}>
  492. <Button
  493. loading={this.state.exportPendingLoading}
  494. onClick={this.exportExec}
  495. style={{ margin: 10 }}
  496. >
  497. 导出excel
  498. </Button>
  499. </div>
  500. </TabPane>
  501. ) : ''}
  502. </Tabs>
  503. <div className="patent-table">
  504. <Spin spinning={this.state.loading}>
  505. <Table
  506. bordered
  507. size="middle"
  508. scroll={this.props.scroll}
  509. columns={
  510. this.state.changeList != undefined
  511. ? this.state.changeList
  512. : this.props.columns
  513. }
  514. onRowClick={this.props.onRowClick ? this.props.onRowClick : () => { }}
  515. dataSource={this.state.dataSource}
  516. pagination={this.state.pagination}
  517. />
  518. </Spin>
  519. </div>
  520. </div>
  521. );
  522. }
  523. }
  524. export default TabelContent;