张延森 5 years ago
parent
commit
ef55148ca8

+ 58
- 41
src/pages/UserManage/Editor/Miniapp.jsx View File

1
-import React, { useState } from 'react';
1
+import React, { useState, useEffect } from 'react';
2
 import { Button, Row, Col, Input, InputNumber, Modal, notification } from 'antd';
2
 import { Button, Row, Col, Input, InputNumber, Modal, notification } from 'antd';
3
 import XForm, { FieldTypes } from '../../../components/XForm';
3
 import XForm, { FieldTypes } from '../../../components/XForm';
4
 import Style from '../style.less';
4
 import Style from '../style.less';
15
     setVal(newVal)
15
     setVal(newVal)
16
 
16
 
17
     if (typeof props.onChange === 'function') {
17
     if (typeof props.onChange === 'function') {
18
+      console.log('--change--->', newVal)
18
       props.onChange(newVal)
19
       props.onChange(newVal)
19
     }
20
     }
20
   }
21
   }
34
 
35
 
35
   const user = props.data || {}
36
   const user = props.data || {}
36
   const appdata = user.miniapp || {};
37
   const appdata = user.miniapp || {};
37
-  const noticeTPL = (appdata.tpls || []).filter(x => x.tplType === 'notice')[0] || {}
38
+  const tpls = appdata.tpls || [];
39
+
40
+  useEffect(() => {
41
+    setQrCode(appdata.qrCode)
42
+  }, [])
38
 
43
 
39
   const showModal = () => {
44
   const showModal = () => {
40
     changeVisible(true);
45
     changeVisible(true);
58
     }).catch();
63
     }).catch();
59
   }
64
   }
60
 
65
 
66
+  const tplFields = (props.tplTyps || []).map((x) => {
67
+    return {
68
+      label: x.name,
69
+      name: `tpl-${x.code}`,
70
+      render: <TplItem />,
71
+      value: tpls.filter(y => y.tplType === x.code)[0] || {},
72
+    }
73
+  })
74
+
61
   const fields = [
75
   const fields = [
62
     {
76
     {
63
       label: '名称',
77
       label: '名称',
107
         { pattern: /^[a-zA-Z0-9]+$/, message: 'AES_KEY 只能由字母与数字组成' }
121
         { pattern: /^[a-zA-Z0-9]+$/, message: 'AES_KEY 只能由字母与数字组成' }
108
       ]
122
       ]
109
     },
123
     },
110
-    // {
111
-    //   label: '业务受理',
112
-    //   name: 'mainbiz',
113
-    //   render: <TplItem />
114
-    // },
115
-    // {
116
-    //   label: '新客户通知',
117
-    //   name: 'newCustomer',
118
-    //   render: <TplItem />
119
-    // },
120
-    {
121
-      label: '消息通知',
122
-      name: 'notice',
123
-      render: <TplItem />,
124
-      value: noticeTPL,
125
-    },
124
+    ...tplFields,
126
     {
125
     {
127
       label: '小程序码',
126
       label: '小程序码',
128
       name: 'qrCode',
127
       name: 'qrCode',
129
       render: () => <img src={qrCode} style={{ width: '240px' }} alt=""/>,
128
       render: () => <img src={qrCode} style={{ width: '240px' }} alt=""/>,
130
-      value: qrCode || appdata.qrCode,
129
+      value: qrCode,
131
     },
130
     },
132
     {
131
     {
133
       action: true,
132
       action: true,
154
     },
153
     },
155
   ]
154
   ]
156
 
155
 
156
+  const checkTPLData = (submitData) => {
157
+    let tplData = [...tpls]
158
+    let errors = []
159
+
160
+    Object.keys(submitData).forEach((key) => {
161
+      if (key.indexOf('tpl-') === 0) {
162
+        const [, code] = key.split('-')
163
+        const { tplId, fieldNum } = submitData[key].result || submitData[key]
164
+        const tplType = (props.tplTyps || []).filter(x => x.code === code)[0] || {}
165
+
166
+        if (tplId && !fieldNum) {
167
+          errors.push(`请填写${tplType.name}模板字段数`)
168
+          return
169
+        }
170
+
171
+        console.log('--->', submitData[key])
172
+
173
+        if (tplId) {
174
+          tplData = [
175
+            ...tplData.filter(x => x.tplType !== code),
176
+            {
177
+              ...submitData[key],
178
+              tplType: code,
179
+              tplName: tplType.name,
180
+            }
181
+          ]
182
+        }
183
+      }
184
+    })
185
+
186
+    return [tplData, errors]
187
+  }
188
+
157
   const handleSubmit = val => {
189
   const handleSubmit = val => {
158
     // 校验字段
190
     // 校验字段
159
     const { mainbiz, newCustomer, notice, ...otherData} = val
191
     const { mainbiz, newCustomer, notice, ...otherData} = val
160
 
192
 
161
-    // if (mainbiz.tplId && !mainbiz.fieldNum) {
162
-    //   notification.error({ message: '请填写业务受理消息模板字段数' })
163
-    //   return
164
-    // }
165
-    
166
-    // if (newCustomer.tplId && !newCustomer.fieldNum) {
167
-    //   notification.error({ message: '请填写新客户通知模板字段数' })
168
-    //   return
169
-    // }
170
-    
171
-    if (notice.tplId && !notice.fieldNum) {
172
-      notification.error({ message: '请填写消息通知模板字段数' })
193
+    console.log('-----val--->', val)
194
+
195
+    const [tplData, errors] = checkTPLData(otherData)
196
+
197
+    if (errors.length > 0) {
198
+      notification.error({ message: errors[0] })
173
       return
199
       return
174
     }
200
     }
175
 
201
 
176
-    const tpls = [
177
-      {
178
-        ...(appdata.tpls || []).filter(x => x.tplType === 'notice')[0] || {},
179
-        ...notice,
180
-        tplType: 'notice'
181
-      },
182
-      ...(appdata.tpls || []).filter(x => x.tplType !== 'notice')
183
-    ]
184
-
185
     const data = {
202
     const data = {
186
       ...appdata,
203
       ...appdata,
187
       ...otherData,
204
       ...otherData,
188
       qrCode: qrCode || appdata.appdata,
205
       qrCode: qrCode || appdata.appdata,
189
       orgId: user.orgId,
206
       orgId: user.orgId,
190
-      tpls,
207
+      tpls: tplData,
191
     }
208
     }
192
 
209
 
193
     saveMiniapp({ data }).then((miniapp) => {
210
     saveMiniapp({ data }).then((miniapp) => {

+ 9
- 1
src/pages/UserManage/Editor/index.jsx View File

8
 import { fetch, apis } from '../../../utils/request';
8
 import { fetch, apis } from '../../../utils/request';
9
 
9
 
10
 const getUser = fetch(apis.member.get);
10
 const getUser = fetch(apis.member.get);
11
+const getTplTypes = fetch(apis.dict.tplType);
11
 
12
 
12
 export default (props) => {
13
 export default (props) => {
13
   const [ tab, changeTab ] = useState(props.location.query.tab - 0 || 1);
14
   const [ tab, changeTab ] = useState(props.location.query.tab - 0 || 1);
14
   const [ user, setUser ] = useState({});
15
   const [ user, setUser ] = useState({});
16
+  const [ tplTyps, setTplTypes ] = useState([])
17
+
18
+
15
   const handleRadioChange = e => {
19
   const handleRadioChange = e => {
16
     if (user.userId) {
20
     if (user.userId) {
17
       changeTab(e.target.value)
21
       changeTab(e.target.value)
18
     }
22
     }
19
   }
23
   }
20
 
24
 
25
+  useEffect(() => {
26
+    getTplTypes().then(list => setTplTypes(list))
27
+  }, [])
28
+
21
   useEffect(() => {
29
   useEffect(() => {
22
     if (props.match.params.id) {
30
     if (props.match.params.id) {
23
       getUser({ urlData: { id: props.match.params.id } }).then((user) => {
31
       getUser({ urlData: { id: props.match.params.id } }).then((user) => {
58
       </div>
66
       </div>
59
       <div style={{ width: '680px', margin: '0 auto' }}>
67
       <div style={{ width: '680px', margin: '0 auto' }}>
60
         { tab === 1 ? <User data={user} {...props} onChange={handleChangeUser} onCancel={handleCancel(1)}/> : null}
68
         { tab === 1 ? <User data={user} {...props} onChange={handleChangeUser} onCancel={handleCancel(1)}/> : null}
61
-        { tab === 2 ? <MiniApp data={user} {...props} onChange={handleChangeUser} onCancel={handleCancel(2)}/> : null}
69
+        { tab === 2 ? <MiniApp data={user} tplTyps={tplTyps} {...props} onChange={handleChangeUser} onCancel={handleCancel(2)}/> : null}
62
         { tab === 3 ? <Menus data={user} {...props} onCancel={handleCancel(3)}/> : null}
70
         { tab === 3 ? <Menus data={user} {...props} onCancel={handleCancel(3)}/> : null}
63
       </div>
71
       </div>
64
     </PageHeaderWrapper>
72
     </PageHeaderWrapper>

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

86
       action: 'center',
86
       action: 'center',
87
     },
87
     },
88
   },
88
   },
89
+  dict: {
90
+    tplType: {
91
+      url: `${prefix}/dict/templateType`,
92
+      method: 'GET',
93
+      action: 'center',
94
+    }
95
+  },
89
 }
96
 }
90
 
97
 
91
 export default apis;
98
 export default apis;