selectContent.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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,getGameState} 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: 5,
  18. showQuickJumper: true,
  19. pageSize: 5,
  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. objColumns: [
  66. {
  67. title: '名称',
  68. dataIndex: 'name',
  69. key: 'name',
  70. render: text => { return text&&text.length>16?text.substr(0,16)+'...':text}
  71. },
  72. {
  73. title: '简介',
  74. dataIndex: 'summary',
  75. key: 'summary',
  76. render: text => { return text&&text.length>16?text.substr(0,16)+'...':text}
  77. },
  78. {
  79. title: '市场价(万元)',
  80. dataIndex: 'price',
  81. key: 'price'
  82. },
  83. {
  84. title: '最低折扣',
  85. dataIndex: 'offset',
  86. key: 'offset'
  87. },
  88. {
  89. title: '会员价(万元)',
  90. dataIndex: 'memberPrice',
  91. key: 'memberPrice'
  92. },
  93. {
  94. title: '活动价(万元)',
  95. dataIndex: 'activityPrice',
  96. key: 'activityPrice'
  97. },
  98. {
  99. title: '活动生效标识',
  100. dataIndex: 'activityFlag',
  101. key: 'activityFlag',
  102. render: (text) => {
  103. return getGameState(text);
  104. }
  105. },
  106. {
  107. title: '操作',
  108. dataIndex: 'caozuo',
  109. key: 'caozuo',
  110. render:(text,recard) => {
  111. return <div className="btnRight">
  112. <Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation();this.subVal(recard)}}>选择</Button>
  113. </div>
  114. }
  115. }
  116. ],
  117. dataSource: [],
  118. }
  119. }
  120. loadData(pageNo) {
  121. this.state.data = [];
  122. this.setState({
  123. selectedRowKeys:[],
  124. page:pageNo,
  125. loading: true
  126. });
  127. $.ajax({
  128. method: "get",
  129. dataType: "json",
  130. crossDomain: false,
  131. url: globalConfig.context + this.props.data&&this.props.data.url?this.props.data.url:"/portal/globalSearch",
  132. data: this.props.data&&this.props.data.url?
  133. {
  134. pageNo: pageNo || 1,
  135. pageSize: 5,
  136. privateProject:this.props.data.privateProject,
  137. auditStatus:this.props.data.auditStatus,
  138. name:this.state.searchVal
  139. }
  140. :{
  141. pageNo: pageNo || 1,
  142. pageSize: 5,
  143. name:this.state.searchVal
  144. },
  145. success: function (data) {
  146. let theArr = [];
  147. if (!data.data || !data.data.list) {
  148. if (data.error && data.error.length) {
  149. message.warning(data.error[0].message);
  150. };
  151. } else {
  152. for (let i = 0; i < data.data.list.length; i++) {
  153. let thisdata = data.data.list[i];
  154. theArr.push({
  155. key: i,
  156. rowId: thisdata.rowId,
  157. id:thisdata.id,
  158. keyword: thisdata.keyword,
  159. summary:thisdata.summary,
  160. title:thisdata.title,
  161. fromTable:thisdata.fromTable,
  162. name:thisdata.name,
  163. price:thisdata.price,
  164. offset:thisdata.offset,
  165. memberPrice:thisdata.memberPrice,
  166. activityPrice:thisdata.activityPrice,
  167. activityFlag:thisdata.activityFlag
  168. });
  169. };
  170. };
  171. this.state.pagination.current = data.data.pageNo;
  172. this.state.pagination.total = data.data.totalCount;
  173. if(data.data&&data.data.list&&!data.data.list.length){
  174. this.state.pagination.current=0;
  175. this.state.pagination.total=0;
  176. };
  177. this.setState({
  178. dataSource: theArr,
  179. pagination: this.state.pagination
  180. });
  181. }.bind(this),
  182. }).always(function () {
  183. this.setState({
  184. loading: false
  185. });
  186. }.bind(this));
  187. }
  188. //点推送时
  189. subVal(recard){
  190. this.props.visFun(true,recard)
  191. }
  192. handOk(){
  193. this.setState({
  194. visible:false
  195. })
  196. this.props.visFun(false);
  197. }
  198. handleCancel(){
  199. this.setState({
  200. visible:false
  201. })
  202. this.props.visFun(false);
  203. }
  204. componentWillReceiveProps(nextProps){
  205. this.state.visible = nextProps.visible;
  206. }
  207. tableRowClick(record, index) {
  208. this.state.RowData = record;
  209. if(this.props.data&&this.props.data.url){
  210. this.setState({
  211. DetailVis: false
  212. });
  213. }else{
  214. this.setState({
  215. DetailVis: true
  216. });
  217. }
  218. }
  219. searchFun(){
  220. this.loadData()
  221. }
  222. okDetail(){
  223. this.setState({
  224. DetailVis: false
  225. });
  226. }
  227. render() {
  228. const formItemLayout = {
  229. labelCol: { span: 6 },
  230. wrapperCol: { span: 12 },
  231. };
  232. const FormItem = Form.Item
  233. let RowData=this.state.RowData||[];
  234. return ( <div>
  235. <Modal
  236. visible={this.state.visible}
  237. onOk={this.handOk.bind(this)}
  238. onCancel={this.handleCancel.bind(this)}
  239. width="800px"
  240. title={this.props.data&&this.props.data.url?'我的项目':"选择推送内容"}
  241. footer=""
  242. >
  243. <div className="sendBody">
  244. <div className="megSearch">
  245. <Input type="text"
  246. size="large"
  247. value={this.state.searchVal}
  248. onChange={(e)=>{this.setState({searchVal:e.target.value})}}/>
  249. <Button type="primary" size="large" onClick={this.searchFun.bind(this)}>搜索</Button>
  250. </div>
  251. <Spin spinning={this.state.loading}>
  252. <Table columns={this.props.data&&this.props.data.url?this.state.objColumns:this.state.columns}
  253. dataSource={this.state.dataSource}
  254. pagination={this.state.pagination}
  255. onRowClick={this.tableRowClick.bind(this)} />
  256. </Spin>
  257. </div>
  258. </Modal>
  259. <Modal
  260. visible={this.state.DetailVis}
  261. title="详情"
  262. onOk={this.okDetail.bind(this)}
  263. onCancel={this.okDetail.bind(this)}
  264. footer=''
  265. width="600px"
  266. >
  267. <div className="detailList">
  268. <div className="clearfix">
  269. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="名称">
  270. <span>{RowData.title}</span>
  271. </FormItem>
  272. </div>
  273. <div className="clearfix">
  274. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="简介">
  275. <p>{RowData.summary}</p>
  276. </FormItem>
  277. </div>
  278. <div className="clearfix">
  279. <FormItem className="half-item" {...formItemLayout} label="类型">
  280. <p>{getMsgType(RowData.fromTable)}</p>
  281. </FormItem>
  282. <FormItem className="half-item" {...formItemLayout} label="关键字">
  283. <p>{RowData.keyword}</p>
  284. </FormItem>
  285. </div>
  286. </div>
  287. </Modal>
  288. </div> );
  289. }
  290. }
  291. export default SelectContent;