index.jsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. import React,{Component} from "react";
  2. import {Form, Button, DatePicker, Input, message, Select, Spin, Table, Tabs, AutoComplete} from "antd";
  3. import {
  4. ShowModal,
  5. } from "@/tools";
  6. import {ChooseList} from "../../manageCenter/order/orderNew/chooseList";
  7. import $ from "jquery/src/ajax";
  8. import moment from "moment";
  9. import AutoCompleteSearch from './autoCompleteSearch';
  10. const {TabPane} = Tabs;
  11. const { RangePicker,MonthPicker } = DatePicker;
  12. const FormItem = Form.Item
  13. class TabelContent extends Component{
  14. constructor(props) {
  15. super(props);
  16. this.state={
  17. changeList:[],
  18. dataSource:[],
  19. pagination: {
  20. defaultCurrent: 1,
  21. defaultPageSize: 10,
  22. showQuickJumper: true,
  23. pageSize: 10,
  24. onChange: function(page) {
  25. this.loadData(page);
  26. }.bind(this),
  27. showTotal: function(total) {
  28. return "共" + total + "条数据";
  29. }
  30. },
  31. searchValues:this.props.searchConfig || {},
  32. contactsOption:[],
  33. departmentLoading:false
  34. }
  35. this.loadData= this.loadData.bind(this);
  36. this.resetAll= this.resetAll.bind(this);
  37. this.exportExec= this.exportExec.bind(this);
  38. this.selectSuperId= this.selectSuperId.bind(this);
  39. this.onRefresh= this.onRefresh.bind(this);
  40. this.autoCompleteSearchRef = {}
  41. }
  42. loadData(pageNo) {
  43. this.setState({
  44. loading:true
  45. })
  46. let searchInfor = {
  47. pageNo: pageNo || 1,
  48. pageSize: this.state.pagination.pageSize,
  49. }
  50. if(this.props.query){
  51. let obj = JSON.parse(JSON.stringify(this.props.query))
  52. searchInfor = Object.assign(searchInfor,obj);
  53. }
  54. if(Object.keys(this.state.searchValues).length > 0){
  55. let obj1 = JSON.parse(JSON.stringify(this.state.searchValues))
  56. searchInfor = Object.assign(searchInfor,obj1);
  57. }
  58. $.ajax({
  59. method: "get",
  60. dataType: "json",
  61. crossDomain: false,
  62. url: globalConfig.context + this.props.tabelApi,
  63. data:searchInfor,
  64. success: function(data) {
  65. ShowModal(this);
  66. this.setState({
  67. loading:false
  68. })
  69. if (data.error && data.error.length === 0) {
  70. this.props.searchOperation && this.props.searchOperation(searchInfor);
  71. if(data.data.list){
  72. this.state.pagination.current = data.data.pageNo;
  73. this.state.pagination.total = data.data.totalCount;
  74. if (data.data && data.data.list && !data.data.list.length) {
  75. this.state.pagination.current = 0;
  76. this.state.pagination.total = 0;
  77. }
  78. this.setState({
  79. dataSource: this.props.dataProcessing ? this.props.dataProcessing(data) : data.data.list,
  80. pagination: this.state.pagination,
  81. pageNo:data.data.pageNo
  82. });
  83. }else{
  84. this.setState({
  85. dataSource: this.props.dataProcessing ? this.props.dataProcessing(data) : data.data,
  86. pagination: false,
  87. });
  88. }
  89. }else{
  90. message.warning(data.error[0].message);
  91. }
  92. }.bind(this)
  93. }).always(
  94. function() {
  95. this.setState({
  96. loading: false
  97. });
  98. }.bind(this)
  99. );
  100. }
  101. exportExec(){
  102. message.config({
  103. duration: 20,
  104. });
  105. let loading = message.loading('下载中...');
  106. this.setState({
  107. exportPendingLoading: true
  108. })
  109. let data ={};
  110. let obj1 = JSON.parse(JSON.stringify(this.state.searchValues))
  111. data = Object.assign(data,obj1);
  112. if(this.props.exportExecProcessing){
  113. data = this.props.exportExecProcessing(data);
  114. }
  115. $.ajax({
  116. method: "get",
  117. dataType: "json",
  118. crossDomain: false,
  119. url: this.props.exportApi,
  120. data,
  121. success: function(data) {
  122. if(data.error.length === 0){
  123. this.download(data.data);
  124. }else{
  125. message.warning(data.error[0].message);
  126. }
  127. }.bind(this),
  128. }).always(function() {
  129. loading();
  130. this.setState({
  131. exportPendingLoading: false
  132. })
  133. }.bind(this));
  134. }
  135. download(fileName){
  136. window.location.href = globalConfig.context + "/open/download?fileName=" + fileName
  137. }
  138. //获取上级组织
  139. selectSuperId() {
  140. this.setState({
  141. departmentLoading: true
  142. });
  143. $.ajax({
  144. method: "get",
  145. dataType: "json",
  146. crossDomain: false,
  147. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  148. data:{},
  149. success: function (data) {
  150. let theArr = [];
  151. if (data.error && data.error.length === 0) {
  152. for(let i=0;i<data.data.length;i++){
  153. let theData = data.data[i];
  154. theArr.push(
  155. {
  156. value:theData.id,
  157. label:theData.name
  158. }
  159. );
  160. };
  161. this.setState({
  162. contactsOption: theArr,
  163. });
  164. }else{
  165. message.warning(data.error[0].message);
  166. }
  167. }.bind(this),
  168. }).always(function () {
  169. this.setState({
  170. departmentLoading: false
  171. });
  172. }.bind(this));
  173. }
  174. componentDidMount() {
  175. this.loadData();
  176. if(this.props.searchList){
  177. let arr = this.props.searchList.filter(v=>v.type === 'departmentSelect')
  178. let arr1 = this.props.searchList.filter(v=>v.defaultValue)
  179. if(arr.length > 0){
  180. this.selectSuperId();
  181. }
  182. if(arr1.length > 0){
  183. for(let i of arr1){
  184. this.state.searchValues[i.dataKey] = i.defaultValue
  185. }
  186. }
  187. }
  188. }
  189. resetAll(){
  190. for(let i of Object.keys(this.autoCompleteSearchRef)){
  191. this.autoCompleteSearchRef[i].onReset();
  192. }
  193. let obj = this.props.query || {};
  194. this.setState({
  195. searchValues: JSON.parse(JSON.stringify(obj))
  196. },()=>{
  197. this.loadData();
  198. })
  199. }
  200. //刷新页面
  201. onRefresh(lv){
  202. if(lv){
  203. this.loadData();
  204. }else{
  205. this.loadData(this.state.pageNo);
  206. }
  207. }
  208. render() {
  209. const { searchValues } = this.state;
  210. return (
  211. <div>
  212. <Tabs defaultActiveKey="1" className="test">
  213. {this.props.searchList && <TabPane tab="搜索" key="1">
  214. <div className="user-search" style={{paddingTop:'10px'}}>
  215. <Form layout="inline">
  216. {
  217. (this.props.searchList || []).map((v,k)=>{
  218. return (
  219. v.type === 'text' ?
  220. <FormItem label={v.title} key={k}>
  221. <Input
  222. placeholder={v.placeholder}
  223. value={searchValues[v.dataKey] ? searchValues[v.dataKey] : (v.defaultValue || undefined)}
  224. style={v.style ? v.style : { width: 150, marginRight: 10}}
  225. onChange={(e) => {
  226. searchValues[v.dataKey] = e.target.value
  227. this.setState({
  228. searchValues: searchValues
  229. });
  230. }}
  231. />
  232. </FormItem> :
  233. v.type === 'autoComplete' ?
  234. <FormItem label={v.title} style={{marginTop:'-8px'}} key={k}>
  235. <AutoCompleteSearch
  236. ref={ref=>this.autoCompleteSearchRef[v.dataKey] = ref}
  237. value={searchValues[v.dataKey]}
  238. onSelect={(value,title)=>{
  239. searchValues[v.dataKey] = value
  240. if(v.dataTitle){searchValues[v.dataTitle] = title}
  241. this.setState({
  242. searchValues: searchValues
  243. });
  244. }}
  245. config={v}
  246. />
  247. </FormItem>
  248. :
  249. v.type === 'select' || v.type === 'departmentSelect' ?
  250. <FormItem label={v.title} style={{marginTop:'-8px'}} key={k}>
  251. <Spin spinning={this.state.departmentLoading}>
  252. {
  253. <Select
  254. placeholder={v.placeholder}
  255. style={v.style ? v.style : { width:200,marginRight: 10}}
  256. value={searchValues[v.dataKey] ? searchValues[v.dataKey] : (v.defaultValue || undefined)}
  257. onChange={(e) => {
  258. searchValues[v.dataKey] = String(e);
  259. if(v.type === 'departmentSelect'){
  260. let arr = this.state.contactsOption.filter(v=>String(v.value) === String(e))
  261. searchValues['depName'] = arr[0].label;
  262. }
  263. this.setState({
  264. searchValues: searchValues
  265. });
  266. }}>
  267. {
  268. v.selectOptionList ?
  269. v.selectOptionList():
  270. (
  271. v.type === 'departmentSelect' ?
  272. this.state.contactsOption :
  273. (v.selectList ?
  274. (
  275. typeof v.selectList === 'function'? v.selectList() : v.selectList
  276. )
  277. :[]
  278. )
  279. ).map((v)=>(
  280. <Select.Option
  281. key={v.value}
  282. value={v.value}
  283. >
  284. {v.label}
  285. </Select.Option>
  286. ))
  287. }
  288. </Select>
  289. }
  290. </Spin>
  291. </FormItem>: v.type === 'times' ?
  292. <FormItem label={v.title} key={k}>
  293. {
  294. v.format === 'YYYY/MM' ?
  295. <MonthPicker
  296. value={searchValues[v.dataKey] ? moment(searchValues[v.dataKey]) : null}
  297. style={{marginRight:'10px',marginTop: '2px'}}
  298. onChange={(data, dataString) => {
  299. searchValues[v.dataKey] = String(dataString);
  300. this.setState({
  301. searchValues: searchValues
  302. });
  303. }}
  304. />:
  305. <RangePicker
  306. style={{marginRight:'10px',marginTop: '2px'}}
  307. value={[
  308. searchValues[v.dataKey[0]]
  309. ? moment(searchValues[v.dataKey[0]])
  310. : null,
  311. searchValues[v.dataKey[1]]
  312. ? moment(searchValues[v.dataKey[1]])
  313. : null,
  314. ]}
  315. onChange={(data, dataString) => {
  316. searchValues[v.dataKey[0]] = String(dataString[0]);
  317. searchValues[v.dataKey[1]] = String(dataString[1]);
  318. this.setState({
  319. searchValues: searchValues
  320. });
  321. }}
  322. />
  323. }
  324. </FormItem>: null
  325. )
  326. })
  327. }
  328. <Button type="primary" onClick={()=>{
  329. this.loadData();
  330. }} style={{marginRight:'10px',marginBottom:'10px'}}>搜索</Button>
  331. <Button onClick={this.resetAll} style={{marginRight:'10px',marginBottom:'10px'}}>重置</Button>
  332. </Form>
  333. </div>
  334. </TabPane>}
  335. <TabPane tab="更改表格显示数据" key="2">
  336. <div style={{ marginLeft: 10 }}>
  337. <ChooseList
  338. columns={this.props.columns}
  339. changeFn={this.changeList}
  340. changeList={this.state.changeList}
  341. top={55}
  342. margin={11}
  343. />
  344. </div>
  345. </TabPane>
  346. {this.props.exportApi && <TabPane tab="导出" key="3">
  347. <div style={{ float: "left" }}>
  348. <Button loading={this.state.exportPendingLoading} onClick={this.exportExec} style={{ margin: 10 }}>导出excel</Button>
  349. </div>
  350. </TabPane>}
  351. </Tabs>
  352. <div className="patent-table">
  353. <Spin spinning={this.state.loading}>
  354. <Table
  355. bordered
  356. size="middle"
  357. scroll={this.props.scroll}
  358. columns={
  359. this.state.changeList.length > 0
  360. ? this.state.changeList
  361. : this.props.columns
  362. }
  363. onRowClick={this.props.onRowClick ? this.props.onRowClick : null}
  364. dataSource={this.state.dataSource}
  365. pagination={this.state.pagination}
  366. />
  367. </Spin>
  368. </div>
  369. </div>
  370. )
  371. }
  372. }
  373. export default TabelContent;