index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <el-dialog
  3. title="添加备品备件"
  4. :visible.sync="dialogVisible"
  5. width="70%"
  6. :before-close="handleClose"
  7. append-to-body
  8. >
  9. <div class="search_wrapper">
  10. <el-input
  11. size="small"
  12. v-model="searchParams.code"
  13. class="search_input"
  14. placeholder="请输入编码"
  15. ></el-input>
  16. <el-button type="primary" size="small" @click="doSearch">搜索</el-button>
  17. </div>
  18. <el-row style="height: 80vh">
  19. <el-col class="tree-col" :span="6">
  20. <div class="table-add" style="margin-left: 10px"></div>
  21. <AssetTree
  22. @handleNodeClick="handleNodeClick"
  23. @setRootId="setRootId"
  24. :type="'7'"
  25. :paramsType="'type'"
  26. ref="treeList"
  27. id="6"
  28. />
  29. </el-col>
  30. <el-col :span="18">
  31. <el-table
  32. ref="dialogMultipleTable"
  33. :data="tableData"
  34. tooltip-effect="dark"
  35. v-loading="tableLoading"
  36. style="width: 100%; overflow: auto"
  37. height="80vh"
  38. border
  39. @select="pickSpareData"
  40. @select-all="pickSpareData"
  41. :header-cell-style="{ background: '#F0F3F3' }"
  42. >
  43. <el-table-column
  44. type="selection"
  45. label="操作"
  46. width="55"
  47. align="center"
  48. />
  49. <el-table-column prop="code" label="备件类别编码" />
  50. <el-table-column prop="name" label="备件类别名称" />
  51. <el-table-column label="型号" prop="modelType"> </el-table-column>
  52. </el-table>
  53. </el-col>
  54. </el-row>
  55. <div slot="footer" class="dialog-footer">
  56. <el-button size="small" @click="submit" type="primary">提 交</el-button>
  57. <el-button size="small" @click="handleClose">关 闭</el-button>
  58. </div>
  59. </el-dialog>
  60. </template>
  61. <script>
  62. import AssetTree from '@/components/AssetTree';
  63. // import { getCategoryList } from '@/api/ledgerAssets';
  64. import { getList } from '@/api/classifyManage/itemInformation';
  65. export default {
  66. components: {
  67. // CommonTree,
  68. AssetTree
  69. },
  70. props: {
  71. selectedSpare: {
  72. type: Array,
  73. default: () => []
  74. }
  75. },
  76. data() {
  77. return {
  78. dialogVisible: false,
  79. searchParams: {
  80. code: '',
  81. page: 1,
  82. size: 99999
  83. },
  84. tableLoading: false,
  85. tableData: [],
  86. currentTreeData: {},
  87. pickSpareDataObject: [],
  88. rootId: null
  89. };
  90. },
  91. watch: {
  92. selectedSpare(val) {
  93. val.map((item) => {
  94. this.tableData.forEach((c) => {
  95. if (item.id === c.id) {
  96. this.$refs.dialogMultipleTable.toggleRowSelection(c, true);
  97. }
  98. });
  99. });
  100. }
  101. },
  102. methods: {
  103. open() {
  104. this.pickSpareDataObject = [];
  105. this.dialogVisible = true;
  106. this.$nextTick(() => {
  107. this.selectedSpare.map((item) => {
  108. this.tableData.forEach((c) => {
  109. if (item.id === c.id) {
  110. this.$refs.dialogMultipleTable.toggleRowSelection(c, true);
  111. }
  112. });
  113. });
  114. });
  115. },
  116. async doSearch() {
  117. const params = {
  118. categoryLevelId: this.currentTreeData.id,
  119. rootCategoryLevelId: this.rootId,
  120. code: this.searchParams.code
  121. };
  122. this._getClassificationSpareList(params);
  123. },
  124. // 获取根节点id
  125. setRootId(id) {
  126. this.rootId = id;
  127. },
  128. // 树结构点击事件
  129. async handleNodeClick(data, node) {
  130. this.currentTreeData = data;
  131. this._getClassificationSpareList(data);
  132. },
  133. // setDefaultList(id){
  134. // let data = {id:id}
  135. // this._getClassificationSpareList(data)
  136. // },
  137. // 获取添加备件弹窗表格数据
  138. async _getClassificationSpareList(data) {
  139. console.log(1);
  140. this.tableLoading = true;
  141. let params = {
  142. page: 1,
  143. size: 10,
  144. categoryLevelId: this.currentTreeData.id
  145. };
  146. const res = await getList(params);
  147. console.log('res', res);
  148. this.tableLoading = false;
  149. if (res.list.length) {
  150. this.tableData = res.list;
  151. // 切换树节点时回显添加了的备品备件
  152. this.$nextTick(() => {
  153. this.selectedSpare.map((item) => {
  154. this.tableData.forEach((c) => {
  155. if (item.id === c.id) {
  156. this.$refs.dialogMultipleTable.toggleRowSelection(c, true);
  157. }
  158. });
  159. });
  160. });
  161. } else {
  162. this.tableData = [];
  163. }
  164. },
  165. // 备件单选框选择时事件
  166. pickSpareData(data) {
  167. this.pickSpareDataObject = data;
  168. },
  169. // 关闭弹窗
  170. handleClose() {
  171. this.$nextTick(() => {
  172. this.$refs.dialogMultipleTable.clearSelection();
  173. this.dialogVisible = false;
  174. });
  175. },
  176. async submit() {
  177. this.$emit('submit', this.pickSpareDataObject);
  178. this.handleClose();
  179. // this.form.exportList = this.pickSpareDataObject
  180. // this.$forceUpdate()
  181. }
  182. }
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. .tree-col {
  187. border: 1px solid #e6ebf5;
  188. margin-right: 10px;
  189. width: 20%;
  190. padding: 0 !important;
  191. height: 100%;
  192. overflow: auto;
  193. }
  194. .search_wrapper {
  195. margin-bottom: 10px;
  196. .search_input {
  197. width: 200px;
  198. margin-right: 10px;
  199. }
  200. }
  201. </style>