buyList.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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,getSecretType,getBuyAuditType} 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/purchase/uploadPicture"}
  51. data={{ 'sign': 'purchase_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 BuyList = 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/user/purchase/listPurchase',
  79. data: {
  80. pageNo: pageNo || 1,
  81. pageSize: this.state.pagination.pageSize,
  82. auditStatus: this.state.auditStatusSearch,
  83. type: this.state.typeSearch,
  84. secretType: this.state.secretTypeSearch,
  85. title: this.state.titleSearch,
  86. },
  87. success: function(data) {
  88. let theArr = [];
  89. if (!data.data || !data.data.list) {
  90. if (data.error && data.error.length) {
  91. message.warning(data.error[0].message);
  92. }
  93. } else {
  94. for (let i = 0; i < data.data.list.length; i++) {
  95. let thisdata = data.data.list[i];
  96. theArr.push({
  97. key: i,
  98. id: thisdata.id,
  99. title: thisdata.title,
  100. type: thisdata.type,
  101. secretType: thisdata.secretType,
  102. auditStatus: thisdata.auditStatus,
  103. topNumber: thisdata.topNumber,
  104. sortNumber: thisdata.sortNumber,
  105. home: thisdata.home,
  106. contacts: thisdata.contacts,
  107. contactsMobile:thisdata.contactsMobile,
  108. orgName:thisdata.orgName,
  109. endTimes:thisdata.endTimes,
  110. userName:thisdata.userName,
  111. });
  112. }
  113. this.state.pagination.current = data.data.pageNo;
  114. this.state.pagination.total = data.data.totalCount;
  115. }
  116. this.setState({
  117. dataSource: theArr,
  118. pagination: this.state.pagination
  119. });
  120. }.bind(this)
  121. }).always(
  122. function() {
  123. this.setState({
  124. loading: false
  125. });
  126. }.bind(this)
  127. );
  128. },
  129. getInitialState() {
  130. return {
  131. loading: false,
  132. flag: true,
  133. timesArr:[],
  134. totalData:{
  135. mark: false,
  136. auditStatus: 0,
  137. },
  138. purchaseImg: [],
  139. pagination: {
  140. defaultCurrent: 1,
  141. defaultPageSize: 10,
  142. showQuickJumper: true,
  143. pageSize: 10,
  144. onChange: function(page) {
  145. this.loadData(page);
  146. this.setState({
  147. selectedRowKeys: []
  148. });
  149. }.bind(this),
  150. showTotal: function(total) {
  151. return '共' + total + '条数据';
  152. }
  153. },
  154. columns: [
  155. {
  156. title: '序号',
  157. dataIndex: 'key',
  158. key: 'key'
  159. },
  160. {
  161. title: '标题',
  162. dataIndex: 'title',
  163. key: 'title'
  164. },
  165. {
  166. title: '信息栏目',
  167. dataIndex: 'type',
  168. key: 'type',
  169. render:text=>{
  170. return text === 0?'中标公司':'投标公司'
  171. }
  172. },
  173. {
  174. title: '密级',
  175. dataIndex: 'secretType',
  176. key: 'secretType',
  177. render:(text)=>{
  178. return getSecretType(text);
  179. }
  180. },
  181. {
  182. title: '有限时限',
  183. dataIndex: 'endTimes',
  184. key: 'endTimes',
  185. width: 200,
  186. },
  187. {
  188. title: '发布人',
  189. dataIndex: 'userName',
  190. key: 'userName',
  191. },
  192. {
  193. title: '排序',
  194. dataIndex: 'sortNumber',
  195. key: 'sortNumber'
  196. },
  197. {
  198. title: '审核状态',
  199. dataIndex: 'auditStatus',
  200. key: 'auditStatus',
  201. render:text=>{
  202. return getBuyAuditType(text);
  203. }
  204. },
  205. {
  206. title: '置顶',
  207. dataIndex: 'topNumber',
  208. key: 'topNumber',
  209. render:(text)=>{
  210. return text?'否':'是';
  211. }
  212. },
  213. {
  214. title: '操作',
  215. dataIndex: 'ads',
  216. key: 'ads',
  217. render:(text,record,index)=>{
  218. return !record.auditStatus?<div>
  219. {<Button type="primary" onClick={(event)=>{
  220. this.stopPropagation(event)
  221. this.tableRowClick(record)
  222. }}>修改</Button>}
  223. {<Popconfirm okText="确定" cancelText="取消" title="是否确认删除?" onConfirm={()=>{
  224. this.delete(record.id)
  225. }}>
  226. <Button type="primary" style={{marginLeft:"10px"}} onClick={(event)=>{
  227. this.stopPropagation(event)
  228. }}>删除</Button>
  229. </Popconfirm>}
  230. </div>:''
  231. }
  232. },
  233. ],
  234. dataSource: []
  235. };
  236. },
  237. componentWillMount() {
  238. this.loadData()
  239. },
  240. detailes(record) {
  241. this.setState({
  242. loading:true
  243. });
  244. $.ajax({
  245. method: 'get',
  246. dataType: 'json',
  247. crossDomain: false,
  248. url: globalConfig.context + '/api/user/purchase/details',
  249. data: {
  250. id: record.id,
  251. },
  252. success: function(data) {
  253. let theArr = [];
  254. let thisdata = data.data;
  255. if (!data.data || !data.data.list) {
  256. if (data.error && data.error.length) {
  257. message.warning(data.error[0].message);
  258. }
  259. }
  260. this.setState({
  261. purchaseImg: thisdata.purchaseImg ? splitUrl(thisdata.purchaseImg, ',', globalConfig.avatarHost + '/upload') : [],
  262. })
  263. Object.assign(this.state.totalData,{
  264. content: thisdata.content,
  265. },this.state.RowData)
  266. }.bind(this)
  267. }).always(
  268. function() {
  269. this.setState({
  270. loading: false
  271. });
  272. }.bind(this)
  273. );
  274. },
  275. stopPropagation(e){
  276. e.stopPropagation();
  277. e.nativeEvent.stopImmediatePropagation();
  278. },
  279. //项目列表整行点击
  280. tableRowClick(record, index) {
  281. this.state.RowData = record;
  282. this.setState({
  283. editvisible: true,
  284. });
  285. this.detailes(record);
  286. },
  287. edithandleCancel(e) {
  288. this.setState({
  289. editvisible: false
  290. },()=>{
  291. this.addReset()
  292. });
  293. this.loadData()
  294. },
  295. search() {
  296. this.loadData();
  297. },
  298. add(){
  299. this.setState({
  300. editvisible: true,
  301. flag: false,
  302. });
  303. console.log(this.state.totalData)
  304. },
  305. addNew(){
  306. let theorgCodeUrl = [];
  307. if (this.state.purchaseImg.length) {
  308. let picArr = [];
  309. this.state.purchaseImg.map(function (item) {
  310. if ( item.response && item.response.data && item.response.data.length ){
  311. picArr.push(item.response.data);
  312. }
  313. });
  314. theorgCodeUrl = picArr.join(",");
  315. };
  316. this.setState({
  317. loading:true
  318. });
  319. if(theorgCodeUrl.length){
  320. this.change("purchaseImg",theorgCodeUrl)
  321. }else{
  322. this.change("purchaseImg",[])
  323. }
  324. $.ajax({
  325. method: 'post',
  326. dataType: 'json',
  327. crossDomain: false,
  328. url: (this.state.flag?'/api/user/purchase/update':'/api/user/purchase/apply'),
  329. data: this.state.totalData,
  330. }).done(function(data) {
  331. this.setState({
  332. loading: false
  333. });
  334. if(!data.error.length) {
  335. message.success('保存成功!');
  336. this.setState({
  337. editvisible:false,
  338. flag:true
  339. })
  340. this.addReset()
  341. this.loadData()
  342. } else {
  343. message.warning(data.error[0].message);
  344. }
  345. }.bind(this));
  346. },
  347. issueNew(){
  348. this.change("auditStatus",1,()=>{
  349. this.addNew()
  350. })
  351. },
  352. delete(id){
  353. this.setState({
  354. loading:true
  355. });
  356. $.ajax({
  357. method: 'post',
  358. dataType: 'json',
  359. crossDomain: false,
  360. url: "/api/user/purchase/delete",
  361. data: {
  362. id: id,
  363. },
  364. }).done(function(data) {
  365. this.setState({
  366. loading: false
  367. });
  368. if(!data.error.length) {
  369. message.success('删除成功!');
  370. this.loadData()
  371. } else {
  372. message.warning(data.error[0].message);
  373. }
  374. }.bind(this));
  375. },
  376. cancelAdd(){
  377. this.setState({
  378. editvisible: false,
  379. },()=>{
  380. this.setState({
  381. flag:true
  382. })
  383. this.addReset()
  384. });
  385. this.loadData()
  386. },
  387. //新增框的清零
  388. addReset(){
  389. this.setState({
  390. totalData:{
  391. auditStatus: 0,
  392. },
  393. purchaseImg:[],
  394. })
  395. },
  396. //搜索部分的清零
  397. reset() {
  398. this.setState({
  399. auditStatusSearch: undefined,
  400. typeSearch: undefined,
  401. secretTypeSearch: undefined,
  402. titleSearch: undefined,
  403. })
  404. this.loadData();
  405. },
  406. getOrgCodeUrl(e) {
  407. this.setState({ purchaseImg: e });
  408. },
  409. change(key, e, f){
  410. if(f === undefined ){
  411. this.state.totalData[key] = e
  412. this.setState({
  413. totalData:this.state.totalData
  414. })
  415. }else if(typeof(f) === "function"){
  416. this.state.totalData[key] = e
  417. this.setState({
  418. totalData:this.state.totalData
  419. },f)
  420. }
  421. },
  422. render() {
  423. const FormItem = Form.Item;
  424. const rowSelection = {
  425. selectedRowKeys: this.state.selectedRowKeys,
  426. onChange: (selectedRowKeys, selectedRows) => {
  427. this.setState({
  428. selectedRows: selectedRows.slice(-1),
  429. selectedRowKeys: selectedRowKeys.slice(-1)
  430. });
  431. }
  432. };
  433. let data = this.state.totalData;
  434. const { TextArea } = Input;//文本域
  435. const { TabPane } = Tabs;//标签页
  436. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;//日期输入框
  437. return (
  438. <div className="user-content">
  439. <div className="content-title">
  440. <span>采购信息列表</span>
  441. <div className="user-search">
  442. <Input
  443. placeholder="企业名称"
  444. style={{ width: '150px', marginRight: '10px', marginBottom: '10px' }}
  445. value={this.state.nameSearch}
  446. onChange={(e) => {
  447. this.setState({ nameSearch: e.target.value });
  448. }}
  449. />
  450. <Button type="primary" onClick={this.search} style={{ marginRight: '10px' }}>
  451. 搜索
  452. </Button>
  453. <Button onClick={this.reset} style={{ marginRight: '10px' }}>
  454. 重置
  455. </Button>
  456. <Button type="primary" onClick={this.add} style={{ marginLeft: '100px'}}>
  457. 新增采购信息
  458. </Button>
  459. </div>
  460. <div className="patent-table">
  461. <Spin spinning={this.state.loading}>
  462. <Table
  463. columns={this.state.columns}
  464. dataSource={this.state.dataSource}
  465. pagination={this.state.pagination}
  466. onRowClick={this.tableRowClick}
  467. />
  468. </Spin>
  469. </div>
  470. </div>
  471. <div className="patent-desc">
  472. <Modal
  473. className="customeDetails"
  474. title={this.state.flag?'采购信息详情':'新增采购信息'}
  475. width="1000px"
  476. visible={this.state.editvisible}
  477. onOk={this.edithandleCancel}
  478. onCancel={this.state.flag?this.edithandleCancel:this.cancelAdd}
  479. footer=""
  480. >
  481. <Form layout="horizontal" onSubmit={this.edithandleSubmit} id="demand-form">
  482. <Spin spinning={this.state.loading}>
  483. <div className="clearfix">
  484. <FormItem
  485. className="half-item"
  486. labelCol={{ span: 8 }}
  487. wrapperCol={{ span: 12 }}
  488. label="标题"
  489. >
  490. <Input placeholder="请输入标题" value={data.title}
  491. onChange={(e)=>{
  492. this.change('title',e.target.value)
  493. }} style={{width:'240px'}} />
  494. </FormItem>
  495. <FormItem
  496. className="half-item"
  497. labelCol={{ span: 8 }}
  498. wrapperCol={{ span: 12 }}
  499. label="信息栏目"
  500. >
  501. <Select value={data.type} style={{ width: 120 }}
  502. placeholder='请选择信息栏目' onChange={(e)=>{
  503. this.change('type',e)
  504. }}>
  505. <Option value={0}>中标公司</Option>
  506. <Option value={1}>投标公司</Option>
  507. </Select>
  508. </FormItem>
  509. <FormItem
  510. className="half-item"
  511. labelCol={{ span: 8 }}
  512. wrapperCol={{ span: 12 }}
  513. label="密级"
  514. >
  515. <Select value={data.secretType} style={{ width: 120 }}
  516. placeholder='请选择密级' onChange={(e)=>{
  517. this.change('secretType',e)
  518. }}>
  519. <Option value={0}>公开</Option>
  520. <Option value={1}>三级</Option>
  521. <Option value={2}>二级</Option>
  522. <Option value={3}>机密</Option>
  523. </Select>
  524. </FormItem>
  525. <FormItem
  526. className="half-item"
  527. labelCol={{ span: 8 }}
  528. wrapperCol={{ span: 12 }}
  529. label="有限时限"
  530. >
  531. <DatePicker placeholder="请输入有限时限" value={data.endTimes ? moment(data.endTimes) : null}
  532. onChange={(e,f)=>{
  533. this.change('endTimes',f)
  534. }} style={{width:'240px'}} />
  535. </FormItem>
  536. <FormItem
  537. className="half-item"
  538. labelCol={{ span: 8 }}
  539. wrapperCol={{ span: 12 }}
  540. label="排序"
  541. >
  542. <Input placeholder="请输入排序" value={data.sortNumber}
  543. onChange={(e)=>{
  544. this.change('sortNumber',e.target.value)
  545. }} style={{width:'240px'}} />
  546. </FormItem>
  547. <FormItem
  548. className="half-item"
  549. labelCol={{ span: 8 }}
  550. wrapperCol={{ span: 12 }}
  551. label="是否置顶"
  552. >
  553. <Radio.Group onChange={(e)=>{
  554. this.change('topNumber',e.target.value)
  555. }} value={data.topNumber}>
  556. <Radio value={0}>是</Radio>
  557. <Radio value={1}>否</Radio>
  558. </Radio.Group>
  559. </FormItem>
  560. </div>
  561. <div className="clearfix">
  562. <FormItem
  563. labelCol={{ span: 4 }}
  564. wrapperCol={{ span: 18 }}
  565. label='采购大图'
  566. >
  567. <PicturesWall
  568. fileList={this.getOrgCodeUrl}
  569. pictureUrl={this.state.purchaseImg} />
  570. <p>图片建议:要清晰。</p>
  571. </FormItem>
  572. </div>
  573. <div className="clearfix">
  574. <FormItem
  575. labelCol={{ span: 4 }}
  576. wrapperCol={{ span: 18 }}
  577. label='详细采购信息'
  578. >
  579. <TextArea placeholder="请输入详细采购信息" value={data.content}
  580. onChange={(e)=>{
  581. this.change('content',e.target.value)
  582. }} rows={8}/>
  583. </FormItem>
  584. </div>
  585. {!data.auditStatus?<div className="clearfix">
  586. <Button type="primary" size="large" onClick={this.addNew} style={{float:'right',marginRight:'80px',marginTop:'20px'}}>保存</Button>
  587. <Button type="primary" size="large" onClick={this.issueNew} style={{float:'right',marginRight:'20px',marginTop:'20px'}}>保存并提交</Button>
  588. </div>:''}
  589. </Spin>
  590. </Form>
  591. </Modal>
  592. </div>
  593. </div>
  594. );
  595. }
  596. })
  597. );
  598. export default BuyList;