From b95cf940af8e01e4eca30b2599b029c2f645bd1e Mon Sep 17 00:00:00 2001
From: charles <981744753@qq.com>
Date: 星期一, 29 四月 2024 10:44:26 +0800
Subject: [PATCH] feat:创建新分支

---
 src/views/dashboard/components/TaskControl.vue |  367 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 354 insertions(+), 13 deletions(-)

diff --git a/src/views/dashboard/components/TaskControl.vue b/src/views/dashboard/components/TaskControl.vue
index 9a69334..b44dfea 100644
--- a/src/views/dashboard/components/TaskControl.vue
+++ b/src/views/dashboard/components/TaskControl.vue
@@ -21,33 +21,147 @@
         寮�濮嬬敓浜�
       </BigButton>
       <template v-if="task?.Procedure.Status === 2 || task?.Procedure.Status === 3">
-        <BigButton class="btn" bg-color="#ff9933">鎵撳嵃</BigButton>
-        <BigButton class="btn" bg-color="#00cc33">鎶ュ伐</BigButton>
-        <BigButton class="btn" bg-color="#ff0000">瀹屾垚</BigButton>
+        <BigButton class="btn" bg-color="#ff9933" :disabled="task?.Procedure.Status === 3">鎵撳嵃</BigButton>
+        <BigButton
+          v-if="task?.ShowCheck"
+          class="btn"
+          bg-color="#00cc33"
+          :disabled="task?.Procedure.Status === 3"
+          @click="openQualityModal"
+          >璐ㄦ</BigButton
+        >
+        <BigButton
+          class="btn"
+          :bg-color="task?.ShowCheck ? '#0066ff' : '#00cc33'"
+          :disabled="task?.Procedure.Status === 3"
+          @click="openReportModal"
+        >
+          鎶ュ伐
+        </BigButton>
+        <el-popconfirm
+          width="340"
+          confirm-button-text="纭畾"
+          cancel-button-text="鍙栨秷"
+          :icon="CircleCloseFilled"
+          icon-color="red"
+          :hide-after="0"
+          :teleported="false"
+          :title="Number(processingPercent) < 100 ? '杩涘害鏈畬鎴愶紝鏄惁鎻愬墠瀹屾垚浠诲姟锛�' : '璇风‘璁ゆ槸鍚﹀凡瀹屾垚姝ょ敓浜т换鍔�?'"
+          placement="top"
+          @confirm="finishTaskProduce"
+        >
+          <template #reference>
+            <BigButton class="btn" bg-color="#ff0000" :disabled="task?.Procedure.Status === 3">瀹屾垚</BigButton>
+          </template>
+        </el-popconfirm>
       </template>
     </div>
   </div>
-  <TaskControlModal v-model="showTaskControlModal" :task="task"></TaskControlModal>
+  <TaskControlModal v-model="showTaskControlModal" :task="task" @produce-start="onProduceStart"></TaskControlModal>
+  <ReportProductionModal
+    v-model="showReportModal"
+    :model-title="modelTitle"
+    :amount="plcInfo?.finishNumber ?? 0"
+    @close="showReportModal = false"
+    @submit="onReportProduction"
+  ></ReportProductionModal>
+  <ReportProductionModal1
+    v-model="showReportModal1"
+    :model-title="modelTitle"
+    :amount="plcInfo?.finishNumber ?? 0"
+    :pass-amount="passAmount"
+    :rework-amount="reworkAmount"
+    :scrapped-amount="scrappedAmount"
+    @close="showReportModal1 = false"
+    @submit="onReportCheck"
+  ></ReportProductionModal1>
 </template>
 <script setup lang="ts">
-import type { Task } from '@/api/task'
-import { ref, toRefs } from 'vue'
+import type { Task, Worker } from '@/api/task'
+import { ref, toRefs, computed } from 'vue'
 import BigButton from '@/views/dashboard/components/BigButton.vue'
 import { useDateFormat } from '@vueuse/core'
 import TaskControlModal from '@/views/dashboard/components/TaskControlModal.vue'
+import { CircleCloseFilled } from '@element-plus/icons-vue'
+import { apiReportWork, procedureUpdate, bulletinReport, bulletinQualityInspection, getQualityInspection } from '@/api'
+import { ElMessage } from 'element-plus'
+import ReportProductionModal from '@/views/dashboard/components/ReportProductionModal.vue'
+import ReportProductionModal1 from '@/views/dashboard/components/ReportProductionModal1.vue'
+import { usePLCStore } from '@/stores/plc'
+import { storeToRefs } from 'pinia'
 
 const props = defineProps<{
   task?: Task
+  workers: Worker[]
 }>()
-const { task } = toRefs(props)
+const { task, workers } = toRefs(props)
+
+const emit = defineEmits<{
+  shouldReload: [task: Task]
+}>()
 
 const showTaskControlModal = ref(false)
+const modelTitle = ref('')
+const passAmount = ref(0)
+const reworkAmount = ref(0)
+const scrappedAmount = ref(0)
 
 /**
  * 寮�濮嬬敓浜�
  */
 function startProduce() {
   showTaskControlModal.value = true
+}
+
+/**
+ * 瀹屾垚浠诲姟
+ */
+function finishTaskProduce() {
+  if (task?.value && task.value?.Procedure?.ID) {
+    //鐐瑰嚮鐨勬椂鍊欎笉鑳芥瘮瀹為檯寮�濮嬫椂闂村ぇ浜�1鍒嗛挓
+    let realStartTime = task.value?.Procedure?.realStartTime
+    if (realStartTime) {
+      realStartTime = realStartTime * 1000
+      let time = Date.now()
+      let differ = Math.abs(time - realStartTime) / 1000
+      if (differ < 60) {
+        ElMessage({
+          message: '宸ュ簭鍒堕�犳椂闂村お鐭紝璇锋鏌ワ紒',
+          type: 'warning'
+        })
+        return true
+      }
+    }
+    procedureUpdate({
+      isFinish: true,
+      isProcessing: false,
+      workOrderProcedureID: Number(task!.value.Procedure.ID)
+    }).then(
+      (res: any) => {
+        ElMessage({
+          message: '鎿嶄綔鎴愬姛锛�',
+          type: 'success'
+        })
+        emit('shouldReload', task.value as Task)
+      },
+      (err) => {
+        console.error(err)
+        ElMessage({
+          message: '鎿嶄綔澶辫触锛�',
+          type: 'warning'
+        })
+      }
+    )
+  } else {
+    ElMessage({
+      message: '褰撳墠璁惧娌℃湁宸ュ簭锛�',
+      type: 'warning'
+    })
+  }
+}
+
+function onProduceStart() {
+  emit('shouldReload', task!.value as Task)
 }
 
 /**
@@ -58,9 +172,198 @@
   if (!timestamp) {
     return '--'
   }
-  const time = useDateFormat(timestamp * 1000, 'YYYY-MM-DD', { locales: 'zh-cn' })
+  const time = useDateFormat(timestamp * 1000, 'YYYY-MM-DD HH:mm:ss', { locales: 'zh-cn' })
   return time.value
 }
+
+const plcStore = usePLCStore()
+const { plcInfo } = storeToRefs(plcStore)
+// 鎶ュ伐
+const showReportModal = ref(false)
+// 鎶ュ伐
+const showReportModal1 = ref(false)
+const reprotIds = ref([])
+const passCount = ref(0)
+function openReportModal() {
+  // 鏈変汉鍛樻墠鍙互鎶ュ伐
+  if (!workers.value || workers.value.length == 0) {
+    ElMessage({
+      message: '娌℃湁浜哄憳淇℃伅涓嶅厑璁告墜鍔ㄦ姤宸ワ紒',
+      type: 'error',
+      duration: 3000
+    })
+    return true
+  }
+  // 浠庡紑濮嬬敓浜у埌鎶ュ伐鐨勭偣鍑绘椂闂翠笉鑳藉皬浜�1鍒嗛挓
+  if (task?.value && task.value?.Procedure?.realStartTime) {
+    let realStartTime = task.value?.Procedure?.realStartTime
+    if (realStartTime) {
+      realStartTime = realStartTime * 1000
+      let time = Date.now()
+      let differ = Math.abs(time - realStartTime) / 1000
+      if (differ < 60) {
+        ElMessage({
+          message: '宸ュ簭鍒堕�犳椂闂村お鐭紝璇锋鏌ワ紒',
+          type: 'warning'
+        })
+        return true
+      }
+    }
+  }
+
+  if (workers.value[0].workerId) {
+    modelTitle.value = '鐢熶骇鎶ュ伐'
+    if (task?.value?.ShowCheck) {
+      getQualityInspection({
+        procedureId: task.value?.Procedure?.procedure.procedureId,
+        workOrderId: task.value?.Order.workOrderId
+      }).then((res: any) => {
+        console.log(res, '999999')
+        passAmount.value = res.data.passAmount
+        passCount.value = res.data.passAmount
+        reworkAmount.value = res.data.reworkAmount
+        scrappedAmount.value = res.data.scrappedAmount
+        reprotIds.value = res.data.ids || []
+        showReportModal1.value = true
+      })
+    } else {
+      showReportModal.value = true
+    }
+  }
+}
+
+// 璐ㄦ
+function openQualityModal() {
+  // 鏈変汉鍛樻墠鍙互鎶ュ伐
+  if (!workers.value || workers.value.length == 0) {
+    ElMessage({
+      message: '娌℃湁浜哄憳淇℃伅涓嶅厑璁歌川妫�锛�',
+      type: 'error',
+      duration: 3000
+    })
+    return true
+  }
+  if (workers.value[0].workerId) {
+    modelTitle.value = '鎻愪氦璐ㄦ'
+    showReportModal.value = true
+  }
+}
+
+/**
+ * 涓婃姤鍔犲伐鏁�
+ * @param amount 鍔犲伐鏁�
+ */
+function onReportProduction(amount: number) {
+  if (!task?.value) {
+    return
+  }
+  // 鏈変汉鍛樻墠鍙互鎶ュ伐
+  if (workers.value[0].workerId) {
+    let requestUrl = task?.value.ShowCheck ? bulletinQualityInspection : apiReportWork
+    let tipStr = task?.value.ShowCheck ? '璐ㄦ' : '鎶ュ伐'
+    requestUrl({
+      workOrderProcedureID: Number(task.value?.Procedure.ID),
+      reportAmount: amount,
+      workerID: workers.value[0].workerId,
+      workerName: workers.value[0].workerName
+    })
+      .then((res: any) => {
+        if (res.code === 200) {
+          ElMessage({
+            message: `${tipStr}鎴愬姛`,
+            type: 'success',
+            duration: 2000
+          })
+          showReportModal.value = false
+        } else {
+          ElMessage({
+            message: `${tipStr}澶辫触`,
+            type: 'error',
+            duration: 3000
+          })
+        }
+      })
+      .catch((err) => {
+        console.error(err)
+      })
+  }
+}
+/**
+ * 璐ㄦ鍚庣殑涓婃姤鍔犲伐鏁�
+ * @param amount 鍔犲伐鏁�
+ */
+function onReportCheck(amount: number) {
+  if (!task?.value) {
+    return
+  }
+  // 鏈変汉鍛樻墠鍙互鎶ュ伐
+  if (workers.value[0].workerId) {
+    bulletinReport({
+      workOrderProcedureID: Number(task.value?.Procedure.ID),
+      reportAmount: passCount.value,
+      workerID: workers.value[0].workerId,
+      workerName: workers.value[0].workerName,
+      ids: reprotIds.value
+    })
+      .then((res: any) => {
+        if (res.code === 200) {
+          ElMessage({
+            message: '鎶ュ伐鎴愬姛',
+            type: 'success',
+            duration: 2000
+          })
+          showReportModal1.value = false
+        } else {
+          ElMessage({
+            message: '鎶ュ伐澶辫触',
+            type: 'error',
+            duration: 3000
+          })
+        }
+      })
+      .catch((err) => {
+        console.error(err)
+      })
+  }
+}
+export interface Statistics {
+  totalNumber: number
+  finishNumber: number
+}
+/**
+ * 璁$畻鐢熶骇杩涘害
+ * @param statistics
+ * @return 杩涘害,0~100
+ */
+function calculateProgress(statistics: Statistics): number {
+  if (!statistics) {
+    return 0
+  }
+
+  if (statistics.finishNumber === 0) {
+    return 0
+  }
+  if (statistics.finishNumber === statistics.totalNumber) {
+    return 100
+  }
+
+  const result = Math.floor((statistics.finishNumber / statistics.totalNumber) * 100)
+  return result > 100 ? 100 : result
+}
+const processingPercent = computed(() => {
+  // if (task?.value?.Procedure?.Status === 1) {
+  //   return 0
+  // }
+
+  if (task?.value?.Procedure?.Status === 3) {
+    return 100
+  }
+  // if (task?.value?.Procedure?.Status === 2 || task?.value?.Procedure?.Status === 1) {
+  //   return calculateProgress(plcStore.plcInfo as Statistics)
+  // }
+
+  return calculateProgress(plcStore.plcInfo as Statistics)
+})
 </script>
 <style scoped lang="scss">
 $title-text-color: #9599af;
@@ -71,10 +374,12 @@
   align-items: start;
   width: 100%;
 }
-.task-info,
-.produce-btn {
-  width: 50%;
+.task-info {
   flex: 1;
+  height: 100%;
+}
+.produce-btn {
+  flex-shrink: 0;
   height: 100%;
 }
 .produce-btn {
@@ -89,7 +394,6 @@
 
 .task-info-item {
   padding: 10px 20px;
-  margin-bottom: 6px;
 }
 .task-info-title {
   font-size: 18px;
@@ -99,7 +403,7 @@
   font-size: 19px;
   color: $content-text-color;
   font-weight: 600;
-  margin-top: 12px;
+  margin-top: 4px;
 }
 .produce-btn {
   display: flex;
@@ -119,4 +423,41 @@
 .finish-btn {
   background-color: #ff0000;
 }
+
+:deep(.el-popper) {
+  background-color: #133f97;
+  color: #fff;
+}
+:deep(.el-popconfirm__main) {
+  font-size: 25px;
+}
+:deep(.el-popconfirm__icon) {
+  font-size: 38px;
+}
+:deep(.el-popconfirm__main) {
+  margin-bottom: 20px;
+}
+:deep(.el-popconfirm__action) {
+  display: flex;
+  align-items: center;
+  justify-content: space-around;
+}
+:deep(.el-popconfirm__action .el-button) {
+  font-size: 22px;
+  height: 54px;
+  width: 140px;
+  color: #fff;
+  background-color: #0ae5ec;
+  &:hover {
+    background-color: #0ae5ec;
+  }
+  &.is-text {
+    color: #92a1c0;
+    background-color: #133f97;
+    border: 1px solid #0ae5ec;
+    &:hover {
+      background-color: #133f97;
+    }
+  }
+}
 </style>

--
Gitblit v1.8.0