el-formid.vue 4.7 KB

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