mcjList.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import 'react-quill/dist/quill.bubble.css';
  4. import moment from 'moment';
  5. import {Form,Icon,Button,Input,Select,Spin,Table,message,DatePicker,Modal,Upload,Popconfirm,Cascader,InputNumber,Radio,TimePicker,Tabs} from 'antd';
  6. import {areaSelect, getProvince} from '@/NewDicProvinceList';//省市区
  7. import { getGameState, splitUrl, getprovince, getStatuslist, getLvl,beforeUploadFile} from '@/tools.js';
  8. const PicturesWall = React.createClass({
  9. getInitialState() {
  10. return {
  11. previewVisible: false,
  12. previewImage: '',
  13. fileList: this.props.pictureUrl,
  14. }
  15. },
  16. getDefaultProps(){
  17. return{
  18. changeClick:this.modifyChange
  19. }
  20. },
  21. handleCancel() {
  22. this.setState({ previewVisible: false })
  23. },
  24. handlePreview(file) {
  25. this.setState({
  26. previewImage: file.url || file.thumbUrl,
  27. previewVisible: true,
  28. });
  29. },
  30. handleChange(info) {
  31. let fileList = info.fileList;
  32. this.setState({ fileList });
  33. this.props.fileList(fileList);
  34. },
  35. componentWillReceiveProps(nextProps) {
  36. this.state.fileList = nextProps.pictureUrl;
  37. },
  38. render() {
  39. const { previewVisible, previewImage, fileList } = this.state;
  40. const uploadButton = (
  41. <div>
  42. <Icon type="plus" />
  43. <div className="ant-upload-text">点击上传</div>
  44. </div>
  45. );
  46. return (
  47. <div style={{display:"inline-block"}}>
  48. <Upload
  49. beforeUpload={beforeUploadFile}
  50. action={globalConfig.context + "/api/admin/militaryIntoCivilian/uploadPicture"}
  51. data={{ 'sign': 'MIC_picture' }}
  52. listType="picture-card"
  53. fileList={fileList}
  54. onPreview={this.handlePreview}
  55. onChange={this.handleChange} >
  56. {fileList.length >= 18 ? null : uploadButton}
  57. </Upload>
  58. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  59. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  60. </Modal>
  61. </div>
  62. );
  63. }
  64. });
  65. // 主体
  66. const McjList = Form.create()(
  67. React.createClass({
  68. loadData(pageNo) {
  69. this.state.data = [];
  70. this.setState({
  71. loading: true,
  72. page: pageNo
  73. });
  74. $.ajax({
  75. method: 'get',
  76. dataType: 'json',
  77. crossDomain: false,
  78. url: globalConfig.context + '/api/admin/civilianIntoMilitary/list',
  79. data: {
  80. pageNo: pageNo || 1,
  81. pageSize: this.state.pagination.pageSize,
  82. name: this.state.nameSearch,
  83. type: this.state.typeSearch,
  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. let ProvinceCityArr = [],
  95. ProvinceS = thisdata.province, //getprovince
  96. citys = thisdata.city,
  97. Areas = thisdata.area;
  98. ProvinceCityArr.push(ProvinceS, citys, Areas);
  99. theArr.push({
  100. key: i,
  101. id: thisdata.id,
  102. name: thisdata.name,
  103. topNumber: thisdata.topNumber,
  104. sortNumber: thisdata.sortNumber,
  105. contacts: thisdata.contacts,
  106. contactsMobile:thisdata.contactsMobile,
  107. ProvinceCity:ProvinceCityArr[0] === null?[]:ProvinceCityArr,
  108. type: thisdata.type,
  109. price: thisdata.price,
  110. releaseStatus: thisdata.releaseStatus,
  111. releaseDates: thisdata.releaseDates,
  112. createTimes:thisdata.createTimes,
  113. editTimes:thisdata.editTimes,
  114. introduction: thisdata.introduction,
  115. });
  116. }
  117. this.state.pagination.current = data.data.pageNo;
  118. this.state.pagination.total = data.data.totalCount;
  119. }
  120. this.setState({
  121. dataSource: theArr,
  122. pagination: this.state.pagination
  123. });
  124. }.bind(this)
  125. }).always(
  126. function() {
  127. this.setState({
  128. loading: false
  129. });
  130. }.bind(this)
  131. );
  132. },
  133. getInitialState() {
  134. return {
  135. loading: false,
  136. flag: true,
  137. ProvinceCity:[],
  138. ProvinceCityC: [],
  139. totalData:{
  140. mark: false,
  141. },
  142. technicalPictureUrl: [],
  143. pagination: {
  144. defaultCurrent: 1,
  145. defaultPageSize: 10,
  146. showQuickJumper: true,
  147. pageSize: 10,
  148. onChange: function(page) {
  149. this.loadData(page);
  150. this.setState({
  151. selectedRowKeys: []
  152. });
  153. }.bind(this),
  154. showTotal: function(total) {
  155. return '共' + total + '条数据';
  156. }
  157. },
  158. columns: [
  159. {
  160. title: '序号',
  161. dataIndex: 'key',
  162. key: 'key'
  163. },
  164. {
  165. title: '标题',
  166. dataIndex: 'name',
  167. key: 'name'
  168. },
  169. {
  170. title: '价格',
  171. dataIndex: 'price',
  172. key: 'price',
  173. },
  174. {
  175. title: '品类',
  176. dataIndex: 'type',
  177. key: 'type',
  178. },
  179. {
  180. title: '排序',
  181. dataIndex: 'sortNumber',
  182. key: 'sortNumber'
  183. },
  184. {
  185. title: '发布状态',
  186. dataIndex: 'releaseStatus',
  187. key: 'releaseStatus',
  188. render:text=>{
  189. return text?'已发布':'未发布';
  190. }
  191. },
  192. {
  193. title: '置顶',
  194. dataIndex: 'topNumber',
  195. key: 'topNumber',
  196. render:text=>{
  197. return text?'否':'是';
  198. }
  199. },
  200. {
  201. title: '操作',
  202. dataIndex: 'a',
  203. key: 'a',
  204. render:(text,record,index)=>{
  205. return <Button type="primary" onClick={()=>{
  206. this.tableRowClick(record)
  207. }}>修改</Button>
  208. }
  209. },
  210. ],
  211. dataSource: []
  212. };
  213. },
  214. componentWillMount() {
  215. this.loadData()
  216. },
  217. detailes(record) {
  218. this.setState({
  219. loading:true
  220. });
  221. $.ajax({
  222. method: 'get',
  223. dataType: 'json',
  224. crossDomain: false,
  225. url: globalConfig.context + '/api/admin/civilianIntoMilitary/details',
  226. data: {
  227. id: record.id,
  228. },
  229. success: function(data) {
  230. let theArr = [];
  231. let thisdata = data.data;
  232. if (!data.data || !data.data.list) {
  233. if (data.error && data.error.length) {
  234. message.warning(data.error[0].message);
  235. }
  236. }
  237. this.setState({
  238. technicalPictureUrl: thisdata.technicalPictureUrl ? splitUrl(thisdata.technicalPictureUrl, ',', globalConfig.avatarHost + '/upload') : [],
  239. })
  240. Object.assign(this.state.totalData,{},this.state.RowData)
  241. }.bind(this)
  242. }).always(
  243. function() {
  244. this.setState({
  245. loading: false
  246. });
  247. }.bind(this)
  248. );
  249. },
  250. stopPropagation(e){
  251. e.stopPropagation();
  252. e.nativeEvent.stopImmediatePropagation();
  253. },
  254. //项目列表整行点击
  255. tableRowClick(record, index) {
  256. this.state.RowData = record;
  257. this.setState({
  258. editvisible: true,
  259. });
  260. this.detailes(record);
  261. },
  262. edithandleCancel(e) {
  263. this.setState({
  264. editvisible: false
  265. },()=>{
  266. this.addReset()
  267. });
  268. this.loadData()
  269. },
  270. search() {
  271. this.loadData();
  272. },
  273. add(){
  274. this.setState({
  275. editvisible: true,
  276. flag: false,
  277. });
  278. },
  279. addNew(){
  280. let theorgCodeUrl = [];
  281. if (this.state.technicalPictureUrl.length) {
  282. let picArr = [];
  283. this.state.technicalPictureUrl.map(function (item) {
  284. if ( item.response && item.response.data && item.response.data.length ){
  285. picArr.push(item.response.data);
  286. }
  287. });
  288. theorgCodeUrl = picArr.join(",");
  289. };
  290. this.setState({
  291. loading:true
  292. });
  293. ["ProvinceCity"].forEach((key)=>{
  294. this.change(key,undefined)
  295. })
  296. if(theorgCodeUrl.length){
  297. this.change("technicalPictureUrl",theorgCodeUrl)
  298. }else{
  299. this.change("technicalPictureUrl",[])
  300. }
  301. $.ajax({
  302. method: 'post',
  303. dataType: 'json',
  304. crossDomain: false,
  305. url: globalConfig.context + (this.state.flag?'/api/admin/civilianIntoMilitary/update':'/api/admin/civilianIntoMilitary/apply'),
  306. data: this.state.totalData,
  307. }).done(function(data) {
  308. this.setState({
  309. loading: false
  310. });
  311. if(!data.error.length) {
  312. message.success('保存成功!');
  313. this.cancelAdd()
  314. } else {
  315. message.warning(data.error[0].message);
  316. }
  317. }.bind(this));
  318. },
  319. saveNew(){
  320. this.change("releaseStatus",0,()=>{
  321. this.addNew()
  322. })
  323. },
  324. issueNew(){
  325. this.change("releaseStatus",1,()=>{
  326. this.addNew()
  327. })
  328. },
  329. delete(id){
  330. this.setState({
  331. loading:true
  332. });
  333. $.ajax({
  334. method: 'post',
  335. dataType: 'json',
  336. crossDomain: false,
  337. url: "/api/admin/civilianIntoMilitary/delete",
  338. data: {
  339. id: id,
  340. },
  341. }).done(function(data) {
  342. this.setState({
  343. loading: false
  344. });
  345. if(!data.error.length) {
  346. message.success('删除成功!');
  347. this.loadData()
  348. } else {
  349. message.warning(data.error[0].message);
  350. }
  351. }.bind(this));
  352. },
  353. cancelAdd(){
  354. this.setState({
  355. editvisible: false,
  356. },()=>{
  357. this.setState({
  358. flag:true
  359. })
  360. this.addReset()
  361. });
  362. this.loadData()
  363. },
  364. //新增框的清零
  365. addReset(){
  366. this.setState({
  367. technicalPictureUrl:[],
  368. totalData:{},
  369. })
  370. },
  371. //搜索部分的清零
  372. reset() {
  373. this.state.mobileSearch = undefined;
  374. this.state.lvlSearch = undefined;
  375. this.state.nameSearch = undefined;
  376. this.state.typeSearch = undefined;
  377. this.loadData();
  378. },
  379. getOrgCodeUrl(e) {
  380. this.setState({ technicalPictureUrl: e });
  381. },
  382. change(key, e, f){
  383. if(f === undefined ){
  384. this.state.totalData[key] = e
  385. this.setState({
  386. totalData:this.state.totalData
  387. })
  388. }else if(typeof(f) === "function"){
  389. this.state.totalData[key] = e
  390. this.setState({
  391. totalData:this.state.totalData
  392. },f)
  393. }
  394. },
  395. render() {
  396. const FormItem = Form.Item;
  397. const rowSelection = {
  398. selectedRowKeys: this.state.selectedRowKeys,
  399. onChange: (selectedRowKeys, selectedRows) => {
  400. this.setState({
  401. selectedRows: selectedRows.slice(-1),
  402. selectedRowKeys: selectedRowKeys.slice(-1)
  403. });
  404. }
  405. };
  406. let data = this.state.totalData;
  407. const { TextArea } = Input;//文本域
  408. const { TabPane } = Tabs;//标签页
  409. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;//日期输入框
  410. return (
  411. <div className="user-content">
  412. <div className="content-title">
  413. <span>页尾内容列表</span>
  414. <div className="user-search">
  415. <Input
  416. placeholder="企业名称"
  417. style={{ width: '150px', marginRight: '10px', marginBottom: '10px' }}
  418. value={this.state.nameSearch}
  419. onChange={(e) => {
  420. this.setState({ nameSearch: e.target.value });
  421. }}
  422. />
  423. <Button type="primary" onClick={this.search} style={{ marginRight: '10px' }}>
  424. 搜索
  425. </Button>
  426. <Button onClick={this.reset} style={{ marginRight: '10px' }}>
  427. 重置
  428. </Button>
  429. <Button type="primary" onClick={this.add} style={{ marginLeft: '100px'}}>
  430. 新增页尾内容
  431. </Button>
  432. </div>
  433. <div className="patent-table">
  434. <Spin spinning={this.state.loading}>
  435. <Table
  436. columns={this.state.columns}
  437. dataSource={this.state.dataSource}
  438. pagination={this.state.pagination}
  439. onRowClick={this.tableRowClick}
  440. />
  441. </Spin>
  442. </div>
  443. </div>
  444. <div className="patent-desc">
  445. <Modal
  446. className="customeDetails"
  447. title={this.state.flag?'民参军信息详情':'新增民参军信息'}
  448. width="1000px"
  449. visible={this.state.editvisible}
  450. onOk={this.edithandleCancel}
  451. onCancel={this.state.flag?this.edithandleCancel:this.cancelAdd}
  452. footer=""
  453. >
  454. <Form layout="horizontal" onSubmit={this.edithandleSubmit} id="demand-form">
  455. <Spin spinning={this.state.loading}>
  456. <div className="clearfix">
  457. <FormItem
  458. className="half-item"
  459. labelCol={{ span: 8 }}
  460. wrapperCol={{ span: 12 }}
  461. label="名称"
  462. >
  463. <Input placeholder="请输入名称" value={data.name}
  464. onChange={(e)=>{
  465. this.change('name',e.target.value)
  466. }} style={{width:'240px'}} />
  467. </FormItem>
  468. <FormItem
  469. className="half-item"
  470. labelCol={{ span: 8 }}
  471. wrapperCol={{ span: 12 }}
  472. label="价格"
  473. >
  474. <Input placeholder="请输入价格" value={data.price}
  475. onChange={(e)=>{
  476. this.change('price',e.target.value)
  477. }} style={{width:'240px'}} />
  478. </FormItem>
  479. <FormItem
  480. className="half-item"
  481. labelCol={{ span: 8 }}
  482. wrapperCol={{ span: 12 }}
  483. label="品类"
  484. >
  485. <Input placeholder="请输入品类" value={data.type}
  486. onChange={(e)=>{
  487. this.change('type',e.target.value)
  488. }} style={{width:'240px'}} />
  489. </FormItem>
  490. <FormItem
  491. className="half-item"
  492. labelCol={{ span: 8 }}
  493. wrapperCol={{ span: 12 }}
  494. label="所在地"
  495. >
  496. <Cascader options={areaSelect()} value={data.ProvinceCity} placeholder="选择城市" style={{width:'95%'}}
  497. onChange={(e)=>{
  498. this.change('ProvinceCity',e)
  499. this.change('province', e[0])
  500. this.change('city', e[1])
  501. this.change('area', e[2])
  502. }} />
  503. </FormItem>
  504. <FormItem
  505. className="half-item"
  506. labelCol={{ span: 8 }}
  507. wrapperCol={{ span: 12 }}
  508. label="联系人"
  509. >
  510. <Input placeholder="请输入联系人" value={data.contacts}
  511. onChange={(e)=>{
  512. this.change('contacts',e.target.value)
  513. }} style={{width:'240px'}} />
  514. </FormItem>
  515. <FormItem
  516. className="half-item"
  517. labelCol={{ span: 8 }}
  518. wrapperCol={{ span: 12 }}
  519. label="合作电话"
  520. >
  521. <Input placeholder="请输入合作电话" value={data.contactsMobile}
  522. onChange={(e)=>{
  523. this.change('contactsMobile',e.target.value)
  524. }} style={{width:'240px'}} />
  525. </FormItem>
  526. <FormItem
  527. className="half-item"
  528. labelCol={{ span: 8 }}
  529. wrapperCol={{ span: 12 }}
  530. label="排序"
  531. >
  532. <Input placeholder="请输入排序" value={data.sortNumber}
  533. onChange={(e)=>{
  534. this.change('sortNumber',e.target.value)
  535. }} style={{width:'240px'}} />
  536. </FormItem>
  537. <FormItem
  538. className="half-item"
  539. labelCol={{ span: 8 }}
  540. wrapperCol={{ span: 12 }}
  541. label="是否置顶"
  542. >
  543. <Radio.Group onChange={(e)=>{
  544. this.change('topNumber',e.target.value)
  545. }} value={data.topNumber}>
  546. <Radio value={0}>是</Radio>
  547. <Radio value={1}>否</Radio>
  548. </Radio.Group>
  549. </FormItem>
  550. </div>
  551. <div className="clearfix">
  552. <FormItem
  553. labelCol={{ span: 4 }}
  554. wrapperCol={{ span: 18 }}
  555. label='信息大图'
  556. >
  557. <PicturesWall
  558. fileList={this.getOrgCodeUrl}
  559. pictureUrl={this.state.technicalPictureUrl} />
  560. <p>图片建议:要清晰。</p>
  561. </FormItem>
  562. </div>
  563. <div className="clearfix">
  564. <FormItem
  565. labelCol={{ span: 4 }}
  566. wrapperCol={{ span: 18 }}
  567. label='商品描述'
  568. >
  569. <TextArea placeholder="请输入商品描述" value={data.introduction}
  570. onChange={(e)=>{
  571. this.change('introduction',e.target.value)
  572. }} rows={8}/>
  573. </FormItem>
  574. </div>
  575. <div className="clearfix">
  576. {!data.releaseStatus?<Button type="primary" size="large" onClick={this.saveNew} style={{float:'right',marginRight:'80px',marginTop:'20px'}}>保存</Button>:
  577. <Button type="primary" size="large" onClick={this.saveNew} style={{float:'right',marginRight:'80px',marginTop:'20px',background:'coral',border:'none'}}>撤回</Button>}
  578. <Button type="primary" size="large" onClick={this.issueNew} style={{float:'right',marginRight:'20px',marginTop:'20px'}}>保存并发布</Button>
  579. </div>
  580. </Spin>
  581. </Form>
  582. </Modal>
  583. </div>
  584. </div>
  585. );
  586. }
  587. })
  588. );
  589. export default McjList;