editChannel.jsx 2.9KB

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