index2.vue 7.1 KB

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