浏览代码

瑞鹰修井新疆项目部日报添加定额时效

Zimo 4 天之前
父节点
当前提交
33a1f5a5e1
共有 1 个文件被更改,包括 72 次插入7 次删除
  1. 72 7
      src/views/pms/iotrydailyreport/ry-xj-form.vue

+ 72 - 7
src/views/pms/iotrydailyreport/ry-xj-form.vue

@@ -7,6 +7,10 @@ import { FormInstance, FormRules } from 'element-plus'
 import { computed, reactive, ref, watch, nextTick } from 'vue'
 import { Delete, Plus } from '@element-plus/icons-vue'
 import dayjs from 'dayjs'
+import { useDebounceFn } from '@vueuse/core'
+import { useUserStore } from '@/store/modules/user'
+
+const userStore = useUserStore()
 
 interface Props {
   visible: boolean
@@ -45,6 +49,8 @@ interface ReportDetail {
   duration: number
   currentOperation: string
   constructionDetail: string
+  allocatedTime: number
+  allocatedEfficiency: number
 }
 
 interface FormOriginal {
@@ -159,7 +165,8 @@ const { t } = useI18n()
 const initFormData = (): Form => {
   const base: any = {
     ratedProductionTime: 0,
-    productionTime: 0
+    productionTime: 0,
+    reportDetails: []
   }
   // 初始化所有非生产时间字段为 0
   NON_PROD_FIELDS.forEach((field) => {
@@ -206,7 +213,9 @@ async function loadDetail(id: number) {
         endTime: formatT(item.endTime),
         duration: item.duration,
         currentOperation: item.currentOperation,
-        constructionDetail: item.constructionDetail
+        constructionDetail: item.constructionDetail,
+        allocatedTime: item.allocatedTime,
+        allocatedEfficiency: item.allocatedEfficiency
       })
     )
 
@@ -233,7 +242,9 @@ const addProductionStatusRow = () => {
     endTime: '',
     duration: 0,
     currentOperation: '',
-    constructionDetail: ''
+    constructionDetail: '',
+    allocatedTime: 0,
+    allocatedEfficiency: 0
   })
 }
 
@@ -431,6 +442,28 @@ const orange = computed(() => {
   if (Math.abs(total - rateTime) > 0.01) return true
   return false
 })
+
+const computedAllocatedEfficiency = useDebounceFn(function (row: ReportDetail) {
+  console.log('row', row)
+  if (!row) return
+
+  if (!row.allocatedTime || !row.duration) return
+
+  console.log('row', row)
+
+  row.allocatedEfficiency = Number(
+    (1 - (row.duration - row.allocatedTime) / row.allocatedTime).toFixed(2)
+  )
+}, 100)
+
+const calculate = (row: ReportDetail) => {
+  calculateDuration(row)
+  computedAllocatedEfficiency(row)
+}
+
+const allocatedTimeDisabled = computed(() => {
+  return userStore.getRoles.includes('RY定额时效')
+})
 </script>
 
 <template>
@@ -713,7 +746,7 @@ const orange = computed(() => {
                 </template>
               </ZmTableColumn>
 
-              <ZmTableColumn :width="130" label="开始时间" prop="startTime">
+              <ZmTableColumn :width="160" label="开始时间" prop="startTime">
                 <template #default="{ row, $index }">
                   <el-form-item
                     v-if="$index >= 0"
@@ -732,13 +765,13 @@ const orange = computed(() => {
                       format="HH:mm"
                       value-format="HH:mm"
                       class="w-full!"
-                      @change="calculateDuration(row)"
+                      @change="calculate(row)"
                       :disabled="isMainFieldDisabled"
                     />
                   </el-form-item>
                 </template>
               </ZmTableColumn>
-              <ZmTableColumn :width="130" label="结束时间" prop="endTime">
+              <ZmTableColumn :width="160" label="结束时间" prop="endTime">
                 <template #default="{ row, $index }">
                   <el-form-item
                     v-if="$index >= 0"
@@ -757,7 +790,7 @@ const orange = computed(() => {
                       format="HH:mm"
                       value-format="HH:mm"
                       class="w-full!"
-                      @change="calculateDuration(row)"
+                      @change="calculate(row)"
                       :disabled="isMainFieldDisabled"
                     />
                   </el-form-item>
@@ -809,6 +842,38 @@ const orange = computed(() => {
                 </template>
               </ZmTableColumn>
 
+              <ZmTableColumn label="定额时长" :width="160" align="center">
+                <template #default="{ row, $index }">
+                  <el-form-item
+                    v-if="$index >= 0"
+                    class="mb-0!"
+                    :prop="`reportDetails.${$index}.allocatedTime`"
+                  >
+                    <el-input-number
+                      v-model="row.allocatedTime"
+                      :disabled="isMainFieldDisabled && allocatedTimeDisabled"
+                      :controls="false"
+                      align="left"
+                      :min="0"
+                      placeholder="请输入定额时长"
+                      class="!w-full"
+                      :precision="2"
+                      @input="computedAllocatedEfficiency(row)"
+                    />
+                  </el-form-item>
+                </template>
+              </ZmTableColumn>
+
+              <ZmTableColumn
+                label="定额时效"
+                :width="120"
+                align="center"
+                prop="allocatedEfficiency"
+                :formatter="
+                  (row) => (row.allocatedEfficiency ? `${row.allocatedEfficiency * 100}%` : '')
+                "
+              />
+
               <ZmTableColumn label="操作" width="80" fixed="right" align="center">
                 <template #default="{ $index }">
                   <el-button