vTable.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div class="vTableCom">
  3. <el-table
  4. ref="multipleTable"
  5. :data="tableList"
  6. header-row-class-name="tableHeader"
  7. header-cell-class-name="tableHeader"
  8. @selection-change="handleSelectionChange"
  9. @sort-change='sortthiscolumn'
  10. size="mini"
  11. :row-class-name="tableRowClassName"
  12. style="width: 100%">
  13. <!-- selection -->
  14. <el-table-column
  15. v-if="table.selection"
  16. align="center"
  17. :fixed="table.fixed"
  18. type="selection"
  19. width="55">
  20. </el-table-column>
  21. <!-- column -->
  22. <el-table-column
  23. align="center"
  24. :width="item.width"
  25. :prop="item.props"
  26. :label="item.label"
  27. :sortable="item.sortable?'custom':false"
  28. v-for="(item,index) in table.column"
  29. :key="index">
  30. <template slot-scope="scope">
  31. <!-- slot 自定义插槽 可以用一个变量来接受item和scope (在订单列表中有使用,可以查看使用方法)-->
  32. <slot v-if="item.type==='slot'" name="slot" :item="item" :scope="scope.row"></slot>
  33. <!-- date -->
  34. <span v-else-if="item.type==='date'">
  35. <span v-if="item.format==='YMD'">{{$utils.formatYMD(scope.row[item.props])}}</span>
  36. <span v-else>{{$utils.format(scope.row[item.props])}}</span>
  37. </span>
  38. <span v-else-if="item.type==='imgList'">
  39. <el-image
  40. v-for="i in scope.row[item.props]"
  41. :key="i.id"
  42. style="width: 70px; height: 70px"
  43. :src="$img+i.imgPath"
  44. :preview-src-list="scope.row[item.props].map(it => $img+it.imgPath)">
  45. </el-image>
  46. </span>
  47. <el-popover
  48. placement="left"
  49. v-else-if="item.type==='cover'"
  50. width="200"
  51. trigger="hover">
  52. <img slot="reference" class="img" :src="scope.row[item.props]" alt="">
  53. <img class="w-100" :src="scope.row[item.props]" alt="">
  54. </el-popover>
  55. <!-- pic -->
  56. <el-popover
  57. placement="left"
  58. v-else-if="item.type==='pic'"
  59. width="200"
  60. trigger="hover">
  61. <img slot="reference" class="img" :src="$img+scope.row[item.props]" alt="">
  62. <img class="w-100" :src="$img+scope.row[item.props]" alt="">
  63. </el-popover>
  64. <!-- <span v-else-if="item.state">{{item.state[scope.row[item.props]]}}</span> -->
  65. <!-- option -->
  66. <span v-else-if="item.options">{{item.options[scope.row[item.props]]}}</span>
  67. <span v-else-if="item.html" v-html="scope.row[item.props]"></span>
  68. <!-- normal -->
  69. <span v-else>{{scope.row[item.props]}}</span>
  70. </template>
  71. </el-table-column>
  72. <!-- handle -->
  73. <el-table-column
  74. label="操作"
  75. v-if="table.handle"
  76. :fixed="table.fixed && 'right'"
  77. :width="table.width"
  78. align="center">
  79. <template slot-scope="scope">
  80. <el-button-group style="display:flex;justify-content: center;">
  81. <el-button
  82. v-for="(item,index) in table.handle.filter(item => scope.row[item.props] === item.key)"
  83. :key="index"
  84. size="small"
  85. style="margin:0px;"
  86. class="btn handelBtn"
  87. @click="handleMethods(scope.$index, scope.row, item)">
  88. {{item.title}}
  89. <!-- v-if="scope.row[item.props]===item.key" -->
  90. </el-button>
  91. </el-button-group>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. </div>
  96. </template>
  97. <script>
  98. export default {
  99. props: {
  100. table: {
  101. type: Object,
  102. default: () => []
  103. },
  104. tableList: {
  105. type: Array,
  106. default: () => []
  107. },
  108. show: {
  109. type: Boolean,
  110. default: false
  111. },
  112. id: {
  113. type: String,
  114. default: () => ''
  115. },
  116. errorList: {
  117. type: Array,
  118. default: () => []
  119. },
  120. sortType: {
  121. type: Boolean,
  122. default: false
  123. },
  124. queryData: {
  125. type: Function,
  126. default: () => {}
  127. },
  128. pickList: {
  129. type: Array,
  130. default: () => []
  131. },
  132. form: Object
  133. },
  134. data () {
  135. return {
  136. orderItem: {}
  137. }
  138. },
  139. mounted () {
  140. },
  141. methods: {
  142. handleMethods (index, item, v) {
  143. this.$emit(v.method, item)
  144. },
  145. handleSelectionChange (val) {
  146. this.id && this.$emit('selection-change', val.map(item => item[this.id]))
  147. },
  148. tableRowClassName ({ row, rowIndex }) {
  149. if (this.errorList.includes(rowIndex)) {
  150. return 'error-row'
  151. }
  152. return ''
  153. },
  154. sortthiscolumn ({ column, prop, order }) {
  155. this.orderItem = order
  156. ? {
  157. [prop]: order === 'ascending' ? 'ASC' : 'DESC'
  158. }
  159. : {}
  160. this.queryData(this.form)
  161. }
  162. }
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. @import './vTable.scss';
  167. </style>
  168. <style lang='scss'>
  169. .el-table .error-row {
  170. background: rgba($color: red, $alpha: 0.3);
  171. }
  172. </style>