@@ -36,6 +36,7 @@ export default createComponent({
3636 lazyLoad : Boolean ,
3737 hideStock : Boolean ,
3838 properties : Array ,
39+ skuProperties : Array ,
3940 addCartText : String ,
4041 stepperTitle : String ,
4142 getContainer : [ String , Function ] ,
@@ -118,6 +119,7 @@ export default createComponent({
118119 selectedProp : { } ,
119120 selectedNum : 1 ,
120121 show : this . value ,
122+ currentSkuProperties : [ ]
121123 } ;
122124 } ,
123125
@@ -155,6 +157,9 @@ export default createComponent({
155157 } ,
156158
157159 computed : {
160+ isSkuProperties ( ) {
161+ return this . skuProperties && this . skuProperties . length ;
162+ } ,
158163 skuGroupClass ( ) {
159164 return [
160165 'van-sku-group-container' ,
@@ -202,7 +207,7 @@ export default createComponent({
202207
203208 selectedSkuComb ( ) {
204209 let skuComb = null ;
205- if ( this . isSkuCombSelected ) {
210+ if ( this . isSkuCombSelected || this . isSkuProperties ) {
206211 if ( this . hasSku ) {
207212 skuComb = getSkuComb ( this . skuList , this . selectedSku ) ;
208213 } else {
@@ -214,6 +219,8 @@ export default createComponent({
214219 }
215220
216221 if ( skuComb ) {
222+ // 更新当前规格属性数据
223+ this . setCurrentSkuProperties ( skuComb . id ) ;
217224 skuComb . properties = getSelectedProperties (
218225 this . propList ,
219226 this . selectedProp
@@ -266,7 +273,7 @@ export default createComponent({
266273 } ,
267274
268275 propList ( ) {
269- return this . properties || [ ] ;
276+ return this . isSkuProperties ? this . currentSkuProperties : this . properties || [ ] ;
270277 } ,
271278
272279 imageList ( ) {
@@ -362,6 +369,10 @@ export default createComponent({
362369 } ,
363370
364371 methods : {
372+ setCurrentSkuProperties ( id ) {
373+ const target = this . skuProperties ?. find ( ( item ) => item . sku_id === id ) || { } ;
374+ this . currentSkuProperties = target . properties || [ ] ;
375+ } ,
365376 resetStepper ( ) {
366377 const { skuStepper } = this . $refs ;
367378 const { selectedNum } = this . initialSku ;
@@ -503,13 +514,20 @@ export default createComponent({
503514 }
504515 : { ...this . selectedSku , [ skuValue . skuKeyStr ] : skuValue . id } ;
505516
517+ // 切换sku清空当前选择属性数据,触发prop-clear
518+ if ( this . isSkuProperties ) {
519+ this . selectedProp = { }
520+ this . onPropClear ( )
521+ }
506522 this . $emit ( 'sku-selected' , {
507523 skuValue,
508524 selectedSku : this . selectedSku ,
509525 selectedSkuComb : this . selectedSkuComb ,
510526 } ) ;
511527 } ,
512-
528+ onPropClear ( ) {
529+ this . $emit ( 'sku-prop-clear' ) ;
530+ } ,
513531 onPropSelect ( propValue ) {
514532 const arr = this . selectedProp [ propValue . skuKeyStr ] || [ ] ;
515533 const pos = arr . indexOf ( propValue . id ) ;
0 commit comments