table.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <!--
  2. * @Author : yuanrunwei
  3. * @Date : 2021-11-01 18:02:58
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2022-02-10 18:31:51
  6. * @FilePath : /spfm-market-front/src/pages/main/performance/components/table.vue
  7. -->
  8. <template>
  9. <el-table
  10. class="simple-table"
  11. :data="computed_list"
  12. v-loading="loading"
  13. @selection-change="handleSelectionChange"
  14. >
  15. <el-table-column
  16. type="selection"
  17. width="55"
  18. :selectable="selectable"
  19. v-if="multiple"
  20. />
  21. <el-table-column
  22. v-for="(
  23. { props, label, type, width, align, children, dictionary, control },
  24. index
  25. ) in config"
  26. :key="index"
  27. :prop="props"
  28. :width="width"
  29. :label="label"
  30. :align="align || 'center'"
  31. >
  32. <template #default="scope">
  33. <div v-if="type === 'edit'">
  34. <el-input
  35. v-if="scope.row[`edit`]"
  36. v-model="scope.row[props]"
  37. autosize
  38. type="textarea"
  39. @change="handleModify"
  40. />
  41. </div>
  42. <div v-if="type === 'number'">{{ scope.$index + 1 }}</div>
  43. <div v-else-if="type === 'textarea'">
  44. <pre class="simple-table-break">{{ scope.row[props] }}</pre>
  45. </div>
  46. <div v-else-if="type === 'date'">
  47. <div>{{ $formatDate(scope.row[props], "YYYY-MM-DD") }}</div>
  48. </div>
  49. <div v-else-if="type === 'time'">
  50. <div>
  51. {{ $formatDate(scope.row[props], "YYYY-MM-DD HH:00:00") }}
  52. </div>
  53. </div>
  54. <div v-else-if="type === 'click'">
  55. <div
  56. v-if="control && Number(scope.row[control]) < 1 && scope.row[props]"
  57. >
  58. <span
  59. v-for="(item, index) in scope.row[props].split(',')"
  60. :key="index"
  61. class="simple-table-click cursor-pointer"
  62. @click="handleClick(props, { ...scope.row, index })"
  63. >
  64. {{ scope.row[props].split(",")[index] }}
  65. </span>
  66. </div>
  67. <div
  68. v-else-if="!control"
  69. class="simple-table-click cursor-pointer"
  70. @click="handleClick(props, scope.row)"
  71. >
  72. {{ scope.row[props] }}
  73. </div>
  74. <div v-else class="cursor-pointer">
  75. {{ scope.row[props] }}
  76. </div>
  77. </div>
  78. <div v-else-if="type === 'dictionary'">
  79. {{ dictionary[scope.row[props]] }}
  80. </div>
  81. <div v-else-if="type === 'file'">
  82. <div v-if="scope.row[props] && scope.row[props].length">
  83. <div
  84. v-for="({ fileName }, index) in scope.row[props]"
  85. :key="index"
  86. @click="downloadFile({ index, rows: scope.row })"
  87. class="simple-table-click cursor-pointer margin-left-10"
  88. >
  89. {{ fileName }}
  90. </div>
  91. </div>
  92. <div v-else></div>
  93. </div>
  94. <div v-else>{{ scope.row[props] }}</div>
  95. </template>
  96. <template v-if="children">
  97. <el-table-column
  98. v-for="({ props, label, width, align, type }, index) in children"
  99. :key="index"
  100. :prop="props"
  101. :width="width"
  102. :label="label"
  103. :align="align || 'center'"
  104. >
  105. <template #default="scope">
  106. <div v-if="type === 'edit'">
  107. <el-input
  108. v-model="scope.row[props]"
  109. @change="handleModify"
  110. autosize
  111. type="textarea"
  112. />
  113. </div>
  114. <div v-else>{{ scope.row[props] }}</div>
  115. </template>
  116. <!-- <template v-if="variable">
  117. <div>{{ scope.row[props] }}</div>
  118. </template> -->
  119. </el-table-column>
  120. </template>
  121. </el-table-column>
  122. <el-table-column
  123. v-if="handleRow.length"
  124. label="操作"
  125. :align="'center'"
  126. :width="handleRow.length * 50"
  127. >
  128. <template slot-scope="scope">
  129. <span
  130. v-for="({ label, props, popconfirm, visible }, index) in handleRow"
  131. :key="index"
  132. class="padding-right-5"
  133. >
  134. <!-- v-if="handleFormat(visible, scope.row)"-->
  135. <span v-if="handleFormat(visible, scope.row)">
  136. <!-- <el-popconfirm
  137. v-if="popconfirm"
  138. :title="`确定要${label}吗?`"
  139. @confirm="handleClick(props, scope.row)"
  140. @cancel="handleCancel"
  141. >
  142. <el-button slot="reference" type="text" size="small">{{
  143. label
  144. }}</el-button>
  145. </el-popconfirm> -->
  146. <el-button
  147. v-if="popconfirm"
  148. type="text"
  149. size="small"
  150. @click="handleConfirm(label, props, scope.row)"
  151. >{{ label }}</el-button
  152. >
  153. <el-button
  154. v-else
  155. @click="handleClick(props, scope.row)"
  156. type="text"
  157. size="small"
  158. >{{ label }}</el-button
  159. >
  160. </span>
  161. </span>
  162. </template>
  163. </el-table-column>
  164. </el-table>
  165. </template>
  166. <script>
  167. export default {
  168. props: {
  169. list: {
  170. type: Array,
  171. default: () => [],
  172. },
  173. config: {
  174. type: Array,
  175. default: () => [],
  176. },
  177. multiple: {
  178. type: Boolean,
  179. default: false,
  180. },
  181. selectable: {
  182. type: Function,
  183. },
  184. loading: {
  185. type: Boolean,
  186. default: false,
  187. },
  188. handleRow: {
  189. type: Array,
  190. default: () => [],
  191. },
  192. },
  193. computed: {
  194. computed_list() {
  195. return this.list.map((element) => ({
  196. ...element,
  197. }));
  198. },
  199. },
  200. methods: {
  201. handleFormat(params, data) {
  202. let visible = true;
  203. if (params) {
  204. visible = false;
  205. Object.keys(params).forEach((element) => {
  206. if (params[element].includes(data[element])) {
  207. visible = true;
  208. }
  209. });
  210. }
  211. return visible;
  212. },
  213. handleConfirm(label, props, row) {
  214. this.$confirm(`确定要${label}吗?`, "提示", {
  215. confirmButtonText: "确定",
  216. cancelButtonText: "取消",
  217. type: "error",
  218. })
  219. .then(() => {
  220. this.$emit(props, row);
  221. })
  222. .catch(() => {});
  223. },
  224. handleClick(props, row) {
  225. this.$emit(props, row);
  226. },
  227. handleCancel() {},
  228. handleSelectionChange(val) {
  229. this.$emit("selection", val);
  230. },
  231. downloadFile(val) {
  232. this.$emit("download", val);
  233. },
  234. handleModify() {
  235. this.$emit("modify", this.computed_list);
  236. },
  237. },
  238. };
  239. </script>