正在显示
4 个修改的文件
包含
44 行增加
和
1 行删除
@@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
5 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 5 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
6 | "opp/controllers" | 6 | "opp/controllers" |
7 | "opp/protocol" | 7 | "opp/protocol" |
8 | + "opp/services/agg" | ||
8 | "opp/services/chance" | 9 | "opp/services/chance" |
9 | "strings" | 10 | "strings" |
10 | ) | 11 | ) |
@@ -292,6 +293,7 @@ func (this *ChanceController) ChanceSubmit() { | @@ -292,6 +293,7 @@ func (this *ChanceController) ChanceSubmit() { | ||
292 | msg = protocol.NewReturnResponse(nil, e) | 293 | msg = protocol.NewReturnResponse(nil, e) |
293 | return | 294 | return |
294 | } | 295 | } |
296 | + agg.SetFormDefaultValue(request.FormList, agg.SetRadioFormValue) | ||
295 | header := controllers.GetRequestHeader(this.Ctx) | 297 | header := controllers.GetRequestHeader(this.Ctx) |
296 | msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request)) | 298 | msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request)) |
297 | } | 299 | } |
@@ -318,6 +320,7 @@ func (this *ChanceController) ChanceUpdate() { | @@ -318,6 +320,7 @@ func (this *ChanceController) ChanceUpdate() { | ||
318 | msg = protocol.NewReturnResponse(nil, e) | 320 | msg = protocol.NewReturnResponse(nil, e) |
319 | return | 321 | return |
320 | } | 322 | } |
323 | + agg.SetFormDefaultValue(request.FormList, agg.SetRadioFormValue) | ||
321 | header := controllers.GetRequestHeader(this.Ctx) | 324 | header := controllers.GetRequestHeader(this.Ctx) |
322 | msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request)) | 325 | msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request)) |
323 | } | 326 | } |
@@ -866,6 +869,7 @@ func (this *ChanceController) DraftSaveChance() { | @@ -866,6 +869,7 @@ func (this *ChanceController) DraftSaveChance() { | ||
866 | } | 869 | } |
867 | header := controllers.GetRequestHeader(this.Ctx) | 870 | header := controllers.GetRequestHeader(this.Ctx) |
868 | request.SelfChecks.SetSelfChecksLevel1ByRule() | 871 | request.SelfChecks.SetSelfChecksLevel1ByRule() |
872 | + agg.SetFormDefaultValue(request.FormList, agg.SetRadioFormValue) | ||
869 | msg = protocol.NewReturnResponse(chance.DraftSaveChance(header, request)) | 873 | msg = protocol.NewReturnResponse(chance.DraftSaveChance(header, request)) |
870 | } | 874 | } |
871 | 875 |
@@ -251,6 +251,28 @@ func GetIncrementSqlBatch(table string, column string, incre int, ids ...int64) | @@ -251,6 +251,28 @@ func GetIncrementSqlBatch(table string, column string, incre int, ids ...int64) | ||
251 | 251 | ||
252 | type Filters func(inputFormList []*protocol.Form) (forms []*protocol.Form) | 252 | type Filters func(inputFormList []*protocol.Form) (forms []*protocol.Form) |
253 | 253 | ||
254 | +type SetFormValue func(form *protocol.Form) | ||
255 | + | ||
256 | +func SetRadioFormValue(form *protocol.Form) { | ||
257 | + if form.InputType != protocol.InputRadio { | ||
258 | + return | ||
259 | + } | ||
260 | + if len(form.Data) > 0 && form.Data[0].Type == protocol.InputText { | ||
261 | + form.Value = form.Data[0].Value | ||
262 | + } | ||
263 | +} | ||
264 | + | ||
265 | +func SetFormDefaultValue(inputFormList []*protocol.Form, funcSetForm ...SetFormValue) { | ||
266 | + if len(inputFormList) == 0 { | ||
267 | + return | ||
268 | + } | ||
269 | + for i := range inputFormList { | ||
270 | + for j := range funcSetForm { | ||
271 | + funcSetForm[j](inputFormList[i]) | ||
272 | + } | ||
273 | + } | ||
274 | +} | ||
275 | + | ||
254 | //清除未填写的表单数据 | 276 | //清除未填写的表单数据 |
255 | func ClearEmptyForm(inputFormList []*protocol.Form) (forms []*protocol.Form) { | 277 | func ClearEmptyForm(inputFormList []*protocol.Form) (forms []*protocol.Form) { |
256 | if len(inputFormList) == 0 { | 278 | if len(inputFormList) == 0 { |
@@ -53,3 +53,14 @@ func Test_GetTopPosition(t *testing.T) { | @@ -53,3 +53,14 @@ func Test_GetTopPosition(t *testing.T) { | ||
53 | t.Fatal("top department error") | 53 | t.Fatal("top department error") |
54 | } | 54 | } |
55 | } | 55 | } |
56 | + | ||
57 | +func TestSetFormValue(t *testing.T) { | ||
58 | + input := []*protocol.Form{ | ||
59 | + {Label: "1", InputType: "radio", Data: []*protocol.FormDataItem{{Type: protocol.InputText, Value: "选项A"}}}, | ||
60 | + } | ||
61 | + SetFormDefaultValue(input, SetRadioFormValue) | ||
62 | + t.Log(input[0].Value) | ||
63 | + if input[0].Value != "选项A" { | ||
64 | + t.Fatal("input:", input[0].Value, " except:", "选项A") | ||
65 | + } | ||
66 | +} |
@@ -270,14 +270,20 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques | @@ -270,14 +270,20 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques | ||
270 | } | 270 | } |
271 | for j := range forms { | 271 | for j := range forms { |
272 | form := forms[j] | 272 | form := forms[j] |
273 | - template.FormList[j] = &protocol.Form{ | 273 | + formItem := &protocol.Form{ |
274 | Id: form.Id, | 274 | Id: form.Id, |
275 | Label: form.Label, | 275 | Label: form.Label, |
276 | Value: "", | 276 | Value: "", |
277 | InputType: form.InputType, | 277 | InputType: form.InputType, |
278 | SectionType: form.Section, | 278 | SectionType: form.Section, |
279 | Required: form.Required, | 279 | Required: form.Required, |
280 | + Data: make([]*protocol.FormDataItem, 0), | ||
281 | + ValueList: make([]*protocol.ValueListItem, 0), | ||
280 | } | 282 | } |
283 | + if len(form.ValueList) > 0 && form.InputType == protocol.InputRadio { | ||
284 | + utils.JsonUnmarshal(form.ValueList, &formItem.ValueList) | ||
285 | + } | ||
286 | + template.FormList[j] = formItem | ||
281 | } | 287 | } |
282 | rsp.Templates = append(rsp.Templates, template) | 288 | rsp.Templates = append(rsp.Templates, template) |
283 | } | 289 | } |
-
请 注册 或 登录 后发表评论