From 8fb1d1a1389c5f981248b459257ceb1ac4e2b28d Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期二, 31 十月 2023 14:37:02 +0800
Subject: [PATCH] 出入库明细分页修改

---
 controllers/location.go |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/controllers/location.go b/controllers/location.go
index 682c1f0..5bfec45 100644
--- a/controllers/location.go
+++ b/controllers/location.go
@@ -30,6 +30,18 @@
 		util.ResponseFormat(c, code.RequestParamError, err)
 		return
 	}
+	if params.ParentId != 0 {
+		//鏌ヨ涓婄骇鍚嶇О
+		first, err := models.NewLocationSearch().SetID(params.ParentId).First()
+		if err != nil {
+			util.ResponseFormat(c, code.RequestParamError, "鏌ヨ涓婄骇鍚嶇О澶辫触")
+			return
+		}
+		params.JointName = first.JointName + "/" + params.Name
+	} else {
+		params.JointName = params.Name
+	}
+
 	err := models.NewLocationSearch().Create(&params)
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鍒涘缓澶辫触")
@@ -55,13 +67,10 @@
 	if params.PageInfo.Check() {
 		search.SetPage(params.Page, params.PageSize)
 	}
-	list, total, err := search.SetKeyword(params.KeyWord).SetOrder("created_at desc").Find()
+	list, total, err := search.SetKeyword(params.KeyWord).SetJointName(params.JointName).SetOrder("created_at desc").Find()
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触")
 		return
-	}
-	for _, location := range list {
-		location.JointName = location.ParentId + "/" + location.Name
 	}
 
 	util.ResponseFormatList(c, code.Success, list, int(total))
@@ -105,6 +114,25 @@
 		util.ResponseFormat(c, code.RequestParamError, err)
 		return
 	}
+	//index := strings.LastIndex(params.JointName, "/")
+	//if index > 0 {
+	//	jn := params.JointName[:index]
+	//	oldName := params.JointName[index+1:]
+	//	if oldName != params.Name {
+	//		params.JointName = jn + "/" + params.Name
+	//	}
+	//}
+	if params.ParentId != 0 {
+		//鏌ヨ涓婄骇鍚嶇О
+		first, err := models.NewLocationSearch().SetID(params.ParentId).First()
+		if err != nil {
+			util.ResponseFormat(c, code.RequestParamError, "鏌ヨ涓婄骇鍚嶇О澶辫触")
+			return
+		}
+		params.JointName = first.JointName + "/" + params.Name
+	} else {
+		params.JointName = params.Name
+	}
 	err := models.NewLocationSearch().Update(&params)
 	if err != nil {
 		util.ResponseFormat(c, code.RequestParamError, "浣嶇疆淇℃伅鏇存柊澶辫触")

--
Gitblit v1.8.0