index.jsx 17 KB

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