Showing
1 changed file
with
31 additions
and
48 deletions
@@ -1033,26 +1033,17 @@ const _getSizeData = (sizeInfo) => { | @@ -1033,26 +1033,17 @@ const _getSizeData = (sizeInfo) => { | ||
1033 | * @param productId | 1033 | * @param productId |
1034 | */ | 1034 | */ |
1035 | const _getProductModelCard = () => { | 1035 | const _getProductModelCard = () => { |
1036 | - | ||
1037 | - let result = []; | ||
1038 | - | ||
1039 | let data = _getCacheDataByName('ItemData::getProductModelCard'); | 1036 | let data = _getCacheDataByName('ItemData::getProductModelCard'); |
1040 | 1037 | ||
1041 | - if (!data) { | ||
1042 | - return result; | ||
1043 | - } | ||
1044 | - | ||
1045 | - if (data.code && data.code === 200) { | ||
1046 | - _(data.data).forEach(val => { | ||
1047 | - result.push({ | ||
1048 | - url: helpers.getForceSourceUrl(val.modelImg), | ||
1049 | - size: val.size, | ||
1050 | - name: val.modelName | ||
1051 | - }); | ||
1052 | - }); | 1038 | + if (!data || _.get(data, 'code', 400) !== 200) { |
1039 | + return []; | ||
1053 | } | 1040 | } |
1054 | 1041 | ||
1055 | - return result; | 1042 | + return _.get(data, 'data', []).map((value) => ({ |
1043 | + url: helpers.getForceSourceUrl(value.modelImg), | ||
1044 | + size: value.size, | ||
1045 | + name: value.modelName | ||
1046 | + })); | ||
1056 | }; | 1047 | }; |
1057 | 1048 | ||
1058 | /** | 1049 | /** |
@@ -1133,11 +1124,9 @@ const _getDetailDataBySizeInfo = (sizeInfo) => { | @@ -1133,11 +1124,9 @@ const _getDetailDataBySizeInfo = (sizeInfo) => { | ||
1133 | let details = ''; | 1124 | let details = ''; |
1134 | 1125 | ||
1135 | // 详情配图 | 1126 | // 详情配图 |
1136 | - if (_.get(sizeInfo, 'productIntroBo.productIntro', null)) { | ||
1137 | - if (_.get(sizeInfo, 'productIntroBo.phrase', null)) { | 1127 | + if (_.has(sizeInfo, 'productIntroBo.phrase')) { |
1138 | details += `${sizeInfo.productDescBo.phrase}<br/>`; | 1128 | details += `${sizeInfo.productDescBo.phrase}<br/>`; |
1139 | } | 1129 | } |
1140 | - } | ||
1141 | 1130 | ||
1142 | // 图片换成懒加载方式 | 1131 | // 图片换成懒加载方式 |
1143 | const replacePairs = { | 1132 | const replacePairs = { |
@@ -1207,42 +1196,35 @@ const _getProductModelTry = () => { | @@ -1207,42 +1196,35 @@ const _getProductModelTry = () => { | ||
1207 | * @param sizeInfoBo | 1196 | * @param sizeInfoBo |
1208 | */ | 1197 | */ |
1209 | const _getSizeAttrByMaxSortId = (maxSortId, sizeList) => { | 1198 | const _getSizeAttrByMaxSortId = (maxSortId, sizeList) => { |
1210 | - let attributeIds = null; | 1199 | + if (_.isEmpty(sizeList)) { |
1200 | + return []; | ||
1201 | + } | ||
1211 | 1202 | ||
1212 | // 不同分类,取得属性值不同 | 1203 | // 不同分类,取得属性值不同 |
1213 | - switch (maxSortId) { | ||
1214 | - case 1: | ||
1215 | - case 2: | ||
1216 | - attributeIds = [3, 4]; | ||
1217 | - break; | ||
1218 | - | ||
1219 | - case 3: | ||
1220 | - attributeIds = [6, 10]; | ||
1221 | - break; | ||
1222 | - case 6: | ||
1223 | - attributeIds = [13]; | ||
1224 | - break; | ||
1225 | - default: | ||
1226 | - attributeIds = []; | 1204 | + let attributeIds = (function(id) { |
1205 | + if (id === 1 && id === 2) { | ||
1206 | + return [3, 4]; | ||
1207 | + } else if (id === 3) { | ||
1208 | + return [6, 10]; | ||
1209 | + } else if (id === 6) { | ||
1210 | + return [13]; | ||
1211 | + } else { | ||
1212 | + return []; | ||
1227 | } | 1213 | } |
1214 | + }(maxSortId)); | ||
1228 | 1215 | ||
1229 | let sizeInfos = []; | 1216 | let sizeInfos = []; |
1230 | - | ||
1231 | let attributeNames = {}; | 1217 | let attributeNames = {}; |
1232 | 1218 | ||
1233 | - if (_.isEmpty(sizeList)) { | ||
1234 | - return sizeInfos; | ||
1235 | - } | ||
1236 | - | ||
1237 | // 获取属性名称 | 1219 | // 获取属性名称 |
1238 | - sizeList.sizeAttributeBos.forEach(size => { | 1220 | + _.get(sizeList, 'sizeAttributeBos', []).forEach((size) => { |
1239 | attributeNames[size.id] = size.attributeName; | 1221 | attributeNames[size.id] = size.attributeName; |
1240 | }); | 1222 | }); |
1241 | 1223 | ||
1242 | - sizeList.sizeBoList.forEach(size => { | 1224 | + _.get(sizeList, 'sizeBoList', []).forEach((size) => { |
1243 | let sizeValues = []; | 1225 | let sizeValues = []; |
1244 | 1226 | ||
1245 | - size.sortAttributes.forEach(sort => { | 1227 | + _.get(size, 'sortAttributes', []).forEach((sort) => { |
1246 | if (_.includes(attributeIds, sort.id)) { | 1228 | if (_.includes(attributeIds, sort.id)) { |
1247 | if (sort.sizeValue) { | 1229 | if (sort.sizeValue) { |
1248 | sizeValues.push( | 1230 | sizeValues.push( |
@@ -1270,16 +1252,18 @@ const _getSizeAttrByMaxSortId = (maxSortId, sizeList) => { | @@ -1270,16 +1252,18 @@ const _getSizeAttrByMaxSortId = (maxSortId, sizeList) => { | ||
1270 | * @return object | 1252 | * @return object |
1271 | */ | 1253 | */ |
1272 | const _getSizeInfo = (productSkn, maxSortId)=> { | 1254 | const _getSizeInfo = (productSkn, maxSortId)=> { |
1273 | - let result = {}; | 1255 | + if (!productSkn) { |
1256 | + return {}; | ||
1257 | + } | ||
1274 | 1258 | ||
1275 | - if (productSkn) { | ||
1276 | - // 并发资源中是否存在数据 | ||
1277 | let sizeInfo = _getCacheDataByName('ItemData::sizeInfo'); | 1259 | let sizeInfo = _getCacheDataByName('ItemData::sizeInfo'); |
1278 | 1260 | ||
1279 | - if (!sizeInfo) { | ||
1280 | - return result; | 1261 | + if (_.isEmpty(sizeInfo)) { |
1262 | + return {}; | ||
1281 | } | 1263 | } |
1282 | 1264 | ||
1265 | + let result = {}; | ||
1266 | + | ||
1283 | // 描述数据 | 1267 | // 描述数据 |
1284 | result.description = _getDescriptionDataBySizeInfo(sizeInfo); | 1268 | result.description = _getDescriptionDataBySizeInfo(sizeInfo); |
1285 | 1269 | ||
@@ -1312,7 +1296,6 @@ const _getSizeInfo = (productSkn, maxSortId)=> { | @@ -1312,7 +1296,6 @@ const _getSizeInfo = (productSkn, maxSortId)=> { | ||
1312 | // 获取尺寸说明 | 1296 | // 获取尺寸说明 |
1313 | result.sizeTitleJson = | 1297 | result.sizeTitleJson = |
1314 | sizeInfo.sizeInfoBo ? JSON.stringify(_getSizeAttrByMaxSortId(maxSortId, sizeInfo.sizeInfoBo)) : ''; | 1298 | sizeInfo.sizeInfoBo ? JSON.stringify(_getSizeAttrByMaxSortId(maxSortId, sizeInfo.sizeInfoBo)) : ''; |
1315 | - } | ||
1316 | 1299 | ||
1317 | return result; | 1300 | return result; |
1318 | }; | 1301 | }; |
-
Please register or login to post a comment