el-form.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div>
  3. <slot :name="list.name"></slot>
  4. <el-table
  5. ref="table"
  6. style="width: 100%"
  7. :data="list.data"
  8. :height="list.height + 'px'"
  9. :max-height="list.height + 'px'"
  10. @row-click="getRowData"
  11. @selection-change="selectionChange"
  12. empty-text="暂无数据"
  13. @cell-click="getRowList"
  14. :cell-style="columnbackgroundStyle"
  15. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  16. >
  17. <!-- 是否多选 -->
  18. <el-table-column
  19. v-if="list.isSelection"
  20. :selecttable="list"
  21. type="selection"
  22. :width="list.width || 50"
  23. align="center"
  24. />
  25. <!-- 是否需要序号 -->
  26. <el-table-column
  27. v-if="list.isIndex"
  28. type="index"
  29. label="序号"
  30. width="55"
  31. align="center"
  32. />
  33. <template v-for="item in list.titledata">
  34. <el-table-column
  35. :key="item.prop"
  36. :prop="item.prop"
  37. :label="item.label"
  38. align="center"
  39. show-overflow-tooltip
  40. :width="item.width || 100"
  41. />
  42. </template>
  43. <!-- 操作列 -->
  44. <el-table-column
  45. v-if="list.isOperation"
  46. v-bind="list.data && list.data.length ? { fixed: 'right' } : null"
  47. style="margin-right: 20px"
  48. class-name="handle-td"
  49. label-class-name="tc"
  50. :label="list.operation.label"
  51. align="center"
  52. >
  53. <!-- UI统一一排放3个,4个以上出现更多 -->
  54. <template slot-scope="scope">
  55. <!-- 三个一排的情况,去掉隐藏的按钮后的长度 -->
  56. <template v-if="list.operation.data.length > 0">
  57. <div class="btn">
  58. <div v-for="item in list.operation.data" :key="item.label">
  59. <template v-if="item.type !== 'icon'">
  60. <el-button
  61. v-bind="item"
  62. :type="item.type ? item.type : ''"
  63. size="mini"
  64. @click.native.prevent="
  65. item.handleRow(scope.$index, scope.row, item.label)
  66. "
  67. >
  68. {{ item.label }}
  69. </el-button>
  70. </template>
  71. <template v-else>
  72. <i
  73. :class="[icon, item.icon]"
  74. v-bind="item"
  75. @click="item.handleRow(scope.$index, scope.row, item.label)"
  76. />
  77. </template>
  78. </div>
  79. </div>
  80. </template>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <div class="page">
  85. <el-pagination
  86. style="display: flex; flex-direction: row-reverse"
  87. v-if="list.pageData.total > 0"
  88. :current-page.sync="page"
  89. :page-sizes="
  90. list.pageData.pageSizes ? list.pageData.pageSizes : [5, 10, 15, 20]
  91. "
  92. :page-size="list.pageData.pageSize"
  93. layout="total, sizes, prev, pager, next, jumper"
  94. :total="list.pageData.total"
  95. @size-change="handleSizeChange"
  96. @current-change="handleCurrentChange"
  97. />
  98. </div>
  99. </div>
  100. </template>
  101. <script>
  102. export default {
  103. data(){
  104. return{
  105. page:1
  106. }
  107. },
  108. props: {
  109. // 表格数据和表格部分属性的对象
  110. // eslint-disable-next-line vue/require-default-prop
  111. list: {
  112. type: Object,
  113. },
  114. },
  115. created() {
  116. },
  117. methods: {
  118. columnbackgroundStyle({ row, column, rowIndex, columnIndex }) {
  119. if (column.type == "default") {
  120. if (column.label === "文件标题"||column.label === "待办事项名称") {
  121. return "color:#0682CD;";
  122. }
  123. }
  124. },
  125. selectionChange(val) {
  126. //多选数字回调
  127. this.$emit("num", val);
  128. },
  129. handleAdd(name) {
  130. this.$emit("toolMsg", name);
  131. },
  132. handleRow(index, row, lable) {
  133. },
  134. handleSizeChange(val) {
  135. this.$emit("changeSize", val);
  136. console.log(`每页 ${val} 条`);
  137. },
  138. handleCurrentChange(val) {
  139. this.$emit("changeNum", val);
  140. console.log(`当前页: ${val}`);
  141. },
  142. // 点击行即可选中
  143. getRowData(row) {
  144. this.$refs.table.toggleRowSelection(row);
  145. },
  146. getRowList(row, column, event, cell) {
  147. this.$emit("clickDemand", column.label, row);
  148. },
  149. },
  150. };
  151. </script>
  152. <style lang="scss" scoped>
  153. .btn{
  154. display: flex;
  155. justify-content: center;
  156. }
  157. </style>