张延森 3 years ago
parent
commit
8613ca701f
5 changed files with 96 additions and 23 deletions
  1. 2
    1
      config/proxy.js
  2. 0
    1
      config/routes.js
  3. 73
    18
      src/pages/building/Edit/Channel.jsx
  4. 18
    0
      src/services/apis.js
  5. 3
    3
      src/utils/request.js

+ 2
- 1
config/proxy.js View File

8
 export default {
8
 export default {
9
   dev: {
9
   dev: {
10
     '/api/': {
10
     '/api/': {
11
-      target: 'https://xlk.njyz.tech/',
11
+      // target: 'https://xlk.njyz.tech/',
12
+      target: 'http://localhost:8081/',
12
       changeOrigin: true,
13
       changeOrigin: true,
13
       pathRewrite: {
14
       pathRewrite: {
14
         '^': '',
15
         '^': '',

+ 0
- 1
config/routes.js View File

86
                 hideInMenu: true,
86
                 hideInMenu: true,
87
                 component: './customer/Customer/PrivateCustomer/CustomerDetail',
87
                 component: './customer/Customer/PrivateCustomer/CustomerDetail',
88
               },
88
               },
89
-
90
               // {
89
               // {
91
               //   path: '/customer/customerlist/list',
90
               //   path: '/customer/customerlist/list',
92
               //   name: '客户列表old',
91
               //   name: '客户列表old',

+ 73
- 18
src/pages/building/Edit/Channel.jsx View File

1
-import React from 'react'
2
-import { Button, Form, Input, Select } from 'antd'
1
+import React, { useEffect, useState } from 'react'
2
+import { connect } from 'dva';
3
+import { Button, Form, Input, message, Select } from 'antd'
4
+import { fetch, apis } from '@/utils/request'
3
 import InputNumber from './components/InputNumber'
5
 import InputNumber from './components/InputNumber'
4
 import { formItemLayout, validMinNum } from './utils'
6
 import { formItemLayout, validMinNum } from './utils'
5
 
7
 
6
-const ChannelForm = (props) => {
7
-  const { form } = props
8
-  const { getFieldDecorator } = form
8
+const getChannel = fetch(apis.building.channel.get)
9
+// const saveChannel = fetch(apis.building.channel.save)
10
+const updateChannel = fetch(apis.building.channel.update)
11
+const getChannelDict = fetch(apis.channelList.getList)
12
+
13
+const ChannelForm = React.forwardRef((props, ref) => {
14
+  const { form, history, user } = props
15
+  const { getFieldDecorator, setFieldsValue, validateFields } = form
16
+  const { query } = history.location;
17
+  const { id } = query;
18
+
19
+  const [loading, setLoading] = useState(false)
20
+  const [dict, setDict] = useState([])
21
+
22
+  const handleSubmit = (e) => {
23
+    e.preventDefault();
24
+    validateFields((err, values) => {
25
+      if (!err) {
26
+        const data = {
27
+          ...values,
28
+          buildingId: id,
29
+        }
30
+
31
+        setLoading(true)
32
+        updateChannel({ data }).then(() => {
33
+          setLoading(false)
34
+          message.success('数据保存成功')
35
+        }).catch(() => {
36
+          setLoading(false)
37
+        })
38
+      }
39
+    });
40
+  }
41
+
42
+  useEffect(() => {
43
+    getChannelDict({ params: { pageSize: 500, institutionId: user.institutionId }}).then((res) => {
44
+      const { records } = res || {}
45
+      if (records?.length) {
46
+        setDict(records)
47
+      }
48
+    })
49
+  }, [])
50
+
51
+  useEffect(() => {
52
+    if (id) {
53
+      getChannel({ urlData: { id } }).then((res) => {
54
+        if (res) {
55
+          setFieldsValue(res)
56
+        }
57
+      })
58
+    }
59
+  }, [id])
9
 
60
 
10
   return (
61
   return (
11
-    <Form {...formItemLayout}>
62
+    <Form {...formItemLayout} onSubmit={handleSubmit}>
12
       <Form.Item label="渠道">
63
       <Form.Item label="渠道">
13
-      {getFieldDecorator('shareContentTitle', {
14
-        rules: [{required: true, message: '请填写分享标题'}]
15
-      })(<Select />)}
64
+      {getFieldDecorator('channelIdList', {
65
+        rules: [{required: true, message: '请选择渠道'}]
66
+      })(
67
+        <Select mode="multiple" style={{ width: '100%' }}>
68
+          {
69
+            dict.map((item) => (<Select.Option key={item.channelId} value={`${item.channelId}`}>{item.channelName}</Select.Option>))
70
+          }          
71
+        </Select>
72
+      )}
16
       </Form.Item>
73
       </Form.Item>
17
       <Form.Item label="报备有效期">
74
       <Form.Item label="报备有效期">
18
-      {getFieldDecorator('posterImg', {
75
+      {getFieldDecorator('expirationDate', {
19
           rules: [{ validator: validMinNum }],
76
           rules: [{ validator: validMinNum }],
20
       })(<InputNumber min={0} step={1} addonAfter="天" />)}
77
       })(<InputNumber min={0} step={1} addonAfter="天" />)}
21
       </Form.Item>
78
       </Form.Item>
22
-      <Form.Item label="报备有效期">
23
-      {getFieldDecorator('posterImg', {
24
-          rules: [{ validator: validMinNum }],
25
-      })(<Input.TextArea row={4} />)}
79
+      <Form.Item label="报备规则">
80
+      {getFieldDecorator('remark', {})(<Input.TextArea row={4} />)}
26
       </Form.Item>
81
       </Form.Item>
27
       <Form.Item label=" " colon={false} style={{marginTop: '2em'}}>
82
       <Form.Item label=" " colon={false} style={{marginTop: '2em'}}>
28
-        <Button style={{marginLeft: '4em'}} type="primary" htmlType="submit">保存</Button>
29
-        <Button style={{marginLeft: '2em'}} onClick={props.onCancel}>取消</Button>
83
+        <Button style={{marginLeft: '4em'}} loading={loading} type="primary" htmlType="submit">保存</Button>
84
+        {/* <Button style={{marginLeft: '2em'}} onClick={props.onCancel}>取消</Button> */}
30
       </Form.Item>
85
       </Form.Item>
31
     </Form>
86
     </Form>
32
   )
87
   )
33
-}
88
+})
34
 
89
 
35
-export default Form.create({})(ChannelForm)
90
+export default connect((s) => ({ user: s.user.currentUser }))(Form.create({})(ChannelForm))

+ 18
- 0
src/services/apis.js View File

201
       method: 'DELETE',
201
       method: 'DELETE',
202
       action: 'admin.marketing.id.delete',
202
       action: 'admin.marketing.id.delete',
203
     },
203
     },
204
+    // 渠道
205
+    channel: {
206
+      get: {
207
+        url: `${prefix}/buildingChannel/:id`,
208
+        method: 'GET',
209
+        action: 'admin.building.channel.get',
210
+      },
211
+      save: {
212
+        url: `${prefix}/buildingChannel`,
213
+        method: 'POST',
214
+        action: 'admin.building.channel.post',
215
+      },
216
+      update: {
217
+        url: `${prefix}/buildingChannel`,
218
+        method: 'PUT',
219
+        action: 'admin.building.channel.post',
220
+      }
221
+    }
204
   },
222
   },
205
   buildingType: {
223
   buildingType: {
206
     getList: {
224
     getList: {

+ 3
- 3
src/utils/request.js View File

82
     } else {
82
     } else {
83
       // console.log('response.headers: ', response.headers)
83
       // console.log('response.headers: ', response.headers)
84
       // console.log('response.headers.Content-Type: ', response.headers.get('Content-Type'))
84
       // console.log('response.headers.Content-Type: ', response.headers.get('Content-Type'))
85
-      console.log(response,'response')
85
+      // console.log(response,'response')
86
       if (response.headers.get('Content-Type') === 'application/octet-stream;charset=utf-8') {
86
       if (response.headers.get('Content-Type') === 'application/octet-stream;charset=utf-8') {
87
         return await response.clone().blob();
87
         return await response.clone().blob();
88
       }
88
       }
91
       if (response.url.indexOf('gaode_amap') !== -1) {
91
       if (response.url.indexOf('gaode_amap') !== -1) {
92
         return await response.clone().json();
92
         return await response.clone().json();
93
       }
93
       }
94
-      console.log(response,'response')
94
+      // console.log(response,'response')
95
       const { code, data, message } = await response.clone().json();
95
       const { code, data, message } = await response.clone().json();
96
-     
96
+
97
       if (code != 1000) {
97
       if (code != 1000) {
98
         if (code === 1001) {
98
         if (code === 1001) {
99
           // notification.error({
99
           // notification.error({