Ver código fonte

完善设置片区负责人功能

huang_an 2 anos atrás
pai
commit
393d42899a

+ 11 - 1
src/api/ledgerAssets/index.js

@@ -1,4 +1,5 @@
 import request from '@/utils/request';
+import httpBlob from '@/utils/httpBlob';
 import { download } from '@/utils/file';
 
 // 获取类别实体分页
@@ -68,7 +69,7 @@ export async function getCount(data) {
 
 // 导出实体
 export async function downloadAsset(params, fileName) {
-  const res = await request.post('/main/asset/page/export', params, {
+  const res = await httpBlob.post('/main/asset/page/export', params, {
     responseType: 'blob'
   });
   download(res.data, fileName);
@@ -100,3 +101,12 @@ export async function changeSubstanceCateId(data) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+//设置片区负责人
+export async function updateRepairUserAndGroup(data) {
+  const res = await request.post(`/main/asset/updateRepairUserAndGroup`, data);
+  if (res.data.code == 0) {
+    return res.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 90 - 0
src/utils/httpBlob.js

@@ -0,0 +1,90 @@
+/**
+ * axios 实例
+ */
+import axios from 'axios';
+import router from '@/router';
+import { MessageBox, Message } from 'element-ui';
+import { API_BASE_URL, TOKEN_HEADER_NAME, LAYOUT_PATH } from '@/config/setting';
+import { getToken, setToken } from './token-util';
+import { logout } from './page-tab-util';
+import JSONBIG from 'json-bigint';
+
+const service = axios.create({
+  baseURL: API_BASE_URL,
+  transformResponse: [
+    function (data) {
+      const json = JSONBIG({
+        storeAsString: true
+      });
+      const res = json.parse(data);
+      return res;
+    }
+  ]
+});
+
+/**
+ * 添加请求拦截器
+ */
+service.interceptors.request.use(
+  (config) => {
+    // 添加 token 到 header
+    const token = getToken();
+    if (token && config.headers) {
+      config.headers.common[TOKEN_HEADER_NAME] = token;
+    }
+    return config;
+  },
+  (error) => {
+    return Promise.reject(error);
+  }
+);
+
+/**
+ * 添加响应拦截器
+ */
+// 添加响应拦截器
+// 添加响应拦截器
+// 添加响应拦截器
+service.interceptors.response.use(
+  (response) => {
+    // token 自动续期
+    if (
+      response.data.code === '-1' &&
+      response.config?.showErrorToast !== false
+    ) {
+      Message.error(response.data.message);
+    }
+
+    // Check if the response content type is 'blob'
+    const isBlob =
+      response.headers['content-type'] &&
+      response.headers['content-type'].toLowerCase().includes('blob');
+
+    // Return the original response for blob data
+    if (isBlob) {
+      return response;
+    }
+
+    // Parse the JSON data for non-blob responses
+    try {
+      const token = response.headers[TOKEN_HEADER_NAME.toLowerCase()];
+      if (token) {
+        setToken(token);
+      }
+
+      // Parse JSON data
+      const json = JSONBIG({
+        storeAsString: true
+      });
+      const data = json.parse(response.data);
+
+      return data;
+    } catch (error) {
+      console.error('JSON parsing error:', error);
+      return Promise.reject(error);
+    }
+  }
+  // ...
+);
+
+export default service;

+ 85 - 25
src/views/ledgerAssets/equipment/components/DialogMoveTo.vue

@@ -1,31 +1,52 @@
 <template>
   <div class="dialog-moveto">
     <el-dialog
-      title="移动到"
+      :title="title"
       :visible.sync="dialogVisible"
       width="30%"
       :before-close="handleClose"
     >
       <div class="form">
         <el-form
-          label-width="77px"
+          label-width="120px"
           :rules="rules"
           :model="addForm"
           ref="form"
           class="ele-form-search"
         >
-          <el-form-item label="设备分类" label-width="100px" prop="id">
-            <template>
-              <el-select v-model="addForm.id" placeholder="请选择">
-                <el-option
-                  v-for="item in list"
-                  :label="item.name"
-                  :value="item.id"
-                  :key="item.id"
-                >
-                </el-option>
-              </el-select>
-            </template>
+          <el-form-item
+            v-if="componentsType == 'move'"
+            label="设备分类"
+            label-width="100px"
+            prop="id"
+          >
+            <el-select v-model="addForm.id" placeholder="请选择">
+              <el-option
+                v-for="item in list"
+                :label="item.name"
+                :value="item.id"
+                :key="item.id"
+              >
+              </el-option>
+            </el-select>
+          </el-form-item>
+          <el-form-item
+            v-if="componentsType == 'person'"
+            label="片区负责人部门"
+            prop="repairGroupId"
+          >
+            <DeptSelect v-model="addForm.repairGroupId" @input="getwhbm" />
+          </el-form-item>
+          <el-form-item v-if="componentsType == 'person'" label="片区负责人">
+            <el-select v-model="addForm.repairUserId" placeholder="请选择">
+              <el-option
+                v-for="item in personList"
+                :key="item.id"
+                :label="item.name"
+                :value="item.id"
+              >
+              </el-option>
+            </el-select>
           </el-form-item>
         </el-form>
       </div>
@@ -39,35 +60,68 @@
   </div>
 </template>
 <script>
-  import { changeSubstanceCateId } from '@/api/ledgerAssets';
+  import {
+    changeSubstanceCateId,
+    updateRepairUserAndGroup
+  } from '@/api/ledgerAssets';
   import { getTreeByPid } from '@/api/classifyManage';
+  import DeptSelect from '@/components/CommomSelect/dept-select.vue';
+  import { getUserPage } from '@/api/system/organization';
   export default {
+    components: { DeptSelect },
     data() {
       return {
+        componentsType: '',
         dialogVisible: false,
         addForm: {},
         loading: false,
         checkoutArr: [],
         rules: {
-          id: [{ required: true, message: '请选择设备分类', trigger: 'blur' }]
+          id: [{ required: true, message: '请选择设备分类', trigger: 'blur' }],
+          repairGroupId: [
+            { required: true, message: '请选择片区负责人部门', trigger: 'blur' }
+          ]
         },
-        list: []
+        list: [],
+        title: '',
+        personList: []
       };
     },
     methods: {
+      async getwhbm() {
+        if (!this.addForm.repairGroupId) return;
+        let data = await getUserPage({
+          pageNum: 1,
+          size: 9999,
+          groupId: this.addForm.repairGroupId
+        });
+        this.personList = data.list;
+      },
       submit() {
         this.$refs.form.validate(async (flag) => {
           if (flag) {
             try {
               this.loading = true;
-              const paramsArr = this.checkoutArr.map((item) => {
-                return { categoryLevelId: this.addForm.id, id: item.id };
-              });
-              console.log(paramsArr);
-              const res = await changeSubstanceCateId(paramsArr);
+              if (this.componentsType == 'move') {
+                const paramsArr = this.checkoutArr.map((item) => {
+                  return { categoryLevelId: this.addForm.id, id: item.id };
+                });
+                console.log(paramsArr);
+                await changeSubstanceCateId(paramsArr);
+              } else {
+                const listId = this.checkoutArr.map((item) => {
+                  return item.id;
+                });
+                const newObj = {
+                  ...this.addForm,
+                  id: listId
+                };
+                console.log(newObj);
+                await updateRepairUserAndGroup(newObj);
+              }
               this.$message.success('成功!');
               this.dialogVisible = false;
-              this.$emit('success');
+              this.$emit('success', true);
             } finally {
               this.loading = false;
             }
@@ -77,11 +131,17 @@
         });
       },
 
-      open(arr, current) {
+      open(arr, current, type) {
         this.addForm = {};
         this.dialogVisible = true;
+        this.componentsType = type;
         this.checkoutArr = arr;
-        this.getTreeData(current);
+        if (type === 'move') {
+          this.getTreeData(current);
+          this.title = '移动到';
+        } else {
+          this.title = '批量设置片区负责人';
+        }
       },
       async getTreeData(current) {
         const res = await getTreeByPid(4);

+ 12 - 12
src/views/ledgerAssets/equipment/components/equipment-list.vue

@@ -38,7 +38,7 @@
         </el-button>
         <el-button
           size="small"
-          :disabled="isCheckout"
+          :disabled="checkRadioData.length == 0"
           icon="el-icon-set-up"
           class="ele-btn-icon"
         >
@@ -46,17 +46,18 @@
         </el-button>
         <el-button
           size="small"
-          :disabled="isCheckout"
+          :disabled="checkRadioData.length == 0"
           icon="el-icon-thumb"
           class="ele-btn-icon"
+          @click="moveTo(checkRadioData, 'person')"
         >
           设置片区负责人
         </el-button>
         <el-button size="small" class="ele-btn-icon">删除</el-button>
         <el-button
           size="small"
-          @click="moveTo(checkRadioData)"
-          :disabled="isCheckout"
+          @click="moveTo(checkRadioData, 'move')"
+          :disabled="checkRadioData.length == 0"
           class="ele-btn-icon"
           >移动到</el-button
         >
@@ -202,7 +203,6 @@
           }
         ],
         networkCounts: {},
-        isCheckout: true,
         checkRadioData: []
       };
     },
@@ -211,13 +211,15 @@
     },
     methods: {
       // 刷新回调
-      sucesstion() {
-        this.reload();
-        this.isCheckout = true;
+      sucesstion(is) {
+        if (is) {
+          this.reload();
+        }
+        this.checkRadioData = [];
       },
       // 移动到
-      moveTo(arr) {
-        this.$refs.movetoRef.open(arr, this.current);
+      moveTo(arr, type) {
+        this.$refs.movetoRef.open(arr, this.current, type);
       },
       // 全选
       changeSelectAll(arr) {
@@ -230,10 +232,8 @@
       },
       selectChange(selection, row) {
         if (selection.length != 0) {
-          this.isCheckout = false;
           this.checkRadioData = selection;
         } else {
-          this.isCheckout = true;
           this.checkRadioData = [];
         }
       },

+ 4 - 0
src/views/ledgerAssets/equipment/index.vue

@@ -23,6 +23,7 @@
             :category-id="current.id"
             :root-id="rootId"
             :current="current"
+            ref="listRef"
           />
         </template>
       </ele-split-layout>
@@ -52,6 +53,9 @@
     methods: {
       handleNodeClick(info) {
         this.current = info;
+        this.$nextTick(() => {
+          this.$refs.listRef.sucesstion(false);
+        });
       },
       // 获取根节点id
       setRootId(id) {