|
|
- import { getuuid, justUpdateFilledFormData } from '@/utils/index.js'
- import { EventBus } from '@/utils/eventBus'
- import { getLatestSn, getLatestSnArr } from '@/api/template'
- export default {
- inject: {
- templateFillType: { default: 'preFill' },
- 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: ''
- },
- formType: {
- 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') {
- const qbData = this.getQbData();
- this.localFormData = { ...this.localFormData, jcb: qbData };
- justUpdateFilledFormData();
- }
- },
- //获取取板数据
- getQbData() {
- let qbData = [];
- if (this.templateSn === "LBA003") {//只有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") {//lba002没有取板步骤,所以检测板数据从检测板数据里面获取;
- const {stepTableFormData=[]} = this.getJcbData() || {};
- qbData = JSON.parse(JSON.stringify(stepTableFormData));
- }
-
- return { stepTableFormData: 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();
- }
- },
- // 点击按钮
- onHandleClickButton(e, item, key) {
- 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,
- })
- }
- },
-
- 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
- ])
- }
- }
- }
- }
|