ChooseMaterial.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <el-dialog
  3. title="选择物料"
  4. :visible.sync="materialdialog"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="60%"
  10. >
  11. <div>
  12. <el-row>
  13. <el-col :span="24" class="topsearch">
  14. <el-form>
  15. <el-row>
  16. <el-col :span="6">
  17. <el-input
  18. v-model.trim="searchKey"
  19. placeholder="输入设备编码或名称"
  20. size="small"
  21. ></el-input>
  22. </el-col>
  23. <el-col :span="6" style="margin-left: 10px">
  24. <el-button type="primary" size="small" @click="searchByKeyWords"
  25. >搜索</el-button
  26. >
  27. <el-button size="small" @click="reset">重置</el-button>
  28. </el-col>
  29. </el-row>
  30. </el-form>
  31. </el-col>
  32. <el-col :span="6" class="tree_col">
  33. <AssetTree
  34. @handleNodeClick="handleNodeClick"
  35. @setRootId="setRootId"
  36. id="1"
  37. ref="treeList"
  38. />
  39. </el-col>
  40. <el-col :span="18" class="table_col">
  41. <el-table
  42. :data="tableData"
  43. ref="tableRef"
  44. height="450"
  45. @row-click="single"
  46. >
  47. <el-table-column
  48. label="序号"
  49. type="index"
  50. width="55"
  51. align="center"
  52. ></el-table-column>
  53. <el-table-column
  54. label="物品编码"
  55. prop="code"
  56. width="200"
  57. ></el-table-column>
  58. <el-table-column label="物品名称" prop="name"></el-table-column>
  59. <el-table-column label="牌号" prop="brandNum"></el-table-column>
  60. <el-table-column label="选择" align="center">
  61. <template slot-scope="scope">
  62. <el-radio
  63. class="radio"
  64. v-model="selectedRow.id"
  65. :label="scope.row.id"
  66. ><i></i
  67. ></el-radio>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <div class="pagination">
  72. <el-pagination
  73. background
  74. layout="total, sizes, prev, pager, next, jumper"
  75. :total="total"
  76. :page-sizes="[5, 10, 20, 50, 100]"
  77. :page-size="pagination.size"
  78. :current-page.sync="pagination.pageNum"
  79. @current-change="handleCurrent"
  80. @size-change="handleSize"
  81. >
  82. </el-pagination>
  83. </div>
  84. </el-col>
  85. </el-row>
  86. </div>
  87. <div class="btns">
  88. <el-button type="primary" size="small" @click="selected">选择</el-button>
  89. <el-button size="small" @click="handleClose">关闭</el-button>
  90. </div>
  91. </el-dialog>
  92. </template>
  93. <script>
  94. import AssetTree from '@/components/AssetTree';
  95. import { getList } from '@/api/classifyManage/itemInformation';
  96. export default {
  97. components: {
  98. AssetTree
  99. },
  100. data () {
  101. return {
  102. materialdialog: false,
  103. tableData: [],
  104. pagination: {
  105. pageNum: 1,
  106. size: 10
  107. },
  108. total: 0,
  109. searchKey: null,
  110. current: null,
  111. rootId: null,
  112. selectedRow: {},
  113. radio: '',
  114. memoId: ''
  115. };
  116. },
  117. methods: {
  118. open (categoryId) {
  119. this.memoId = categoryId;
  120. this.materialdialog = true;
  121. if (this.current?.id) {
  122. this._getList();
  123. }
  124. },
  125. handleNodeClick (info) {
  126. this.current = info;
  127. this._getList();
  128. },
  129. // 获取根节点id
  130. setRootId (id) {
  131. this.rootId = id;
  132. },
  133. handleClose () {
  134. this.materialdialog = false;
  135. this.selectedRow = {};
  136. this.searchKey = '';
  137. },
  138. handleCurrent (page) {
  139. this.pagination.pageNum = page;
  140. this._getList();
  141. },
  142. handleSize (size) {
  143. this.pagination.pageNum = 1;
  144. this.pagination.size = size;
  145. this._getList();
  146. },
  147. async _getList () {
  148. const res = await getList({
  149. ...this.pagination,
  150. searchKey: this.searchKey,
  151. categoryLevelId: this.current.id
  152. });
  153. this.total = res.count;
  154. this.tableData = res.list;
  155. if (!this.current.id) {
  156. this.$nextTick(() => {
  157. this.$refs.tableRef.setCurrentRow(
  158. this.tableData.find((i) => i.id == this.memoId)
  159. );
  160. });
  161. }
  162. },
  163. // 弹窗 - 按关键字搜索
  164. searchByKeyWords () {
  165. this.pagination.pageNum = 1;
  166. this._getList();
  167. },
  168. // 重置
  169. reset () {
  170. this.searchKey = '';
  171. this.pagination.pageNum = 1;
  172. this._getList();
  173. },
  174. // 单击获取id
  175. single (row) {
  176. this.selectedRow = row;
  177. },
  178. selected () {
  179. if (!this.selectedRow.id) {
  180. return this.$message.error('请选择物料!');
  181. }
  182. this.$emit('success', this.selectedRow);
  183. this.handleClose();
  184. }
  185. }
  186. };
  187. </script>
  188. <style lang="scss" scoped>
  189. .tree_col {
  190. border: 1px solid #eee;
  191. padding: 10px 0;
  192. box-sizing: border-box;
  193. height: 500px;
  194. overflow: auto;
  195. }
  196. .table_col {
  197. padding-left: 10px;
  198. ::v-deep .el-table th.el-table__cell {
  199. background: #f2f2f2;
  200. }
  201. }
  202. .pagination {
  203. text-align: right;
  204. padding: 10px 0;
  205. }
  206. .btns {
  207. text-align: center;
  208. padding: 10px 0;
  209. }
  210. .topsearch {
  211. margin-bottom: 15px;
  212. }
  213. </style>