commonTable.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="height_100" v-DivHeight="getDivHeight">
  3. <el-table :data="tableData" border header-row-class-name="custom-table-header" @sort-change="sortChange"
  4. v-if="showTable" :maxHeight="tableHeight" v-el-table-infinite-scroll="getList" :infinite-scroll-distance="10"
  5. :infinite-scroll-disabled="disabled" style="width: 100%">
  6. <el-table-column label="#" width="60" type="index" align="center">
  7. <template slot-scope="scope">
  8. <span>{{ (scope.$index + 1) + ((queryParams.current - 1) * queryParams.size) }}</span>
  9. </template>
  10. </el-table-column>
  11. <el-table-column v-for="item in column.filter(item => !item.ifHidden)" :render-header=" $commonJS.renderHeaderMethods" :key="item.value" :prop="item.value"
  12. :label="item.name" align="center" sortable="custom">
  13. <template slot-scope="scope">
  14. <div v-if="['name'].includes(item.value)">
  15. <el-link type="primary" @click="handleItem(scope.row, item.value)" >
  16. <span v-html="$commonJS.getColumnData(scope.row, item)"></span>
  17. </el-link>
  18. </div>
  19. <div v-else-if="['ifSearch'].includes(item.value)" v-html="$commonJS.getColumnData(scope.row, item , null , {data:ifSearch})"></div>
  20. <div v-else v-html="$commonJS.getColumnData(scope.row, item)"></div>
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="操作" align="center" width="120px">
  24. <template slot-scope="scope">
  25. <div>
  26. <el-dropdown split-button type="primary" size="small" @command="handleCommand($event, scope.row)">
  27. <span @click="handleCommand('e', scope.row)">编辑</span>
  28. <el-dropdown-menu slot="dropdown" style="text-align: center;">
  29. <el-dropdown-item divided class="color-red" command="1">删除</el-dropdown-item>
  30. </el-dropdown-menu>
  31. </el-dropdown>
  32. </div>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. </div>
  37. </template>
  38. <script>
  39. import { getTableHeight } from '@/views/components/mixins'
  40. import mixins from '../mixins'
  41. export default {
  42. mixins: [mixins,getTableHeight],
  43. components: {},
  44. props: {
  45. column: {//显示栏位管理数组
  46. type: Array,
  47. default: () => {
  48. return []
  49. }
  50. },
  51. row: null,
  52. //操作信息
  53. handleMessage: ''
  54. },
  55. data() {
  56. return {
  57. ifSearch: {
  58. false:'否',
  59. true:'是',
  60. },
  61. //正在努力加载中
  62. isFlag: false,
  63. //没有更多啦!
  64. isMore: false,
  65. //禁用懒加载
  66. disabled: true,
  67. params: {
  68. size: 5,
  69. current: 0
  70. },
  71. // 排序数组
  72. sort: [
  73. {
  74. "orderBy": "createTime",
  75. "orderType": 1
  76. }
  77. ],
  78. //事件类型及所选
  79. action: {
  80. type: '',//1表示删除,2表示其他,3表示新增
  81. id: ''
  82. }
  83. };
  84. },
  85. computed: {},
  86. watch: {
  87. handleMessage(val) {
  88. if (val) {
  89. this.updateData()
  90. }
  91. }
  92. },
  93. mounted() {
  94. if (!this.row) {
  95. this.disabled = true
  96. } else {
  97. this.disabled = false
  98. }
  99. },
  100. methods: {
  101. //更新数据
  102. updateData() {
  103. if (this.action.type == 1) {
  104. if (this.tableData.length == 1) {
  105. return false
  106. }
  107. var startIndex = this.tableData.findIndex(item => {
  108. return item.id == this.action.id
  109. })
  110. this.tableData.splice(startIndex, 1)
  111. let params = {
  112. ...this.params,
  113. searchQuery: this.$commonJS.objectToString(this.row.searchOption),//检索条件
  114. orderDTOList: this.sort,//排序
  115. groupField: this.row.groupBy,
  116. groupFieldValue: this.row.row.value,
  117. }
  118. this.getList2(params, 1)
  119. } else if (this.action.type == 2) {
  120. let params = {
  121. ...this.params,
  122. searchQuery: `id=${this.action.id}`,//检索条件
  123. groupField: this.row.groupBy,
  124. groupFieldValue: this.row.row.value,
  125. }
  126. this.getList2(params, 2)
  127. }
  128. },
  129. getList2(params, type) {
  130. this.$api.queryPatentDigProject(params).then(res => {
  131. if (res.code == 200) {
  132. if (type == 1) {
  133. var startIndex = (params.current - 1) * size
  134. var endIndex = this.tableData.length
  135. var len = endIndex - startIndex
  136. this.tableData.splice(startIndex, len, ...res.data.data)
  137. this.params.total = res.data.total
  138. } else if (type == 2) {
  139. var startIndex = this.tableData.findIndex(item => {
  140. return item.id == this.action.id
  141. })
  142. this.tableData.splice(startIndex, 1, ...res.data.data)
  143. }
  144. }
  145. }).catch(err => {
  146. })
  147. },
  148. getList() {
  149. if (!this.row) return;
  150. if (this.disabled) return;
  151. if (this.params.current * this.params.size >= this.params.total) {
  152. this.isMore = true
  153. this.disabled = true
  154. setTimeout(() => {
  155. this.isMore = false;
  156. this.isFlag = false
  157. }, 1000)
  158. }
  159. this.params.current += 1
  160. let params = {
  161. ...this.params,
  162. searchQuery: this.$commonJS.objectToString(this.row.searchOption),//检索条件
  163. orderDTOList: this.sort,//排序
  164. groupField: this.row.groupBy,
  165. groupFieldValue: this.row.row.value,
  166. }
  167. this.isMore = false;
  168. this.isFlag = true;
  169. this.$api.queryPatentDigProject(params).then(res => {
  170. if (res.code == 200) {
  171. this.tableData.push(...res.data.data)
  172. this.params.total = res.data.total
  173. }
  174. }).catch(err => {
  175. })
  176. setTimeout(() => {
  177. this.isMore = false;
  178. this.isFlag = false
  179. }, 1000)
  180. },
  181. // 排序
  182. sortChange({ column, prop, order }) {
  183. this.handleSort({ column, prop, order })
  184. if (!this.row) {
  185. this.$emit('on-sort', { column, prop, order })
  186. }
  187. },
  188. // 排序方法
  189. handleSort({ column, prop, order }) {
  190. //如需要多个字段排序,则不需要清空
  191. var params = {
  192. sort:this.sort,
  193. column,
  194. prop,
  195. order,
  196. }
  197. this.sort = this.$commonJS.getSortData(params)
  198. this.params.current = 0
  199. this.disabled = false
  200. this.tableData.splice(0)
  201. this.getList()
  202. },
  203. },
  204. };
  205. </script>
  206. <style lang="scss" scoped></style>