Browse Source

渠道添加

dingxin 5 years ago
parent
commit
a0c638f51a
2 changed files with 83 additions and 63 deletions
  1. 47
    25
      src/pages/channel/addChannel.jsx
  2. 36
    38
      src/pages/channel/channelList.jsx

+ 47
- 25
src/pages/channel/addChannel.jsx View File

@@ -1,37 +1,64 @@
1
-import React from 'react';
2
-import { Form, Select, Input, Button } from 'antd';
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';
3 4
 import channels from './channelList.less';
5
+import router from 'umi/router';
6
+import request from '../../utils/request'
4 7
 
5 8
 const { TextArea } = Input;
6 9
 const { Option } = Select;
7 10
 
8
-class App extends React.Component {
9
-  handleSubmit = e => {
11
+const header = props => {
12
+  // eslint-disable-next-line react-hooks/rules-of-hooks
13
+  const [data, setData] = useState({ channelNmae: [], result: [] })
14
+  // eslint-disable-next-line react-hooks/rules-of-hooks
15
+
16
+  // useEffect(() => {
17
+  //   addChannel({ pageNum: 1, pageSize: 10 })
18
+  // }, [])
19
+
20
+  function addChannel(params) {
21
+      request({
22
+        url: '/api/admin/channel',
23
+        method: 'POST',
24
+        data: { ...params },
25
+    // eslint-disable-next-line no-shadow
26
+    }).then(data => {
27
+        console.log(data)
28
+        setData(data)
29
+         // eslint-disable-next-line no-unused-expressions
30
+         router.go(-1)
31
+    })
32
+  }
33
+
34
+  function handleSubmit(e) {
10 35
     e.preventDefault();
11
-    this.props.form.validateFields((err, values) => {
12
-      console.log('Form.Item', values.note)
36
+    props.form.validateFields((err, values) => {
13 37
       if (!err) {
14
-       alert('Received values of form: ', values);
38
+        console.log('Received values of form: ', values);
39
+        // eslint-disable-next-line max-len
40
+        addChannel({ channelName: values.channelName, channelContact: values.channelContact, contactTel: values.contactTel })
15 41
       }
16 42
     });
17
-  };
43
+  }
44
+
45
+  const { getFieldDecorator } = props.form;
18 46
 
19
-  render() {
20
-    const { getFieldDecorator } = this.props.form;
21
-    return (
22
-      <Form labelCol={{ span: 7 }} wrapperCol={{ span: 12 }} onSubmit={this.handleSubmit}>
47
+  return (
48
+  <>
49
+        <Form labelCol={{ span: 7 }} wrapperCol={{ span: 12 }} onSubmit={handleSubmit}>
23 50
         <Form.Item label="渠道名称">
24
-          {getFieldDecorator('note', {
51
+          {getFieldDecorator('channelName', {
25 52
             rules: [{ required: true, message: '请输入渠道名称' }],
26 53
           })(<Input className={channels.inpuit} / >)}
27 54
         </Form.Item>
28 55
         <Form.Item label="联系人">
29
-          {getFieldDecorator('note2', {
56
+          {getFieldDecorator('channelContact', {
30 57
             rules: [{ required: true, message: ' 请输入联系人' }],
31 58
           })(<Input className={channels.inpuit} />)}
32 59
         </Form.Item>
33 60
         <Form.Item label="联系电话">
34
-          {getFieldDecorator('note3', {
61
+          {getFieldDecorator('contactTel', {
35 62
             rules: [{ required: true, message: '请输入联系电话' }],
36 63
           })(<Input className={channels.inpuit} />)}
37 64
         </Form.Item>
@@ -42,19 +69,14 @@ class App extends React.Component {
42 69
           <Button type="primary" htmlType="submit">
43 70
             保存
44 71
           </Button>
45
-          <Button className={channels.formButton} type="primary" htmlType="submit">
72
+          <Button className={channels.formButton} onClick = {() => router.go(-1)} type="primary" htmlType="submit">
46 73
             取消
47 74
           </Button>
48 75
         </Form.Item>
49 76
       </Form>
50
-    );
51
-  }
77
+  </>
78
+)
52 79
 }
53 80
 
54
-const WrappedApp = Form.create({ name: 'coordinated' })(App);
55
-
56
-export default () => (
57
-  <>
58
-    <WrappedApp />
59
-  </>
60
-);
81
+const WrappedNormalLoginForm = Form.create({ name: 'header' })(header);
82
+export default WrappedNormalLoginForm

+ 36
- 38
src/pages/channel/channelList.jsx View File

@@ -6,27 +6,7 @@ import router from 'umi/router';
6 6
 import request from '../../utils/request'
7 7
 
8 8
 const { Option } = Select;
9
-function handleChange(value) {
10
-  console.log(`selected ${value}`);
11
-}
12
-
13 9
 
14
-const menu = (
15
-  <Menu onClick={handleMenuClick}>
16
-    <Menu.Item key="1">
17
-      <Icon type="user" />
18
-      1st menu item
19
-    </Menu.Item>
20
-    <Menu.Item key="2">
21
-      <Icon type="user" />
22
-      2nd menu item
23
-    </Menu.Item>
24
-    <Menu.Item key="3">
25
-      <Icon type="user" />
26
-      3rd item
27
-    </Menu.Item>
28
-  </Menu>
29
-);
30 10
 // const dataSource = [
31 11
 //   {
32 12
 //     key: '1',
@@ -117,45 +97,63 @@ function toEditGoods() {
117 97
 
118 98
 const header = props => {
119 99
   // eslint-disable-next-line react-hooks/rules-of-hooks
120
-  const [data, setData] = useState({ records: [] })
121
-//   const [page, changePage] = useState({})
100
+  const [data, setData] = useState({ channelNmae: [], result: [] })
101
+  // eslint-disable-next-line react-hooks/rules-of-hooks
102
+  // const [queryData, setQueryData] = useState({ pageNum: 1, pageSize: 10 })
103
+  //   const [page, changePage] = useState({})
122 104
   // eslint-disable-next-line react-hooks/rules-of-hooks
123 105
   useEffect(() => {
124
-    request({
125
-        url: '/api/admin/channel',
126
-        method: 'GET',
127
-        params: { pageNum: 1, pageSize: 10 },
128
-    // eslint-disable-next-line no-shadow
129
-    }).then(data => {
130
-        console.log(data)
131
-        setData(data)
132
-    })
106
+    getList({ pageNum: 1, pageSize: 10 })
133 107
   }, [])
134 108
 
109
+  function getList(params) {
110
+    request({
111
+      url: '/api/admin/channel',
112
+      method: 'GET',
113
+      params: { ...params },
114
+  // eslint-disable-next-line no-shadow
115
+  }).then(data => {
116
+      console.log(data)
117
+      setData(data)
118
+  })
119
+  }
120
+  // value 的值
121
+  function handleChange(value) {
122
+    // setQueryData({ ...queryData, channelId: value });
123
+    localStorage.setItem('value', value);
124
+  }
125
+  // 查询
126
+  function queryList() {
127
+    getList({ pageNum: 1, pageSize: 10, channelId: localStorage.getItem('value') })
128
+  }
129
+ // 重置
130
+ function reset() {
131
+  getList({ pageNum: 1, pageSize: 10 })
132
+ }
135 133
   return (
136 134
     <>
137 135
       <div className={channels.searchBox}>
138 136
         <dvi>
139 137
           <span className={channels.selectName}>渠道名称</span>
140 138
           <Select defaultValue="请选择" style={{ width: 180 }} onChange={handleChange}>
141
-              {data.records.map(Item =>
139
+          <option value="">全部</option>
140
+              {data.channelNmae.map(Item =>
142 141
                 <Option value={ Item.channelId }> { Item.channelName } </Option>,
143 142
               )}
144 143
               {/* {listItems} */}
145 144
           </Select>
146 145
 
147 146
         </dvi>
148
-        <Button className={channels.about} onClick={ header }>查询</Button>
147
+        <div >
148
+        <Button style ={{ backgroundColor: '#00bfff' } } onClick={() => queryList() }>查询</Button>
149
+        <Button onClick={() => reset() }>重置</Button>
150
+        </div>
149 151
       </div>
150 152
       <Button className={channels.addBtn} onClick={toEditGoods}>新增</Button>
151
-      <Table dataSource={data.records} columns={columns} />
153
+      <Table dataSource={data.result.records} columns={columns} />
152 154
   </>
153 155
   )
154 156
 }
155 157
 
156
-function handleMenuClick(e) {
157
-  message.info('Click on menu item.');
158
-  console.log('click', e);
159
-}
160 158
 
161 159
 export default header