index.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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: "10px" }}>
  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, marginRight: 10 }
  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. // console.log(ref);
  296. (this.autoCompleteSearchRef[v.dataKey] = ref)
  297. }
  298. }
  299. value={searchValues[v.dataKey]}
  300. onSelect={(value, title) => {
  301. // console.log(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, marginRight: 10 }
  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={{ marginRight: "10px", 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={{ marginRight: "10px", 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, marginRight: 10 }
  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;