my-table.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template id="my-table">
  2. <div class="my-table">
  3. <div class="my-table-header" flex>
  4. <div v-for="(header,index) in headerList" :key="index" :style="getHeaderStyle(header)">
  5. <div>{{header.label}}</div>
  6. </div>
  7. </div>
  8. <div class="list-contain" v-infinite-scroll="onReachBottom">
  9. <div class="list-content" v-for="(item,i) in data" flex :style="getRow()" :key="i">
  10. <div v-for="(header,j) in headerList" :key="j" :style="getContentStyle(header)">
  11. <slot v-if="header.slot" :name="header.slot" :index="i" :item="item"></slot>
  12. <!-- <slot v-if="header.goods_name" :name="header.slot" :index="i" :item="item"></slot> -->
  13. <div v-else-if="header.props == 'goods_name'" flex>
  14. <el-image class="list-goods-img" :src="item.cover_pic" fit="cover"></el-image>
  15. <div class="over1">{{item[header.props]}}</div>
  16. </div>
  17. <div v-else>{{item[header.props]}}</div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. Vue.component('my-table', {
  25. name: "my-table",
  26. template: '#my-table',
  27. props: {
  28. data: {
  29. type: Array,
  30. required: true,
  31. default () {
  32. return []
  33. }
  34. },
  35. options: {
  36. type: Array,
  37. required: true,
  38. default () {
  39. return []
  40. }
  41. },
  42. vertical: {
  43. type: String,
  44. default: '',
  45. }
  46. },
  47. data() {
  48. return {}
  49. },
  50. computed: {
  51. headerList() {
  52. let headerList = this.options.map(item => {
  53. const {
  54. props,
  55. label,
  56. width,
  57. textAlign,
  58. slot
  59. } = item
  60. let result = {
  61. width,
  62. props,
  63. label,
  64. textAlign: textAlign
  65. }
  66. if (slot) {
  67. result.slot = props
  68. }
  69. return result
  70. })
  71. console.log(headerList, "headerList");
  72. return headerList
  73. }
  74. },
  75. methods: {
  76. onReachBottom() {
  77. this.$emit("onReachBottom")
  78. },
  79. getHeaderStyle(header) {
  80. const width = header.width || 0
  81. const padding = `10px 0 `
  82. const textAlign = header.textAlign || 'center'
  83. let result = {
  84. width: `${width}px`,
  85. padding,
  86. textAlign,
  87. borderBottom: '1px solid #fff'
  88. }
  89. if (!width)(result.flex = 1)
  90. return result
  91. },
  92. getContentStyle(header) {
  93. const width = header.width || 0
  94. const padding = `20px 0 0 0`
  95. const textAlign = header.textAlign || 'center'
  96. let result = {
  97. width: `${width}px`,
  98. padding,
  99. textAlign,
  100. }
  101. if (!width)(result.flex = 1)
  102. return result
  103. },
  104. getRow() {
  105. const vertical = this.vertical || 'center'
  106. let result = {
  107. 'align-items': vertical
  108. }
  109. return result
  110. }
  111. }
  112. });
  113. </script>
  114. <style>
  115. .my-table {
  116. display: flex;
  117. flex-direction: column;
  118. height: 100%;
  119. }
  120. .list-contain {
  121. flex: 1;
  122. overflow-y: scroll;
  123. }
  124. .list-goods-img{
  125. width: 32px;
  126. height: 32px;
  127. min-width: 32px;
  128. margin-right: 12px;
  129. border-radius: 4px;
  130. }
  131. </style>