<!-- 生物样品分析溶液配制表 -->
<template>
	<div>
		<div class="detail-container">
			<div class="detail-title"><img src="@/assets/images/detail-title.png">{{ formData.bdmc ||
				$t('template.common.pageTitle') }}<img src="@/assets/images/detail-title.png" /></div>
			<div class="detail-content">
				<div class="content">
					<BaseInfoFormPcakge fieldItemLabel="template.common.baseInfo" label="template.common.baseInfo" ref="baseInfoRef"
						:formConfig="baseInfoFormConfig" :formData="formData" />
					<TableList label="template.common.reagentInfo" :columns="sysjColumns"
						:dataSource="resource" />
					<TableList label="template.common.instrumentInfo" :columns="yqsColumns"
						:dataSource="yqResource" />
					<BaseInfoFormPcakge fieldItemLabel="template.common.storageCondition" label="template.common.storageCondition" ref="storageConditionRef"
						:formConfig="storageFormConfig" :formData="formData" />
					<LineLabel label="template.common.operationSteps" />
					<div class="template-form-item">
						<BaseInfoFormPcakge fieldItemLabel="template.common.operationSteps" ref="stepFormPackageRef" :formConfig="stepFormConfig" @blur="onHandleBlur"
							:formData="formData" />
					</div>
					<Step ref="stepRef" :formData="formData.stepData"></Step>
					<BaseInfoFormPcakge fieldItemLabel="template.common.remark" label="template.common.remark" ref="remarkRef" :formConfig="remarkConig"
						:formData="formData" />

				</div>
			</div>
		</div>
		<!-- <button @click = "onSave">保存</button> -->
	</div>
</template>

<script>
import BaseInfoFormPcakge from "@/components/Template/BaseInfoFormPcakge";
import LineLabel from "@/components/Template/LineLabel";
import TableList from "@/components/Template/Table";
import Step from "@/components/Template/Step";
import templateMixin from "../../mixins/templateMixin";
import CustomTable from '@/components/Template/CustomTable.vue';
import { getLatestSn } from '@/api/template';

export default {
	name: "SWYPFXRYPZB",
	components: { BaseInfoFormPcakge, LineLabel, TableList, Step, CustomTable },
	mixins: [templateMixin],
	props: {
		fillType: {
			type: String,
			default: 'preFill',
		},
	},
	computed: {
		storageFormConfig() {
			return [
				{
					type: "conditionItem",
					config: {
						storageCondition: {
							label: 'template.common.storageConditionLabel',
							type: "select",
							fillType: "preFill",
							options: this.getDictOptions("business_cctj"),
							otherCode: "storageConditionOther",
						},

					}
				}
			];
		},
		remarkConig() {
			return [
				{
					type: "cellItem",
					config: {
						remark: {
							label: "",
							type: "textarea",
							fillType: "actFill",
							span: 1,
							placeholder: 'template.common.remarkPlaceholder',
							maxlength: 1000,
							rows: 5
						}
					}
				}
			]
		},
		
		baseInfoFormConfig() {
			return [
				{
					type: "cardItem",
					config: {
						studyMc: {
							label: 'template.common.testName',
							type: "input",
							disabled: true,
						},
						studySn: {
							label: 'template.common.testNumber',
							type: "input",
							disabled: true,
						},
						methodCode: {
							label: 'template.common.methodCode',
							type: "input",
							fillType: "preFill",
							maxlength: 50
						},
						versionNum: {
							label: 'template.common.versionNumber',
							type: "input",
							fillType: "actFill",
							prepend:"V",
							maxlength: 50
						},

					}
				},
				{
					type: "conditionItem",
					label: 'template.common.testConfigurationConditions',
					config: {
						pre: {
							label: 'template.common.preFill',
							type: "select",
							multiple: true,
							fillType: "preFill",
							options: this.getDictOptions('business_pztj'),
							otherCode: "preOther",
						},
						act: {
							label: 'template.common.actualFill',
							type: "select",
							fillType: "actFill",
							otherCode: "actOther",
							multiple: true,
							compareTo: "pre",
							options: this.getDictOptions('business_pztj')
						}
					}
				},
				{
					type: "cellItem",
					label: 'template.common.configurationTime',
					config: {
						startDate: {
							label: 'template.common.startTime',
							type: "input",
						},
						endDate: {
							label: 'template.common.endTime',
							type: "input",
						},
					}
				}
			]
		},
		stepFormConfig() {
			return [
				{
					type: "step",
					config: {
						targetName: {
							label: 'template.common.targetSolutionName',
							type: "input",
							fillType: "preFill",
							maxlength: 50
						},
						targetCode: {
							label: 'template.common.targetSolutionCode',
							type: "input",
							subType: "span",
							fillType: "preFill",
							subKey: "targetCodeSn",
							maxlength: 20
						},
						targetPreConcentration: {
							label: 'template.common.targetPreConcentration',
							type: "inputNumber",
							subType: "select",
							subKey: "targetPreConcentrationUnit",
							fillType: "preFill",
							subOptions: this.getDictOptions('business_nddw'),
							maxlength: 10,
							selectTo:"targetActConcentrationUnit",//下拉选择后，赋值到对应字段
						},
						targetActConcentration: {
							label: 'template.common.targetActConcentration',
							type: "inputNumber",
							subType: "select",
							subKey: "targetActConcentrationUnit",
							compareTo: "targetPreConcentration",//与哪个字段比较
							fillType: "actFill",
							subFillType: "preFill",
							subOptions: this.getDictOptions('business_nddw'),
							copyFrom: "targetPreConcentration",//复制哪个字段
							maxlength: 10
						},
						targetPreVolume: {
							label: 'template.common.targetPreVolume',
							type: "inputNumber",
							subType: "select",
							subKey: "targetPreVolumeUnit",
							subOptions: this.getDictOptions('business_tjdw'),
							fillType: "preFill",
							maxlength: 10,
							selectTo:"targetActVolumeUnit",//下拉选择后，赋值到对应字段
						},
						targetActVolume: {
							label: 'template.common.targetActVolume',
							type: "inputNumber",
							subType: "select",
							subKey: "targetActVolumeUnit",
							fillType: "actFill",
							subFillType: "preFill",
							subOptions: this.getDictOptions('business_tjdw'),
							compareTo: "targetPreVolume",//与哪个字段比较
							copyFrom: "targetPreVolume",//复制哪个字段
							maxlength: 10
						},
						effectivePeriod: {
							label: 'template.common.effectivePeriod',
							type: "inputNumber",
							subType: "select",
							subKey: "effectivePeriodUnit",
							fillType: "preFill",
							subOptions: this.getDictOptions('business_yxqdw'),
							maxlength: 10
						},
						expireDate: {
							label: 'template.common.expireDate',
							type: "input",
						},
					}
				}
			]
		},
	},
	data() {
		return {
			resource: [],
			yqResource: [],
			sysjColumns: [
				{ label: 'template.common.reagentName', prop: "mc" },//名称
				{ label: 'template.common.reagentCode', prop: "bh" },//编号
				{ label: 'template.common.reagentNo', prop: "ph" },//批号 试剂，供试品才有
				{ label: 'template.common.concentration', prop: "nd" },//浓度
				{ label: 'template.common.source', prop: "source" },//来源 
				{ label: 'template.common.reagentExpireDate', prop: "sxrq" },//失效日期
			],
			yqsColumns: [
				{ label: 'template.common.instrumentName', prop: "instrumentName" },
				{ label: 'template.common.instrumentModel', prop: "instrumentModel" },
				{ label: 'template.common.instrumentCode', prop: "instrumentCode" },
				{ label: 'template.common.nextTestDate', prop: "nextTestDate" },
			],
			formData: {}
		};
	},
	mounted() {

	},
	watch: {
		formData: {
			immediate: true,
			handler(v) {
				if(!v.targetCodeSn && this.fillType === "actFill"){
					this.getCode();
				}
			}
		}
	},
	methods: {
		//获取目标溶液编号
		async getCode(){
			const result = await getLatestSn({
				count: 1,
			})
			if(result.code == 200){
				this.$refs.stepFormPackageRef.updateFormData("targetCodeSn",result.data)
			}
		},
		//获取已填写的表单数据
		getFilledFormData(){
			return this.getFilledFormDataByRefs(["baseInfoRef", "storageConditionRef", "stepFormPackageRef", "stepRef", "remarkRef"])
		},
		async getFormData() {
			let content = await this.validFormFields(["baseInfoRef", "storageConditionRef", "stepFormPackageRef", "stepRef", "remarkRef"]);
			//生成resource
			let tmpResource = []
			//配置的试剂
			tmpResource.push({
				mc: content.targetName,
				bh: content.targetCode+content.targetCodeSn,
				ph: '',
				nd: content.targetActConcentration + content.targetActConcentrationUnit,
				source: 'ELN配制',
				sxrq: content.expireDate,
				ndz: content.targetActConcentration,
				nddw: content.targetActConcentrationUnit,
				kc: content.targetActVolume,
				kcdw: content.targetActVolumeUnit,
				syl: null,
				syldw:content.targetActVolumeUnit,
				yxzq:content.effectivePeriod,
				yxzqdw:content.effectivePeriodUnit,
			})
			//使用的试剂
			this.resource=tmpResource
			
			return content;
		},
		async onSave() {
			const formData = await this.getFilledFormData();

			console.log(formData, "formData")
		},

	}
};
</script>
<style rel="stylesheet/scss" lang="scss">
.mt-20 {
	margin-top: 20px;
}
</style>