haoxuan
2023-10-31 70ca3fe1992a1c7a4a5ba0e6f7f8fbc979462a4b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<template>
  <div class="task-control-modal">
    <BaseModal v-model="modelData" :wider="false">
      <template #title>新任务</template>
      <div class="modal-content">
        <div v-if="!messageError" class="content-title">
          <div class="content-title-item">当前任务:{{ task?.Procedure.procedure.procedureName || '' }}</div>
          <div class="content-title-item">
            生产数量:
            <div class="leaf-shape box">
              {{ task?.Order?.amount || 0 }}
            </div>
          </div>
        </div>
 
        <div v-if="!!messageError" class="content-tips">
          <div class="error-t">
            <span v-if="messageError === '下发成功!'" class="el-icon-success color_success"></span>
            <span v-else class="el-icon-error color_error"></span>
          </div>
          <div class="error-m">
            {{ messageError }}
          </div>
          <div class="font_size_20 color_fff" style="text-align: center; width: 100%; margin: 10px 0">
            <span v-if="messageError === '下发成功!'" style="font-size: 30px"></span>
            <span v-else>请重试</span>
          </div>
        </div>
 
        <div v-else class="content-scroll">
          <div class="scroll-container">
            <el-scrollbar always class="scroller">
              <template v-if="task">
                <div class="info">
                  <div class="info-item">订单编号:{{ task.Order.orderId || '' }}</div>
                  <div class="info-item">工单编号:{{ task.Order.workOrderId || '' }}</div>
                  <div class="info-item">产品名称:{{ task.Order.productName || '' }}</div>
                  <div class="info-item">数量:{{ task.Order.amount || 0 }}{{ task.Order.unit }}</div>
                  <div class="info-item">交货日期:{{ task.Order.deliverDate || '' }}</div>
                  <div class="info-item">工时: {{ task.Procedure.procedure.workHours || '' }}</div>
                  <div class="info-item">
                    计划时间: {{ formatDate(task.Procedure.startTime) || '' }}
                    -
                    {{ formatDate(task.Procedure.endTime) }}
                  </div>
 
                  <div class="info-item">客户名称:{{ task.Order.customer || '' }}</div>
                  <div class="info-item info-item-two">通道: {{ CHANNEL_NAME_MAP[task.Channel] || '' }}</div>
 
                  <div class="info-item info-item-two">参数要求:{{ task.Order.parameter || '' }}</div>
 
                  <div class="info-item-two">
                    <div style="color: #4efefa; font-size: 18px; margin-bottom: 10px; margin-top: 20px">工艺参数</div>
                    <div v-for="(item, index) in craftParams" :key="index" class="info-item info-item-two">
                      {{ item.Key }}:{{ item.Value || '' }}
                    </div>
                  </div>
                </div>
 
                <div class="title-auto-box"></div>
                <div v-if="getCraftParamsErrMsg" class="process-err-tip">
                  <div class="tip-icon">
                    <span class="el-icon-error color_error"></span>
                  </div>
                  <div class="tip-content">提示: {{ getCraftParamsErrMsg }}</div>
                </div>
 
                <div v-if="countdown30s.countdownStatus.value === 'running'" class="countdown">
                  {{ countdown30s.formattedTime.value }}
                </div>
 
                <!--              <div v-if="showBtn === 2 || showBtn === 3" class="process-box">-->
                <!--                <div-->
                <!--                  style="-->
                <!--                    color: red;-->
                <!--                    font-size: 26px;-->
                <!--                    width: 100%;-->
                <!--                    text-align: center;-->
                <!--                    margin-bottom: 15px;-->
                <!--                    line-height: 35px;-->
                <!--                  "-->
                <!--                  :class="showBtn === 3 && isLoading ? 'margin-top-10px' : 'margin-top-40px'"-->
                <!--                >-->
                <!--                  <div v-if="showBtn === 2 || (showBtn === 3 && !isLoading)" class="gif-box">-->
                <!--                    <template v-if="showBtn === 2">-->
                <!--                      <div class="gif">-->
                <!--                        <img src="../../public/shan.gif" />-->
                <!--                      </div>-->
                <!--                    </template>-->
                <!--                    <template v-if="showBtn === 3 && !isLoading">-->
                <!--                      <div class="gif">-->
                <!--                        <span class="yuandian"></span>-->
                <!--                      </div>-->
                <!--                    </template>-->
                <!--                    <div class="gif-right">-->
                <!--                      <div>-&#45;&#45;&#45;&#45; 剩余时间 -&#45;&#45;&#45;&#45;</div>-->
                <!--                      <div>-->
                <!--                        <span>00:{{ countdown30s.formattedTime }}</span>-->
                <!--                      </div>-->
                <!--                    </div>-->
                <!--                  </div>-->
                <!--                  {{ message }}-->
                <!--                </div>-->
                <!--                <template v-if="showBtn === 3 && isLoading">-->
                <!--                  <div class="progress-item">-->
                <!--                    <span>{{ (+num / 30) * 100 }}%</span>-->
                <!--                    <el-progress-->
                <!--                      style="width: calc(100% - 50px); float: right"-->
                <!--                      define-back-color="#CDC6C6"-->
                <!--                      color="#00cc66"-->
                <!--                      text-color="#fff"-->
                <!--                      :text-inside="true"-->
                <!--                      :stroke-width="20"-->
                <!--                      :percentage="(+num / 30) * 100"-->
                <!--                    ></el-progress>-->
                <!--                  </div>-->
                <!--                </template>-->
                <!--              </div>-->
              </template>
            </el-scrollbar>
          </div>
        </div>
      </div>
      <template #footer>
        <div class="btn">
          <BigButton bg-color="#4765c0" @click="closeModal">暂缓生产</BigButton>
          <BigButton
            v-if="countdown30s.countdownStatus.value !== 'complete'"
            color="#0d0d0d"
            :disabled="countdown30s.countdownStatus.value === 'running'"
            @click="startCountdown30s"
          >
            生产准备
          </BigButton>
          <BigButton v-if="countdown30s.countdownStatus.value === 'complete'" bg-color="#4efefa" @click="startProduce">
            开始生产
          </BigButton>
        </div>
      </template>
    </BaseModal>
  </div>
</template>
<script setup lang="ts">
import type { CraftParam, Task } from '@/api/task'
import { useDateFormat, useVModel } from '@vueuse/core'
import { computed, ref, toRefs, watch } from 'vue'
import BigButton from '@/views/dashboard/components/BigButton.vue'
import { CHANNEL_NAME_MAP } from '@/common/constants'
import { getCraftParams, sendProcessParams } from '@/api'
import { useCountDown } from '@/common/composable'
import { storeToRefs } from 'pinia'
import { useTasksStore } from '@/stores/tasks'
 
export interface TaskControlModalProps {
  task?: Task
  /** 是否展示模态框 */
  modelValue: boolean
}
const props = withDefaults(defineProps<TaskControlModalProps>(), {
  task: undefined,
  modelValue: false
})
const emit = defineEmits<{
  'update:modelValue': [show: boolean]
}>()
 
const modelData = useVModel(props, 'modelValue', emit)
function closeModal() {
  modelData.value = false
}
const { task } = toRefs(props)
 
const messageError = ref('')
 
/**
 * 格式化时间戳
 * @param timestamp 后端返的10位时间戳
 */
function formatDate(timestamp?: number) {
  if (!timestamp) {
    return '--'
  }
  const time = useDateFormat(timestamp * 1000, 'YYYY-MM-DD', { locales: 'zh-cn' })
  return time.value
}
 
// 工艺参数
const craftParams = ref<CraftParam[]>()
// 获取工艺参数失败信息
const getCraftParamsErrMsg = ref('')
 
/**
 * 获取当前展示的任务的工艺参数
 */
function getTaskProduceParams(taskId?: number) {
  if (taskId) {
    craftParams.value = []
    getCraftParamsErrMsg.value = ''
    getCraftParams({ id: taskId }).then(
      (res) => {
        craftParams.value = res.data.Params ?? []
        getCraftParamsErrMsg.value = ''
        // TODO: 处理各个按钮显隐
        // this.getInfo()
        console.log('processParams', craftParams.value)
      },
      (err) => {
        console.error(err)
        craftParams.value = []
        getCraftParamsErrMsg.value = '获取工艺参数失败!'
      }
    )
  }
}
 
watch(modelData, () => {
  // 弹窗显示时获取工艺参数
  if (modelData.value) {
    getTaskProduceParams(task?.value?.Procedure?.ID)
  }
})
 
const countdown30s = useCountDown(3)
 
function startCountdown30s() {
  countdown30s.startCountdown()
}
 
/**
 * 下发工艺参数
 */
function startProduce() {
  if (task.value?.Procedure?.ID) {
    message.value = '工艺参数下发中...'
 
    isLoading.value = true
    sendProcessParams({
      procedureId: task.value.Procedure.ID
    })
      .then(
        (res) => {
          console.log(res)
          messageError.value = '下发成功'
        },
        (err) => {
          console.error(err)
          messageError.value = err.msg ? err.msg : '抱歉,工序下发失败!'
        }
      )
      .finally(() => {
        isLoading.value = false
      })
  }
}
 
const { channels } = storeToRefs(useTasksStore())
const safeProduce = computed(() => {
  if (task?.value?.Channel) {
    return channels?.value?.[task.value.Channel]?.Prompt?.safeProduce
  }
  return ''
})
const message = ref(safeProduce.value)
const isLoading = ref(false)
</script>
<style scoped lang="scss">
.modal-content {
  height: 550px;
}
.content-scroll {
  height: 400px;
  overflow: hidden;
}
:deep(.el-dialog__body) {
  padding: 0 20px;
}
.btn {
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.content-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 40px;
}
.content-title-item {
  width: 50%;
  font-size: 20px;
  color: #4efefa;
}
 
.leaf-shape {
  position: relative;
  display: inline-block;
  width: 140px;
  height: 46px;
  border-radius: 23px 0 23px 0;
  text-align: center;
  line-height: 46px;
  color: #fff;
  background: url('/leaf-shape.png') no-repeat center center / cover;
}
.scroll-container {
  margin: 0 auto;
  padding: 10px 20px;
  width: calc(100% - 40px);
  height: 400px;
}
.info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  background-color: #0e246a;
  padding: 10px 20px;
}
.info-item {
  width: 50%;
  height: 35px;
  line-height: 35px;
  font-size: 16px;
  color: #fff;
}
.info-item-two {
  width: 100%;
}
</style>