weiximei 5 years ago
parent
commit
367c214bac
1 changed files with 20 additions and 7 deletions
  1. 20
    7
      src/pages/UserManage/Editor/Miniapp.jsx

+ 20
- 7
src/pages/UserManage/Editor/Miniapp.jsx View File

@@ -14,10 +14,19 @@ const TplItem = React.forwardRef((props, ref) => {
14 14
     setVal(props.value)
15 15
   }, [props.value])
16 16
 
17
+  console.log('props.value:', props)
18
+
17 19
   const handleChange = field => e => {
18
-    const newVal = { ...val, [`${field}`]: (e.target ? e.target.value : e) }
20
+    // console.log(field, e)
21
+    let inputVal = null
22
+    if (field === 'tplId') {
23
+      inputVal = (e.target ? e.target.value : e)
24
+    }
25
+    if (field === 'fieldNum') {
26
+      inputVal = e
27
+    }
28
+    const newVal = { ...val, [`${field}`]: inputVal }
19 29
     setVal(newVal)
20
-
21 30
     if (typeof props.onChange === 'function') {
22 31
       console.log('--change--->', newVal)
23 32
       props.onChange(newVal)
@@ -26,8 +35,8 @@ const TplItem = React.forwardRef((props, ref) => {
26 35
 
27 36
   return (
28 37
     <Input.Group compact ref={ref}>
29
-      <Input style={{ width: '70%' }} value={val.tplId} placeholder="消息模板ID" onChange={handleChange('tplId')}></Input>
30
-      <InputNumber style={{ width: '30%' }} value={val.fieldNum} placeholder="字段数" onChange={handleChange('fieldNum')}></InputNumber>
38
+      <Input style={{ width: '70%' }} value={val.tplId} placeholder="消息模板ID" onChange={e => handleChange('tplId')(e)}></Input>
39
+      <InputNumber style={{ width: '30%' }} value={val.fieldNum} placeholder="字段数" onChange={e => handleChange('fieldNum')(e)}></InputNumber>
31 40
     </Input.Group>
32 41
   );
33 42
 })
@@ -162,15 +171,18 @@ const Miniapp = (props) => {
162 171
   ]
163 172
 
164 173
   const checkTPLData = (submitData) => {
165
-    let tplData = [...tpls]
174
+    // let tplData = [...tpls]
175
+    let tplData = []
166 176
     let errors = []
167 177
 
168 178
     Object.keys(submitData).forEach((key) => {
169 179
       if (key.indexOf('tpl-') === 0) {
170
-        const [, code] = key.split('-')
180
+        // const [, code] = key.split('-')
181
+        const code = key.substring(key.indexOf('-') + 1, key.length)
182
+        console.log('code:', code)
171 183
         const { tplId, fieldNum } = submitData[key].result || submitData[key]
172 184
         const tplType = (props.tplTyps || []).filter(x => x.code === code)[0] || {}
173
-
185
+    
174 186
         if (tplId && !fieldNum) {
175 187
           errors.push(`请填写${tplType.name}模板字段数`)
176 188
           return
@@ -201,6 +213,7 @@ const Miniapp = (props) => {
201 213
     console.log('-----val--->', val)
202 214
 
203 215
     const [tplData, errors] = checkTPLData(otherData)
216
+    console.log('-----tplData--->', tplData)
204 217
 
205 218
     if (errors.length > 0) {
206 219
       notification.error({ message: errors[0] })