DialogMoveTo.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div class="dialog-moveto">
  3. <el-dialog
  4. title="移动到"
  5. :visible.sync="dialogVisible"
  6. width="30%"
  7. :before-close="handleClose"
  8. >
  9. <div class="form">
  10. <el-form
  11. label-width="77px"
  12. :rules="rules"
  13. :model="addForm"
  14. ref="form"
  15. class="ele-form-search"
  16. >
  17. <el-form-item label="设备分类" label-width="100px" prop="id">
  18. <template>
  19. <el-select v-model="addForm.id" placeholder="请选择">
  20. <el-option
  21. v-for="item in list"
  22. :label="item.name"
  23. :value="item.id"
  24. :key="item.id"
  25. >
  26. </el-option>
  27. </el-select>
  28. </template>
  29. </el-form-item>
  30. </el-form>
  31. </div>
  32. <span slot="footer" class="dialog-footer">
  33. <el-button @click="handleClose">取 消</el-button>
  34. <el-button type="primary" @click="submit" :loading="loading"
  35. >确 定</el-button
  36. >
  37. </span>
  38. </el-dialog>
  39. </div>
  40. </template>
  41. <script>
  42. import { changeSubstanceCateId } from '@/api/ledgerAssets';
  43. import { getTreeByPid } from '@/api/classifyManage';
  44. export default {
  45. data() {
  46. return {
  47. dialogVisible: false,
  48. addForm: {},
  49. loading: false,
  50. checkoutArr: [],
  51. rules: {
  52. id: [{ required: true, message: '请选择设备分类', trigger: 'blur' }]
  53. },
  54. list: []
  55. };
  56. },
  57. methods: {
  58. submit() {
  59. this.$refs.form.validate(async (flag) => {
  60. if (flag) {
  61. try {
  62. this.loading = true;
  63. const paramsArr = this.checkoutArr.map((item) => {
  64. return { categoryLevelId: this.addForm.id, id: item.id };
  65. });
  66. console.log(paramsArr);
  67. const res = await changeSubstanceCateId(paramsArr);
  68. this.$message.success('成功!');
  69. this.dialogVisible = false;
  70. this.$emit('success');
  71. } finally {
  72. this.loading = false;
  73. }
  74. } else {
  75. return false;
  76. }
  77. });
  78. },
  79. open(arr, current) {
  80. this.addForm = {};
  81. this.dialogVisible = true;
  82. this.checkoutArr = arr;
  83. this.getTreeData(current);
  84. },
  85. async getTreeData(current) {
  86. const res = await getTreeByPid(4);
  87. if (res.code == 0) {
  88. this.list = [];
  89. console.log(current);
  90. console.log('==res.data', res.data);
  91. res.data.forEach((e) => {
  92. if (e.id == current.parentId) {
  93. e.children.forEach((item) => {
  94. if (item.id == current.preParentId) {
  95. this.list = item.children;
  96. }
  97. });
  98. }
  99. });
  100. }
  101. },
  102. handleClose() {
  103. this.dialogVisible = false;
  104. }
  105. }
  106. };
  107. </script>