|
@@ -1,4 +1,4 @@
|
1
|
|
-import React, { useState } from 'react';
|
|
1
|
+import React, { useState, useEffect } from 'react';
|
2
|
2
|
import { Button, Row, Col, Input, InputNumber, Modal, notification } from 'antd';
|
3
|
3
|
import XForm, { FieldTypes } from '../../../components/XForm';
|
4
|
4
|
import Style from '../style.less';
|
|
@@ -15,6 +15,7 @@ const TplItem = React.forwardRef((props, ref) => {
|
15
|
15
|
setVal(newVal)
|
16
|
16
|
|
17
|
17
|
if (typeof props.onChange === 'function') {
|
|
18
|
+ console.log('--change--->', newVal)
|
18
|
19
|
props.onChange(newVal)
|
19
|
20
|
}
|
20
|
21
|
}
|
|
@@ -34,7 +35,11 @@ const Miniapp = (props) => {
|
34
|
35
|
|
35
|
36
|
const user = props.data || {}
|
36
|
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
|
44
|
const showModal = () => {
|
40
|
45
|
changeVisible(true);
|
|
@@ -58,6 +63,15 @@ const Miniapp = (props) => {
|
58
|
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
|
75
|
const fields = [
|
62
|
76
|
{
|
63
|
77
|
label: '名称',
|
|
@@ -107,27 +121,12 @@ const Miniapp = (props) => {
|
107
|
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
|
126
|
label: '小程序码',
|
128
|
127
|
name: 'qrCode',
|
129
|
128
|
render: () => <img src={qrCode} style={{ width: '240px' }} alt=""/>,
|
130
|
|
- value: qrCode || appdata.qrCode,
|
|
129
|
+ value: qrCode,
|
131
|
130
|
},
|
132
|
131
|
{
|
133
|
132
|
action: true,
|
|
@@ -154,40 +153,58 @@ const Miniapp = (props) => {
|
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
|
189
|
const handleSubmit = val => {
|
158
|
190
|
// 校验字段
|
159
|
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
|
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
|
202
|
const data = {
|
186
|
203
|
...appdata,
|
187
|
204
|
...otherData,
|
188
|
205
|
qrCode: qrCode || appdata.appdata,
|
189
|
206
|
orgId: user.orgId,
|
190
|
|
- tpls,
|
|
207
|
+ tpls: tplData,
|
191
|
208
|
}
|
192
|
209
|
|
193
|
210
|
saveMiniapp({ data }).then((miniapp) => {
|