qinhb 1 year ago
parent
commit
44bb190f36

+ 9 - 0
src/api/device/index.ts

@@ -1,4 +1,5 @@
 import request from "@/utils/request";
 import request from "@/utils/request";
+import {OrderInfoQuery} from "@/api/order/types";
 
 
 /**
 /**
  * 设备维护
  * 设备维护
@@ -39,3 +40,11 @@ export function allocateAudit(params: any) {
     data: params,
     data: params,
   });
   });
 }
 }
+
+export function allocateExport(deviceNo: String) {
+  return request({
+    url: "/api/v1/device/allocate/export/" + deviceNo,
+    method: "get",
+    responseType: "arraybuffer",
+  });
+}

+ 1 - 1
src/hooks/userCrud.ts

@@ -42,7 +42,7 @@ export const useCrud = (config?: UseCrudConfig) => {
 
 
   /** 表格的分页数据 v-model */
   /** 表格的分页数据 v-model */
   const page = ref<PageOption>({
   const page = ref<PageOption>({
-    total: 12220,
+    total: 0,
     currentPage: 1,
     currentPage: 1,
     pageSize: 10,
     pageSize: 10,
   });
   });

+ 0 - 287
src/hooks/userCrud.ts~

@@ -1,287 +0,0 @@
-import request from "@/utils/request";
-import { PageOption } from "@smallwei/avue";
-import { ElMessageBox, ElMessage } from "element-plus";
-import { useUserStoreHook } from "@/store/modules/user";
-import { checkPerm } from "@/directive/permission";
-
-interface UseCrudConfig {
-  // 模块的url,用来进行增删改查
-  src?: string;
-  // 需要操作的数据
-  row?: any;
-  // done用于结束操作
-  done?: () => void;
-  // 具体操作的行
-  index?: number;
-  // 用于中断操作
-  loading?: () => void;
-  // 查询参数 一般用search的值就可以了
-  params?: object;
-  // 是否是编辑,如果是编辑调用更新,否则调用新增
-  isEdit?: boolean;
-}
-
-export const useCrud = (config?: UseCrudConfig) => {
-  const url = ref(config?.src);
-
-  /** 表格配置属性 */
-  const option = ref({
-    searchIcon: true,
-    searchIndex: 3, //searchIcon是否启用功能按钮, searchIndex配置收缩展示的个数,默认为2个
-    index: true, //是否显示第几项
-    indexLabel: '序号',
-    indexWidth: "55px",
-    refreshBtn: false,
-    border: true,
-    viewBtn: true,
-  });
-  const data = ref<any>([]); //表格数据
-  const form = ref({}); //新增或者编辑弹出的表单绑定值
-  /** 表格顶部搜索的表单的变量 v-model */
-  const search = ref({});
-
-  /** 表格的分页数据 v-model */
-  const page = ref<PageOption>({
-    total: 12220,
-    currentPage: 1,
-    pageSize: 10,
-  });
-  /** 配置项结构 v-model */
-  // defaults ?: AvueCrudDefaults;
-
-  const toDeleteIds = ref<Array<string>>([]);
-
-  const save = async (config?: UseCrudConfig) => {
-    try {
-      const path = config?.isEdit ? "/update" : "/add";
-      const res = (await request({
-        url: `${url.value}${path}`,
-        method: "post",
-        data: form.value,
-      })) as any;
-      if (res?.code == 200) {
-        Methords.dataList();
-        config?.done && config?.done();
-        ElMessage.success(res?.msg ?? "");
-      } else {
-        config?.loading && config?.loading();
-        ElMessage.error(res?.msg ?? "");
-      }
-    } catch (err) {
-      config?.loading && config?.loading();
-    }
-  };
-
-  const handleSearchData = () => {
-    // const array = [null, undefined, ""];
-    search.value = Object.fromEntries(
-      Object.entries(search.value).filter(
-        ([key, value]) =>{
-          alert(value)
-          return value !== null &&
-          value !== undefined &&
-          Object.keys(value).length !== 0
-        }
-      )
-    );
-  };
-
-  /**
-   * 表格增删改查等基本方法
-   */
-  const Methords = {
-    /**
-     * 查询方法
-     */
-    dataList: async (config?: UseCrudConfig) => {
-      handleSearchData();
-      try {
-        const res = await request({
-          url: `${url.value}/page`,
-          method: "post",
-          data: {
-            pageNo: page.value.currentPage,
-            pageSize: page.value.pageSize,
-            ...search.value,
-          },
-        });
-        if (res?.data) {
-          data.value = res?.data?.records || [];
-          page.value.total = res?.data?.totalCount || 0;
-        }
-        config?.done && config?.done();
-      } catch (err) {
-        config?.loading && config?.loading();
-      } finally {
-        config?.done && config?.done();
-      }
-    },
-
-    createRow: (row: any, done: () => void, loading: () => void) => {
-      save({ row: row, done: done, loading: loading });
-    },
-
-    updateRow: (
-      row: any,
-      index: number,
-      done: () => void,
-      loading: () => void
-    ) => {
-      save({
-        row: row,
-        done: done,
-        loading: loading,
-        index: index,
-        isEdit: true,
-      });
-    },
-
-    deleteRow: async (row: any, index: number, done: () => void) => {
-      ElMessageBox.confirm("是否删除所选中数据?", "提示", {
-        confirmButtonText: "确定",
-        cancelButtonText: "取消",
-        type: "warning",
-      }).then(async () => {
-        try {
-          const res = await request({
-            url: `${url.value}/del`,
-            method: "post",
-            data: { id: row.id ?? "" },
-          });
-          Methords.dataList();
-          config?.done && config?.done();
-        } catch (err) {
-          config?.loading && config?.loading();
-        } finally {
-          config?.done && config?.done();
-        }
-      });
-    },
-
-    // 设置selection: true,后监听选中改变事件,将Id存入数组
-    selectionChange: (rows?: any[]) => {
-      toDeleteIds.value = [];
-      rows?.forEach((element) => {
-        toDeleteIds.value.push(element.id);
-      });
-    },
-
-    /**
-     * 表格上方的多选删除方法
-     */
-    multipleDelete: async () => {
-      ElMessageBox.confirm("是否删除所选中数据?", "提示", {
-        confirmButtonText: "确定",
-        cancelButtonText: "取消",
-        type: "warning",
-      }).then(async () => {
-        try {
-          const res = await request({
-            url: `${url.value}/batch-del`,
-            method: "post",
-            data: { ids: toDeleteIds.value },
-          });
-          Methords.dataList();
-          config?.done && config?.done();
-        } catch (err) {
-          config?.loading && config?.loading();
-        } finally {
-          config?.done && config?.done();
-        }
-      });
-    },
-
-    /**
-     * 点击搜索按钮触发
-     */
-    searchChange: async (params: any, done: () => void) => {
-      // 点击搜索的时候重置search的值,要不然会传过去所有的值包括空字符串的值
-      search.value = params;
-      page.value.currentPage = 1;
-      Methords.dataList({ done: done });
-    },
-
-    /**
-     * 点击清空按钮触发
-     */
-    resetChange: async (item: any) => {
-      page.value.currentPage = 1;
-      Methords.dataList();
-    },
-  };
-
-  /**
-   * 表格辅助方法,按钮权限,导入导出
-   */
-  const Utils = {
-    checkBtnPerm: (str: string) => {
-      // 「超级管理员」拥有所有的按钮权限
-      const { roles, perms } = useUserStoreHook().user;
-      if (roles.includes("ROOT")) {
-        return true;
-      }
-      const hasPerm = perms?.some((perm) => {
-        return str.includes(perm);
-      });
-      return hasPerm;
-    },
-
-    /**
-     * 根据返回的数据下载文件
-     */
-    downloadFile: (response: any) => {
-      const fileData = response.data;
-      const fileName = decodeURI(
-        response.headers["content-disposition"].split(";")[1].split("=")[1]
-      );
-      const fileType =
-        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8";
-      const blob = new Blob([fileData], { type: fileType });
-      const downloadUrl = window.URL.createObjectURL(blob);
-      const downloadLink = document.createElement("a");
-      downloadLink.href = downloadUrl;
-      downloadLink.download = fileName;
-      document.body.appendChild(downloadLink);
-      downloadLink.click();
-      document.body.removeChild(downloadLink);
-      window.URL.revokeObjectURL(downloadUrl);
-    },
-
-    /**
-     * 下载模版 传入url
-     */
-    downloadTemplate: async (urlStr: string) => {
-      const response = await request({
-        url: urlStr,
-        method: "get",
-        responseType: "arraybuffer",
-      });
-      Utils.downloadFile(response);
-    },
-
-    /**
-     * 根据搜索项导出数据
-     */
-    exportData: async (urlStr: string) => {
-      const response = await request({
-        url: urlStr,
-        method: "post",
-        data: search.value,
-        responseType: "arraybuffer",
-      });
-      Utils.downloadFile(response);
-    },
-  };
-
-  return {
-    url,
-    option,
-    data,
-    form,
-    search,
-    page,
-    toDeleteIds,
-    Methords,
-    Utils,
-  };
-};

+ 28 - 6
src/views/device/allocate/index.vue

@@ -37,7 +37,7 @@
                    text
                    text
                    type="primary"
                    type="primary"
                    :size="size">记录</el-button>
                    :size="size">记录</el-button>
-        <el-button @click="maintenance(row,1)"
+        <el-button @click="handleExport(row)"
                    icon="el-icon-download"
                    icon="el-icon-download"
                    text
                    text
                    type="primary"
                    type="primary"
@@ -73,7 +73,7 @@
           </el-card>
           </el-card>
         </el-timeline-item>
         </el-timeline-item>
 
 
-        <el-timeline-item center placement="top"  :type="maintenanceInfo.state === 1 ? 'primary' : maintenanceInfo.state === 0 ? 'info' : 'success'">
+        <el-timeline-item center placement="top"  :type="maintenanceInfo.state === 0 ? 'primary' : maintenanceInfo.state === 0 ? 'info' : 'success'">
           <el-card v-if="viewPage">
           <el-card v-if="viewPage">
             <h4>调拨审批</h4>
             <h4>调拨审批</h4>
             <p>审批人员: {{maintenanceInfo.auditUser}}</p>
             <p>审批人员: {{maintenanceInfo.auditUser}}</p>
@@ -106,7 +106,7 @@ import { ref, getCurrentInstance } from "vue";
 import { useCrud } from "@/hooks/userCrud";
 import { useCrud } from "@/hooks/userCrud";
 import ButtonPermKeys from "@/common/configs/buttonPermission";
 import ButtonPermKeys from "@/common/configs/buttonPermission";
 import {getUserList} from "@/api/user"
 import {getUserList} from "@/api/user"
-import {allocateAudit} from "@/api/device/index";
+import {allocateAudit,allocateExport} from "@/api/device/index";
 import { useCommonStoreHook } from "@/store";
 import { useCommonStoreHook } from "@/store";
 import dictDataUtil from "@/common/configs/dictDataUtil";
 import dictDataUtil from "@/common/configs/dictDataUtil";
 const { isShowTable, tableType } = toRefs(useCommonStoreHook());
 const { isShowTable, tableType } = toRefs(useCommonStoreHook());
@@ -149,7 +149,7 @@ const maintenanceInfo = ref(null)
 const maintenance = (row,type)=>{
 const maintenance = (row,type)=>{
   viewPage.value = type === 0 ? false : true
   viewPage.value = type === 0 ? false : true
   maintenanceInfo.value = row
   maintenanceInfo.value = row
-  maintenanceInfo.value.handResult = 0
+  maintenanceInfo.value.auditResult = 1
   dialog1.visible = true
   dialog1.visible = true
 }
 }
 const queryUserList = ()=>{
 const queryUserList = ()=>{
@@ -157,6 +157,29 @@ const queryUserList = ()=>{
     userList.value = data.data
     userList.value = data.data
   })
   })
 }
 }
+const handleExport = (row) => {
+  allocateExport(row.deviceNo).then((response) => {
+    downFile(response);
+  });
+}
+/** 文件下载 */
+const downFile = (response) => {
+  const fileData = response.data;
+  const fileName = decodeURI(
+      response.headers["content-disposition"].split(";")[1].split("=")[1]
+  );
+  const fileType =
+      "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8";
+  const blob = new Blob([fileData], { type: fileType });
+  const downloadUrl = window.URL.createObjectURL(blob);
+  const downloadLink = document.createElement("a");
+  downloadLink.href = downloadUrl;
+  downloadLink.download = fileName;
+  document.body.appendChild(downloadLink);
+  downloadLink.click();
+  document.body.removeChild(downloadLink);
+  window.URL.revokeObjectURL(downloadUrl);
+}
 const maintenanceInfoForm = ref('maintenanceInfoForm')
 const maintenanceInfoForm = ref('maintenanceInfoForm')
 const maintenanceSubmit =()=>{
 const maintenanceSubmit =()=>{
   //alert(JSON.stringify(maintenanceInfo.value))
   //alert(JSON.stringify(maintenanceInfo.value))
@@ -319,10 +342,9 @@ option.value = Object.assign(option.value, {
       ],
       ],
     },
     },
     {
     {
-      label: "调拨单号",
+      label: "状态",
       prop: "state",
       prop: "state",
       display: false,
       display: false,
-      search: true,
       type: "select",
       type: "select",
       dicData: [{label: '待审核',value:0},{label: '通过',value:1},{label: '驳回',value:2}],
       dicData: [{label: '待审核',value:0},{label: '通过',value:1},{label: '驳回',value:2}],
     },
     },

+ 311 - 0
src/views/device/metering/index.vue

@@ -0,0 +1,311 @@
+<template>
+  <div class="mainContentBox">
+    <avue-crud
+        ref="crudRef"
+        v-model:search="search"
+        v-model="form"
+        :data="data"
+        :option="option"
+        v-model:page="page"
+        @row-save="createRow"
+        @row-update="updateRow"
+        @row-del="deleteRow"
+        @search-change="searchChange"
+        @search-reset="resetChange"
+        @size-change="dataList"
+        @current-change="dataList"
+        @selection-change="selectionChange"
+    >
+      <template #menu-left="{ size }">
+        <el-button
+          :disabled="toDeleteIds.length < 1"
+          type="danger"
+          icon="el-icon-delete"
+          :size="size"
+          @click="multipleDelete"
+          >删除</el-button
+        >
+      </template>
+      <template #menu="{size,row,index}">
+        <el-button @click="maintenance(row,0)"
+                   icon="el-icon-check"
+                   text
+                   type="primary"
+                   :size="size">流程</el-button>
+        <el-button @click="maintenance(row,1)"
+                   icon="el-icon-fold"
+                   text
+                   type="primary"
+                   :size="size">记录</el-button>
+      </template>
+    </avue-crud>
+    <el-dialog
+        v-model="dialog.visible"
+        :title="dialog.title"
+        width="850px"
+        @close="dialog.visible = false"
+    >
+      <device-page  @deviceInfo="deviceInfo"/>
+    </el-dialog>
+
+    <el-dialog
+        v-model="dialog1.visible"
+        :title="dialog1.title"
+        width="750px"
+        height="80%"
+        @close="dialog1.visible = false">
+      <el-timeline style="max-width: 500px;margin-left: 100px">
+        <el-timeline-item center type="success" placement="top">
+          <el-card>
+            <h4>设备报故</h4>
+            <p>设备编号: {{maintenanceInfo.deviceNo}}</p>
+            <p>设备名称: {{maintenanceInfo.deviceName}}</p>
+            <p>报故人员: {{maintenanceInfo.creator}}</p>
+            <p>故障描述: {{maintenanceInfo.bugRemark}}</p>
+            <p>报故时间: {{maintenanceInfo.created}}</p>
+          </el-card>
+        </el-timeline-item>
+        <el-timeline-item center placement="top"  :type="maintenanceInfo.state === 0 ? 'primary' : 'success'">
+          <el-card v-if="viewPage">
+            <h4>设备维修</h4>
+            <p>维修人员: {{maintenanceInfo.handleUser}}</p>
+            <p>维修内容: {{maintenanceInfo.handleContent}}</p>
+            <p>处理结果: {{maintenanceInfo.handleUser ? (maintenanceInfo.handleResult === 0 ? '可正常运行' : '报废') : ''}}</p>
+          </el-card>
+          <el-card v-if="!viewPage">
+            <h4>设备维修</h4>
+            <el-form ref="maintenanceInfoForm1" :model="maintenanceInfo" label-width="auto" style="max-width: 400px" :rules="rules1">
+              <el-form-item label="维修人员" prop="handleUser">
+                <el-input :disabled="maintenanceInfo.state !== 0" v-model="maintenanceInfo.handleUser" />
+              </el-form-item>
+              <el-form-item label="维修内容" prop="handleContent">
+                <el-input :disabled="maintenanceInfo.state !== 0" type="textarea" :rows="2" v-model="maintenanceInfo.handleContent" />
+              </el-form-item>
+              <el-form-item label="处理结果">
+                <el-radio-group :disabled="maintenanceInfo.state !== 0" v-model="maintenanceInfo.handleResult" class="ml-4">
+                  <el-radio :value="0">可正常运行</el-radio>
+                  <el-radio :value="1">报废</el-radio>
+                </el-radio-group>
+              </el-form-item>
+              <el-form-item style="margin-left: 45%">
+                <el-button type="primary" v-if="maintenanceInfo.state === 0" :disabled="maintenanceInfo.state !== 0" @click="maintenanceSubmit1">保存</el-button>
+              </el-form-item>
+            </el-form>
+          </el-card>
+        </el-timeline-item>
+        <el-timeline-item center placement="top"  :type="maintenanceInfo.state === 1 ? 'primary' : maintenanceInfo.state === 0 ? 'info' : 'success'">
+          <el-card v-if="viewPage">
+            <h4>设备审批</h4>
+            <p>审批人员: {{maintenanceInfo.auditUser}}</p>
+            <p>审批结果: {{maintenanceInfo.auditUser ? (maintenanceInfo.auditResult === 0 ? '通过' : '不通过') : ''}}</p>
+          </el-card>
+          <el-card v-if="!viewPage">
+            <h4>设备审批</h4>
+            <el-form ref="maintenanceInfoForm2" v-if="maintenanceInfo.state >= 1" :model="maintenanceInfo" label-width="auto" style="max-width: 400px" :rules="rules2">
+              <el-form-item label="审批人员" prop="auditUser">
+                <el-input :disabled="maintenanceInfo.state !== 1 && readonly"  v-model="maintenanceInfo.auditUser" />
+              </el-form-item>
+              <el-form-item label="审批结果">
+                <el-radio-group :disabled="maintenanceInfo.state !== 1 && readonly" v-model="maintenanceInfo.auditResult" class="ml-4">
+                  <el-radio :value="0">通过</el-radio>
+                  <el-radio :value="1">不通过</el-radio>
+                </el-radio-group>
+              </el-form-item>
+              <el-form-item style="margin-left: 45%">
+                <el-button type="primary" v-if="maintenanceInfo.state ===1" :disabled="maintenanceInfo.state !== 1" @click="maintenanceSubmit2">保存</el-button>
+              </el-form-item>
+            </el-form>
+          </el-card>
+        </el-timeline-item>
+      </el-timeline>
+    </el-dialog>
+  </div>
+</template>
+<script setup>
+import { ref, getCurrentInstance } from "vue";
+import { useCrud } from "@/hooks/userCrud";
+import ButtonPermKeys from "@/common/configs/buttonPermission";
+import {getUserList} from "@/api/user"
+import {repair,audit} from "@/api/device/index";
+import { useCommonStoreHook } from "@/store";
+import dictDataUtil from "@/common/configs/dictDataUtil";
+const { isShowTable, tableType } = toRefs(useCommonStoreHook());
+const test = () => {
+  isShowTable.value = true;
+  tableType.value = tableType.value == 1 ? 2 : 1;
+};
+
+const viewPage = ref(true)
+
+const dialog = reactive({
+  title: "设备选择",
+  visible: false,
+});
+const dialog1 = reactive({
+  title: "设备维修",
+  visible: false,
+});
+const userList = ref([])
+// 传入一个url,后面不带/
+const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
+  useCrud({
+    src: "/api/v1/device/repair",
+  });
+const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } = Methords; //增删改查
+const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
+const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
+const crudRef = ref(null); //crudRef.value 获取avue-crud对象
+const deviceInfo = (value) => {
+  form.value.deviceNo = value.deviceNo
+  form.value.deviceName =value.deviceName
+  form.value.deviceType = value.deviceType
+  form.value.devicePosition = value.devicePosition
+  dialog.visible = false
+}
+const maintenanceInfo = ref(null)
+const maintenance = (row,type)=>{
+  viewPage.value = type === 0 ? false : true
+  maintenanceInfo.value = row
+  maintenanceInfo.value.handResult = 0
+  dialog1.visible = true
+}
+const queryUserList = ()=>{
+  getUserList({}).then((data)=>{
+    userList.value = data.data
+  })
+}
+const maintenanceInfoForm1 = ref('maintenanceInfoForm1')
+const maintenanceInfoForm2 = ref('maintenanceInfoForm2')
+const maintenanceSubmit1 =()=>{
+  //alert(JSON.stringify(maintenanceInfo.value))
+  maintenanceInfoForm1.value.validate((isValid, invalidFields) => {
+    if (isValid) {
+      repair(maintenanceInfo.value).then((data)=>{
+        ElMessage({
+          message: data.msg,
+          type: "success",
+        });
+        dialog1.visible = false
+        dataList()
+      })
+    }
+  })
+}
+const maintenanceSubmit2 =()=>{
+  //alert(JSON.stringify(maintenanceInfo.value))
+  maintenanceInfoForm2.value.validate((isValid, invalidFields) => {
+    if (isValid) {
+      audit(maintenanceInfo.value).then((data)=>{
+        ElMessage({
+          message: data.msg,
+          type: "success",
+        });
+        dialog1.visible = false
+        dataList()
+      })
+    }
+  })
+}
+const rules1 = reactive({
+  handleUser: [
+    { required: true, message: '维修人员不能为空', trigger: 'blur' }
+  ],
+  handleContent: [
+    { required: true, message: '维修内容不能为空', trigger: 'blur' }
+  ]
+})
+const rules2 = reactive({
+  auditUser: [
+    { required: true, message: '审批人员不能为空', trigger: 'blur' }
+  ]
+})
+// 设置表格列或者其他自定义的option
+option.value = Object.assign(option.value, {
+  delBtn: false,
+  selection: true,
+  labelWidth: 150,
+  viewBtn: false,
+  editBtn: false,
+  column: [
+    {
+      label: "设备编号",
+      prop: "deviceNo",
+      search: true,
+      rules: [
+        {
+          required: true,
+          message: "设备编号不能为空",
+          trigger: "trigger",
+        },
+      ],
+      click: ({ value, column }) => {
+        if(column.boxType){
+          dialog.visible = true
+        }
+      },
+    },
+    {
+      label: "设备名称",
+      prop: "deviceName",
+      addDisabled: true,
+      search: true,
+    },
+    {
+      label: "设备类型",
+      prop: "deviceType",
+      type: "select",
+      addDisabled: true,
+      search: true,
+      dicUrl:
+        dictDataUtil.request_url +
+        dictDataUtil.TYPE_CODE.device_type,
+      props: {
+        label: "dictLabel",
+        value: "dictValue",
+      },
+      rules: [
+        {
+          required: true,
+          message: "设备类型不能为空",
+          trigger: "trigger",
+        },
+      ],
+    },
+    {
+      label: "设备位置",
+      addDisabled: true,
+      prop: "devicePosition",
+    },
+    {
+      label: "故障描述",
+      prop: "bugRemark",
+      minRows: 2, //最小行/最小值
+      type: "textarea", //类型为多行文本域框
+      maxlength: 512, //最大输入长度
+    },
+    {
+      label: "维修状态",
+      prop: "state",
+      type: "select",
+      display: false,
+      dicData:[{label: '待维修',value: 0},{label: '待审批 ',value: 1},{label: '已完成',value: 2}],
+    },
+    {
+      label: "报故人",
+      prop: "creator",
+      display: false,
+    },
+    {
+      label: "报故日期",
+      prop: "created",
+      width: "180",
+      display: false,
+    },
+  ],
+});
+
+onMounted(() => {
+  dataList();
+  queryUserList()
+});
+</script>