<!-- 生物分析生物样品采集管制备表 -->
<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.dl017.xbxx" label="template.dl.dl017.xbxx"
						ref="swypyjInfoRef" :formConfig="swypyjInfoFormConfig" :formData="formData"
						/>

          <LineLabel label="template.dl.dl017.xbczqk" />
					<CustomTable
							@headerSelectChange="onHeaderSelectChange"
							fieldItemLabel="template.common.operationSteps" @blur="onHandleTableBlur"
							@beforeSaveRecord = "beforeSaveRecord" @onRegentSubmit="(e) => onRegentSubmit"
							:showAddRow="false" :showOperation="false"
							ref="stepTableRef" :columns="stepColumns" :formData="formData">
							<!-- <template slot="operation" slot-scope="{ row, rowIndex, columns }">
								<TableOpertaion @startConfig="startConfig" @configComplete="configComplete"
									@printTag="printTag" @subPackageSubmit="subPackageSubmit" :fillType="fillType"
									:row="row" :rowIndex="rowIndex" :columns="columns" @deleteRow="deleteRow">
								</TableOpertaion>
							</template> -->
						</CustomTable>

					<LineLabel label="template.dl.dl017.czbz" />
					<Step ref="stepRef" :formData="formData.stepData"></Step>

					<BaseInfoFormPackage 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 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 CustomTable from '@/components/Template/CustomTable.vue';
import { EventBus } from "@/utils/eventBus";
import { uniqeResource } from "@/utils/calUnitTools";
import { debounce } from 'lodash-es'
import TableOpertaionDelete from "@/components/Template/operation/TableOpertaionDelete.vue"

export default {
	name: "DL017",
  dicts: [
        'business_dl_qsxjbltj','business_tjdw'
    ],
	components: { BaseInfoFormPackage, LineLabel, TableList, Step, CustomTable,TableOpertaionDelete },
	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.dl017.sydd',
					config: {
						sydd: {
							label: 'template.dl.dl017.sydd',
							type: "input",
							fillType: "actFill",
						},
					}
				},
				{
					type: "cellItem",
					label: 'template.dl.dl017.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.dl017.qxbd',
							type: 'qxbd',
							fillType: 'actFill',
              qxbdType:'DL017',
							filledCodes:['bdmc','bdbh'],
						},
            bltj: {
							label: 'template.dl.dl017.bltj',
							type: 'select',
							fillType: 'preFill',
							options: this.getDictOptions('business_dl_qsxjbltj'),
							otherCode: 'bltjOther',
              showOtherLabel:false
						},
					}
				}
			]
		},
		// 秋水仙碱加液情况
		stepColumns() {
			return [
				{
					label: "template.dl.dl017.jlzb",
					prop: "jlzb",
					width: 180,
					bodyType: "input",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},
        {
					label: "template.dl.dl017.xybh",
					prop: "xybh",
					width: 180,
					bodyType: "input",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.sjqszqk",
					prop: "sjqszqk",
					width: 180,
					bodyType: "input",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.sjqcdqk",
					prop: "sjqcdqk",
					width: 180,
					bodyType: "input",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.saqqtqk",
					prop: "saqqtqk",
					width: 180,
					bodyType: "input",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.ddpyy",
					prop: "ddpyy",
					width: 180,
					bodyType: "checkbox",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.xd",
					prop: "xd",
					width: 180,
					bodyType: "checkbox",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.sj",
					prop: "sj",
					width: 180,
					bodyType: "checkbox",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.ds",
					prop: "ds",
					width: 180,
					bodyType: "checkbox",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.dy1gd",
					prop: "dy1gd",
					width: 180,
					bodyType: "checkbox",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.dy2gd",
					prop: "dy2gd",
					width: 180,
					bodyType: "checkbox",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.dy3gd",
					prop: "dy3gd",
					width: 180,
					bodyType: "checkbox",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},{
					label: "template.dl.dl017.dy4gd",
					prop: "dy4gd",
					width: 180,
					bodyType: "checkbox",
					bodyFillType: "actFill",
					bodyMaxlength: 10,
					bodyDisabled: true,
				},
			]
		},
	},
	data() {
		return {
			formData: {},
		};
	},
	mounted() {
	},
	methods: {
    onRegentSubmit(e) {
      const { selectInfo, key, rowIndex } = e
      const { row } = selectInfo

      if (key === 'yqbh') {
        const params = {
          yqmc: row.mc,
          yqxh: row.xh,
          xccsjzjdrq: row.jzrq
        }
        // this.$refs.yqsyTableRef.updateDataSourceByRowIndex(rowIndex, params)
      }
    },
    //选择table header下拉框也要更新体积
		onHeaderSelectChange(data){
			const {key, headerSelectFields,dataSource=[]} = data;
			const keys = [
				'targetStartSolutionVolumeUnit',
				'targetDiluentVolumeUnit',
				'targetSolutionConcentrationUnit',
				'targetSolutionVolumeUnit',
			]
			if(keys.includes(key)){
				const {targetStartSolution,subTargetStartSolution} = this.$refs.swypyjInfoRef?.getFilledFormData();
				const params = {
					subTargetStartSolution,
					headerSelectFields
				}
				this.batchUpdateTargetStartSolutionVolume(dataSource,targetStartSolution,params)
			}
		},
    beforeSaveRecord(data){
			const formFields = this.$refs.swypyjInfoRef?.getFilledFormData();
			this.onCommonVerifyNdException(formFields,data);
		},
    configComplete(val) {
			const { rowData, headerSelectFields } = val;
			//计算实际目标溶液体积(实际起始溶液体积+实际稀释液体积)
			const { total, unit } = addTj([rowData.actStartSolutionVolume, rowData.actDiluentVolume], [headerSelectFields.actStartSolutionVolumeUnit, headerSelectFields.actDiluentVolumeUnit])
			let postData = {
				mc: null,
				bh: rowData.targetSolutionCode + rowData.subTargetSolutionCode,
				nd: rowData.actSolutionConcentration,//实际目标溶液浓度
				nddw: headerSelectFields.actSolutionConcentrationUnit,
				studySubjectId: this.formData.studySubjectId,
				studyFormId:this.formData.id,
				studyId:this.formData.studyId,
				kc: total,
				kcdw: unit,
			}
			this.configCompleteRequest(postData);
		},
    //分装回调
		subPackageSubmit(data) {
			const { fzsj, rowData, headerSelectFields } = data;
			const { fzList = [], dw = "", mybh } = fzsj;
			if (fzList && fzList.length > 0) {
				const list = fzList.map((item) => {
					return {
						bh: mybh + item.preCode + item.subCode,
						kc: item.num,
						kcdw: dw,
					}
				})
				let postData = {
					studyId: this.formData.studyId,
					studyFormId: this.formData.id,
					bh: mybh,
					nd: rowData.actSolutionConcentration || 0,
					nddw: headerSelectFields.actSolutionConcentrationUnit,
					studySubjectId: this.formData.studySubjectId,
			     	studyFormId:this.formData.id,
					list: list
				}
				this.subPackageRequest(postData);
			}
		},
		//获取已填写的表单数据
		getFilledFormData() {
			return this.getFilledFormDataByRefs(["baseInfoRef",  "swypyjInfoRef", "stepTableRef", "stepRef","remarkRef"])
		},
		//获取填写完成的表单数据
		async getFormData() {
			let content = await this.validFormFields(["baseInfoRef",  "swypyjInfoRef", "stepTableRef", "stepRef","remarkRef"]);
			return content;
		},
		getResource() {
			//使用的试剂、仪器
			const stepResource = this.$refs.stepRef.getStepResource()
			this.resourceTmp = stepResource.sjResource || []
			this.yqResourceTmp = stepResource.yqResource || []
			return this.resourceTmp;
		},
		//保存
		async onSave() {
			let content = await this.$refs.stepRef.getFormData();
			console.log(content);
		},
		// 删除表格行
		// deleteRow(rowIndex) {
		// 	const tableRef = this.$refs['tableRef'];
		// 	if (tableRef) {
		// 		tableRef.deleteRow(rowIndex);
		// 	}
		// },
	}
};
</script>
<style rel="stylesheet/scss" lang="scss">
</style>
