table.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!--
  2. * @Author : yuanrunwei
  3. * @Date : 2021-11-01 18:02:58
  4. * @LastEditors : yuanrunwei
  5. * @LastEditTime : 2021-12-03 21:22:43
  6. * @FilePath : \spfm-market-front\src\pages\main\performance\components\table.vue
  7. -->
  8. <template>
  9. <el-table class="simple-table" :data="computed_list" v-loading="loading">
  10. <el-table-column
  11. v-for="({ props, label, type, width, align, children }, index) in config"
  12. :key="index"
  13. :prop="props"
  14. :width="width"
  15. :label="label"
  16. :align="align || 'center'"
  17. >
  18. <template #default="scope">
  19. <div v-if="type === 'edit'">
  20. <el-input
  21. v-if="scope.row[`${props}_${type}`]"
  22. v-model="scope.row[props]"
  23. autosize
  24. type="textarea"
  25. />
  26. <pre v-else>{{ scope.row[props] }}</pre>
  27. <el-button
  28. size="mini"
  29. class="margin-top-10"
  30. @click="handleEdit({ scope, type, props })"
  31. >
  32. {{ !scope.row[`${props}_${type}`] ? "编辑" : "完成" }}
  33. </el-button>
  34. </div>
  35. <div v-else>{{ scope.row[props] }}</div>
  36. </template>
  37. <template v-if="children">
  38. <el-table-column
  39. v-for="({ props, label, width, align }, index) in children"
  40. :key="index"
  41. :prop="props"
  42. :width="width"
  43. :label="label"
  44. :align="align || 'center'"
  45. >
  46. <template #default="scope">
  47. <div>{{ scope.row[props] }}</div>
  48. </template>
  49. </el-table-column>
  50. </template>
  51. </el-table-column>
  52. <el-table-column
  53. v-if="handleRow.length"
  54. label="操作"
  55. :width="handleRow.length * 50"
  56. >
  57. <template slot-scope="scope">
  58. <span
  59. v-for="({ label, props, popconfirm, visible }, index) in handleRow"
  60. :key="index"
  61. class="padding-right-5"
  62. >
  63. <span v-if="handleFormat(visible,scope.row)">
  64. <el-popconfirm v-if="popconfirm" :title="`确定要${label}吗?`">
  65. <el-button
  66. slot="reference"
  67. @click="handleClick(props, scope.row)"
  68. type="text"
  69. size="small"
  70. >{{ label }}</el-button
  71. >
  72. </el-popconfirm>
  73. <el-button
  74. v-else
  75. @click="handleClick(props, scope.row)"
  76. type="text"
  77. size="small"
  78. >{{ label }}</el-button
  79. >
  80. </span>
  81. </span>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. </template>
  86. <script>
  87. export default {
  88. props: {
  89. list: {
  90. type: Array,
  91. default: () => [],
  92. },
  93. config: {
  94. type: Array,
  95. default: () => [],
  96. },
  97. loading: {
  98. type: Boolean,
  99. default: false,
  100. },
  101. handleRow: {
  102. type: Array,
  103. default: () => [],
  104. },
  105. },
  106. computed: {
  107. computed_list() {
  108. const object = {};
  109. this.config
  110. .filter(({ type }) => type === "edit")
  111. .forEach(({ props, type }) => {
  112. object[`${props}_${type}`] = false;
  113. });
  114. return this.list.map((element) => ({
  115. ...element,
  116. ...object,
  117. }));
  118. },
  119. },
  120. methods: {
  121. handleFormat(params,data) {
  122. let visible = true;
  123. if (params) {
  124. visible = false;
  125. console.log(Object.keys(params));
  126. Object.keys(params).forEach((element) => {
  127. if (params[element].includes(data[element])) {
  128. visible = true;
  129. }
  130. });
  131. }
  132. return visible;
  133. },
  134. handleClick(props, row) {
  135. this.$emit(props, row);
  136. },
  137. handleEdit({ scope, type, props }) {
  138. scope.row[`${props}_${type}`] = !scope.row[`${props}_${type}`];
  139. this.$emit(props, scope.row);
  140. },
  141. },
  142. };
  143. </script>