Pārlūkot izejas kodu

交接单:已耗时

lxf 1 gadu atpakaļ
vecāks
revīzija
0d568ef69b

+ 5 - 1
src/main.js

@@ -55,7 +55,9 @@ import {
   getPdfTransverseA4,
   translateIntoEnglish,
   random,
-  deepClone
+  deepClone,
+  timeInterval,
+  compareTime
 } from '@/utils/util'
 
 // 分页组件
@@ -99,6 +101,8 @@ app.config.globalProperties.getPdfTransverseA4 = getPdfTransverseA4
 app.config.globalProperties.translateIntoEnglish = translateIntoEnglish
 app.config.globalProperties.random = random
 app.config.globalProperties.deepClone = deepClone
+app.config.globalProperties.timeInterval = timeInterval
+app.config.globalProperties.compareTime = compareTime
 
 
 // 全局组件挂载

+ 34 - 0
src/utils/util.js

@@ -342,3 +342,37 @@ export function deepClone(data) {
   }
   return obj;
 }
+
+// 计算时间间隔
+export function timeInterval(smallTime, largeTime) {
+  //一般前端使用的时间分隔符是"-",需要替换成"/"
+  let large = new Date(largeTime.replace("-", "/").replace("-", "/"));
+  let small = new Date(smallTime.replace("-", "/").replace("-", "/"));
+  if (large > small) {
+    let date3 = large.getTime() - new Date(small).getTime(); //时间差的毫秒数
+    //计算出相差天数
+    let days = Math.floor(date3 / (24 * 3600 * 1000));
+    //计算出小时数
+    let leave1 = date3 % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
+    let hours = Math.floor(leave1 / (3600 * 1000));
+    //计算相差分钟数
+    let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
+    let minutes = Math.floor(leave2 / (60 * 1000));
+    //计算相差秒数
+    let leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
+    let seconds = Math.round(leave3 / 1000);
+    return { days: days, hours: hours, minutes: minutes, seconds: seconds };
+  }
+  return { days: 0, hours: 0, minutes: 0, seconds: 0 };
+}
+
+// 比较时间大小
+export function compareTime(date1, date2) {
+  var oDate1 = new Date(date1);
+  var oDate2 = new Date(date2);
+  if (oDate1.getTime() > oDate2.getTime()) {
+    return true; //第一个大
+  } else {
+    return false; //第二个大
+  }
+}

+ 27 - 3
src/views/EHSD/procurement/handoverSlipEHSD/index.vue

@@ -31,7 +31,9 @@
           </div>
         </template>
         <template #timeSpent="{ item }">
-          <div style="width: 100%">已耗时</div>
+          <div style="width: 100%">
+            <span>{{ getTimeSpent(item) }}</span>
+          </div>
         </template>
       </byTable>
     </div>
@@ -64,6 +66,7 @@
 import { computed, ref } from "vue";
 import byTable from "@/components/byTable/index";
 import byForm from "@/components/byForm/index";
+import moment from "moment";
 
 const { proxy } = getCurrentInstance();
 const sourceList = ref({
@@ -230,10 +233,10 @@ const checkTheTransferSlip = (item) => {
   rowData.value.fileList = [];
   rowData.value.packageFileList = [];
   openAllFile.value = true;
-  proxy.post("/fileInfo/getList", { businessIdList: [item.contractId],fileType: 1 }).then((fileObj) => {
+  proxy.post("/fileInfo/getList", { businessIdList: [item.contractId], fileType: 1 }).then((fileObj) => {
     rowData.value.fileList = fileObj[item.contractId] || [];
   });
-  proxy.post("/fileInfo/getList", { businessIdList: [item.contractId],fileType: 2 }).then((fileObj) => {
+  proxy.post("/fileInfo/getList", { businessIdList: [item.contractId], fileType: 2 }).then((fileObj) => {
     rowData.value.packageFileList = fileObj[item.contractId] || [];
   });
 };
@@ -275,6 +278,27 @@ const formConfig = computed(() => {
     },
   ];
 });
+const getTimeSpent = (item) => {
+  let text = "";
+  if (item.sampleTime && item.updateTime) {
+    let data = { days: 0, hours: 0, minutes: 0, seconds: 0 };
+    if (proxy.compareTime(item.sampleTime, item.updateTime)) {
+      data = proxy.timeInterval(item.sampleTime, moment().format("yyyy-MM-DD HH:mm:ss"));
+    } else {
+      data = proxy.timeInterval(item.updateTime, moment().format("yyyy-MM-DD HH:mm:ss"));
+    }
+    if (data.days) {
+      text = data.days + "天" + data.hours + "小时" + data.minutes + "分";
+    } else {
+      if (data.hours) {
+        text = data.hours + "小时" + data.minutes + "分";
+      } else {
+        text = data.minutes + "分";
+      }
+    }
+  }
+  return text;
+};
 </script>
 
 <style lang="scss" scoped>

+ 27 - 3
src/views/EHSD/procurement/handoverSlipSampleEHSD/index.vue

@@ -31,7 +31,9 @@
           </div>
         </template>
         <template #timeSpent="{ item }">
-          <div style="width: 100%">已耗时</div>
+          <div style="width: 100%">
+            <span>{{ getTimeSpent(item) }}</span>
+          </div>
         </template>
       </byTable>
     </div>
@@ -64,6 +66,7 @@
 import { computed, ref } from "vue";
 import byTable from "@/components/byTable/index";
 import byForm from "@/components/byForm/index";
+import moment from "moment";
 
 const { proxy } = getCurrentInstance();
 const sourceList = ref({
@@ -230,10 +233,10 @@ const checkTheTransferSlip = (item) => {
   rowData.value.fileList = [];
   rowData.value.packageFileList = [];
   openAllFile.value = true;
-  proxy.post("/fileInfo/getList", { businessIdList: [item.contractId],fileType: 1 }).then((fileObj) => {
+  proxy.post("/fileInfo/getList", { businessIdList: [item.contractId], fileType: 1 }).then((fileObj) => {
     rowData.value.fileList = fileObj[item.contractId] || [];
   });
-  proxy.post("/fileInfo/getList", { businessIdList: [item.contractId],fileType: 2 }).then((fileObj) => {
+  proxy.post("/fileInfo/getList", { businessIdList: [item.contractId], fileType: 2 }).then((fileObj) => {
     rowData.value.packageFileList = fileObj[item.contractId] || [];
   });
 };
@@ -275,6 +278,27 @@ const formConfig = computed(() => {
     },
   ];
 });
+const getTimeSpent = (item) => {
+  let text = "";
+  if (item.sampleTime && item.updateTime) {
+    let data = { days: 0, hours: 0, minutes: 0, seconds: 0 };
+    if (proxy.compareTime(item.sampleTime, item.updateTime)) {
+      data = proxy.timeInterval(item.sampleTime, moment().format("yyyy-MM-DD HH:mm:ss"));
+    } else {
+      data = proxy.timeInterval(item.updateTime, moment().format("yyyy-MM-DD HH:mm:ss"));
+    }
+    if (data.days) {
+      text = data.days + "天" + data.hours + "小时" + data.minutes + "分";
+    } else {
+      if (data.hours) {
+        text = data.hours + "小时" + data.minutes + "分";
+      } else {
+        text = data.minutes + "分";
+      }
+    }
+  }
+  return text;
+};
 </script>
 
 <style lang="scss" scoped>