DialogMoveTo.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="dialog-moveto">
  3. <el-dialog
  4. :title="title"
  5. :visible.sync="dialogVisible"
  6. width="30%"
  7. :before-close="handleClose"
  8. :fullscreen="fullscreen"
  9. class="fullscreen"
  10. >
  11. <template slot="title">
  12. <modalTitle
  13. :title="title"
  14. @setFullscreen="fullscreen = !fullscreen"
  15. ></modalTitle>
  16. </template>
  17. <div class="form">
  18. <el-form
  19. label-width="120px"
  20. :rules="rules"
  21. :model="addForm"
  22. ref="form"
  23. class="ele-form-search"
  24. >
  25. <el-form-item
  26. v-if="componentsType == 'move'"
  27. label="设备分类"
  28. label-width="100px"
  29. prop="id"
  30. >
  31. <el-select v-model="addForm.id" placeholder="请选择">
  32. <el-option
  33. v-for="item in list"
  34. :label="item.name"
  35. :value="item.id"
  36. :key="item.id"
  37. >
  38. </el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item
  42. v-if="componentsType == 'person'"
  43. label="片区负责人部门"
  44. prop="areaPersonInChargeGroupId"
  45. >
  46. <DeptSelect v-model="addForm.areaPersonInChargeGroupId" @input="getwhbm" />
  47. </el-form-item>
  48. <el-form-item v-if="componentsType == 'person'" label="片区负责人">
  49. <el-select v-model="addForm.areaPersonInChargeUserId" placeholder="请选择" filterable>
  50. <el-option
  51. v-for="item in personList"
  52. :key="item.id"
  53. :label="item.name"
  54. :value="item.id"
  55. @click.native="personChange(item)"
  56. >
  57. </el-option>
  58. </el-select>
  59. </el-form-item>
  60. </el-form>
  61. </div>
  62. <span slot="footer" class="dialog-footer">
  63. <el-button @click="handleClose">取 消</el-button>
  64. <el-button type="primary" @click="submit" :loading="loading"
  65. >确 定</el-button
  66. >
  67. </span>
  68. </el-dialog>
  69. </div>
  70. </template>
  71. <script>
  72. import modalTitle from '@/components/modalTitle.vue';
  73. import {
  74. changeSubstanceCateId,
  75. updateRepairUserAndGroup
  76. } from '@/api/ledgerAssets';
  77. import { getTreeByPid } from '@/api/classifyManage';
  78. import DeptSelect from '@/components/CommomSelect/dept-select.vue';
  79. import { getUserPage } from '@/api/system/organization';
  80. export default {
  81. components: { DeptSelect, modalTitle },
  82. data() {
  83. return {
  84. fullscreen: false,
  85. componentsType: '',
  86. dialogVisible: false,
  87. addForm: {
  88. areaPersonInChargePhone:'',
  89. areaPersonInChargeUserId:'',
  90. areaPersonInChargeGroupId:'',
  91. },
  92. loading: false,
  93. checkoutArr: [],
  94. rules: {
  95. id: [{ required: true, message: '请选择设备分类', trigger: 'blur' }],
  96. areaPersonInChargeGroupId: [
  97. { required: true, message: '请选择片区负责人部门', trigger: 'blur' }
  98. ]
  99. },
  100. list: [],
  101. title: '',
  102. personList: []
  103. };
  104. },
  105. methods: {
  106. async getwhbm() {
  107. if (!this.addForm.areaPersonInChargeGroupId) return;
  108. this.$set(this.addForm,'areaPersonInChargePhone','')
  109. this.$set(this.addForm,'areaPersonInChargeUserId','')
  110. let data = await getUserPage({
  111. pageNum: 1,
  112. size: 9999,
  113. groupId: this.addForm.areaPersonInChargeGroupId
  114. });
  115. this.personList = data.list;
  116. },
  117. personChange(item) {
  118. this.addForm.areaPersonInChargePhone=item.phone
  119. console.log(item);
  120. },
  121. submit() {
  122. this.$refs.form.validate(async (flag) => {
  123. if (flag) {
  124. try {
  125. this.loading = true;
  126. if (this.componentsType == 'move') {
  127. const paramsArr = this.checkoutArr.map((item) => {
  128. return { categoryLevelId: this.addForm.id, id: item.id };
  129. });
  130. console.log(paramsArr);
  131. await changeSubstanceCateId(paramsArr);
  132. } else {
  133. const listId = this.checkoutArr.map((item) => {
  134. return item.id;
  135. });
  136. const newObj = {
  137. ...this.addForm,
  138. id: listId
  139. };
  140. console.log(newObj);
  141. await updateRepairUserAndGroup(newObj);
  142. }
  143. this.$message.success('成功!');
  144. this.dialogVisible = false;
  145. this.$emit('success', true);
  146. } finally {
  147. this.loading = false;
  148. }
  149. } else {
  150. return false;
  151. }
  152. });
  153. },
  154. open(arr, current, type) {
  155. this.addForm = {};
  156. this.dialogVisible = true;
  157. this.componentsType = type;
  158. this.checkoutArr = arr;
  159. if (type === 'move') {
  160. this.getTreeData(current);
  161. this.title = '移动到';
  162. } else {
  163. this.title = '批量设置片区负责人';
  164. }
  165. },
  166. async getTreeData(current) {
  167. const res = await getTreeByPid(4);
  168. if (res.code == 0) {
  169. this.list = [];
  170. console.log(current);
  171. console.log('==res.data', res.data);
  172. res.data.forEach((e) => {
  173. if (e.id == current.parentId) {
  174. e.children.forEach((item) => {
  175. if (item.id == current.preParentId) {
  176. this.list = item.children;
  177. }
  178. });
  179. }
  180. });
  181. }
  182. },
  183. handleClose() {
  184. this.dialogVisible = false;
  185. }
  186. }
  187. };
  188. </script>