作者 yangfu

修改模板列表,单选表单赋值

... ... @@ -5,6 +5,7 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/controllers"
"opp/protocol"
"opp/services/agg"
"opp/services/chance"
"strings"
)
... ... @@ -292,6 +293,7 @@ func (this *ChanceController) ChanceSubmit() {
msg = protocol.NewReturnResponse(nil, e)
return
}
agg.SetFormDefaultValue(request.FormList, agg.SetRadioFormValue)
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request))
}
... ... @@ -318,6 +320,7 @@ func (this *ChanceController) ChanceUpdate() {
msg = protocol.NewReturnResponse(nil, e)
return
}
agg.SetFormDefaultValue(request.FormList, agg.SetRadioFormValue)
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceUpdate(header, request))
}
... ... @@ -866,6 +869,7 @@ func (this *ChanceController) DraftSaveChance() {
}
header := controllers.GetRequestHeader(this.Ctx)
request.SelfChecks.SetSelfChecksLevel1ByRule()
agg.SetFormDefaultValue(request.FormList, agg.SetRadioFormValue)
msg = protocol.NewReturnResponse(chance.DraftSaveChance(header, request))
}
... ...
... ... @@ -251,6 +251,28 @@ func GetIncrementSqlBatch(table string, column string, incre int, ids ...int64)
type Filters func(inputFormList []*protocol.Form) (forms []*protocol.Form)
type SetFormValue func(form *protocol.Form)
func SetRadioFormValue(form *protocol.Form) {
if form.InputType != protocol.InputRadio {
return
}
if len(form.Data) > 0 && form.Data[0].Type == protocol.InputText {
form.Value = form.Data[0].Value
}
}
func SetFormDefaultValue(inputFormList []*protocol.Form, funcSetForm ...SetFormValue) {
if len(inputFormList) == 0 {
return
}
for i := range inputFormList {
for j := range funcSetForm {
funcSetForm[j](inputFormList[i])
}
}
}
//清除未填写的表单数据
func ClearEmptyForm(inputFormList []*protocol.Form) (forms []*protocol.Form) {
if len(inputFormList) == 0 {
... ...
... ... @@ -53,3 +53,14 @@ func Test_GetTopPosition(t *testing.T) {
t.Fatal("top department error")
}
}
func TestSetFormValue(t *testing.T) {
input := []*protocol.Form{
{Label: "1", InputType: "radio", Data: []*protocol.FormDataItem{{Type: protocol.InputText, Value: "选项A"}}},
}
SetFormDefaultValue(input, SetRadioFormValue)
t.Log(input[0].Value)
if input[0].Value != "选项A" {
t.Fatal("input:", input[0].Value, " except:", "选项A")
}
}
... ...
... ... @@ -270,14 +270,20 @@ func Templates(header *protocol.RequestHeader, request *protocol.TemplatesReques
}
for j := range forms {
form := forms[j]
template.FormList[j] = &protocol.Form{
formItem := &protocol.Form{
Id: form.Id,
Label: form.Label,
Value: "",
InputType: form.InputType,
SectionType: form.Section,
Required: form.Required,
Data: make([]*protocol.FormDataItem, 0),
ValueList: make([]*protocol.ValueListItem, 0),
}
if len(form.ValueList) > 0 && form.InputType == protocol.InputRadio {
utils.JsonUnmarshal(form.ValueList, &formItem.ValueList)
}
template.FormList[j] = formItem
}
rsp.Templates = append(rsp.Templates, template)
}
... ...