张延森 преди 5 години
родител
ревизия
ef55148ca8
променени са 3 файла, в които са добавени 74 реда и са изтрити 42 реда
  1. 58
    41
      src/pages/UserManage/Editor/Miniapp.jsx
  2. 9
    1
      src/pages/UserManage/Editor/index.jsx
  3. 7
    0
      src/services/apis.js

+ 58
- 41
src/pages/UserManage/Editor/Miniapp.jsx Целия файл

@@ -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) => {

+ 9
- 1
src/pages/UserManage/Editor/index.jsx Целия файл

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

+ 7
- 0
src/services/apis.js Целия файл

@@ -86,6 +86,13 @@ const apis = {
86 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 98
 export default apis;