diff --git a/src/components/craft/AddCraft/index.vue b/src/components/craft/AddCraft/index.vue index c6e197a..c0344fc 100644 --- a/src/components/craft/AddCraft/index.vue +++ b/src/components/craft/AddCraft/index.vue @@ -5,6 +5,7 @@ import { getSolsList } from 'apis/solution' import emptyIcon from 'assets/images/empty.svg' import { FtMessage } from 'libs/message' import { allPropertiesDefined } from 'libs/utils' +import { cloneDeep } from 'lodash' import { onMounted, ref } from 'vue' import { useRoute } from 'vue-router' @@ -34,6 +35,10 @@ onMounted(async () => { step.params.minutes = Math.floor(step.params.second / 60) step.params.seconds = step.params.second % 60 } + if (step.params.coolingSecond) { + step.params.coolingMinutes = Math.floor(step.params.coolingSecond / 60) + step.params.coolingSeconds = step.params.coolingSecond % 60 + } }) } loading.value = false @@ -64,15 +69,19 @@ const okHandle = async () => { } // 找到第一个参数不完整的步骤 const invalidStepIndex = form.value.stepList?.findIndex( - (step: any) => { + (step: any, index) => { if (['startHeating', 'shaking'].includes(step.method)) { if (step.params.minutes || step.params.seconds) { step.params.second = (step.params.minutes || 0) * 60 + (step.params.seconds || 0) || undefined } + if (step.params.coolingMinutes || step.params.coolingSeconds) { + step.params.coolingSecond = (step.params.coolingMinutes || 0) * 60 + (step.params.coolingSeconds || 0) || undefined + } } + step.params.description = `${index + 1}.` switch (step.method) { case 'addLiquid': - step.params.description = step.params.addLiquidList.map((liquid: { containerId: number, volume: number }) => `添加${solutionList.value.find(s => s.id === containerList.value.find(c => c.id === liquid.containerId)?.solutionId)?.name}-${liquid.volume}ml `).join(';') + step.params.description = '添加溶液' break case 'startHeating': step.params.description = `加热: ${step.params.temperature}度, 保持${step.params.minutes || 0}分${step.params.seconds || 0}秒` @@ -115,7 +124,7 @@ const cancel = () => { } const stepMap: Record = { - addLiquid: { name: '加液', method: 'addLiquid', params: { addLiquidList: [{ containerId: undefined, volume: undefined }], description: undefined } }, + // addLiquid: { name: '加液', method: 'addLiquid', params: { addLiquidList: [{ containerId: undefined, volume: undefined }], description: undefined } }, startHeating: { name: '加热', method: 'startHeating', params: { temperature: undefined, second: undefined, description: undefined, minutes: undefined, seconds: undefined } }, shaking: { name: '摇匀', method: 'shaking', params: { second: undefined } }, takePhoto: { name: '拍照', method: 'takePhoto', params: { } }, @@ -124,13 +133,93 @@ const stepMap: Record = { const addStep = (data: CraftTypes.StepItem) => { form.value.stepList?.push(data) } + +const addLiquidForm = ref({ + tubeNums: [], + solutionList: [ + { + solutionId: undefined, + volume: undefined, + offset: undefined, + }, + ], +}) +const addLiquidRules = { + tubeNums: [ + { required: true, message: '请选择试管', trigger: 'change' }, + ], +} + +const addLiquidFormRef = ref() + +const activeTube = ref(Array.from({ length: 16 }).fill(false)) + +const selectVisible = ref(false) +const checkChange = () => { + activeTube.value = Array.from({ length: 16 }).fill(selectVisible.value) + addLiquidForm.value.tubeNums = activeTube.value.map((item, index) => index + 1).filter(item => activeTube.value[item - 1]) + addLiquidFormRef.value.validateField('tubeNums') +} + +const mousedownHandle = async (e: Event) => { + let event + if ('touches' in e) { + event = (e.touches as TouchList)[0] + } + else { + event = e + } + if (event.target!.classList!.contains('tube-inner')) { + const num = event.target!.getAttribute('index') + activeTube.value[Number(num) - 1] = !activeTube.value[Number(num) - 1] + addLiquidForm.value.tubeNums = activeTube.value.map((item, index) => index + 1).filter(item => activeTube.value[item - 1]) + } +} + +const addHandle = async () => { + try { + const valid = await addLiquidFormRef.value.validate() + if (!valid) { + return + } + console.log(addLiquidForm.value) + // addList.value!.push(addLiquidForm) + const index = form.value.stepList?.findIndex(item => item.method === 'addLiquid') + if (index !== -1) { + form.value.stepList?.[index || 0].params?.push(cloneDeep(addLiquidForm.value)) + } + else { + form.value.stepList?.push({ + name: '加液', + method: 'addLiquid', + params: [cloneDeep(addLiquidForm.value)], + } as CraftTypes.StepItem) + } + addLiquidForm.value = { + tubeNums: [], + solutionList: [ + { + solutionId: undefined, + volume: undefined, + offset: undefined, + }, + ], + } + activeTube.value = Array.from({ length: 16 }).fill(false) + selectVisible.value = false + addLiquidFormRef.value.resetFields() + } + catch (error) { + console.log(error) + } +}