Files
mes-ui-d2/src/pages/demo/d2-crud/demo13/code.js
liyang fbc61146cf 删除不必要的
Former-commit-id: e8d0399649f030c9876ba1d69464693936bed060 [formerly e8d0399649f030c9876ba1d69464693936bed060 [formerly e8d0399649f030c9876ba1d69464693936bed060 [formerly e8d0399649f030c9876ba1d69464693936bed060 [formerly bc48870f23c75a583db5b9e41936f1437c470ac0 [formerly c68b2fb0992173d2441fd536233d5c2075fc544e]]]]]
Former-commit-id: a36c5ce2a288d2d909ce8b09cc595ce80d28c15e
Former-commit-id: d4c76f476b1fa7f38e6fabdd9d21f520f5f14a34
Former-commit-id: 9c745093b13b846bfd627b7f7fb011db7b7297da [formerly 3f3223ff1a1e480c6864b96a76aec0f175b6678a]
Former-commit-id: 1d749c73671d29fc363199fb248d5997fe7e92b3
Former-commit-id: cb85dac90c6fa2062882ea2ebf6e40518e91a54b
Former-commit-id: 9dc07127b3a14f3a7a00b1d26b679f6866a487cd
Former-commit-id: d6298c124901c531fd1bfb87b865d11e0454875e
Former-commit-id: a1996901ac9efc4e1e94fe5e8548bd40ae8c7366
2018-11-17 12:06:50 +08:00

106 lines
2.2 KiB
JavaScript

export default `<template>
<div>
<d2-crud
:columns="columns"
:data="data"
:options="options"/>
</div>
</template>
<script>
export default {
data () {
return {
columns: [
{
title: 'ID',
key: 'id'
},
{
title: '姓名',
key: 'name'
},
{
title: '数值 1',
key: 'amount1'
},
{
title: '数值 2',
key: 'amount2'
},
{
title: '数值 3',
key: 'amount3'
}
],
data: [
{
id: '12987122',
name: '王小虎',
amount1: '234',
amount2: '3.2',
amount3: 10
},
{
id: '12987123',
name: '王小虎',
amount1: '165',
amount2: '4.43',
amount3: 12
},
{
id: '12987124',
name: '王小虎',
amount1: '324',
amount2: '1.9',
amount3: 9
},
{
id: '12987125',
name: '王小虎',
amount1: '621',
amount2: '2.2',
amount3: 17
},
{
id: '12987126',
name: '王小虎',
amount1: '539',
amount2: '4.1',
amount3: 15
}
],
options: {
showSummary: true,
summaryMethod (param) {
const { columns, data } = param
const sums = []
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '总价'
return
}
const values = data.map(item => Number(item[column.property]))
if (!values.every(value => isNaN(value))) {
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr)
if (!isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)
sums[index] += ' 元'
} else {
sums[index] = 'N/A'
}
})
return sums
}
}
}
}
}
</script>`