<!-- 生物样品接收记录表 -->
<template>
	<div>
		<div class="detail-container">
			<div class="detail-title"><img src="@/assets/images/detail-title.png">{{ formData.bdmc }}<img src="@/assets/images/detail-title.png" /></div>
			<div class="detail-content">
				<div class="content">
					<BaseInfoFormPackage 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="yqColumns" :dataSource="yqResource" />

					<BaseInfoFormPackage fieldItemLabel="template.dl.dl020.xbxx" label="template.dl.dl020.xbxx"
						ref="swypyjInfoRef" :formConfig="swypyjInfoFormConfig" :formData="formData"
						/>

          <LineLabel label="template.dl.dl020.czbz" />
          <Step ref="stepRef" :formData="formData.stepData"></Step>
					<BaseInfoFormPackage fieldItemLabel="template.dl.dl020.dlbz" label="template.dl.dl020.dlbz"
						ref="remarkRef" :formConfig="remarkConig" :formData="formData" />
				</div>
			</div>
		</div>
		<!-- <button @click="onSave">保存</button> -->
	</div>
</template>

<script>
import BaseInfoFormPackage from "@/components/Template/BaseInfoFormPackage";
import LineLabel from "@/components/Template/LineLabel";
import TableList from "@/components/Template/Table";
import Step from "@/components/Template/Step";
import templateMixin from "../../mixins/templateMixin";
import moment from "moment";

export default {
	name: "DL020",
	components: { BaseInfoFormPackage, LineLabel, TableList, Step },
	mixins: [templateMixin],
	props: {
		fillType: {
			type: String,
			default: 'preFill',
		},
	},
	computed: {
		// 备注表单配置
		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,
						},
					}
				},
				{
					type: "cellItem",
					label: 'template.dl.dl020.sydd',
					config: {
						sydd: {
							label: 'template.dl.dl020.sydd',
							type: "input",
							fillType: "actFill",
						},
					}
				},
				{
					type: "cellItem",
					label: 'template.dl.dl020.czsj',
					config: {
						startDate: {
							label: 'template.common.startTime',
							type: "input",
						},
						endDate: {
							label: 'template.common.endTime',
							type: "input",
						},
					}
				}
			]
		},
		// 生物样品移交记录表信息
		swypyjInfoFormConfig() {
			return [
				{
					type: "cellItem",
					config: {
						qxbd: {
							span:1,
							label: 'template.dl.dl020.qxbd',
							type: 'qxbd',
							fillType: 'actFill',
							filledCodes:['bdmc','bdbh'],
						},
					}
				},
			]
		},
	},
	data() {
		return {
			formData: {},
		};
	},
	mounted() {
	},
	methods: {
		//获取已填写的表单数据
		async getFilledFormData() {
      let content = await this.validFormFields(["baseInfoRef", "swypyjInfoRef", "stepRef", "remarkRef"]);
			return content;
		},
		//获取填写完成的表单数据
		async getFormData() {
			//先校验再获取值
			const validFlag = await this.validFields();
			if (!validFlag) {
				return false;
			}
			let content = this.getFilledFormData();
			return content
		},
		//只做校验
		async validFields() {
			// 构建需要验证的引用数组
			let refsToValidate = ["baseInfoRef", "swypyjInfoRef", "stepRef", "remarkRef"];
			return await this.validFormFields(refsToValidate);
		},
		getResource() {
			// let content = this.getFilledFormData();
			//使用的试剂、仪器
			const stepResource = this.$refs.stepRef.getStepResource()
			this.resourceTmp = stepResource.sjResource || []
			this.yqResourceTmp = stepResource.yqResource || []
			return this.resourceTmp;
		},
		//保存
		async onSave() {
			const formData = this.getStepResource();
			console.log(formData, "formData")
		},
	}
};
</script>
<style rel="stylesheet/scss" lang="scss">
.mt-20 {
	margin-top: 20px;
}

.print-btn {
	margin-bottom: 20px;
}
.config-header-end {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	margin-bottom: 15px;
	font-weight: bold;
	font-size: 16px;
	color: #303133;
}
</style>
