index.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import React,{Component} from "react";
  2. import {Form, Button, DatePicker, Input, message, Select, Spin, Table, Tabs} 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. const {TabPane} = Tabs;
  10. const { RangePicker } = DatePicker;
  11. const FormItem = Form.Item
  12. class TabelContent extends Component{
  13. constructor(props) {
  14. super(props);
  15. this.state={
  16. changeList:[],
  17. dataSource:[],
  18. pagination: {
  19. defaultCurrent: 1,
  20. defaultPageSize: 10,
  21. showQuickJumper: true,
  22. pageSize: 10,
  23. onChange: function(page) {
  24. this.loadData(page);
  25. }.bind(this),
  26. showTotal: function(total) {
  27. return "共" + total + "条数据";
  28. }
  29. },
  30. searchValues:{},
  31. contactsOption:[]
  32. }
  33. this.loadData= this.loadData.bind(this);
  34. this.exportExec= this.exportExec.bind(this);
  35. this.selectSuperId= this.selectSuperId.bind(this);
  36. }
  37. loadData(pageNo) {
  38. this.setState({
  39. loading:true
  40. })
  41. $.ajax({
  42. method: "get",
  43. dataType: "json",
  44. crossDomain: false,
  45. url: globalConfig.context + this.props.tabelApi,
  46. data: {
  47. pageNo: pageNo || 1,
  48. pageSize: this.state.pagination.pageSize,
  49. },
  50. success: function(data) {
  51. ShowModal(this);
  52. this.setState({
  53. loading:false
  54. })
  55. if (data.error && data.error.length === 0) {
  56. this.state.pagination.current = data.data.pageNo;
  57. this.state.pagination.total = data.data.totalCount;
  58. if (data.data && data.data.list && !data.data.list.length) {
  59. this.state.pagination.current = 0;
  60. this.state.pagination.total = 0;
  61. }
  62. this.setState({
  63. dataSource: this.props.dataProcessing ? this.props.dataProcessing(data) : data.data.list,
  64. pagination: this.state.pagination,
  65. pageNo:data.data.pageNo
  66. });
  67. }else{
  68. message.warning(data.error[0].message);
  69. }
  70. }.bind(this)
  71. }).always(
  72. function() {
  73. this.setState({
  74. loading: false
  75. });
  76. }.bind(this)
  77. );
  78. }
  79. exportExec(){
  80. let data = {
  81. clockStart:this.state.releaseDate[0],
  82. clockEnd:this.state.releaseDate[1],
  83. createStart:this.state.createReleaseDate[0],
  84. createEnd:this.state.createReleaseDate[1],
  85. depId:this.state.superId,
  86. aid:this.state.theTypes
  87. };
  88. for(let i of Object.keys(data)){
  89. if(!data[i]){
  90. delete data[i]
  91. }
  92. }
  93. window.location.href =
  94. globalConfig.context +
  95. this.props.exportApi + "?" +
  96. $.param(data);
  97. }
  98. //获取上级组织
  99. selectSuperId() {
  100. this.setState({
  101. departmentLoading: true
  102. });
  103. $.ajax({
  104. method: "get",
  105. dataType: "json",
  106. crossDomain: false,
  107. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  108. data:{},
  109. success: function (data) {
  110. let theArr = [];
  111. if (data.error && data.error.length === 0) {
  112. for(let i=0;i<data.data.length;i++){
  113. let theData = data.data[i];
  114. theArr.push(
  115. {
  116. value:theData.id,
  117. label:theData.name
  118. }
  119. );
  120. };
  121. this.setState({
  122. contactsOption: theArr,
  123. });
  124. }else{
  125. message.warning(data.error[0].message);
  126. }
  127. }.bind(this),
  128. }).always(function () {
  129. this.setState({
  130. departmentLoading: false
  131. });
  132. }.bind(this));
  133. }
  134. componentDidMount() {
  135. this.loadData();
  136. if(this.props.searchList){
  137. let arr = this.props.searchList.filter(v=>v.type === 'departmentSelect')
  138. let arr1 = this.props.searchList.filter(v=>v.defaultValue)
  139. if(arr.length > 0){
  140. this.selectSuperId();
  141. }
  142. if(arr1.length > 0){
  143. for(let i of arr1){
  144. this.state.searchValues[i.dataKey] = i.defaultValue
  145. }
  146. }
  147. }
  148. }
  149. render() {
  150. const { searchValues } = this.state;
  151. return (
  152. <div>
  153. <Tabs defaultActiveKey="1" className="test">
  154. <TabPane tab="搜索" key="1">
  155. <div className="user-search" style={{paddingTop:'10px'}}>
  156. <Form layout="inline">
  157. {
  158. (this.props.searchList || []).map((v,k)=>(
  159. v.type === 'text' ?
  160. <FormItem label={v.title}>
  161. <Input
  162. key={k}
  163. placeholder={v.placeholder}
  164. value={v.value ? v.value : (v.defaultValue || undefined)}
  165. style={v.style ? v.style : { width: 150, marginRight: 10}}
  166. onChange={(e) => {
  167. searchValues[v.dataKey] = e.target.value
  168. this.setState({
  169. searchValues: searchValues
  170. });
  171. }}
  172. />
  173. </FormItem> :
  174. v.type === 'select' || v.type === 'departmentSelect' ?
  175. <FormItem label={v.title} style={{marginTop:'-8px'}}>
  176. <Spin spinning={this.state.departmentLoading}>
  177. {
  178. <Select
  179. key={k}
  180. placeholder={v.placeholder}
  181. style={v.style ? v.style : { width:200,marginRight: 10}}
  182. value={searchValues[v.dataKey] ? searchValues[v.dataKey] : (v.defaultValue || undefined)}
  183. onChange={(e) => {
  184. searchValues[v.dataKey] = String(e);
  185. this.setState({
  186. searchValues: searchValues
  187. });
  188. }}>
  189. {
  190. v.selectOptionList ?
  191. v.selectOptionList():
  192. (
  193. v.type === 'departmentSelect' ?
  194. this.state.contactsOption :
  195. (v.selectList || [])
  196. ).map((v)=>(
  197. <Select.Option
  198. key={v.value}
  199. value={v.value}
  200. >
  201. {v.label}
  202. </Select.Option>
  203. ))
  204. }
  205. </Select>
  206. }
  207. </Spin>
  208. </FormItem>: v.type === 'times' ?
  209. <FormItem label={v.title}>
  210. <RangePicker
  211. style={{marginRight:'10px',marginTop: '2px'}}
  212. value={[
  213. searchValues[v.dataKey[0]]
  214. ? moment(searchValues[v.dataKey[0]])
  215. : null,
  216. searchValues[v.dataKey[1]]
  217. ? moment(searchValues[v.dataKey[1]])
  218. : null,
  219. ]}
  220. onChange={(data, dataString) => {
  221. searchValues[v.dataKey[0]] = String(dataString[0]);
  222. searchValues[v.dataKey[1]] = String(dataString[1]);
  223. this.setState({
  224. searchValues: searchValues
  225. });
  226. }}
  227. />
  228. </FormItem>: null
  229. ))
  230. }
  231. <Button type="primary" onClick={()=>{
  232. this.loadData();
  233. }} style={{marginRight:'10px',marginBottom:'10px'}}>搜索</Button>
  234. <Button onClick={this.resetAll} style={{marginRight:'10px',marginBottom:'10px'}}>重置</Button>
  235. </Form>
  236. </div>
  237. </TabPane>
  238. <TabPane tab="更改表格显示数据" key="2">
  239. <div style={{ marginLeft: 10 }}>
  240. <ChooseList
  241. columns={this.props.columns}
  242. changeFn={this.changeList}
  243. changeList={this.state.changeList}
  244. top={55}
  245. margin={11}
  246. />
  247. </div>
  248. </TabPane>
  249. {this.props.exportApi && <TabPane tab="导出" key="3">
  250. <div style={{ float: "left" }}>
  251. <Button onClick={this.exportExec} style={{ margin: 10 }}>导出excel</Button>
  252. </div>
  253. </TabPane>}
  254. </Tabs>
  255. <div className="patent-table">
  256. <Spin spinning={this.state.loading}>
  257. <Table
  258. bordered
  259. size="middle"
  260. scroll={{ x: 800, y: 0 }}
  261. columns={
  262. this.state.changeList.length > 0
  263. ? this.state.changeList
  264. : this.props.columns
  265. }
  266. dataSource={this.state.dataSource}
  267. pagination={this.state.pagination}
  268. />
  269. </Spin>
  270. </div>
  271. </div>
  272. )
  273. }
  274. }
  275. export default TabelContent;