index.jsx 18 KB

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