AddDialog.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <el-dialog
  3. :title="dialogTitle"
  4. :visible.sync="equipmentdialog"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="65%"
  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="searchForm.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. <!-- <vTreeList
  34. @handleNodeClick="handleNodeClick"
  35. ref="commonTree"
  36. :defaultExpandAll="false"
  37. :defaultExpandedKeys="defaultExpandedKeys"
  38. :type="typeValue"
  39. /> -->
  40. <AssetTree
  41. :props="defaultProps"
  42. :default-expanded-keys="defaultExpandedKeys"
  43. :expand-on-click-node="false"
  44. node-key="id"
  45. paramsType="type"
  46. :type="typeValue"
  47. :init="false"
  48. ref="tree"
  49. :highlight-current="true"
  50. @handleNodeClick="handleNodeClick"
  51. />
  52. </el-col>
  53. <el-col :span="18" class="table_col">
  54. <el-table
  55. :data="tableData"
  56. height="450"
  57. highlight-current-row
  58. @selection-change="handleSelectionChange"
  59. :row-key="getRowKeys"
  60. ref="tableRef"
  61. >
  62. <el-table-column
  63. type="selection"
  64. width="60"
  65. align="center"
  66. :reserve-selection="true"
  67. ></el-table-column>
  68. <el-table-column
  69. label="物品编码"
  70. prop="informationCode"
  71. width="130"
  72. ></el-table-column>
  73. <el-table-column
  74. label="物品名称"
  75. prop="informationName"
  76. ></el-table-column>
  77. <el-table-column
  78. label="牌号"
  79. prop="brandNum"
  80. v-if="dialogTitle != '选择设备' && dialogTitle != '选择备品备件'"
  81. ></el-table-column>
  82. <el-table-column
  83. label="型号"
  84. prop="modelType"
  85. v-if="dialogTitle != '选择物料'"
  86. ></el-table-column>
  87. <el-table-column
  88. label="收缩系数"
  89. prop="shrinkageCoefficient"
  90. v-if="dialogTitle == '选择模具'"
  91. >
  92. <template slot-scope="scope">
  93. <span>
  94. {{ JSON.parse(scope.row.extendField).shrinkageCoefficient }}
  95. </span>
  96. </template>
  97. </el-table-column>
  98. <el-table-column
  99. label="大模体型号"
  100. prop="dieBodyModel"
  101. v-if="dialogTitle == '选择模具'"
  102. width="120"
  103. >
  104. <template slot-scope="scope">
  105. <span>
  106. {{ JSON.parse(scope.row.extendField).dieBodyModel }}
  107. </span>
  108. </template>
  109. </el-table-column>
  110. </el-table>
  111. <div class="pagination">
  112. <el-pagination
  113. background
  114. layout="total, sizes, prev, pager, next, jumper"
  115. :total="pagination.total"
  116. :page-sizes="[15, 30, 50, 100, 500]"
  117. :page-size="pagination.size"
  118. :current-page.sync="pagination.page"
  119. @current-change="handleCurrent"
  120. @size-change="handleSize"
  121. >
  122. </el-pagination>
  123. </div>
  124. </el-col>
  125. </el-row>
  126. </div>
  127. <div class="btns">
  128. <el-button type="primary" size="small" @click="selected">选择</el-button>
  129. <el-button size="small" @click="handleClose">关闭</el-button>
  130. </div>
  131. </el-dialog>
  132. </template>
  133. <script>
  134. import AssetTree from '@/components/AssetTree';
  135. import { getList } from '@/api/classifyManage/itemInformation';
  136. export default {
  137. components: { AssetTree },
  138. props: {
  139. typeValue: {
  140. type: String,
  141. default: ''
  142. },
  143. mapList: {
  144. type: Array,
  145. default: []
  146. },
  147. dialogTitle: {
  148. type: String,
  149. default: ''
  150. }
  151. },
  152. data () {
  153. return {
  154. treeLoading: false,
  155. equipmentdialog: false,
  156. defaultExpandedKeys: [],
  157. tableData: [],
  158. currentTreeData: {},
  159. pagination: {
  160. page: 1,
  161. size: 10,
  162. total: 0
  163. },
  164. searchForm: {},
  165. defaultProps: {
  166. children: 'children',
  167. value: 'code',
  168. label: 'name'
  169. },
  170. currentKey: null,
  171. tableSelectionList: []
  172. };
  173. },
  174. watch: {
  175. equipmentdialog (val) {
  176. if (val) {
  177. this.$nextTick(() => {
  178. this.$refs.tree.getTreeData().then(() => {
  179. if (this.tableData.length) this.$refs.tableRef.clearSelection();
  180. this.$nextTick(() => {
  181. this.mapList.forEach((item) => {
  182. const row = this.tableData.find((i) => i.id === item.id);
  183. if (row) {
  184. this.$refs.tableRef.toggleRowSelection(row, true);
  185. }
  186. });
  187. });
  188. });
  189. });
  190. // if(this.tableData.length) this.$refs.tableRef.clearSelection()
  191. }
  192. },
  193. typeValue (val) {
  194. if (val) {
  195. this.currentKey = null;
  196. }
  197. }
  198. },
  199. methods: {
  200. handleClose () {
  201. this.equipmentdialog = false;
  202. this.tableSelectionList = [];
  203. },
  204. handleCurrent (page) {
  205. this.pagination.page = page;
  206. this.handleList();
  207. },
  208. handleSize (size) {
  209. this.pagination.page = 1;
  210. this.pagination.size = size;
  211. this.handleList();
  212. },
  213. handleSelectionChange (val) {
  214. this.tableSelectionList = val;
  215. },
  216. // handleCurSelectionChange (selection, row) {
  217. // },
  218. toDelete (val) {
  219. console.log('触发删除', val);
  220. },
  221. getRowKeys (row) {
  222. return row.id;
  223. },
  224. // 确定
  225. selected () {
  226. this.$emit('submit', this.tableSelectionList);
  227. this.handleClose();
  228. },
  229. // 树点击事件
  230. handleNodeClick (data, node) {
  231. if (data.id === this.currentTreeData.id) return;
  232. this.currentTreeData = data;
  233. this.searchForm.classificationId = data.id;
  234. this.handleList();
  235. },
  236. async handleList () {
  237. const params = {
  238. ...this.searchForm,
  239. ...this.pagination
  240. };
  241. const res = await getList(params);
  242. if (res?.success) {
  243. this.tableData = res.data.records;
  244. this.pagination.total = res.data.total;
  245. if (this.tableData.length) this.$refs.tableRef.clearSelection();
  246. this.$nextTick(() => {
  247. this.mapList.forEach((item) => {
  248. const row = this.tableData.find((i) => i.id === item.id);
  249. if (row) {
  250. this.$refs.tableRef.toggleRowSelection(row, true);
  251. }
  252. });
  253. });
  254. }
  255. },
  256. // 弹窗 - 按关键字搜索
  257. searchByKeyWords () {
  258. if (!this.currentTreeData) {
  259. this.$message.warning('请先选择设备!');
  260. return;
  261. }
  262. this.pagination.page = 1;
  263. this.handleList();
  264. },
  265. // 重置
  266. reset () {
  267. this.pagination.page = 1;
  268. this.searchForm.searchKey = '';
  269. this.handleList();
  270. },
  271. // 设置默认高亮行
  272. setCurrentKey (id) {
  273. this.currentKey = id;
  274. this.$refs.tree.setCurrentKey(this.currentKey);
  275. }
  276. }
  277. };
  278. </script>
  279. <style lang="scss" scoped>
  280. .tree_col {
  281. border: 1px solid #eee;
  282. padding: 10px 0;
  283. box-sizing: border-box;
  284. height: 500px;
  285. overflow: auto;
  286. }
  287. .table_col {
  288. padding-left: 10px;
  289. :deep(.el-table th.el-table__cell) {
  290. background: #f2f2f2;
  291. }
  292. }
  293. .pagination {
  294. text-align: right;
  295. padding: 10px 0;
  296. }
  297. .btns {
  298. text-align: center;
  299. padding: 10px 0;
  300. }
  301. .topsearch {
  302. margin-bottom: 15px;
  303. }
  304. </style>