statementsUtil.js
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict'
import {formatImageUrl} from './util';
//获取应用实例
let app = getApp();
function parseComputeData(data, imageHeight, imageWidth) {
let newData = {};
for (var item in data){
let key = item;
let value = data[item];
if(key === "shopping_cart_data"){
for(var shaoppingItem in value){
newData[shaoppingItem] = value[shaoppingItem];
}
}else {
if(key === "delivery_address"){
value = parseDeliveryAddress(value);
}
if(key === "goods_list"){
value = parseGoods(value,imageHeight,imageWidth);
}
if(key === "delivery_way"){
value = parseDelivery(value);
}
newData[key] = value;
}
}
return newData;
}
//解析处理配送方式数据
function parseDelivery(deliverys) {
let newData = [];
deliverys && deliverys.map((item, index) => {
let isChecked = item["default"];
if(isChecked === 'Y'){
item.checked = true;
}else{
item.checked = false;
}
newData.push(item);
});
return newData;
}
//解析处理商品数据
function parseGoods(list,imageHeight,imageWidth) {
list && list.map((item, index) => {
let imageUrl = formatImageUrl(item.goods_images,imageWidth,imageHeight,2)
item.goods_images = imageUrl;
});
return list;
}
//解析处理配送地址数据
function parseDeliveryAddress(address){
for (var key in address){
if(key === 'consignee'){
let value = address[key];
address.user_name = value;
}
}
return address;
}
module.exports = {
parseComputeData,
}