advertisementList.jsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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 {
  6. Form,
  7. Icon,
  8. Button,
  9. Input,
  10. Select,
  11. Spin,
  12. Table,
  13. message,
  14. DatePicker,
  15. Modal,
  16. Upload,
  17. Popconfirm,
  18. Cascader,
  19. InputNumber,
  20. Radio,
  21. TimePicker,
  22. Tabs,
  23. Tag
  24. } from "antd";
  25. import { areaSelect, getProvince } from "@/NewDicProvinceList"; //省市区
  26. import {
  27. getGameState,
  28. splitUrl,
  29. getprovince,
  30. getStatuslist,
  31. getLvl,
  32. beforeUploadFile,
  33. getPicPath
  34. } from "@/tools.js";
  35. const { Option } = Select;
  36. const PicturesWall = React.createClass({
  37. getInitialState() {
  38. return {
  39. previewVisible: false,
  40. previewImage: "",
  41. fileList: []
  42. };
  43. },
  44. getDefaultProps() {
  45. return {
  46. changeClick: this.modifyChange
  47. };
  48. },
  49. handleCancel() {
  50. this.setState({ previewVisible: false });
  51. },
  52. handlePreview(file) {
  53. this.setState({
  54. previewImage: file.url || file.thumbUrl,
  55. previewVisible: true
  56. });
  57. },
  58. handleChange(info) {
  59. let fileList = info.fileList;
  60. this.setState({ fileList });
  61. this.props.fileList(fileList);
  62. },
  63. componentWillReceiveProps(nextProps) {
  64. this.state.fileList = nextProps.pictureUrl;
  65. },
  66. render() {
  67. const { previewVisible, previewImage, fileList } = this.state;
  68. const uploadButton = (
  69. <div>
  70. <Icon type="plus" />
  71. <div className="ant-upload-text">点击上传</div>
  72. </div>
  73. );
  74. return (
  75. <div style={{ display: "inline-block" }}>
  76. <Upload
  77. beforeUpload={beforeUploadFile}
  78. // action={globalConfig.context + "/api/admin/purchase/uploadPicture"}
  79. // url: '//172.16.0.253:8080' + '/api/admin/banners/addBanners',
  80. action={globalConfig.context + "/api/admin/banners/uploadFile"}
  81. data={{ sign: "purchase_picture" }}
  82. listType="picture-card"
  83. fileList={fileList}
  84. onPreview={this.handlePreview}
  85. onChange={this.handleChange}
  86. >
  87. {fileList && fileList.length >= 1 ? null : uploadButton}
  88. </Upload>
  89. <Modal
  90. maskClosable={false}
  91. visible={previewVisible}
  92. footer={null}
  93. onCancel={this.handleCancel}
  94. >
  95. <img alt="" style={{ width: "100%" }} src={previewImage} />
  96. </Modal>
  97. </div>
  98. );
  99. }
  100. });
  101. //主体
  102. const AdvertisementList = Form.create()(
  103. React.createClass({
  104. loadData(pageNo) {
  105. this.state.data = [];
  106. this.setState({
  107. loading: true,
  108. page: pageNo
  109. });
  110. $.ajax({
  111. method: "get",
  112. dataType: "json",
  113. // url: globalConfig.context + '/api/admin/listCases',
  114. url: globalConfig.context + "/api/admin/banners/listBanners",
  115. data: {
  116. pageNo: pageNo || this.state.pagination.current || 1,
  117. pageSize: this.state.pagination.pageSize,
  118. position: this.state.positionSearch
  119. },
  120. success: function(data) {
  121. let theArr = [];
  122. if (!data.data || !data.data.list) {
  123. if (data.error && data.error.length) {
  124. message.warning(data.error[0].message);
  125. }
  126. } else {
  127. for (let i = 0; i < data.data.list.length; i++) {
  128. let thisdata = data.data.list[i];
  129. theArr.push({
  130. key: i + 1,
  131. id: thisdata.id,
  132. title: thisdata.title,
  133. bannerUrl: thisdata.bannerUrl,
  134. sort: thisdata.sort,
  135. display: thisdata.display,
  136. position: thisdata.position
  137. });
  138. }
  139. this.state.pagination.current = data.data.pageNo;
  140. this.state.pagination.total = data.data.totalCount;
  141. }
  142. this.setState({
  143. dataSource: theArr,
  144. pagination: this.state.pagination
  145. });
  146. }.bind(this)
  147. }).always(
  148. function() {
  149. this.setState({
  150. loading: false
  151. });
  152. }.bind(this)
  153. );
  154. },
  155. getInitialState() {
  156. return {
  157. loading: false,
  158. flag: true,
  159. imgeditvisible: false,
  160. activeKey: "1",
  161. purchaseImg: [],
  162. maximg: "",
  163. timesArr: [],
  164. pagination: {
  165. defaultCurrent: 1,
  166. defaultPageSize: 10,
  167. showQuickJumper: true,
  168. pageSize: 10,
  169. onChange: function(page) {
  170. this.loadData(page);
  171. this.setState({
  172. selectedRowKeys: []
  173. });
  174. }.bind(this),
  175. showTotal: function(total) {
  176. return "共" + total + "条数据";
  177. }
  178. },
  179. //数据类型
  180. columns: [
  181. {
  182. title: "序号",
  183. dataIndex: "key",
  184. key: "key"
  185. },
  186. {
  187. title: "广告位置",
  188. dataIndex: "position",
  189. key: "position",
  190. render: text => {
  191. if (text == 0) {
  192. return <span>首页</span>;
  193. }else if(text == 1) {
  194. return <span>产品中心</span>;
  195. }else if(text == 2) {
  196. return <span>战略合作</span>;
  197. }else if(text == 3) {
  198. return <span>服务客户</span>;
  199. }else if(text == 4) {
  200. return <span>新闻动态</span>;
  201. }else if(text == 5) {
  202. return <span>关于科德</span>;
  203. }else if(text == 6) {
  204. return <span>联系我们</span>;
  205. }else {
  206. return "未知"
  207. }
  208. }
  209. },
  210. {
  211. title: "广告缩略图",
  212. dataIndex: "bannerUrl",
  213. key: "bannerUrl",
  214. render: url => {
  215. let path = getPicPath(globalConfig.avatarUploadHost, url);
  216. return (
  217. <div style={{ textAlign: "center" }}>
  218. <img src={path} style={{ width: "100px", height: 50 }} />
  219. <Button
  220. className="buttonimg"
  221. style={{ marginLeft: 10 }}
  222. onClick={e => {
  223. this.stopPropagation(e);
  224. this.maximg(path);
  225. }}
  226. >
  227. 查看大图
  228. </Button>
  229. </div>
  230. );
  231. }
  232. },
  233. {
  234. title: "是否显示",
  235. dataIndex: "display",
  236. key: "display",
  237. render: s => {
  238. return s ? (
  239. <Tag color="#87d068">显示</Tag>
  240. ) : (
  241. <Tag color="#f50">未显示</Tag>
  242. );
  243. }
  244. },
  245. {
  246. title: "排序",
  247. dataIndex: "sort",
  248. key: "sort"
  249. },
  250. {
  251. title: "操作",
  252. dataIndex: "c",
  253. render: (text, record, index) => {
  254. return (
  255. <div>
  256. {
  257. <Button
  258. type="primary"
  259. onClick={event => {
  260. this.stopPropagation(event);
  261. this.tableRowClick(record);
  262. }}
  263. >
  264. 编辑
  265. </Button>
  266. }
  267. {
  268. <Popconfirm
  269. okText="确定"
  270. cancelText="取消"
  271. title="您确定删除?删除后,广告将不再显示"
  272. onConfirm={() => {
  273. this.delete(record.id);
  274. }}
  275. >
  276. <Button
  277. type="danger"
  278. style={{ marginLeft: "10px" }}
  279. onClick={event => {
  280. this.stopPropagation(event);
  281. }}
  282. >
  283. 删除
  284. </Button>
  285. </Popconfirm>
  286. }
  287. {!record.display ? (
  288. <Button
  289. type="primary"
  290. style={{ marginLeft: "10px" }}
  291. onClick={event => {
  292. this.stopPropagation(event);
  293. this.edit(record, "1");
  294. }}
  295. >
  296. 显示
  297. </Button>
  298. ) : (
  299. <Button
  300. type="primary"
  301. style={{ marginLeft: "10px" }}
  302. onClick={event => {
  303. this.stopPropagation(event);
  304. this.edit(record, "0");
  305. }}
  306. >
  307. 隐藏
  308. </Button>
  309. )}
  310. </div>
  311. );
  312. }
  313. }
  314. ],
  315. //数据列表
  316. dataSource: [
  317. ]
  318. };
  319. },
  320. componentWillMount() {
  321. this.loadData();
  322. },
  323. detailes(record) {
  324. this.setState({
  325. loading: true
  326. });
  327. $.ajax({
  328. method: "get",
  329. dataType: "json",
  330. crossDomain: false,
  331. url: globalConfig.context + "/api/admin/banners/selectBanners",
  332. data: {
  333. id: record.id
  334. },
  335. success: function(data) {
  336. let thisdata = data.data;
  337. this.setState({
  338. id: thisdata.id,
  339. title: thisdata.title,
  340. bannerUrl: thisdata.bannerUrl
  341. ? splitUrl(thisdata.bannerUrl, ",", globalConfig.avatarUploadHost)
  342. : [],
  343. sortNumber: thisdata.sort,
  344. display: thisdata.display,
  345. position: thisdata.position
  346. });
  347. }.bind(this)
  348. }).always(
  349. function() {
  350. this.setState({
  351. loading: false
  352. });
  353. }.bind(this)
  354. );
  355. },
  356. //点击大图
  357. maximg(url) {
  358. this.setState({
  359. imgeditvisible: true,
  360. maximg: url
  361. });
  362. },
  363. //删除按钮
  364. delete(id) {
  365. $.ajax({
  366. method: "post",
  367. dataType: "json",
  368. crossDomain: false,
  369. url: globalConfig.context + "/api/admin/banners/deleteBanners",
  370. data: {
  371. id
  372. },
  373. success: function(data) {
  374. this.loadData();
  375. }.bind(this)
  376. }).always(
  377. function() {
  378. this.setState({
  379. loading: false
  380. });
  381. }.bind(this)
  382. );
  383. },
  384. //阻止默认冒泡
  385. stopPropagation(e) {
  386. e.stopPropagation();
  387. e.nativeEvent.stopImmediatePropagation();
  388. },
  389. imghandleCancel() {
  390. this.setState({
  391. imgeditvisible: false
  392. });
  393. },
  394. //项目列表整行点击
  395. tableRowClick(record, index) {
  396. this.state.RowData = record;
  397. this.setState({
  398. editvisible: true
  399. });
  400. this.detailes(record);
  401. },
  402. edithandleCancel(e) {
  403. this.setState(
  404. {
  405. editvisible: false
  406. },
  407. () => {
  408. this.addReset();
  409. }
  410. );
  411. this.loadData();
  412. },
  413. search() {
  414. this.loadData();
  415. },
  416. add() {
  417. this.setState({
  418. editvisible: true,
  419. flag: false
  420. });
  421. this.addReset();
  422. },
  423. cancelAdd() {
  424. this.setState(
  425. {
  426. editvisible: false
  427. },
  428. () => {
  429. this.setState({
  430. flag: true
  431. });
  432. this.addReset();
  433. }
  434. );
  435. this.loadData();
  436. },
  437. edit(record, display) {
  438. if (!display) {
  439. if (!this.state.bannerUrl || !this.state.bannerUrl.length) {
  440. message.warning("请上传图片!");
  441. return;
  442. }
  443. if (!this.state.title) {
  444. message.warning("请填写广告标题");
  445. return;
  446. }
  447. }
  448. $.ajax({
  449. method: "post",
  450. dataType: "json",
  451. url: globalConfig.context + "/api/admin/banners/updateBanners",
  452. data: {
  453. id: record ? record.id : this.state.id,
  454. sort: this.state.sortNumber,
  455. display: display || this.state.display,
  456. position: this.state.position,
  457. bannerUrl: this.state.bannerUrl
  458. ? this.state.bannerUrl[0].response.data
  459. : undefined,
  460. title: this.state.title
  461. },
  462. success: function(data) {
  463. let theArr = [];
  464. if (data.error.length || data.data.list == "") {
  465. if (data.error && data.error.length) {
  466. message.warning(data.error[0].message);
  467. }
  468. } else {
  469. this.cancelAdd();
  470. }
  471. }.bind(this)
  472. }).always(
  473. function() {
  474. this.setState({
  475. loading: false
  476. });
  477. }.bind(this)
  478. );
  479. },
  480. addNew() {
  481. if (!this.state.bannerUrl || !this.state.bannerUrl.length) {
  482. message.warning("请上传图片!");
  483. return;
  484. }
  485. if (!this.state.title) {
  486. message.warning("请填写广告标题");
  487. return;
  488. }
  489. $.ajax({
  490. method: "post",
  491. dataType: "json",
  492. url: globalConfig.context + "/api/admin/banners/addBanners",
  493. data: {
  494. sort: this.state.sortNumber,
  495. display: this.state.display,
  496. position: this.state.position,
  497. bannerUrl: this.state.bannerUrl
  498. ? this.state.bannerUrl[0].response.data
  499. : undefined,
  500. title: this.state.title
  501. },
  502. success: function(data) {
  503. let theArr = [];
  504. if (data.error.length || data.data.list == "") {
  505. if (data.error && data.error.length) {
  506. message.warning(data.error[0].message);
  507. }
  508. } else {
  509. this.loadData();
  510. this.cancelAdd();
  511. }
  512. }.bind(this)
  513. }).always(
  514. function() {
  515. this.setState({
  516. loading: false
  517. });
  518. }.bind(this)
  519. );
  520. },
  521. //新增框的清零
  522. addReset() {
  523. this.setState({
  524. bannerUrl: undefined,
  525. title: undefined,
  526. sortNumber: undefined,
  527. display: 1,
  528. position: "0"
  529. });
  530. },
  531. //搜索部分的清零
  532. reset() {
  533. this.state.positionSearch = undefined;
  534. this.loadData();
  535. },
  536. imgOk() {
  537. this.setState({
  538. imgeditvisible: false
  539. });
  540. },
  541. getOrgCodeUrl(e) {
  542. this.setState({ bannerUrl: e });
  543. },
  544. render() {
  545. const FormItem = Form.Item;
  546. const rowSelection = {
  547. selectedRowKeys: this.state.selectedRowKeys,
  548. onChange: (selectedRowKeys, selectedRows) => {
  549. this.setState({
  550. selectedRows: selectedRows.slice(-1),
  551. selectedRowKeys: selectedRowKeys.slice(-1)
  552. });
  553. }
  554. };
  555. const { TextArea } = Input; //文本域
  556. const { TabPane } = Tabs; //标签页
  557. const { MonthPicker, RangePicker, WeekPicker } = DatePicker; //日期输入框
  558. const dateFormat = "YYYY/MM/DD"; //日期格式
  559. const theData = this.state.data || {};
  560. return (
  561. <div className="user-content">
  562. <div className="content-title">
  563. <span>广告列表</span>
  564. <div className="user-search">
  565. <Select
  566. placeholder="请选择广告位置"
  567. style={{ width: 150 }}
  568. value={
  569. this.state.positionSearch
  570. ? this.state.positionSearch + ""
  571. : []
  572. }
  573. onChange={e => {
  574. this.setState({
  575. positionSearch: e
  576. });
  577. }}
  578. >
  579. <Option value="0">首页</Option>
  580. <Option value="1">产品中心</Option>
  581. <Option value="2">战略合作</Option>
  582. <Option value="3">服务客户</Option>
  583. <Option value="4">新闻动态</Option>
  584. <Option value="5">关于科德</Option>
  585. <Option value="6">联系我们</Option>
  586. </Select>
  587. <Button
  588. type="primary"
  589. onClick={this.search}
  590. style={{ marginRight: "10px" }}
  591. >
  592. 搜索
  593. </Button>
  594. <Button onClick={this.reset} style={{ marginRight: "10px" }}>
  595. 重置
  596. </Button>
  597. <Button
  598. type="primary"
  599. onClick={this.add}
  600. style={{ marginLeft: "100px" }}
  601. >
  602. 新增广告
  603. </Button>
  604. </div>
  605. <div className="patent-table">
  606. <Spin spinning={this.state.loading}>
  607. <Table
  608. columns={this.state.columns}
  609. dataSource={this.state.dataSource}
  610. onRowClick={this.tableRowClick}
  611. pagination={this.state.pagination}
  612. bordered
  613. size="small"
  614. />
  615. </Spin>
  616. </div>
  617. </div>
  618. <div className="patent-desc">
  619. <Modal
  620. className="customeDetails"
  621. title={this.state.flag ? "广告详情" : "新增广告"}
  622. visible={this.state.editvisible}
  623. onOk={this.edithandleCancel}
  624. width={"500px"}
  625. onCancel={
  626. this.state.flag ? this.edithandleCancel : this.cancelAdd
  627. }
  628. footer=""
  629. >
  630. <Form
  631. layout="horizontal"
  632. onSubmit={this.edithandleSubmit}
  633. id="demand-form"
  634. >
  635. <Spin spinning={this.state.loading}>
  636. <div className="clearfix">
  637. <FormItem
  638. className="half-item"
  639. labelCol={{ span: 8 }}
  640. wrapperCol={{ span: 12 }}
  641. label="广告位置"
  642. >
  643. <Select
  644. placeholder="请选择广告位置"
  645. style={{ width: 120 }}
  646. value={this.state.position + ""}
  647. onChange={e => {
  648. this.setState({
  649. position: e
  650. });
  651. }}
  652. >
  653. <Option value="0">首页</Option>
  654. <Option value="1">产品中心</Option>
  655. <Option value="2">战略合作</Option>
  656. <Option value="3">服务客户</Option>
  657. <Option value="4">新闻动态</Option>
  658. <Option value="5">关于科德</Option>
  659. <Option value="6">联系我们</Option>
  660. </Select>
  661. </FormItem>
  662. <div className="clearfix">
  663. <FormItem
  664. className="half-item"
  665. labelCol={{ span: 8 }}
  666. wrapperCol={{ span: 12 }}
  667. label="广告标题"
  668. >
  669. <Input
  670. placeholder="请输入标题"
  671. value={this.state.title}
  672. onChange={e => {
  673. this.setState({ title: e.target.value });
  674. }}
  675. style={{ width: "240px" }}
  676. />
  677. </FormItem>
  678. </div>
  679. <div className="clearfix">
  680. <FormItem
  681. className="half-item"
  682. labelCol={{ span: 8 }}
  683. wrapperCol={{ span: 12 }}
  684. label="排序"
  685. >
  686. <Input
  687. placeholder="请输入排序"
  688. value={this.state.sortNumber}
  689. onChange={e => {
  690. this.setState({ sortNumber: e.target.value });
  691. }}
  692. style={{ width: "240px" }}
  693. />
  694. </FormItem>
  695. </div>
  696. <FormItem
  697. className="half-item"
  698. labelCol={{ span: 8 }}
  699. wrapperCol={{ span: 12 }}
  700. label="是否显示"
  701. >
  702. <Radio.Group
  703. onChange={e => {
  704. this.setState({
  705. display: e.target.value
  706. });
  707. }}
  708. value={this.state.display}
  709. >
  710. <Radio value={1}>是</Radio>
  711. <Radio value={0}>否</Radio>
  712. </Radio.Group>
  713. </FormItem>
  714. </div>
  715. <div className="clearfix">
  716. <FormItem
  717. labelCol={{ span: 4 }}
  718. wrapperCol={{ span: 18 }}
  719. label="广告大图"
  720. >
  721. <PicturesWall
  722. fileList={this.getOrgCodeUrl}
  723. pictureUrl={this.state.bannerUrl}
  724. />
  725. <p>图片建议:要清晰。</p>
  726. </FormItem>
  727. </div>
  728. <div className="clearfix">
  729. <Button
  730. type="primary"
  731. size="large"
  732. onClick={() => {
  733. this.state.flag ? this.edit() : this.addNew();
  734. }}
  735. style={{
  736. display: "block",
  737. margin: "auto"
  738. }}
  739. >
  740. 保存
  741. </Button>
  742. </div>
  743. </Spin>
  744. </Form>
  745. </Modal>
  746. </div>
  747. <Modal
  748. visible={this.state.imgeditvisible}
  749. onCancel={this.imghandleCancel}
  750. onOk={this.imgOk}
  751. >
  752. <img style={{ width: "100%" }} src={this.state.maximg} />
  753. </Modal>
  754. </div>
  755. );
  756. }
  757. })
  758. );
  759. export default AdvertisementList;