Skip to content

Commit

Permalink
更新商品图片及商品图片集完成
Browse files Browse the repository at this point in the history
  • Loading branch information
shen100 committed May 23, 2017
1 parent 24b89ab commit 9e56c69
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
16 changes: 16 additions & 0 deletions go/controller/product/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go/model/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 19 additions & 6 deletions nodejs/static/javascripts/admin/containers/product/EditProduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class EditProduct extends Component {
status : '3', //等待上架
imageID : '',
imageData : '',
imageURL : '',
previewVisible : false,
previewImage : '',
imageIDs : '[]',
imageList : [],
ueditor : null,
loadCalled : false, //是否已加载UEditor
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -203,7 +216,7 @@ class EditProduct extends Component {
}
}
this.setState({
imageIDs : imageIDs,
imageIDs : JSON.stringify(imageIDs),
imageList : data.fileList
});
}
Expand Down Expand Up @@ -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 }
</Upload>
<Modal visible={previewVisible} onCancel={this.onCancelPreview}
footer={null}>
Expand Down

0 comments on commit 9e56c69

Please sign in to comment.