知与行后台管理端

editChannel.jsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React, { useState, useEffect } from 'react';
  2. import { Input, Menu, Dropdown, Button, Icon, message, Table, Divider, Tag, Select, Form, Alert } from 'antd';
  3. import { FormattedMessage } from 'umi-plugin-react/locale';
  4. import channels from './channelList.less';
  5. import router from 'umi/router';
  6. import request from '../../utils/request'
  7. const { TextArea } = Input;
  8. const { Option } = Select;
  9. const header = props => {
  10. // eslint-disable-next-line react-hooks/rules-of-hooks
  11. useEffect(() => {
  12. getById()
  13. }, [])
  14. // 查询当前信息
  15. function getById() {
  16. request({
  17. url: `/api/admin/channel/${props.location.query.id}`,
  18. method: 'GET',
  19. // eslint-disable-next-line no-shadow
  20. }).then(data => {
  21. props.form.setFieldsValue(data)
  22. })
  23. }
  24. // 编辑
  25. function editChannel(data) {
  26. request({
  27. url: `/api/admin/channel/${props.location.query.id}`,
  28. method: 'PUT',
  29. data: { ...data },
  30. // eslint-disable-next-line no-shadow
  31. }).then(data => {
  32. // eslint-disable-next-line no-unused-expressions
  33. router.go(-1)
  34. })
  35. }
  36. function handleSubmit(e) {
  37. e.preventDefault();
  38. props.form.validateFields((err, values) => {
  39. if (!err) {
  40. console.log('values', values)
  41. editChannel({ ...values })
  42. }
  43. });
  44. }
  45. function go() {
  46. router.push({
  47. pathname: '/channel/channelList',
  48. });
  49. }
  50. const { getFieldDecorator } = props.form;
  51. return (
  52. <>
  53. <Form labelCol={{ span: 7 }} wrapperCol={{ span: 12 }} onSubmit={handleSubmit}>
  54. <Form.Item label="渠道名称">
  55. {getFieldDecorator('channelName', {
  56. rules: [{ required: true, message: '请输入渠道名称' }],
  57. })(<Input className={channels.inpuit} />)}
  58. </Form.Item>
  59. <Form.Item label="联系人">
  60. {getFieldDecorator('channelContact', {
  61. rules: [{ required: true, message: ' 请输入联系人' }],
  62. })(<Input className={channels.inpuit} />)}
  63. </Form.Item>
  64. <Form.Item label="联系电话">
  65. {getFieldDecorator('contactTel', {
  66. rules: [{ required: true, message: '请输入联系电话' }],
  67. })(<Input className={channels.inpuit} />)}
  68. </Form.Item>
  69. <Form.Item label="说明描述">
  70. {getFieldDecorator('explain', {
  71. })(<TextArea className={channels.inpuitTxt} rows={8} />)}
  72. </Form.Item>
  73. <Form.Item wrapperCol={{ span: 15, offset: 7 }}>
  74. <Button type="primary" htmlType="submit">
  75. 保存
  76. </Button>
  77. <Button className={channels.formButton} onClick = { go } type="primary" htmlType="submit">
  78. 取消
  79. </Button>
  80. </Form.Item>
  81. </Form>
  82. </>
  83. )
  84. }
  85. const WrappedNormalLoginForm = Form.create({ name: 'header' })(header);
  86. export default WrappedNormalLoginForm