@@ -107,45 +107,64 @@ class EditProduct extends Component {
107
107
} ) ;
108
108
}
109
109
componentWillReceiveProps ( nextProps ) {
110
+ var self = this ;
110
111
var product = nextProps . data . product ;
111
112
var allCategories = nextProps . data . categories ;
112
- if ( product && allCategories && allCategories . length > 0 ) {
113
- var categories = [ ] ;
114
- for ( var i = 0 ; i < product . categories . length ; i ++ ) {
115
- var parentId = product . categories [ i ] . parentId ;
116
- var id = product . categories [ i ] . id ;
117
- categories . push ( utils . parseTreeNodeKey ( allCategories , id ) ) ;
118
- }
119
-
120
- var imageList = [ ] ;
121
- var pImageList = product . images || [ ] ;
122
- for ( var i = 0 ; i < pImageList . length ; i ++ ) {
123
- imageList . push ( {
124
- uid : pImageList [ i ] . id ,
125
- name : pImageList [ i ] . orignalTitle ,
126
- status : 'done' ,
127
- url : pImageList [ i ] . url
128
- } ) ;
129
- }
130
-
131
- var imageURL = product . image && product . image . url || '' ;
132
113
133
- this . setState ( {
134
- productId : product . id ,
135
- categories : categories ,
136
- name : product . name ,
137
- detail : product . detail ,
138
- originalPrice : product . originalPrice ,
139
- price : product . price ,
140
- remark : product . remark ,
141
- status : product . status + '' ,
142
- imageID : product . imageID ,
143
- imageData : imageURL ,
144
- imageIDs : product . imageIDs ,
145
- imageList : imageList ,
114
+ function onDataReady ( data ) {
115
+ var product = data . product ;
116
+ self . loadUEditor ( ) ;
117
+ self . setState ( {
118
+ productId : product && product . id || '' ,
119
+ categories : data . categories || [ ] ,
120
+ name : product && product . name || '' ,
121
+ detail : product && product . detail || '' ,
122
+ originalPrice : product && product . originalPrice ,
123
+ price : product && product . price ,
124
+ remark : product && product . remark || '' ,
125
+ status : ( product && product . status + '' ) || '3' ,
126
+ imageID : product && product . imageID || '' ,
127
+ imageData : data . imageURL || '' ,
128
+ imageIDs : product && product . imageIDs || '[]' ,
129
+ imageList : data . imageList || [ ] ,
146
130
isLoading : false
147
131
} ) ;
148
- this . loadUEditor ( ) ;
132
+ }
133
+ if ( allCategories && allCategories . length > 0 ) {
134
+ if ( this . state . productId ) {
135
+ if ( product ) {
136
+ var categories = [ ] ;
137
+ for ( var i = 0 ; i < product . categories . length ; i ++ ) {
138
+ var parentId = product . categories [ i ] . parentId ;
139
+ var id = product . categories [ i ] . id ;
140
+ categories . push ( utils . parseTreeNodeKey ( allCategories , id ) ) ;
141
+ }
142
+
143
+ var imageList = [ ] ;
144
+ var pImageList = product . images || [ ] ;
145
+ for ( var i = 0 ; i < pImageList . length ; i ++ ) {
146
+ imageList . push ( {
147
+ uid : pImageList [ i ] . id ,
148
+ name : pImageList [ i ] . orignalTitle ,
149
+ status : 'done' ,
150
+ url : pImageList [ i ] . url
151
+ } ) ;
152
+ }
153
+
154
+ var imageURL = product . image && product . image . url || '' ;
155
+ onDataReady ( {
156
+ product : product ,
157
+ imageURL : imageURL ,
158
+ imageList : imageList ,
159
+ categories : categories
160
+ } ) ;
161
+ }
162
+ } else {
163
+ onDataReady ( {
164
+ product : null ,
165
+ imageURL : ''
166
+ } ) ;
167
+ }
149
168
}
150
169
}
151
170
onNameBlur ( event ) {
@@ -351,11 +370,11 @@ class EditProduct extends Component {
351
370
</ div >
352
371
</ FormItem >
353
372
< FormItem { ...formItemLayout } label = "原价" >
354
- < InputNumber min = { 0 } max = { 100 } defaultValue = { originalPrice } step = { 0.01 } onBlur = { this . onOriginalPriceBlur } />
373
+ < InputNumber min = { 0 } max = { 1000000 } defaultValue = { originalPrice } step = { 0.01 } onBlur = { this . onOriginalPriceBlur } />
355
374
元
356
375
</ FormItem >
357
376
< FormItem { ...formItemLayout } label = "促销价" >
358
- < InputNumber min = { 0 } max = { 100 } defaultValue = { price } step = { 0.01 } onBlur = { this . onPriceBlur } />
377
+ < InputNumber min = { 0 } max = { 1000000 } defaultValue = { price } step = { 0.01 } onBlur = { this . onPriceBlur } />
359
378
元
360
379
</ FormItem >
361
380
< FormItem { ...formItemLayout } label = "备注" >
0 commit comments