index.jsx 19 KB

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