batchRefer.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div>
  3. <el-dialog :title="reciveForm.title" width="1000px" :close-on-click-modal="false" :append-to-body="true" v-dialogDrag
  4. class="userDialog" :visible.sync="visible">
  5. <el-container style="height: 500px">
  6. <el-container>
  7. <el-header style="text-align: left; font-size: 12px; height: 30px">
  8. <el-form size="small" :inline="true" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()"
  9. @submit.native.prevent>
  10. <el-form-item prop="param" label="名称/编号">
  11. <el-input size="small" v-model="searchForm.search" placeholder="输入名称/编号查询" clearable></el-input>
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" @click="refreshList()" size="small" icon="el-icon-search">查询</el-button>
  15. <el-button @click="resetSearch()" size="small" icon="el-icon-refresh-right">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. </el-header>
  19. <el-main>
  20. <el-table :data="dataList" v-loading="loading" size="small" border ref="contractTable"
  21. @select="handleSelectionChange" @row-click="rowSelect" height="calc(100% - 40px)" style="width: 100%">
  22. <el-table-column type="selection" header-align="center" align="center" width="50">
  23. </el-table-column>
  24. <el-table-column prop="id" header-align="center" align="center" sortable="custom" min-width="90" label="id">
  25. </el-table-column>
  26. <el-table-column prop="name" header-align="center" align="center" sortable="custom" min-width="90"
  27. label="名称">
  28. </el-table-column>
  29. </el-table>
  30. <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
  31. :current-page="searchForm.pageNo" :page-sizes="[5, 10, 15, 20]" :page-size="searchForm.pageSize"
  32. :total="total" layout="total, sizes, prev, pager, next, jumper">
  33. </el-pagination>
  34. </el-main>
  35. </el-container>
  36. </el-container>
  37. <span slot="footer">
  38. <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
  39. <el-button size="small" type="primary" icon="el-icon-circle-check" @click="doSubmit()">确定</el-button>
  40. </span>
  41. </el-dialog>
  42. </div>
  43. </template>
  44. <script>
  45. import { getBatchRefer } from '@/api/purchase/basic'
  46. export default {
  47. data() {
  48. return {
  49. searchForm: {
  50. search: '',
  51. pageNo: 1,
  52. pageSize: 10,
  53. },
  54. reciveForm: {},
  55. dataListAllSelections: [], // 所有选中的数据包含跨页数据
  56. idKey: "id", // 标识列表数据中每一行的唯一键的名称(需要按自己的数据改一下)
  57. dataList: [],
  58. total: 0,
  59. orders: [],
  60. loading: false,
  61. visible: false,
  62. };
  63. },
  64. props: {
  65. selectData: {
  66. type: Array,
  67. default: () => {
  68. return [];
  69. },
  70. },
  71. // 是否启用单选
  72. single: {
  73. type: Boolean,
  74. default: false
  75. }
  76. },
  77. methods: {
  78. init(val) {
  79. this.visible = true;
  80. console.log("🚀 ~ file: refers.vue:79 ~ init ~ init(val):", val)
  81. this.reciveForm = val
  82. this.searchForm.search = ''
  83. this.$nextTick(() => {
  84. this.dataListAllSelections = JSON.parse(JSON.stringify(this.selectData));
  85. this.resetSearch();
  86. });
  87. },
  88. // 获取数据列表
  89. refreshList() {
  90. this.loading = true;
  91. let params = { ...this.searchForm, ...this.reciveForm }
  92. getBatchRefer(params).then(res => {
  93. console.log('res', res)
  94. this.dataList = res.rows;
  95. this.total = res.total
  96. this.loading = false;
  97. this.$nextTick(() => {
  98. this.setSelectRow();
  99. });
  100. });
  101. },
  102. // 每页数
  103. sizeChangeHandle(val) {
  104. this.searchForm.pageSize = val;
  105. this.refreshList();
  106. },
  107. // 当前页
  108. currentChangeHandle(val) {
  109. this.searchForm.pageNo = val;
  110. this.refreshList();
  111. },
  112. // 排序
  113. resetSearch() {
  114. this.searchForm.pageNo = 1
  115. this.searchForm.search = ''
  116. this.refreshList();
  117. },
  118. // 表格选中数据
  119. rowSelect(row, column, event) {
  120. this.$refs.contractTable.clearSelection();
  121. this.$refs.contractTable.toggleRowSelection(row);
  122. this.dataListAllSelections = this.single ? [row] : selection
  123. },
  124. // 选中数据
  125. handleSelectionChange(selection, row) {
  126. if (this.single && selection.length > 1) {
  127. this.$refs.contractTable.clearSelection();
  128. this.$refs.contractTable.toggleRowSelection(row);
  129. }
  130. this.dataListAllSelections = this.single ? [row] : selection
  131. },
  132. // 设置选中的方法
  133. setSelectRow() {
  134. this.$refs.contractTable.clearSelection();
  135. if (!this.dataListAllSelections || this.dataListAllSelections.length <= 0) {
  136. return;
  137. }
  138. for (let i = 0; i < this.dataList.length; i++) {
  139. if (this.dataListAllSelections.some(item => item[this.idKey] == this.dataList[i][this.idKey])) {
  140. // 设置选中,记住table组件需要使用ref="table"
  141. this.$refs.contractTable.toggleRowSelection(this.dataList[i], true);
  142. }
  143. }
  144. },
  145. doSubmit() {
  146. this.visible = false;
  147. console.log('选择的数据?', this.dataListAllSelections)
  148. this.$emit("doSubmit", this.dataListAllSelections);
  149. },
  150. },
  151. };
  152. </script>
  153. <style lang="scss">
  154. .userDialog {
  155. .el-dialog__body {
  156. padding: 10px 0px 0px 10px;
  157. color: #606266;
  158. font-size: 14px;
  159. word-break: break-all;
  160. }
  161. .el-main {
  162. padding: 20px 20px 5px 20px;
  163. .el-pagination {
  164. margin-top: 5px;
  165. }
  166. }
  167. }
  168. </style>