From 1519870c0e18171ced014a840e86a459dc6b00f1 Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期二, 12 十二月 2023 17:26:06 +0800
Subject: [PATCH] 报工记录列表增加人员姓名

---
 src/views/dashboard/components/TaskControl.vue |  224 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 210 insertions(+), 14 deletions(-)

diff --git a/src/views/dashboard/components/TaskControl.vue b/src/views/dashboard/components/TaskControl.vue
index bb55687..cb9d2e2 100644
--- a/src/views/dashboard/components/TaskControl.vue
+++ b/src/views/dashboard/components/TaskControl.vue
@@ -21,29 +21,114 @@
         寮�濮嬬敓浜�
       </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 class="btn" bg-color="#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="璇风‘璁ゆ槸鍚﹀凡瀹屾垚姝ょ敓浜т换鍔�?"
+          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" @produce-start="onProduceStart"></TaskControlModal>
+  <ReportProductionModal
+    v-model="showReportModal"
+    :amount="plcInfo?.finishNumber ?? 0"
+    @close="showReportModal = false"
+    @submit="onReportProduction"
+  ></ReportProductionModal>
 </template>
 <script setup lang="ts">
-import type { Task } from '@/api/task'
-import { toRefs } from 'vue'
+import type { Task, Worker } from '@/api/task'
+import { ref, toRefs } 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, finishTask } from '@/api'
+import { ElMessage } from 'element-plus'
+import ReportProductionModal from '@/views/dashboard/components/ReportProductionModal.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)
+
 /**
  * 寮�濮嬬敓浜�
  */
 function startProduce() {
-  // TODO:
-  // console.log(1)
+  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
+      }
+    }
+    finishTask({ id: task!.value.Procedure.ID }).then(
+      (res) => {
+        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)
 }
 
 /**
@@ -54,8 +139,81 @@
   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)
+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) {
+    showReportModal.value = true
+  }
+}
+
+/**
+ * 涓婃姤鍔犲伐鏁�
+ * @param amount 鍔犲伐鏁�
+ */
+function onReportProduction(amount: number) {
+  if (!task?.value) {
+    return
+  }
+  // 鏈変汉鍛樻墠鍙互鎶ュ伐
+  if (workers.value[0].workerId) {
+    apiReportWork({
+      procedureId: task.value?.Procedure.ID,
+      reportAmount: amount,
+      workerID: workers.value[0].workerId
+    })
+      .then((res) => {
+        if (res.code === 200) {
+          ElMessage({
+            message: '鎶ュ伐鎴愬姛',
+            type: 'success',
+            duration: 2000
+          })
+          showReportModal.value = false
+        } else {
+          ElMessage({
+            message: '鎶ュ伐澶辫触',
+            type: 'error',
+            duration: 3000
+          })
+        }
+      })
+      .catch((err) => {
+        console.error(err)
+      })
+  }
 }
 </script>
 <style scoped lang="scss">
@@ -67,10 +225,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 {
@@ -85,7 +245,6 @@
 
 .task-info-item {
   padding: 10px 20px;
-  margin-bottom: 6px;
 }
 .task-info-title {
   font-size: 18px;
@@ -95,7 +254,7 @@
   font-size: 19px;
   color: $content-text-color;
   font-weight: 600;
-  margin-top: 12px;
+  margin-top: 4px;
 }
 .produce-btn {
   display: flex;
@@ -115,4 +274,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