statementsUtil.js 1.54 KB
'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,
}