test.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view>
  3. <lyy-table :headerFixed="true" :contents="contents" :headers="headers" :totalRow="totalRow" @rowClick="rowClick"></lyy-table>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name:"btable",
  9. data() {
  10. return {
  11. loading:false,
  12. totalRow:['sales','orders','saleroom','gross','test2'],
  13. headers:[{
  14. label: '排名',
  15. key: 'rank',
  16. width: 50
  17. }, {
  18. label: '姓名',
  19. key: 'name',
  20. width: 75
  21. }, {
  22. label: '部门',
  23. key: 'dept',
  24. width: 100
  25. }, {
  26. label: '销量',
  27. key: 'sales',
  28. width: 100,
  29. sort:true
  30. },{
  31. label:'销量完成率',
  32. key:'sales_task',
  33. width:130,
  34. sort:true,
  35. format:{
  36. type:'progress',
  37. keys:['sales','sales_task','orders'],
  38. template:'{0}/{1}*100'
  39. }
  40. },{
  41. label: '订单',
  42. key: 'orders',
  43. width: 100,
  44. sort:true
  45. }, {
  46. label: '销售额',
  47. key: 'saleroom',
  48. width: 125,
  49. sort:true
  50. }, {
  51. label: '毛利',
  52. key: 'gross',
  53. width: 125,
  54. sort:true
  55. }, {
  56. label: 'string格式化',
  57. key: 'test1',
  58. width: 125,
  59. format:{
  60. type:'string',
  61. keys:['name','dept'],
  62. template:'{0}--{1}'
  63. }
  64. }, {
  65. label: '计算格式化',
  66. key: 'test2',
  67. width: 125,
  68. sort:true,
  69. format:{
  70. type:'compute',
  71. keys:['orders','sales'],
  72. template:'{0}*{1}'
  73. }
  74. }, {
  75. label: 'html普通格式化',
  76. key: 'test3',
  77. width: 200,
  78. format:{
  79. type:'html',
  80. keys:['name','dept'],
  81. template:'<span><h1>{0}</h1>{1}</span>'
  82. }
  83. }, {
  84. label: 'html条件格式化',
  85. key: 'test4',
  86. width: 125,
  87. format:{
  88. type:'html',
  89. keys:['orders'],
  90. template:function(e){
  91. if(e[0]>1){
  92. return '<p style="color:red">'+e[0]+'</p>'
  93. } else return '<p style="color:green">'+e[0]+'</p>'
  94. }
  95. }
  96. }],
  97. contents:[{"rank":1,"id":10000,"name":"张三","dept":"销售一部","sales":26,'sales_task':100,"orders":2,"saleroom":2050000,"gross":240002},
  98. {"rank":2,"id":10002,"name":"王五","dept":"销售一部","sales":25,'sales_task':100,"orders":2,"saleroom":1530000,"gross":232001},
  99. {"rank":3,"id":10004,"name":"小明","dept":"销售二部","sales":50,'sales_task':120,"orders":2,"saleroom":1200000,"gross":130000},
  100. {"rank":4,"id":10001,"name":"李四","dept":"销售二部","sales":43,'sales_task':120,"orders":1,"saleroom":1100000,"gross":80001},
  101. {"rank":5,"id":10003,"name":"小红","dept":"销售三部","sales":19,'sales_task':80,"orders":1,"saleroom":200000,"gross":23334}],
  102. }
  103. },
  104. methods:{
  105. rowClick(e){
  106. console.log(e)
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .uni-progress{
  113. color: red;
  114. /deep/ .uni-progress-info{
  115. font-size: 10px !important;
  116. }
  117. }
  118. </style>