fix: 给药bug处理

This commit is contained in:
GranceWang 2024-08-15 18:38:49 +08:00
parent b10dc89005
commit 5983e407d1

View File

@ -117,7 +117,7 @@
<Plus/> <Plus/>
</el-icon> </el-icon>
</el-button> </el-button>
<el-button size="small" color="#006080" :disabled="scope.row.speed <= 0 || !whetherControl" <el-button size="small" color="#006080" :disabled="!whetherControl"
@click="tableItemMinus(scope)"> @click="tableItemMinus(scope)">
<el-icon> <el-icon>
<Minus/> <Minus/>
@ -155,7 +155,7 @@
<Plus/> <Plus/>
</el-icon> </el-icon>
</el-button> </el-button>
<el-button size="small" color="#006080" :disabled="scope.row.speed <= 0 || !whetherControl" <el-button size="small" color="#006080" :disabled="!whetherControl"
@click="tableItemMinus(scope)"> @click="tableItemMinus(scope)">
<el-icon> <el-icon>
<Minus/> <Minus/>
@ -192,6 +192,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import {h} from 'vue';
import _ from 'lodash';
import {computed, onMounted, onUnmounted, reactive, ref, watch} from 'vue'; import {computed, onMounted, onUnmounted, reactive, ref, watch} from 'vue';
import {useRouter} from 'vue-router' import {useRouter} from 'vue-router'
import {ElMessage,ElMessageBox} from 'element-plus'; import {ElMessage,ElMessageBox} from 'element-plus';
@ -632,31 +634,42 @@ function msgLogScrollBottom() {
const tableItemPlus = (e: any) => { const tableItemPlus = (e: any) => {
const obj = medicineCustom.find(item => item.name === e.row.medicineName) || {plus: 1}; const obj = medicineCustom.find(item => item.name === e.row.medicineName) || {plus: 1};
if ((e.row.medicineRate + e.row.change) >=obj.total) { const medicineRate= e.row.medicineRate
e.row.change =obj.total - e.row.medicineRate const currTotal=_.add(Number(medicineRate),Number(e.row.change))
if (currTotal >=obj.total) {
e.row.change =_.subtract(obj.total , medicineRate)
return return
}; };
let rate= Number(e.row.change); const currRate= Number(e.row.change);
if (isNaN(rate)) { if (isNaN(currRate)) {
return return
} }
rate += obj.plus; const rate=_.add(Number(currRate), Number(obj.plus));
e.row.change = rate.toFixed(2); e.row.change =_.floor(rate,2)
} }
const tableItemMinus = (e: any) => { const tableItemMinus = (e: any) => {
const obj = medicineCustom.find(item => item.name === e.row.medicineName) || {plus: 1}; const obj = medicineCustom.find(item => item.name === e.row.medicineName) || {plus: 1};
if (!isAIDose.value && e.row.medicineRate + e.row.change - obj.plus <= 0) return; const medicineRate= e.row.medicineRate;
e.row.change -= obj.plus; const change=e.row.change;
const nowTotal=_.subtract(Number(medicineRate) ,Number(change))
const res=_.subtract(obj.total,nowTotal)
if (res <= 0) return;
e.row.change = _.subtract(change,obj.plus)
if (e.row.change < 0) e.row.change = 0; if (e.row.change < 0) e.row.change = 0;
else e.row.change = Number(e.row.change).toFixed(2); else e.row.change = _.floor(e.row.change,2)
} }
const tableItemConfirm = (e: any, tableData: any) => { const tableItemConfirm = (e: any, tableData: any) => {
const finalRate=_.add(Number(e.row.medicineRate),Number(e.row.change))
ElMessageBox.confirm('确定给药吗?', '确认提示', { ElMessageBox.confirm('确定给药吗?', '确认提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
message: h('p', null, [
h('span', null, '确定给药吗?'),
h('div', { style: 'font-size:14px;color:#085a75' }, `药物名称:${e.row.medicineName}`),
h('div', { style: 'font-size:14px;color:#085a75' }, `速率:${finalRate}`),
]),
}) })
.then(() => { .then(() => {
// //
@ -668,7 +681,7 @@ const tableItemConfirm = (e: any, tableData: any) => {
date: currentRemote.value.date, date: currentRemote.value.date,
flag: "1", flag: "1",
medicine: e.row.medicineName, medicine: e.row.medicineName,
value: Number(e.row.medicineRate)+Number(e.row.change), value: _.add(Number(e.row.medicineRate),Number(e.row.change)),
index: currentRemote.value.index index: currentRemote.value.index
} }
remoteWsStore.sendMedicine(params, function () { remoteWsStore.sendMedicine(params, function () {