lodash中map的使用(支付)

27 篇文章 0 订阅

支付报表
把几个对象推平放在一个对象中,_.assign


let data = [
          { appName: "APP", payCounts: 9, refundAmount: 0.1, refundCounts: 1, totalAmount: 433.32, tradeSubject: "01", tradeWay: "" },
          { appName: "APP", payCounts: 9, refundAmount: 0.1, refundCounts: 1, totalAmount: 433.32, tradeSubject: "02", tradeWay: "" },
          { appName: "APP", payCounts: 9, refundAmount: 0.1, refundCounts: 1, totalAmount: 433.32, tradeSubject: "03", tradeWay: "" },
          { appName: "APP", payCounts: 9, refundAmount: 0.1, refundCounts: 1, totalAmount: 433.32, tradeSubject: "04", tradeWay: "" },
          { appName: "自助机", payCounts: 9, refundAmount: 0.1, refundCounts: 1, totalAmount: 433.32, tradeSubject: "01", tradeWay: "" },
          { appName: "自助机", payCounts: 9, refundAmount: 0.1, refundCounts: 1, totalAmount: 433.32, tradeSubject: "02", tradeWay: "" },
          { appName: "自助机", payCounts: 9, refundAmount: 0.1, refundCounts: 1, totalAmount: 433.32, tradeSubject: "03", tradeWay: "" },
          { appName: "自助机", payCounts: 9, refundAmount: 0.1, refundCounts: 1, totalAmount: 433.32, tradeSubject: "04", tradeWay: "" },
        ]
        let groupData = _.groupBy(data, 'appName')
        console.log(_.map(groupData, item => {
          return _.assign({}, ..._.map(item, val => {
            let obj = {}
            _.forEach(val, (value, key) => {
              obj[key + val.tradeSubject] = value
            })
            return obj
          }))
        }))



支付首页


manager
1234qwer

0: {payTime: "1597334400000", receiptAmount: "2.1", tradeSubject: "01"}
1: {payTime: "", receiptAmount: "", tradeSubject: "02"}
2: {payTime: "", receiptAmount: "", tradeSubject: "03"}
3: {payTime: "", receiptAmount: "", tradeSubject: "04"}
4: {payTime: "", receiptAmount: "", tradeSubject: "05"}
5: {payTime: "", receiptAmount: "", tradeSubject: "06"}
6: {payTime: "", receiptAmount: "", tradeSubject: "01"}
7: {payTime: "", receiptAmount: "", tradeSubject: "02"}
8: {payTime: "", receiptAmount: "", tradeSubject: "03"}
9: {payTime: "", receiptAmount: "", tradeSubject: "04"}
               … … … … … … 
36: {payTime: "", receiptAmount: "", tradeSubject: "06"}

        let aaaa = _.groupBy(data, 'tradeSubject')
		
01: (6) [{}, {}, {}, {}, {}, {}]
	0: {payTime: "1597334400000", receiptAmount: "2.1", tradeSubject: "01"}
	1: {payTime: "", receiptAmount: "", tradeSubject: ""}
	2: {payTime: "", receiptAmount: "", tradeSubject: ""}
	3: {payTime: "", receiptAmount: "", tradeSubject: ""}
	4: {payTime: "", receiptAmount: "", tradeSubject: ""}
	5: {payTime: "", receiptAmount: "", tradeSubject: ""}
02: (6) [{}, {}, {}, {}, {}, {}]
03: (5) [{}, {}, {}, {}, {}]
04: (6) [{}, {}, {}, {}, {}, {}]
05: (5) [{}, {}, {}, {}, {}]
06: (5) [{}, {}, {}, {}, {}]		
        let bbbb = _.get(aaaa, '01', [])

0: {payTime: "1597334400000", receiptAmount: "2.1", tradeSubject: "01"}
	0:
	payTime: 1597334400000
	receiptAmount: 2.1
	tradeSubject: "01"
1: {payTime: "", receiptAmount: "", tradeSubject: ""}
2: {payTime: "", receiptAmount: "", tradeSubject: ""}
3: {payTime: "", receiptAmount: "", tradeSubject: ""}
4: {payTime: "", receiptAmount: "", tradeSubject: ""}
5: {payTime: "", receiptAmount: "", tradeSubject: ""}
		
 		let ccccc = _.map([
          { 'key': '01', name: '挂号', witdth: '30' },
          { 'key': '02', name: '取药', witdth: '30' },
          { 'key': '03', name: '检查', witdth: '30' },
          { 'key': '04', name: '检验', witdth: '30' },
          { 'key': '05', name: '住院', witdth: '30' },
          { 'key': '06', name: '体检', witdth: '30' }
        ], ({ key, name, witdth: barMaxWidth }) => {
          if (!!_.get(aaaa, key)) {
            return { name, type: 'bar', barMaxWidth, data: _.map(_.get(aaaa, key, []), 'receiptAmount') }
          }
        })
		
0: {__ob__: Observer}
	0:
	barMaxWidth: "30"
	data: Array(6)
	data: Array(6)
	0: 2.1
	1: 1.1
	2: 1
	3: 1
	4: 3.1
	5: 2.1
	name: "挂号"
	type: "bar"
1: {__ob__: Observer}
2: {__ob__: Observer}
3: {__ob__: Observer}
4: {__ob__: Observer}
5: {__ob__: Observer}		```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值