feat:样品分析计算
This commit is contained in:
9
App.vue
9
App.vue
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { onLaunch, onShow, onError } from '@dcloudio/uni-app'
|
||||
import { onLaunch, onShow, onError,onHide } from '@dcloudio/uni-app'
|
||||
|
||||
import { NxInit } from './nx'
|
||||
import $store from '@/nx/store'
|
||||
@@ -29,7 +29,12 @@ onError(err => {
|
||||
console.log('AppOnError:', err)
|
||||
})
|
||||
|
||||
onShow(() => {})
|
||||
onShow(() => {
|
||||
console.log('显示')
|
||||
})
|
||||
onHide(()=>{
|
||||
console.log('隐藏了')
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
const isDev = process.env.NODE_ENV === 'development'
|
||||
// 正式环境
|
||||
const BaseUrl = isDev ? 'http://172.17.19.29:48080/admin-api' : 'http://172.17.19.29:48080/admin-api'
|
||||
const upgradeBaseUrl = isDev? 'http://172.17.19.29:48080/admin-api':'http://172.17.19.29:48080/admin-api'
|
||||
const upgradeBaseUrl = isDev ? 'http://172.17.19.29:48080/admin-api' : 'http://172.17.19.29:48080/admin-api'
|
||||
const websocketUrl = isDev ? 'ws://172.17.19.11:30330' : 'ws://172.17.19.11:30330'
|
||||
|
||||
// 公司测试环境
|
||||
|
||||
@@ -264,7 +264,16 @@ const rollbackAssayTask = data => {
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 手动配料 post 参数与自动下发配料一致
|
||||
const manualIngredients = data => {
|
||||
return request({
|
||||
url: '/qms/bus/sample/analysis/manualIngredients',
|
||||
method: 'POST',
|
||||
data: {
|
||||
...data
|
||||
}
|
||||
})
|
||||
}
|
||||
/*
|
||||
* 查询回收率配置*/
|
||||
const queryConRecoveryRateList = param => {
|
||||
@@ -311,5 +320,6 @@ export default {
|
||||
rollbackAssayTask,
|
||||
submitTask,
|
||||
taskIngredients,
|
||||
queryQmsDicSampleProcessCodeList
|
||||
queryQmsDicSampleProcessCodeList,
|
||||
manualIngredients
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ math.config({
|
||||
export { math }
|
||||
/*
|
||||
* 计算当前样品分析值*/
|
||||
export function calcAnalysisValue(group) {
|
||||
|
||||
export function calcAnalysisValue(group, externalFormData, taskIngredientsWay) {
|
||||
const MAX_ITERATIONS = 5 // 防止无限循环
|
||||
let iterations = 0
|
||||
let changed = true
|
||||
@@ -21,7 +22,6 @@ export function calcAnalysisValue(group) {
|
||||
let formula = ele.formula
|
||||
let formulas = formula.split('|')
|
||||
let formulaVal = ''
|
||||
console.log(formulas)
|
||||
formulas.forEach(f => {
|
||||
let value = ''
|
||||
if (f.charAt(0) === 'p') {
|
||||
@@ -38,18 +38,18 @@ export function calcAnalysisValue(group) {
|
||||
|
||||
formulaVal += value
|
||||
})
|
||||
console.log(formulaVal)
|
||||
|
||||
let v
|
||||
if (formulaVal.startsWith('Get')) {
|
||||
//计算公式为Get开头的,都是执行方法
|
||||
let v = ''
|
||||
if (formulaVal.startsWith('Get_')) {
|
||||
//计算公式为Get开头的,都是执行方法,只有人工配料才执行
|
||||
if (taskIngredientsWay !== 'manual') continue
|
||||
v = eval(formulaVal)
|
||||
} else if (formulaVal.startsWith('GetFrom')) {
|
||||
v = evaluateGetFromFormula(formulaVal, false, externalFormData)
|
||||
} else {
|
||||
v = math.evaluate(formulaVal).toString()
|
||||
v = isFinite(v) ? v.toString() : 0
|
||||
}
|
||||
console.log(v)
|
||||
|
||||
ele.value = handleRoundFiveNumber(v, ele.decimalPosition)
|
||||
changed = true
|
||||
}
|
||||
@@ -60,9 +60,54 @@ export function calcAnalysisValue(group) {
|
||||
}
|
||||
}
|
||||
|
||||
// parse: 是否解析公式
|
||||
export function evaluateGetFromFormula(formula, parse, externalFormData, currentColumn, row, dynamicsColumns) {
|
||||
let formulaVal = formula
|
||||
if (parse) {
|
||||
formulaVal = parseFormula(formulaVal, row, dynamicsColumns)
|
||||
}
|
||||
let relFormulaVal = formulaVal.split(':')[1]
|
||||
for (const [key, value] of Object.entries(externalFormData)) {
|
||||
if (relFormulaVal.includes(key)) {
|
||||
relFormulaVal = relFormulaVal.replace(key, value || 0)
|
||||
}
|
||||
}
|
||||
console.log(relFormulaVal)
|
||||
|
||||
try {
|
||||
let v = math.evaluate(relFormulaVal)
|
||||
v = isFinite(v) ? v : 0
|
||||
if (parse) {
|
||||
return handleRoundFiveNumber(v, currentColumn.decimalPosition)
|
||||
}
|
||||
return v
|
||||
} catch (e) {
|
||||
console.warn('GetFrom formula evaluate error:', relFormulaVal, e)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
// 解析公式
|
||||
function parseFormula(formula, row, dynamicsColumns) {
|
||||
let formulas = formula.split('|')
|
||||
let formulaVal = ''
|
||||
formulas.forEach(f => {
|
||||
if (f.charAt(0) === 'p') {
|
||||
let o = dynamicsColumns.find(i => 'p' + i.paramNo === f && i.type !== 'project')
|
||||
const currentColumnData = row[o.fieldIndex]
|
||||
formulaVal += currentColumnData.value ? currentColumnData.value : 0
|
||||
} else if (f.charAt(0) === 'e') {
|
||||
let o = dynamicsColumns.find(i => 'e' + i.paramNo === f)
|
||||
formulaVal += row[o.fieldIndex]?.value ? row[o.fieldIndex].value : 0
|
||||
} else {
|
||||
formulaVal += f
|
||||
}
|
||||
})
|
||||
return formulaVal
|
||||
}
|
||||
// 根据样品和配置列计算分析值
|
||||
export function calcRowAnalysisValue(row, columnObj, dynamicsColumns) {
|
||||
export function calcRowAnalysisValue(row, columnObj, dynamicsColumns, externalFormData, taskIngredientsWay) {
|
||||
if (!columnObj.paramNo || !row[columnObj.fieldIndex]) return
|
||||
|
||||
for (let i = 0; i < dynamicsColumns.length; i++) {
|
||||
let curItem = dynamicsColumns[i]
|
||||
if (curItem.fieldIndex === columnObj.fieldIndex) continue
|
||||
@@ -70,30 +115,19 @@ export function calcRowAnalysisValue(row, columnObj, dynamicsColumns) {
|
||||
let param = columnObj.fieldIndex.charAt(0) === 'p' ? 'p' + columnObj.paramNo : 'e' + columnObj.paramNo
|
||||
if (curItem.formula && curItem.formula.includes(param)) {
|
||||
let formula = curItem.formula
|
||||
let formulas = formula.split('|')
|
||||
let formulaVal = ''
|
||||
formulas.forEach(f => {
|
||||
if (f.charAt(0) === 'p') {
|
||||
let o = dynamicsColumns.find(i => 'p' + i.paramNo === f && i.type !== 'project')
|
||||
formulaVal += row[o.fieldIndex]?.value ? row[o.fieldIndex].value : 0
|
||||
} else if (f.charAt(0) === 'e') {
|
||||
let o = dynamicsColumns.find(i => 'e' + i.paramNo === f)
|
||||
formulaVal += row[o.fieldIndex]?.value ? row[o.fieldIndex].value : 0
|
||||
} else {
|
||||
formulaVal += f
|
||||
}
|
||||
})
|
||||
let formulaVal = parseFormula(formula, row, dynamicsColumns)
|
||||
let v
|
||||
if (formulaVal.startsWith('Get')) {
|
||||
formulaVal = formulaVal.replace(')', ",'" + row.conBaseSampleId + "')")
|
||||
if (formulaVal.startsWith('Get_')) {
|
||||
if (taskIngredientsWay !== 'manual') continue
|
||||
v = eval(formulaVal)
|
||||
} else if (formulaVal.startsWith('GetFrom')) {
|
||||
v = evaluateGetFromFormula(formulaVal, false, externalFormData)
|
||||
} else {
|
||||
v = math.evaluate(formulaVal).toString()
|
||||
v = isFinite(v) ? v : 0
|
||||
}
|
||||
|
||||
row[curItem.fieldIndex].value = handleRoundFiveNumber(Number(v), row[curItem.fieldIndex].decimalPosition)
|
||||
calcRowAnalysisValue(row, curItem, dynamicsColumns)
|
||||
calcRowAnalysisValue(row, curItem, dynamicsColumns, externalFormData)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,6 +196,27 @@ const Get_C_KNO3_bySValue = function (sValue, weight, operator) {
|
||||
|
||||
return ''
|
||||
}
|
||||
function Get_C_KNO3(sValue, weight, operator) {
|
||||
//判断sValue是数字
|
||||
|
||||
if (sValue === 0 || weight === 0) {
|
||||
return ''
|
||||
}
|
||||
let S = number(sValue)
|
||||
const W = number(weight)
|
||||
if (W === 0) return ''
|
||||
const V = ((W * S) / 100) * 22 - 75
|
||||
if (operator === '<' && V < 0) {
|
||||
console.log(math.abs(V / 12))
|
||||
|
||||
return math.abs(V / 12)
|
||||
}
|
||||
if (operator === '>=' && V >= 0) {
|
||||
console.log(V / 4)
|
||||
return V / 4
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 处理数值数据:四舍六入奇进偶不进
|
||||
* 1,如果取小数的最后一位为5,5前为奇数进位,为偶不进,五后非零就进一,五后皆零看奇偶,五前为偶应舍去,五前为奇要进一
|
||||
|
||||
@@ -66,21 +66,25 @@
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<u-button
|
||||
v-if="taskIngredientsStatus === 'allow_submit' || taskIsIngredients == '0'"
|
||||
class="btn-operation"
|
||||
type="primary"
|
||||
@click="submitTask()"
|
||||
>数据上报</u-button
|
||||
>
|
||||
<u-button
|
||||
v-else
|
||||
class="btn-operation"
|
||||
type="primary"
|
||||
:disabled="taskIngredientsStatus === 'in_progress'"
|
||||
@click="handleIngredients()"
|
||||
>{{ taskIngredientsStatus === 'initial' ? '下发配料' : '等待配料' }}</u-button
|
||||
>
|
||||
<view v-if="taskIsIngredients == 1" class="x-f">
|
||||
<template v-if="taskIngredientsWay === 'initial'">
|
||||
<u-button class="btn-operation mr10" type="primary" @click="handleIngredients()">自动配料</u-button>
|
||||
<u-button class="btn-operation ml10" type="primary" @click="handleManualIngredients()">人工配料</u-button>
|
||||
</template>
|
||||
<template v-else-if="taskIngredientsWay == 'automatic'">
|
||||
<u-button
|
||||
v-if="taskIngredientsStatus === 'allow_submit'"
|
||||
class="btn-operation"
|
||||
type="primary"
|
||||
@click="submitTask()"
|
||||
>数据上报</u-button
|
||||
>
|
||||
<u-button v-else class="btn-operation" type="primary" :disabled="taskIngredientsStatus === 'in_progress'"
|
||||
>等待配料</u-button
|
||||
>
|
||||
</template>
|
||||
</view>
|
||||
<u-button v-else class="btn-operation" type="primary" @click="submitTask()">数据上报</u-button>
|
||||
</u-col>
|
||||
<u-col span="6">
|
||||
<view class="x-bc">
|
||||
@@ -269,6 +273,7 @@ import {
|
||||
calcAnalysisValue,
|
||||
handleRoundFiveNumber,
|
||||
calcRowAnalysisValue,
|
||||
evaluateGetFromFormula,
|
||||
math,
|
||||
groupByField,
|
||||
validateElementRange
|
||||
@@ -287,6 +292,7 @@ const { proxy } = getCurrentInstance()
|
||||
const taskId = ref('')
|
||||
const taskIngredientsStatus = ref('') //配料状态
|
||||
const taskIsIngredients = ref('')
|
||||
const taskIngredientsWay = ref('')
|
||||
const configReportTemplateKey = ref('')
|
||||
const elId = nx.$helper.uuid()
|
||||
const scrollTop = ref(0) //tab标题的滚动条位置
|
||||
@@ -685,7 +691,7 @@ const saveAuncelData = () => {
|
||||
syncFieldValueByEqualParamNo()
|
||||
//计算
|
||||
try {
|
||||
calcAnalysisValue(fieldGroup.value)
|
||||
calcAnalysisValue(fieldGroup.value, dynamicFormData, taskIngredientsWay.value)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
@@ -767,7 +773,7 @@ function updateTableDataByConfigFields() {
|
||||
const columnObj = tab.columns.find(c => {
|
||||
if (c.formula) {
|
||||
let FromKey = c.formula.split(':')
|
||||
return FromKey[1] === key
|
||||
return FromKey[1] === key || FromKey[0] === 'GetFrom'
|
||||
}
|
||||
return false
|
||||
})
|
||||
@@ -775,9 +781,21 @@ function updateTableDataByConfigFields() {
|
||||
tab.tableData.forEach(row => {
|
||||
// 赋值配置列参与计算
|
||||
if (row[columnObj.fieldIndex]) {
|
||||
row[columnObj.fieldIndex].value = dynamicFormData[key]
|
||||
calcRowAnalysisValue(row, columnObj, tab.columns)
|
||||
if (columnObj.formula.startsWith('From')) {
|
||||
row[columnObj.fieldIndex].value = dynamicFormData[key]
|
||||
}
|
||||
if (columnObj.formula.startsWith('GetFrom')) {
|
||||
row[columnObj.fieldIndex].value = evaluateGetFromFormula(
|
||||
columnObj.formula,
|
||||
true,
|
||||
dynamicFormData,
|
||||
columnObj,
|
||||
row,
|
||||
tab.columns
|
||||
)
|
||||
}
|
||||
}
|
||||
calcRowAnalysisValue(row, columnObj, tab.columns, dynamicFormData, taskIngredientsWay.value)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -935,11 +953,13 @@ async function getSampleAnalysisByTaskId() {
|
||||
businessAssayTasNo,
|
||||
formValue,
|
||||
ingredientsStatus,
|
||||
isIngredients
|
||||
isIngredients,
|
||||
ingredientsWay
|
||||
} = await nx.$api.assayTask.batchSampleAndQcAnalysisByTaskId(taskId.value)
|
||||
title.value = '样品分析-任务单编号:' + businessAssayTasNo
|
||||
taskIngredientsStatus.value = ingredientsStatus
|
||||
taskIsIngredients.value = isIngredients
|
||||
taskIngredientsWay.value = ingredientsWay
|
||||
// 处理分析数据
|
||||
assayGroups.value = assayTaskAnalysisDataList.map(group => {
|
||||
// 必须深拷贝 datas!防止多个表格共享引用
|
||||
@@ -1142,7 +1162,7 @@ const listenNumKeyboard = () => {
|
||||
selectedField.value.symbol = symbol
|
||||
}
|
||||
syncFieldValueByEqualParamNo()
|
||||
calcAnalysisValue(fieldGroup.value)
|
||||
calcAnalysisValue(fieldGroup.value, dynamicFormData, taskIngredientsWay.value)
|
||||
//自动跳转下一个字段
|
||||
setTimeout(() => {
|
||||
autoNextField()
|
||||
@@ -1171,7 +1191,7 @@ const clearFieldVal = () => {
|
||||
}
|
||||
selectedField.value.value = ''
|
||||
//重新计算
|
||||
calcAnalysisValue(fieldGroup.value)
|
||||
calcAnalysisValue(fieldGroup.value, dynamicFormData, taskIngredientsWay.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1222,7 +1242,7 @@ const submitTask = () => {
|
||||
const url = `/pages/analysis/sample/pdf-preview?businessAssayTaskId=${taskId.value}&reportKey=${configReportTemplateKey.value}&showConfirmBtn=true`
|
||||
uni.navigateTo({ url })
|
||||
}
|
||||
// 配料下发
|
||||
// 自动配料
|
||||
function handleIngredients() {
|
||||
if (checkSampleReturning()) return
|
||||
const params = {
|
||||
@@ -1232,6 +1252,16 @@ function handleIngredients() {
|
||||
getSampleAnalysisByTaskId()
|
||||
})
|
||||
}
|
||||
// 人工配料
|
||||
function handleManualIngredients() {
|
||||
const params = {
|
||||
businessAssayTaskId: taskId.value
|
||||
}
|
||||
nx.$api.assayTask.manualIngredients(params).then(res => {
|
||||
getSampleAnalysisByTaskId()
|
||||
})
|
||||
}
|
||||
//
|
||||
function checkSampleReturning() {
|
||||
const analysisSampleData = assayGroups.value.find(t => t.value == 'analysis').tableData
|
||||
const hasReturning = analysisSampleData.some(item => item.rollbackStatus === 'in_progress')
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import nx from '@/nx'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { calcRowAnalysisValue } from '@/nx/helper/calcAnalysisValue'
|
||||
import { calcRowAnalysisValue, evaluateGetFromFormula } from '@/nx/helper/calcAnalysisValue'
|
||||
import tools from '@/nx/utils/tools'
|
||||
|
||||
const pageLoading = ref(false)
|
||||
@@ -161,15 +161,14 @@ async function loadTaskDetail() {
|
||||
fieldKey: item.fieldKey,
|
||||
type: item.fieldType,
|
||||
placeholder: '请输入',
|
||||
hidden:false
|
||||
|
||||
hidden: false
|
||||
}
|
||||
if (customConfig?.componentProps?.options) {
|
||||
field.options = customConfig.componentProps.options
|
||||
}
|
||||
if(customConfig.hidden){
|
||||
field.hidden = true
|
||||
}
|
||||
if (customConfig.hidden) {
|
||||
field.hidden = true
|
||||
}
|
||||
return field
|
||||
})
|
||||
formFields.value = [...staticFormSchema, ...dynamicFormSchema]
|
||||
@@ -208,7 +207,7 @@ async function updateTableDataByConfigFields() {
|
||||
const columnObj = tab.columns.find(c => {
|
||||
if (c.formula) {
|
||||
let FromKey = c.formula.split(':')
|
||||
return FromKey[1] === key
|
||||
return FromKey[1] === key || FromKey[0] === 'GetFrom'
|
||||
}
|
||||
return false
|
||||
})
|
||||
@@ -216,9 +215,21 @@ async function updateTableDataByConfigFields() {
|
||||
tab.tableData.forEach(row => {
|
||||
// 赋值配置列参与计算
|
||||
if (row[columnObj.fieldIndex]) {
|
||||
row[columnObj.fieldIndex].value = formData[key]
|
||||
calcRowAnalysisValue(row, columnObj, tab.columns)
|
||||
if (columnObj.formula.startsWith('From')) {
|
||||
row[columnObj.fieldIndex].value = dynamicFormData[key]
|
||||
}
|
||||
if (columnObj.formula.startsWith('GetFrom')) {
|
||||
row[columnObj.fieldIndex].value = evaluateGetFromFormula(
|
||||
columnObj.formula,
|
||||
true,
|
||||
realFormData.value,
|
||||
columnObj,
|
||||
row,
|
||||
tab.columns
|
||||
)
|
||||
}
|
||||
}
|
||||
calcRowAnalysisValue(row, columnObj, tab.columns, realFormData.value)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -320,11 +331,14 @@ function checkPropertyEquality() {
|
||||
for (const column of allColumns) {
|
||||
const formula = column.formula
|
||||
if (!formula) continue
|
||||
const target = formula.split(':')[1]
|
||||
const originalValue = dynamicFormData.value[target]
|
||||
const currentValue = realFormData.value[target]
|
||||
if (!looseEqual(originalValue, currentValue)) {
|
||||
return true
|
||||
for (const [key, value] of Object.entries(dynamicFormData.value)) {
|
||||
if (formula.includes(key)) {
|
||||
const originalValue = value
|
||||
const currentValue = realFormData.value[key]
|
||||
if (!looseEqual(originalValue, currentValue)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user