魏熙美 преди 5 години
родител
ревизия
939175838e

+ 8
- 1
src/pages/carouselFigure/SelectActivity.jsx Целия файл

@@ -56,7 +56,14 @@ export default (props) => {
56 56
         }}
57 57
         onCancel={() => setVisible(false)}
58 58
       >
59
-        <Select defaultValue={chooseVal} onChange={handleChange} style={{ width: '90%' }}>
59
+        <Select
60
+        showSearch
61
+        filterOption={(input, option) =>
62
+          option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
63
+        }
64
+        defaultValue={chooseVal} 
65
+        onChange={handleChange} 
66
+        style={{ width: '90%' }}>
60 67
           {
61 68
             list.map(x => (<Select.Option key={x.dynamicId} value={x.dynamicId}>{x.title}</Select.Option>))
62 69
           }

+ 74
- 0
src/pages/carouselFigure/SelectGroup.jsx Целия файл

@@ -0,0 +1,74 @@
1
+import React, { useState, useEffect } from 'react';
2
+import { Select, Modal } from 'antd';
3
+import { apis, fetch } from '../../utils/request';
4
+
5
+const getGroupList = fetch(apis.groupActivity.list)
6
+
7
+export default props => {
8
+  const {
9
+    value,
10
+    onChange,
11
+    ...rest
12
+  } = props;
13
+
14
+  const [list, setList] = useState([]);
15
+  const [visible, setVisible] = useState(false);
16
+  const [group, setGroup] = useState({ groupId: undefined, groupName: '请选择拼团' })
17
+  const getGroupTitle = val => {
18
+    return (list.filter(x => x.groupActicityId == val)[0] || {}).activityName || '请选择拼团'
19
+  }
20
+  const updateGroup = val => setGroup({ groupId: val, groupName: getGroupTitle(val) })
21
+
22
+  const buildingId = props.buildingId()
23
+
24
+  useEffect(() => {
25
+    getGroupList({
26
+      params: {
27
+        buildingId,
28
+        pageNum: 1,
29
+        pageSize: 999,
30
+      },
31
+    }).then(data => {
32
+      setList(data.records || [])
33
+
34
+      updateGroup(buildingId ? undefined : value);
35
+    })
36
+  }, [buildingId]);
37
+
38
+  if (value !== group.groupId) {
39
+    updateGroup(value);
40
+  }
41
+
42
+  const handleChange = val => {
43
+      onChange(val)
44
+  }
45
+
46
+  return (
47
+    <div>
48
+      <div onClick={() => setVisible(true)}>{group.groupName}</div>
49
+      <Modal
50
+        title="请选择拼团"
51
+        visible={visible}
52
+        onOk={() => {
53
+          updateGroup(value)
54
+          onChange(value)
55
+          setVisible(false)
56
+        }}
57
+        onCancel={() => setVisible(false)}
58
+      >
59
+        <Select
60
+          showSearch
61
+          value={value ? parseInt(value) : undefined}
62
+          onChange={handleChange}
63
+          style={{ width: '90%' }}
64
+          filterOption={(input, option) =>
65
+            option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
66
+          }>
67
+          {
68
+            list.map(x => (<Select.Option key={x.groupActicityId} value={x.groupActicityId}>{x.activityName}</Select.Option>))
69
+          }
70
+        </Select>
71
+      </Modal>
72
+    </div>
73
+  );
74
+}

+ 76
- 0
src/pages/carouselFigure/SelectHelp.jsx Целия файл

@@ -0,0 +1,76 @@
1
+import React, { useState, useEffect } from 'react';
2
+import { Select, Modal } from 'antd';
3
+import { apis, fetch } from '../../utils/request';
4
+
5
+const getHelpList = fetch(apis.helpActivity.list)
6
+
7
+export default props => {
8
+  const {
9
+    value,
10
+    onChange,
11
+    ...rest
12
+  } = props;
13
+
14
+  const [list, setList] = useState([]);
15
+  const [visible, setVisible] = useState(false);
16
+  const [help, setHelp] = useState({ helpId: undefined, helpName: '请选择助力' })
17
+  const getHelpTitle = val => {
18
+    return (list.filter(x => x.helpActivityId == val)[0] || {}).title || '请选择助力'
19
+  }
20
+
21
+  const updateHelp = val => setHelp({ helpId: val, helpName: getHelpTitle(val) })
22
+
23
+  const buildingId = props.buildingId()
24
+
25
+  useEffect(() => {
26
+    getHelpList({
27
+      params: {
28
+        buildingId,
29
+        pageNum: 1,
30
+        pageSize: 999,
31
+      },
32
+    }).then(data => {
33
+      setList(data.records || [])
34
+
35
+      updateHelp(value ? undefined : value);
36
+    })
37
+  }, [buildingId]);
38
+
39
+  if (value !== help.helpId) {
40
+    updateHelp(value);
41
+  }
42
+
43
+  const handleChange = val => {
44
+    onChange(val)
45
+  }
46
+
47
+  return (
48
+    <div>
49
+      <div onClick={() => setVisible(true)}>{help.helpName}</div>
50
+      <Modal
51
+        title="请选择助力"
52
+        visible={visible}
53
+        onOk={() => {
54
+          updateHelp(value)
55
+          onChange(value)
56
+          setVisible(false)
57
+        }}
58
+        onCancel={() => setVisible(false)}
59
+      >
60
+        <Select
61
+          placeholder="请选择助力"
62
+          showSearch
63
+          value={value ? parseInt(value) : undefined}
64
+          onChange={handleChange}
65
+          style={{ width: '90%' }}
66
+          filterOption={(input, option) =>
67
+            option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
68
+          }>
69
+          {
70
+            list.map(x => (<Select.Option key={x.helpActivityId} value={x.helpActivityId}>{x.title}</Select.Option>))
71
+          }
72
+        </Select>
73
+      </Modal>
74
+    </div>
75
+  );
76
+}

+ 14
- 6
src/pages/carouselFigure/SelectNews.jsx Целия файл

@@ -37,9 +37,9 @@ export default (props) => {
37 37
     updateNews(value);
38 38
   }
39 39
 
40
-  let chooseVal = value
41
-
42
-  const handleChange = val => chooseVal = val
40
+  const handleChange = val => {
41
+    onChange(val)
42
+  }
43 43
 
44 44
   return (
45 45
     <div>
@@ -48,13 +48,21 @@ export default (props) => {
48 48
         title="请选择资讯"
49 49
         visible={visible}
50 50
         onOk={() => {
51
-          updateNews(chooseVal)
52
-          onChange(chooseVal)
51
+          updateNews(value)
52
+          onChange(value)
53 53
           setVisible(false)
54 54
         }}
55 55
         onCancel={() => setVisible(false)}
56 56
       >
57
-        <Select defaultValue={chooseVal} onChange={handleChange} style={{ width: '90%' }}>
57
+        <Select
58
+          showSearch
59
+          value={value ? parseInt(value) : undefined}
60
+          onChange={handleChange}
61
+          style={{ width: '90%' }}
62
+          filterOption={(input, option) =>
63
+            option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
64
+          }
65
+        >
58 66
           {
59 67
             list.map(x => (<Select.Option key={x.newsId} value={x.newsId}>{x.newsName}</Select.Option>))
60 68
           }

+ 1
- 1
src/pages/carouselFigure/advertisingList.jsx Целия файл

@@ -53,7 +53,7 @@ const toEdit = (contentId) => () => {
53 53
       dataIndex: 'contentType',
54 54
       key: 'contentType',
55 55
       align: 'center',
56
-      render: (contentType) => <span>{ contentType === 'project' ? '项目' : contentType === 'activity' ? '活动' : contentType === 'news' ? '资讯' : contentType === 'other' ? '其他' : '' }</span>
56
+      render: (contentType) => <span>{ contentType === 'project' ? '项目' : contentType === 'activity' ? '活动' : contentType === 'news' ? '资讯' : contentType === 'other' ? '其他' : contentType === 'help' ? '助力' : contentType === 'group' ? '拼团' : '' }</span>
57 57
     },
58 58
     {
59 59
       title: '发布位置',

+ 1
- 1
src/pages/carouselFigure/carouselFigureList.jsx Целия файл

@@ -53,7 +53,7 @@ const toEditCarouse = (contentId) => () => {
53 53
       dataIndex: 'contentType',
54 54
       key: 'contentType',
55 55
       align: 'center',
56
-      render: (contentType) => <span>{ contentType === 'project' ? '项目' : contentType === 'activity' ? '活动' : contentType === 'news' ? '资讯' : contentType === 'other' ? '其他' : '' }</span>
56
+      render: (contentType) => <span>{ contentType === 'project' ? '项目' : contentType === 'activity' ? '活动' : contentType === 'news' ? '资讯' : contentType === 'other' ? '其他' : contentType === 'help' ? '助力' : contentType === 'group' ? '拼团' : '' }</span>
57 57
     },
58 58
     {
59 59
       title: '发布位置',

+ 29
- 0
src/pages/carouselFigure/editAdvertising.jsx Целия файл

@@ -11,6 +11,8 @@ import SelectActivity from './SelectActivity';
11 11
 import SelectNews from './SelectNews';
12 12
 import apis from '../../services/apis';
13 13
 import request from '../../utils/request'
14
+import SelectHelp from './SelectHelp';
15
+import SelectGroup from './SelectGroup';
14 16
 
15 17
 /**
16 18
  *
@@ -22,12 +24,17 @@ import request from '../../utils/request'
22 24
   let contentVisible = false
23 25
   let activityVisible = false
24 26
   let newsVisible = false
27
+  let helpVisible = false
28
+  let groupVisible = false
25 29
   let buildingId = ''
26 30
 
27 31
   const setExtraData = (data) => {
28 32
     contentVisible = data.contentType === 'other';
29 33
     activityVisible = data.contentType === 'activity';
30 34
     newsVisible = data.contentType === 'news';
35
+    helpVisible = data.contentType === 'help';
36
+    groupVisible = data.contentType === 'group';
37
+
31 38
     buildingId = data.buildingId
32 39
   }
33 40
   
@@ -101,6 +108,14 @@ import request from '../../utils/request'
101 108
         {
102 109
           label: '其他',
103 110
           value: 'other'
111
+        },
112
+        {
113
+          label: '拼团',
114
+          value: 'group'
115
+        },
116
+        {
117
+          label: '助力',
118
+          value: 'help'
104 119
         }],
105 120
         value: data.contentType,
106 121
       },
@@ -125,6 +140,20 @@ import request from '../../utils/request'
125 140
         value: data.content,
126 141
         hidden: () => !contentVisible,
127 142
       },
143
+      {
144
+        label: '发布助力',
145
+        name: 'targetId',
146
+        render: <SelectHelp buildingId={() => buildingId} />,
147
+        hidden: () => !helpVisible,
148
+        value: data.targetId,
149
+      },
150
+      {
151
+        label: '发布拼团',
152
+        name: 'targetId',
153
+        render: <SelectGroup buildingId={() => buildingId} />,
154
+        hidden: () => !groupVisible,
155
+        value: data.targetId,
156
+      },
128 157
       {
129 158
         label: '状态',
130 159
         name: 'status',

+ 180
- 111
src/pages/carouselFigure/editCarousel.jsx Целия файл

@@ -1,14 +1,18 @@
1 1
 import React, { useState, useEffect } from 'react';
2
-import { Form, Input, Button, Icon, Select, Tabs, Radio, DatePicker,message } from 'antd';
2
+import { Form, Input, Button, Icon, Select, Tabs, Radio, DatePicker, message } from 'antd';
3 3
 import { FormattedMessage } from 'umi-plugin-react/locale';
4
-import styles from '../style/GoodsList.less';
5 4
 import moment from 'moment';
6 5
 import router from 'umi/router';
6
+import styles from '../style/GoodsList.less';
7 7
 import BuildSelect from '../../components/SelectButton/BuildSelect'
8
-import XForm, { FieldTypes } from '../../components/XForm';
8
+import { createForm, FieldTypes } from '../../components/XForm';
9 9
 import Wangedit from '../../components/Wangedit/Wangedit'
10 10
 import apis from '../../services/apis';
11 11
 import request from '../../utils/request'
12
+import SelectHelp from './SelectHelp';
13
+import SelectGroup from './SelectGroup';
14
+import SelectNews from './SelectNews';
15
+import SelectActivity from './SelectActivity';
12 16
 
13 17
 const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
14 18
 /**
@@ -17,130 +21,195 @@ const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
17 21
  * @param {*} props
18 22
  * @returns
19 23
  */
20
- const Edit = (props) => {
21
-  const [ tab, changeTab ] = useState('basic')
22
-  const contentId = props.location.query.contentId
23
-  const [ data, setData ] = useState({})
24
-  if(contentId){
25
-    useEffect(() => {
26
-      getDetail(contentId);
27
-    },[])
24
+ const Edit = props => {
25
+  let contentVisible = false
26
+  let activityVisible = false
27
+  let newsVisible = false
28
+  let helpVisible = false
29
+  let groupVisible = false
30
+  let buildingId = ''
28 31
 
29
-  // 查询列表
30
-  const getDetail = (contentId) => {
31
-    request({ ...apis.carsuseFigure.getExtendContent,urlData:{id: contentId}}).then((data) => {
32
-        console.log(data)
33
-        setData(data)
34
-    })
35
-  }
32
+  const setExtraData = data => {
33
+    contentVisible = data.contentType === 'other';
34
+    activityVisible = data.contentType === 'activity';
35
+    newsVisible = data.contentType === 'news';
36
+    helpVisible = data.contentType === 'help';
37
+    groupVisible = data.contentType === 'group';
38
+
39
+    buildingId = data.buildingId
36 40
   }
37 41
 
38
-  const cancelPage = () =>{
39
-    router.push({
40
-      pathname: '/carouselFigure/carouselFigureList',
41
-    });
42
+    
43
+  const handleFormValueChange = (props, changedValues, allValues) => {
44
+    setExtraData(allValues)
42 45
   }
43
- 
44
-    const fields = [
45
-      {
46
-        label: '所属项目',
47
-        name: 'buildingId',
48
-        render: <BuildSelect />,
49
-        value: data.buildingId,
50
-      },
51
-      {
52
-        label: '商品图片',
53
-        name: 'image',
54
-        type: FieldTypes.ImageUploader,
55
-        value: data.image,
56
-        help: '建议图片尺寸:640px*330px',
57
-      },
58
-      {
59
-        label: '标题',
60
-        name: 'title',
61
-        type: FieldTypes.Text,
62
-        value: data.title,
63
-      },
64
-      {
65
-        label: '发布位置',
66
-        name: 'showPosition',
67
-        type: FieldTypes.Select,
68
-        dict: [{
69
-          label: '首页',
70
-          value: 'index'
46
+
47
+  const XForm = createForm({ onValuesChange: handleFormValueChange })
48
+
49
+  return (props) => {
50
+
51
+    const [tab, changeTab] = useState('basic')
52
+    const { contentId } = props.location.query
53
+    const [data, setData] = useState({})
54
+    if (contentId) {
55
+      // eslint-disable-next-line react-hooks/rules-of-hooks
56
+      useEffect(() => {
57
+        getDetail(contentId);
58
+      }, [])
59
+
60
+    // 查询列表
61
+    const getDetail = contentId => {
62
+      request({ ...apis.carsuseFigure.getExtendContent, urlData: { id: contentId } }).then(data => {
63
+          console.log(data)
64
+          setExtraData(data)
65
+          setData(data)
66
+      })
67
+    }
68
+    }
69
+
70
+    const cancelPage = () => {
71
+      router.push({
72
+        pathname: '/carouselFigure/carouselFigureList',
73
+      });
74
+    }
75
+
76
+      const fields = [
77
+        {
78
+          label: '所属项目',
79
+          name: 'buildingId',
80
+          render: <BuildSelect />,
81
+          value: data.buildingId,
71 82
         },
72 83
         {
73
-          label: '商城',
74
-          value: 'mall'
75
-        }],
76
-        value: data.showPosition,
77
-      },
78
-      {
79
-        label: '类型',
80
-        name: 'contentType',
81
-        type: FieldTypes.Select,
82
-        dict: [{
83
-          label: '活动',
84
-          value: 'activity'
84
+          label: '商品图片',
85
+          name: 'image',
86
+          type: FieldTypes.ImageUploader,
87
+          value: data.image,
88
+          help: '建议图片尺寸:640px*330px',
85 89
         },
86 90
         {
87
-          label: '项目',
88
-          value: 'project'
91
+          label: '标题',
92
+          name: 'title',
93
+          type: FieldTypes.Text,
94
+          value: data.title,
89 95
         },
90 96
         {
91
-          label: '资讯',
92
-          value: 'news'
97
+          label: '发布位置',
98
+          name: 'showPosition',
99
+          type: FieldTypes.Select,
100
+          dict: [{
101
+            label: '首页',
102
+            value: 'index',
103
+          },
104
+          {
105
+            label: '商城',
106
+            value: 'mall',
107
+          }],
108
+          value: data.showPosition,
93 109
         },
94 110
         {
95
-          label: '其他',
96
-          value: 'other'
97
-        }],
98
-        value: data.contentType,
99
-      },
100
-      {
101
-        label: '发布内容',
102
-        name: 'content',
103
-        render: <Wangedit />,
104
-        value: data.content,
105
-      },
106
-      {
107
-        label: '状态',
108
-        name: 'status',
109
-        type: FieldTypes.Select,
110
-        dict: [{
111
-          label: "启用",
112
-          value: 1
111
+          label: '类型',
112
+          name: 'contentType',
113
+          type: FieldTypes.Select,
114
+          dict: [{
115
+            label: '活动',
116
+            value: 'activity',
117
+          },
118
+          {
119
+            label: '项目',
120
+            value: 'project',
121
+          },
122
+          {
123
+            label: '资讯',
124
+            value: 'news',
125
+          },
126
+          {
127
+            label: '其他',
128
+            value: 'other',
129
+          },
130
+          {
131
+            label: '拼团',
132
+            value: 'group',
133
+          },
134
+          {
135
+            label: '助力',
136
+            value: 'help',
137
+          }],
138
+          value: data.contentType,
113 139
         },
114 140
         {
115
-          label: "停用",
116
-          value: 0
117
-        },],
118
-        value: data.status != null ? data.status : 1,
119
-      },
120
-    ]
121
-  
122
-    const handleSubmit = val => { 
123
-      val.showType = 'banner'
124
-      if(contentId){
125
-        request({ ...apis.carsuseFigure.updataExtendContent,urlData:{id: contentId}, data: val,}).then((data) => {
126
-          cancelPage()
127
-        }).catch((err) => {
128
-          message.info(err.msg || err.message)
129
-        })
130
-      }else{
131
-        request({ ...apis.carsuseFigure.addExtendContent, data: val,}).then((data) => {
132
-          cancelPage()
133
-        }).catch((err) => {
134
-          message.info(err.msg || err.message)
135
-        })
141
+          label: '发布活动',
142
+          name: 'targetId',
143
+          render: <SelectActivity buildingId={() => buildingId} />,
144
+          hidden: () => !activityVisible,
145
+          value: data.targetId,
146
+        },
147
+        {
148
+          label: '发布资讯',
149
+          name: 'targetId',
150
+          render: <SelectNews buildingId={() => buildingId} />,
151
+          hidden: () => !newsVisible,
152
+          value: data.targetId,
153
+        },
154
+        {
155
+          label: '发布内容',
156
+          name: 'content',
157
+          render: <Wangedit />,
158
+          value: data.content,
159
+          hidden: () => !contentVisible,
160
+        },
161
+        {
162
+          label: '发布助力',
163
+          name: 'targetId',
164
+          render: <SelectHelp buildingId={() => buildingId} />,
165
+          hidden: () => !helpVisible,
166
+          value: data.targetId,
167
+        },
168
+        {
169
+          label: '发布拼团',
170
+          name: 'targetId',
171
+          render: <SelectGroup buildingId={() => buildingId} />,
172
+          hidden: () => !groupVisible,
173
+          value: data.targetId,
174
+        },
175
+        {
176
+          label: '状态',
177
+          name: 'status',
178
+          type: FieldTypes.Select,
179
+          dict: [{
180
+            label: '启用',
181
+            value: 1,
182
+          },
183
+          {
184
+            label: '停用',
185
+            value: 0,
186
+          } ],
187
+          value: data.status != null ? data.status : 1,
188
+        },
189
+      ]
190
+
191
+      const handleSubmit = val => {
192
+        val.showType = 'banner'
193
+        if (contentId) {
194
+          request({ ...apis.carsuseFigure.updataExtendContent, urlData: { id: contentId }, data: val  }).then(data => {
195
+            cancelPage()
196
+          }).catch(err => {
197
+            message.info(err.msg || err.message)
198
+          })
199
+        } else{
200
+          request({ ...apis.carsuseFigure.addExtendContent, data: val  }).then(data => {
201
+            cancelPage()
202
+          }).catch(err => {
203
+            message.info(err.msg || err.message)
204
+          })
205
+        }
136 206
       }
137
-    }
138 207
 
139
-  return (
140
-    <XForm onSubmit={handleSubmit} onCancel={cancelPage} fields={fields}></XForm>
141
-  );
208
+    return (
209
+      <XForm onSubmit={handleSubmit} onCancel={cancelPage} fields={fields}></XForm>
210
+    );
211
+  }
142 212
  }
143 213
 
144 214
 
145
-
146
-export default Edit
215
+export default Edit()