selectContent.jsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import {Component} from 'react';
  2. import {Button,Modal,message,Table,Spin,Input, Row,Col,Card,Form} from 'antd';
  3. import './selectContent.less';
  4. import {getMsgType} from '@/tools';
  5. class SelectContent extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. loading:false,
  10. RowData:[],
  11. recD:[],
  12. selectedRowKeys: [],
  13. selectedRows: [],
  14. loading: false,
  15. pagination: {
  16. defaultCurrent: 1,
  17. defaultPageSize: 10,
  18. showQuickJumper: true,
  19. pageSize: 10,
  20. onChange: function (page) {
  21. this.loadData(page);
  22. }.bind(this),
  23. showTotal: function (total) {
  24. return '共' + total + '条数据';
  25. }
  26. },
  27. columns: [
  28. {
  29. title: '名称',
  30. dataIndex: 'title',
  31. key: 'title',
  32. render: text => { return text&&text.length>16?text.substr(0,16)+'...':text}
  33. },
  34. {
  35. title: '简介',
  36. dataIndex: 'summary',
  37. key: 'summary',
  38. render: text => { return text&&text.length>16?text.substr(0,16)+'...':text}
  39. },
  40. {
  41. title: '类型',
  42. dataIndex: 'fromTable',
  43. key: 'fromTable',
  44. render:(text)=>{
  45. return getMsgType(text)
  46. }
  47. },
  48. {
  49. title: '关键字',
  50. dataIndex: 'keyword',
  51. key: 'keyword',
  52. render: text => { return text&&text.length>16?text.substr(0,16)+'...':text}
  53. },
  54. {
  55. title: '操作',
  56. dataIndex: 'caozuo',
  57. key: 'caozuo',
  58. render:(text,recard) => {
  59. return <div className="btnRight">
  60. <Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation();this.subVal(recard)}}>选择</Button>
  61. </div>
  62. }
  63. }
  64. ],
  65. dataSource: [],
  66. }
  67. }
  68. loadData(pageNo) {
  69. this.state.data = [];
  70. this.setState({
  71. selectedRowKeys:[],
  72. page:pageNo,
  73. loading: true
  74. });
  75. $.ajax({
  76. method: "get",
  77. dataType: "json",
  78. crossDomain: false,
  79. url: globalConfig.context + "/portal/globalSearch",
  80. data: {
  81. pageNo: pageNo || 1,
  82. pageSize: 5,
  83. name:this.state.searchVal
  84. },
  85. success: function (data) {
  86. let theArr = [];
  87. if (!data.data || !data.data.list) {
  88. if (data.error && data.error.length) {
  89. message.warning(data.error[0].message);
  90. };
  91. } else {
  92. for (let i = 0; i < data.data.list.length; i++) {
  93. let thisdata = data.data.list[i];
  94. theArr.push({
  95. key: i,
  96. rowId: thisdata.rowId,
  97. keyword: thisdata.keyword,
  98. summary:thisdata.summary,
  99. title:thisdata.title,
  100. fromTable:thisdata.fromTable
  101. });
  102. };
  103. };
  104. this.state.pagination.current = data.data.pageNo;
  105. this.state.pagination.total = data.data.totalCount;
  106. if(data.data&&data.data.list&&!data.data.list.length){
  107. this.state.pagination.current=0;
  108. this.state.pagination.total=0;
  109. };
  110. this.setState({
  111. dataSource: theArr,
  112. pagination: this.state.pagination
  113. });
  114. }.bind(this),
  115. }).always(function () {
  116. this.setState({
  117. loading: false
  118. });
  119. }.bind(this));
  120. }
  121. //点推送时
  122. subVal(recard){
  123. this.props.visFun(true,recard)
  124. }
  125. handOk(){
  126. this.setState({
  127. visible:false
  128. })
  129. this.props.visFun(false);
  130. }
  131. handleCancel(){
  132. this.setState({
  133. visible:false
  134. })
  135. this.props.visFun(false);
  136. }
  137. componentWillReceiveProps(nextProps){
  138. this.state.visible = nextProps.visible;
  139. }
  140. tableRowClick(record, index) {
  141. this.state.RowData = record;
  142. this.setState({
  143. DetailVis: true
  144. });
  145. }
  146. searchFun(){
  147. this.loadData()
  148. }
  149. okDetail(){
  150. this.setState({
  151. DetailVis: false
  152. });
  153. }
  154. render() {
  155. const formItemLayout = {
  156. labelCol: { span: 6 },
  157. wrapperCol: { span: 12 },
  158. };
  159. const FormItem = Form.Item
  160. let RowData=this.state.RowData||[];
  161. return ( <div>
  162. <Modal
  163. visible={this.state.visible}
  164. onOk={this.handOk.bind(this)}
  165. onCancel={this.handleCancel.bind(this)}
  166. width="800px"
  167. title="选择推送内容"
  168. footer=""
  169. >
  170. <div className="sendBody">
  171. <div className="megSearch">
  172. <Input type="text"
  173. size="large"
  174. value={this.state.searchVal}
  175. onChange={(e)=>{this.setState({searchVal:e.target.value})}}/>
  176. <Button type="primary" size="large" onClick={this.searchFun.bind(this)}>搜索</Button>
  177. </div>
  178. <Spin spinning={this.state.loading}>
  179. <Table columns={this.state.columns}
  180. dataSource={this.state.dataSource}
  181. pagination={this.state.pagination}
  182. onRowClick={this.tableRowClick.bind(this)} />
  183. </Spin>
  184. </div>
  185. </Modal>
  186. <Modal
  187. visible={this.state.DetailVis}
  188. title="详情"
  189. onOk={this.okDetail.bind(this)}
  190. onCancel={this.okDetail.bind(this)}
  191. footer=''
  192. width="600px"
  193. >
  194. <div className="detailList">
  195. <div className="clearfix">
  196. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="名称">
  197. <span>{RowData.title}</span>
  198. </FormItem>
  199. </div>
  200. <div className="clearfix">
  201. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="简介">
  202. <p>{RowData.summary}</p>
  203. </FormItem>
  204. </div>
  205. <div className="clearfix">
  206. <FormItem className="half-item" {...formItemLayout} label="类型">
  207. <p>{getMsgType(RowData.fromTable)}</p>
  208. </FormItem>
  209. <FormItem className="half-item" {...formItemLayout} label="关键字">
  210. <p>{RowData.keyword}</p>
  211. </FormItem>
  212. </div>
  213. </div>
  214. </Modal>
  215. </div> );
  216. }
  217. }
  218. export default SelectContent;