table.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!--
  2. * @Author : yuanrunwei
  3. * @Date : 2021-11-01 18:02:58
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2021-12-22 19:55:28
  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="(
  12. { props, label, type, width, align, children, dictionary },
  13. index
  14. ) in config"
  15. :key="index"
  16. :prop="props"
  17. :width="width"
  18. :label="label"
  19. :align="align || 'center'"
  20. >
  21. <template #default="scope">
  22. <div v-if="type === 'edit'">
  23. <el-input
  24. v-if="scope.row[`edit`]"
  25. v-model="scope.row[props]"
  26. autosize
  27. type="textarea"
  28. @change="handleModify"
  29. />
  30. </div>
  31. <div v-else-if="type === 'textarea'">
  32. <pre class="simple-table-break">{{ scope.row[props] }}</pre>
  33. </div>
  34. <div v-else-if="type === 'date'">
  35. <div>{{ $formatDate(scope.row[props], "YYYY-MM-DD") }}</div>
  36. </div>
  37. <div v-else-if="type === 'click'">
  38. <div
  39. class="simple-table-click cursor-pointer"
  40. @click="handleClick(props, scope.row)"
  41. >
  42. {{ scope.row[props] }}
  43. </div>
  44. </div>
  45. <div v-else-if="type === 'dictionary'">
  46. {{ dictionary[scope.row[props]] }}
  47. </div>
  48. <div v-else>{{ scope.row[props] }}</div>
  49. </template>
  50. <template v-if="children">
  51. <el-table-column
  52. v-for="(
  53. { props, label, width, align, type }, index
  54. ) in children"
  55. :key="index"
  56. :prop="props"
  57. :width="width"
  58. :label="label"
  59. :align="align || 'center'"
  60. >
  61. <template #default="scope">
  62. <div v-if="type === 'edit'">
  63. <el-input
  64. v-model="scope.row[props]"
  65. @change="handleModify"
  66. autosize
  67. type="textarea"
  68. />
  69. </div>
  70. <div v-else>{{ scope.row[props] }}</div>
  71. </template>
  72. </el-table-column>
  73. </template>
  74. </el-table-column>
  75. <el-table-column
  76. v-if="handleRow.length"
  77. label="操作"
  78. :width="handleRow.length * 50"
  79. >
  80. <template slot-scope="scope">
  81. <span
  82. v-for="(
  83. { label, props, popconfirm, visible }, index
  84. ) in handleRow"
  85. :key="index"
  86. class="padding-right-5"
  87. >
  88. <span v-if="handleFormat(visible, scope.row)">
  89. <el-popconfirm
  90. v-if="popconfirm"
  91. :title="`确定要${label}吗?`"
  92. @confirm="handleClick(props,scope.row)"
  93. @cancel="handleCancel"
  94. >
  95. <el-button
  96. slot="reference"
  97. type="text"
  98. size="small"
  99. >{{ label }}</el-button
  100. >
  101. </el-popconfirm>
  102. <el-button
  103. v-else
  104. @click="handleClick(props, scope.row)"
  105. type="text"
  106. size="small"
  107. >{{ label }}</el-button
  108. >
  109. </span>
  110. </span>
  111. </template>
  112. </el-table-column>
  113. </el-table>
  114. </template>
  115. <script>
  116. export default {
  117. props: {
  118. list: {
  119. type: Array,
  120. default: () => [],
  121. },
  122. config: {
  123. type: Array,
  124. default: () => [],
  125. },
  126. loading: {
  127. type: Boolean,
  128. default: false,
  129. },
  130. handleRow: {
  131. type: Array,
  132. default: () => [],
  133. },
  134. },
  135. computed: {
  136. computed_list() {
  137. return this.list.map((element) => ({
  138. ...element,
  139. }));
  140. },
  141. },
  142. methods: {
  143. handleFormat(params, data) {
  144. let visible = true;
  145. if (params) {
  146. visible = false;
  147. Object.keys(params).forEach((element) => {
  148. if (params[element].includes(data[element])) {
  149. visible = true;
  150. }
  151. });
  152. }
  153. return visible;
  154. },
  155. handleClick(props, row) {
  156. console.log('aaaaaaaaa')
  157. this.$emit(props, row);
  158. },
  159. handleCancel(){
  160. console.log('我被关闭了')
  161. },
  162. handleModify() {
  163. this.$emit("modify", this.computed_list);
  164. },
  165. },
  166. };
  167. </script>