caipin 4 years ago
parent
commit
e11ba772a0
1 changed files with 52 additions and 18 deletions
  1. 52 18
      web/api/project_account_api.go

+ 52 - 18
web/api/project_account_api.go

@@ -9,6 +9,7 @@ package api
 import (
 	"fmt"
 
+	"github.com/iris-contrib/middleware/csrf"
 	"github.com/kataras/iris/v12"
 	"go.mod/services"
 	"go.mod/web/utils"
@@ -81,40 +82,73 @@ func (c *ProjectAccountApi) GetList() {
 // @Tags 项目账号相关
 // @Description 获得项目账号角色列表
 // @Security ApiKeyAuth
-// @Param   name     body    string     true        "检索内容"
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Router /api/projectAccount/group [get]
 func (c *ProjectAccountApi) GetGroup() {
 
 	// 获得检索关键字
-	AccountData := viewmodels.ProjectAccount{}
-	err := c.Ctx.ReadForm(&AccountData)
-	if err != nil {
-		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("JSON转换异常, error=%s", err)})
-		return
-	}
+	// AccountData := viewmodels.ProjectAccount{}
+	// err := c.Ctx.ReadForm(&AccountData)
+	// if err != nil {
+	// 	c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("JSON转换异常, error=%s", err)})
+	// 	return
+	// }
 
 	// 获得项目ID
-	projectId, err := utils.GetProjectId(c.Ctx)
-	if err != nil {
-		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
-		return
-	}
+	// projectId, err := utils.GetProjectId(c.Ctx)
+	// if err != nil {
+	// 	c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+	// 	return
+	// }
 
 	// accountData := c.ServiceProjectAccount.GetAll(projectId)
 	// 检索
-	accountData := c.ServiceProjectAccount.Search(AccountData.Name, projectId)
+	// accountData := c.ServiceProjectAccount.Search(AccountData.Name, projectId)
 
-	roleDate := map[int]string{
+	groupDate := map[int]string{
 		1: "建设单位",
 		2: "监理单位",
 		3: "施工单位",
 		4: "设计单位",
 	}
 	c.Ctx.JSON(iris.Map{
-		"code":        0,
-		"msg":         "",
-		"roleDate":    roleDate,
-		"accountData": accountData,
+		"code": 0,
+		"msg":  "",
+		"date": groupDate,
+		// "accountData": accountData,
+	})
+}
+
+// @Summary 检索账号信息
+// @Tags 项目账号相关
+// @Description 检索字段:账号 姓名 单位 手机 前匹配
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   name     body    string     true        "检索内容"
+// @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
+// @Router /api/projectAccount/search [get]
+func (c *ProjectAccountApi) GetSearch() {
+	// 获得项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	c.Ctx.Header("X-CSRF-Token", csrf.Token(c.Ctx))
+
+	// 获得检索关键字
+	AccountData := viewmodels.ProjectAccount{}
+	err = c.Ctx.ReadForm(&AccountData)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("JSON转换异常, error=%s", err)})
+		return
+	}
+
+	// 检索
+	dataList := c.ServiceProjectAccount.Search(AccountData.Name, projectIdInt)
+	c.Ctx.JSON(iris.Map{
+		"code": 0, "msg": "",
+		"data": dataList,
 	})
 }