From 9e56c69f9804ac37b3a5ced1902f51100cde2965 Mon Sep 17 00:00:00 2001 From: shen100 Date: Wed, 24 May 2017 00:20:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=8F=8A=E5=95=86=E5=93=81=E5=9B=BE=E7=89=87=E9=9B=86?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/controller/product/product.go | 16 ++++++++++++ go/model/product.go | 2 +- .../actions/product/requestSaveProduct.js | 2 +- .../admin/containers/product/EditProduct.js | 25 ++++++++++++++----- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/go/controller/product/product.go b/go/controller/product/product.go index 7c69c6bd..8264ff70 100644 --- a/go/controller/product/product.go +++ b/go/controller/product/product.go @@ -287,6 +287,22 @@ func Info(ctx *iris.Context) { return } + if db.First(&product.Image, product.ImageID).Error != nil { + product.Image = model.Image{} + } + + var imagesSQL []uint + if err := json.Unmarshal([]byte(product.ImageIDs), &imagesSQL); err == nil { + var images []model.Image + if db.Where("id in (?)", imagesSQL).Find(&images).Error != nil { + product.Images = nil + } else { + product.Images = images + } + } else { + product.Images = nil + } + if db.Model(&product).Related(&product.Categories, "categories").Error != nil { ctx.JSON(iris.StatusOK, iris.Map{ "errNo" : model.ErrorCode.ERROR, diff --git a/go/model/product.go b/go/model/product.go index ccf6abe5..7bbdbb85 100644 --- a/go/model/product.go +++ b/go/model/product.go @@ -15,8 +15,8 @@ type Product struct { Price float64 `json:"price"` OriginalPrice float64 `json:"originalPrice"` Status int `json:"status"` - Image Image `json:"image"` ImageID uint `json:"imageID"` + Image Image `json:"image"` ImageIDs string `json:"imageIDs"` Images []Image `json:"images"` Remark string `json:"remark"` diff --git a/nodejs/static/javascripts/admin/actions/product/requestSaveProduct.js b/nodejs/static/javascripts/admin/actions/product/requestSaveProduct.js index 9cbdd715..46c401f6 100644 --- a/nodejs/static/javascripts/admin/actions/product/requestSaveProduct.js +++ b/nodejs/static/javascripts/admin/actions/product/requestSaveProduct.js @@ -26,7 +26,7 @@ export default function(product) { categories : categories, status : parseInt(product.status), imageID : product.imageID, - imageIDs : JSON.stringify(product.imageIDs), + imageIDs : product.imageIDs, originalPrice : product.originalPrice, price : product.price, remark : product.remark, diff --git a/nodejs/static/javascripts/admin/containers/product/EditProduct.js b/nodejs/static/javascripts/admin/containers/product/EditProduct.js index fcccd01b..27fe71fe 100644 --- a/nodejs/static/javascripts/admin/containers/product/EditProduct.js +++ b/nodejs/static/javascripts/admin/containers/product/EditProduct.js @@ -53,9 +53,9 @@ class EditProduct extends Component { status : '3', //等待上架 imageID : '', imageData : '', - imageURL : '', previewVisible : false, previewImage : '', + imageIDs : '[]', imageList : [], ueditor : null, loadCalled : false, //是否已加载UEditor @@ -117,6 +117,19 @@ class EditProduct extends Component { categories.push(utils.parseTreeNodeKey(allCategories, id)); } + var imageList = []; + var pImageList = product.images || []; + for (var i = 0; i < pImageList.length; i++) { + imageList.push({ + uid : pImageList[i].id, + name : pImageList[i].orignalTitle, + status : 'done', + url : pImageList[i].url + }); + } + + var imageURL = product.image && product.image.url || ''; + this.setState({ productId : product.id, categories : categories, @@ -127,8 +140,9 @@ class EditProduct extends Component { remark : product.remark, status : product.status + '', imageID : product.imageID, - imageData : product.imageURL, - imageURL : product.imageURL, + imageData : imageURL, + imageIDs : product.imageIDs, + imageList : imageList, isLoading : false }); this.loadUEditor(); @@ -171,7 +185,6 @@ class EditProduct extends Component { var self = this; if (info.file.status === 'done') { self.setState({ - imageURL : info.file.response.data.url, imageID : info.file.response.data.id }); (function(originFileObj, callback) { @@ -203,7 +216,7 @@ class EditProduct extends Component { } } this.setState({ - imageIDs : imageIDs, + imageIDs : JSON.stringify(imageIDs), imageList : data.fileList }); } @@ -329,7 +342,7 @@ class EditProduct extends Component { onPreview={this.onPreview} beforeUpload={this.onBeforeUpload} onChange={this.onImageListChange}> - { imageList.length >= 3 ? null : uploadButton } + { imageList.length >= 6 ? null : uploadButton }