categoryDialog.vue 5.4 KB

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