import { getuuid, justUpdateFilledFormData } from '@/utils/index.js'
|
|
import { EventBus } from '@/utils/eventBus'
|
|
import { getLatestSn, getLatestSnArr } from '@/api/template'
|
|
import { getBalance, getPh } from '@/utils/tpph.js';
|
|
export default {
|
|
inject: {
|
|
templateFillType: { default: 'preFill' },
|
|
templateData: { default: {} },
|
|
templateSn: { default: '' },
|
|
getStepData: { default: () => null },
|
|
getJcbData: { default: () => null },
|
|
getMybh: { default: () => null },
|
|
getMybhByIndex: { default: (index) => null }
|
|
},
|
|
dicts: [
|
|
'business_tjdw',
|
|
'business_czhj',
|
|
'business_rqcz',
|
|
'business_zldw',
|
|
'business_yqscdw',
|
|
'business_zsdw',
|
|
'business_wddw',
|
|
'business_ccwz',
|
|
'business_ggdw',
|
|
'business_hjxx',
|
|
'business_zzzc',
|
|
'business_step_pcr',
|
|
'business_fycx',
|
|
'business_step_pcrfxyp',
|
|
'business_cctj'
|
|
],
|
|
props: {
|
|
formData: {
|
|
type: Object,
|
|
default: () => ({})
|
|
},
|
|
stepIndex: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
formIndex: {
|
|
type: Number,
|
|
default: 0
|
|
},
|
|
formType: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
fieldItemLabel: {
|
|
type: String,
|
|
default: ''
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
uuid: getuuid(),
|
|
fzInfo: {},
|
|
localFormData: {},
|
|
}
|
|
},
|
|
mounted() {
|
|
EventBus.$on('dialogSubPackageSubmit', (data) => {
|
|
this.onSubPackageSubmit(data)
|
|
})
|
|
EventBus.$on('subPackageDialogPrintTag', (data) => {
|
|
this.onPrintTag(data)
|
|
})
|
|
},
|
|
destroyed() {
|
|
EventBus.$off('dialogSubPackageSubmit')
|
|
EventBus.$off('subPackageDialogPrintTag')
|
|
},
|
|
|
|
methods: {
|
|
//处理jcb更新
|
|
commonHandleJcbUpdate() {
|
|
this.localFormData = this.formData;
|
|
if (!this.formData.jcb && this.templateFillType === 'actFill') {
|
|
setTimeout(() => {
|
|
const qbData = this.getQbData();
|
|
this.localFormData = { ...this.localFormData, jcb: qbData };
|
|
justUpdateFilledFormData();
|
|
}, 3000);
|
|
}
|
|
},
|
|
//获取取板数据
|
|
getQbData() {
|
|
let qbData = [];
|
|
if (this.templateSn === "LBA003" || this.templateSn === "ADA003") {//只有lba003才会有取板步骤,所以检测板数据从取板数据里面获取;
|
|
const stepData = this.getStepData() || [];
|
|
const filterData = stepData.filter((item) => item.type === "qb");
|
|
const allQbData = [];
|
|
filterData.forEach((item) => {
|
|
const { stepTableFormData = [] } = item.formData.qb || {};
|
|
const parseData = JSON.parse(JSON.stringify(stepTableFormData));
|
|
allQbData.push(...parseData);
|
|
})
|
|
qbData = [...new Map(allQbData.map(item => [item.mc, item])).values()]
|
|
} else if (this.templateSn === "LBA002" || this.templateSn === "ADA002") {//lba002没有取板步骤,所以检测板数据从检测板数据里面获取;
|
|
const { stepTableFormData = [] } = this.getJcbData() || {};
|
|
qbData = stepTableFormData;
|
|
}
|
|
|
|
return { stepTableFormData: JSON.parse(JSON.stringify(qbData)) }
|
|
},
|
|
//回填编号 preField 前缀 updateField 需要更新的字段
|
|
async handleBackfillCode(preField, updateField) {
|
|
const updateValue = this.formData[updateField];
|
|
if (this.templateFillType === 'actFill' && !updateValue) {
|
|
const stepFormData = this.getFilledFormData();
|
|
const preValue = stepFormData[preField];
|
|
const result = await this.getLatestSn({
|
|
pre: preValue,
|
|
})
|
|
this.$refs.stepFormPackageRef.updateFormData(updateField, result[0])
|
|
this.justUpdateFilledFormData();
|
|
}
|
|
},
|
|
justUpdateFilledFormData() {
|
|
justUpdateFilledFormData();
|
|
},
|
|
//获取最新的多个编号
|
|
async getLatestSnArr(params) {
|
|
const res = await getLatestSnArr(params)
|
|
if (res.code === 200) {
|
|
return res.data
|
|
}
|
|
return []
|
|
},
|
|
async getLatestSn(params) {
|
|
const defaultParams = {
|
|
count: 1,
|
|
type: 1,
|
|
pre: ''
|
|
}
|
|
const finalParams = { ...defaultParams, ...params }
|
|
const res = await getLatestSn(finalParams)
|
|
if (res.code === 200) {
|
|
return res.data
|
|
}
|
|
return []
|
|
},
|
|
// 打印标签
|
|
onPrintTag(data) {
|
|
this.$emit('printTag')
|
|
},
|
|
onSubPackageSubmit(data) {
|
|
if (data.uuid === this.uuid) {
|
|
delete data.uuid //删除uuid字段,不然会导致下次匹配的时候匹配到错误的uuid
|
|
this.$refs.stepFormPackageRef.updateFormData('fzInfo', data)
|
|
this.justUpdateFilledFormData();
|
|
}
|
|
},
|
|
onBeforeSaveRecord(params) {
|
|
const { callback, item } = params
|
|
|
|
const { buttonName } = item;
|
|
if (buttonName === '获取值') {
|
|
const { dataSource, yqCode } = item;
|
|
const stepFormData = this.getFilledFormData()
|
|
if (dataSource === "tp" || dataSource === "ph") {//电子天平或PH测量仪
|
|
const yq = stepFormData[yqCode] || "";
|
|
const obj = {
|
|
tp:"请选择电子天平",
|
|
ph:"请选择PH测量仪"
|
|
}
|
|
if (!yq) {
|
|
callback.prevent(obj[dataSource])
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// 点击按钮
|
|
async onHandleClickButton(e, item, key,signData) {
|
|
const {
|
|
buttonName = '',
|
|
myCodeFields = [],
|
|
maxVolumeField = '',
|
|
maxVolumeUnitField = ''
|
|
} = e
|
|
|
|
if (buttonName === '分装') {
|
|
const stepFormData = this.getFilledFormData()
|
|
const fzInfo = stepFormData.fzInfo || this.formData.fzInfo;
|
|
let fields = [], options = []
|
|
let maxVolume, maxVolumeUnit;
|
|
if (this.getMybh || this.getMybhByIndex) {//某些表单的步骤需要分装表单上的数据
|
|
let result = {};
|
|
if (this.getMybh) {
|
|
result = this.getMybh()
|
|
} else if (this.getMybhByIndex) {
|
|
result = this.getMybhByIndex(this.formIndex, this.formType)
|
|
}
|
|
const { mybh, mybhOptions = [], maxVolume: max, maxVolumeUnit: unit } = result
|
|
// if ((!mybh && !mybhOptions.length) || !max || !unit) {
|
|
// this.$message.warning('请先填写分装数据')
|
|
// return
|
|
// }
|
|
options = mybhOptions
|
|
fields.push(mybh)
|
|
maxVolume = max || ''
|
|
maxVolumeUnit = unit || ''
|
|
} else {
|
|
if (!myCodeFields.length || !maxVolumeField || !maxVolumeUnitField) {
|
|
this.$message.warning('请配制分装参数')
|
|
return
|
|
}
|
|
maxVolume = stepFormData[maxVolumeField]
|
|
maxVolumeUnit = stepFormData[maxVolumeUnitField]
|
|
myCodeFields.forEach((key) => {
|
|
fields.push(stepFormData[key])
|
|
})
|
|
}
|
|
EventBus.$emit('showSubPackageDialog', {
|
|
mybh: fields.join(''),
|
|
id: this.stepIndex,
|
|
fzType: 'step',
|
|
...fzInfo,
|
|
maxVolume,
|
|
mybhOptions: options,
|
|
maxVolumeUnit,
|
|
uuid: this.uuid,
|
|
})
|
|
} else if (buttonName === '获取值') {
|
|
const { dataSource, dwField = "", fillField,fillDwField = "", yqCode } = e;
|
|
const stepFormData = this.getFilledFormData()
|
|
const yqInfo = stepFormData[`yqInfo_${yqCode}`] || {};
|
|
if (dataSource === "tp") {//电子天平
|
|
const dw = stepFormData[dwField] || "";
|
|
const oldValue = stepFormData[fillDwField] || "";
|
|
const result = await getBalance({ yq: yqInfo, dw });
|
|
if (result.success) {
|
|
const value = dw?result.value:`${result.value}${result.unit}`
|
|
if(fillDwField){//需要回填的单位字段
|
|
this.$refs.stepFormPackageRef.updateFormData(fillField, value)
|
|
this.$refs.stepFormPackageRef.updateFormData(fillDwField, result.unit,{isUpdateRecord:true,signData,record:{
|
|
oldValue,
|
|
inputValue:result.value+result.unit
|
|
}})
|
|
}else{
|
|
this.$refs.stepFormPackageRef.updateFormData(fillField, value,{isUpdateRecord:true,signData})
|
|
}
|
|
|
|
|
|
} else {
|
|
this.$message.error(result.message || "获取值失败");
|
|
}
|
|
|
|
}else if(dataSource === "ph"){
|
|
const result = await getPh({ yq: yqInfo });
|
|
if (result.success) {
|
|
this.$refs.stepFormPackageRef.updateFormData(fillField, result.value,{isUpdateRecord:true,signData})
|
|
} else {
|
|
this.$message.error(result.message || "获取值失败");
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
async getFormData() {
|
|
const data = await this.$refs.stepFormPackageRef.getFormData();
|
|
data.fzInfo = data.fzInfo || this.formData.fzInfo;
|
|
return data
|
|
},
|
|
getFilledFormData() {
|
|
const data = this.$refs.stepFormPackageRef?.getFilledFormData();
|
|
data.fzInfo = data.fzInfo || this.formData.fzInfo;
|
|
return data
|
|
},
|
|
getSjResource() {
|
|
const data = this.$refs.stepFormPackageRef?.getSjResource();
|
|
data.fzInfo = data.fzInfo || this.formData.fzInfo;
|
|
return data
|
|
},
|
|
//试验配制条件options
|
|
getDictOptions(dictType) {
|
|
return this.dict.type[dictType] || []
|
|
},
|
|
resetRecord() {
|
|
this.$refs.stepFormPackageRef.resetRecord()
|
|
},
|
|
//更新温层数据
|
|
updateWcData(key, value) {
|
|
const options = this.getDictOptions('business_ccwz')
|
|
const selectedOption = options.find((item) => item.value === value)
|
|
if (selectedOption) {
|
|
this.$refs.stepFormPackageRef.updateFormData(key, [
|
|
selectedOption.raw.remark
|
|
])
|
|
}
|
|
}
|
|
}
|
|
}
|