index.jsx 19 KB

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