mine-handler.js 2.19 KB
import moment from 'moment';

export function parseAssetList(json) {
  let {
    data,
    page,
    pagetotal,
    summary
  } = json;
  let parsedList = data ? data.map((item) => {
    let price = '';

    if (item.amount !== null) {
      if (item.incomeOutcome === 2) {
        if (item.amount > 0) {
          price = '-' + Number(Math.abs(item.amount)).toFixed(2);
        } else {
          price = '+' + Number(Math.abs(item.amount)).toFixed(2);
        }
      } else {
        if (item.amount > 0) {
          price += '+' + Number(Math.abs(item.amount)).toFixed(2);
        } else {
          price += '-' + Number(Math.abs(item.amount)).toFixed(2);
        }
      }
    }
    return {
      title: item.tradeTypeDesc + '(订单号:' + item.orderCode + ')',
      price: price,
      tradeTypeDesc: item.tradeTypeDesc,
      type: item.tradeType,
      productName: item.productName,
      sizeName: item.sizeName,
      time: moment(new Date(item.createTime * 1000)).format('YYYY.MM.DD HH:mm'),
      normalFlag: item.normalFlag,
    };
  }) : [];
  let endReached = parsedList.length === 0 || page === pagetotal;
  let dealedList = {
    currentPage: page,
    list: parsedList,
    endReached,
  };

  if (summary) {
    dealedList.compensateIncome = summary.compensateIncome;
    dealedList.goodsIncome = summary.goodsIncome;
    dealedList.totalIncome = summary.totalIncome;
  }
  return dealedList;
}
export function formatNumber(number) {
  return parseFloat(number) < 0 ? '-¥' + Math.abs(parseFloat(number)).toFixed(2) : '¥' + Math.abs(parseFloat(number)).toFixed(2);
}

export function maskAccount(string) {
  if (/^1[3|4|5|7|8][0-9]{9}$/.test(string)) {
    return string.substring(0, 3) + '****' + string.substring(7);
  } else if (/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test(string.toLowerCase())) {
    if (string.indexOf('@') > 3) {
      return string.substring(0, 3) + '****' + string.substring(string.lastIndexOf('@'));
    } else {
      return '****' + string.substring(string.lastIndexOf('@'));
    }
  } else if (string.length > 2) {
    return string.substring(0, 1) + '****' + string.substring(string.length - 1);
  }
  return string.substring(0, 1) + '****';
}