index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div>
  3. <el-dialog 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="code">
  11. <el-input size="small" v-model.trim="searchForm.code" placeholder="请输入物料编号查询" clearable></el-input>
  12. </el-form-item>
  13. <el-form-item prop="name">
  14. <el-input size="small" v-model="searchForm.name" placeholder="请输入物料名称查询" clearable></el-input>
  15. </el-form-item>
  16. <el-form-item>
  17. <el-button type="primary" @click="refreshList()" size="small" icon="el-icon-search">查询</el-button>
  18. <el-button @click="resetSearch()" size="small" icon="el-icon-refresh-right">重置</el-button>
  19. </el-form-item>
  20. </el-form>
  21. </el-header>
  22. <el-main>
  23. <el-table :data="dataList" v-loading="loading" size="small" border ref="contractTable" @row-click="rowSelect"
  24. @select="handleSelectionChange" :selection="selectedRows" @selection-change="watchSel" height="calc(100% - 40px)" style="width: 100%">
  25. <el-table-column type="selection" header-align="center" align="center" width="50">
  26. </el-table-column>
  27. <el-table-column prop="code" header-align="center" align="center" sortable="custom" min-width="90"
  28. label="物料编码">
  29. </el-table-column>
  30. <el-table-column prop="name" header-align="center" align="center" sortable="custom" min-width="90"
  31. label="物料名称">
  32. </el-table-column>
  33. </el-table>
  34. <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
  35. :current-page="searchForm.pageNo" :page-sizes="[5, 10, 15, 20]" :page-size="searchForm.pageSize"
  36. :total="total" layout="total, sizes, prev, pager, next, jumper">
  37. </el-pagination>
  38. </el-main>
  39. </el-container>
  40. </el-container>
  41. <span slot="footer">
  42. <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
  43. <el-button size="small" type="primary" icon="el-icon-circle-check" @click="doSubmit()">确定</el-button>
  44. </span>
  45. </el-dialog>
  46. </div>
  47. </template>
  48. <script>
  49. import axios from 'axios'
  50. import { getMaterialList } from '@/api/changeApply/basic'
  51. export default {
  52. data() {
  53. return {
  54. searchForm: {
  55. code: '',
  56. name: '',
  57. isSync: '',
  58. pageNo: 1,
  59. pageSize: 10,
  60. },
  61. dataListAllSelections: [], // 所有选中的数据包含跨页数据
  62. idKey: "id", // 标识列表数据中每一行的唯一键的名称(需要按自己的数据改一下)
  63. dataList: [],
  64. total: 0,
  65. orders: [],
  66. loading: false,
  67. visible: false,
  68. selectedRows:[]
  69. };
  70. },
  71. props: {
  72. selectData: {
  73. type: Array,
  74. default: () => {
  75. return [];
  76. },
  77. },
  78. // 是否启用单选
  79. single: {
  80. type: Boolean,
  81. default: true
  82. }
  83. },
  84. methods: {
  85. init(val) {
  86. this.visible = true;
  87. this.searchForm.isSync = val
  88. this.$nextTick(() => {
  89. this.dataListAllSelections = JSON.parse(JSON.stringify(this.selectData));
  90. this.resetSearch();
  91. });
  92. },
  93. // 获取数据列表
  94. refreshList() {
  95. this.loading = true;
  96. // axios({
  97. // url: "http://172.16.62.241:8000/drp-admin/system/material/list", // 自己的接口路径
  98. // method: "post",
  99. // data: {
  100. // // current: this.pageNo,
  101. // size: this.pageSize,
  102. // // orders: this.orders,
  103. // // ...this.searchForm,
  104. // },
  105. let params = {
  106. ...this.searchForm,
  107. // 默认查询已启用
  108. isEnable: '0'
  109. }
  110. getMaterialList(params).then(({ data }) => {
  111. console.log('data', data)
  112. this.dataList = data.tableBody.rows;
  113. this.total = data.tableBody.total;
  114. this.loading = false;
  115. this.$nextTick(() => {
  116. this.setSelectRow();
  117. });
  118. });
  119. },
  120. // 每页数
  121. sizeChangeHandle(val) {
  122. console.log('每页数:', val)
  123. this.searchForm.pageSize = val;
  124. this.refreshList();
  125. },
  126. // 当前页
  127. currentChangeHandle(val) {
  128. console.log('当前页:', val)
  129. this.searchForm.pageNo = val;
  130. this.refreshList();
  131. },
  132. // 排序
  133. resetSearch() {
  134. this.$refs['searchForm'].resetFields();
  135. this.searchForm.pageNo = 1;
  136. this.refreshList();
  137. },
  138. watchSel(rows) {
  139. console.log('监听得到选中吗', rows)
  140. this.dataListAllSelections = rows
  141. },
  142. // 表格选中数据
  143. rowSelect(row) {
  144. // this.$refs.contractTable.clearSelection();
  145. // this.$refs.contractTable.toggleRowSelection(row);
  146. // this.dataListAllSelections = this.single ? [row] : selection
  147. this.$refs.contractTable.toggleRowSelection(row);
  148. },
  149. // 选中数据
  150. handleSelectionChange(selection, row) {
  151. console.log('selection',selection)
  152. console.log('row',[row])
  153. if (this.single && selection.length > 1) {
  154. this.$refs.contractTable.clearSelection();
  155. this.$refs.contractTable.toggleRowSelection(row);
  156. }
  157. this.dataListAllSelections = this.single ? [row] : selection
  158. },
  159. // 设置选中的方法
  160. setSelectRow() {
  161. this.$refs.contractTable.clearSelection();
  162. if (!this.dataListAllSelections || this.dataListAllSelections.length <= 0) {
  163. return;
  164. }
  165. for (let i = 0; i < this.dataList.length; i++) {
  166. if (this.dataListAllSelections.some(item => item[this.idKey] == this.dataList[i][this.idKey])) {
  167. // 设置选中,记住table组件需要使用ref="table"
  168. this.$refs.contractTable.toggleRowSelection(this.dataList[i], true);
  169. }
  170. }
  171. },
  172. doSubmit() {
  173. this.visible = false;
  174. console.log('选择的数据?', this.dataListAllSelections)
  175. this.$emit("doSubmit", this.dataListAllSelections);
  176. },
  177. },
  178. };
  179. </script>
  180. <style lang="scss">
  181. .userDialog {
  182. .el-dialog__body {
  183. padding: 10px 0px 0px 10px;
  184. color: #606266;
  185. font-size: 14px;
  186. word-break: break-all;
  187. }
  188. .el-main {
  189. padding: 20px 20px 5px 20px;
  190. .el-pagination {
  191. margin-top: 5px;
  192. }
  193. }
  194. }
  195. </style>