<!-- 麻醉/精神药品配制/领取申请单 -->
<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">
					<LineLabel label="基本信息" />
					<div class="template-form-item">
						<BaseInfoFormPcakge @clickable = "onClickSybh" ref="baseInfoRef" :formConfig="baseInfoFormConfig"
							:formData="formData" />
					</div>
					
					<BaseInfoFormPcakge label="备注" ref="remarkRef" :formConfig="remarkConig" :formData="formData" />

				</div>
			</div>
		</div>
			<SelectReagentDialog 
			type = "MJYLQSQD"
			selectedCode="sn"
			title = "请选择试验/部门"
			:searchForm="searchForm"
			:columns="columns"
			@submit="onDialogSubmit"
			:listApi="public_studyList"
			ref="selectReagentDialogRef" >
			</SelectReagentDialog>
	</div>
</template>

<script>
import BaseInfoFormPcakge from "@/components/Template/BaseInfoFormPcakge";
import LineLabel from "@/components/Template/LineLabel";
import templateMixin from "../../mixins/templateMixin";
import CustomTable from '@/components/Template/CustomTable.vue';
import TableOpertaion from "@/components/Template/operation/TableOpertaion.vue";
import SelectReagentDialog from "../../dialog/SelectReagentDialog.vue";
import { public_studyList } from '@/api/business/public/public';

export default {
	name: "MJYLQSQD",
	dicts:["business_gyjl","business_gynd","business_dwzs","business_dwsl","business_dwtz","business_sywzmc"],
	components: { BaseInfoFormPcakge, LineLabel, CustomTable, TableOpertaion,SelectReagentDialog },		
	mixins: [templateMixin],
	props: {
		value: {
			type: {},
			default: () => { },
		},
		fillType: {
			type: String,
			default: 'preFill',
		},
	},
	watch: {
		value: {
			immediate: true,
			handler(v) {

			}
		},
		fillType: {
			immediate: true,
			handler(v) {
				console.log(v,"fillType")
			}
		},
	},
	computed: {
		
		// 备注表单配置
		remarkConig() {
			return [
				{
					type: "cellItem",
					config: {
						remark: {
							label: "",
							type: "textarea",
							fillType: "actFill",
							span: 1,
							placeholder: "请输入备注",
							maxlength: 1000,
							rows: 5
						}
					}
				}
			]
		},
		// 试验基本信息表单配置
		baseInfoFormConfig() {
			return [
				{
					type: "step",
					config: {
						syNo: {
							label: "试验编号或部门名称",
							type: "clickable",
							fillType: "actFill",
						},
						SD: {
							label: "SD/部长",
							type: "input",
							fillType: "actFill",
							disabled: true,
						},
						sywzmc: {
							label: "试验物质名称",
							type: "select",
							fillType: "actFill",
							otherCode: "sywzmcOther",
							options: this.getDictOptions('business_sywzmc'),
						},
						gyjl: {
							label: "给药剂量",
							type: "select",
							fillType: "actFill",
							otherCode: "gyjlOther",
							options: this.getDictOptions('business_gyjl'),
						},
						xynd: {
							label: "需要浓度",
							type: "select",
							fillType: "actFill",
							otherCode: "xyndOther",
							options: this.getDictOptions('business_gynd'),
						},
						xyl: {
							label: "需要量",
							type: "inputNumber",
							fillType: "actFill",
						},
						xysj: {
							label: "需要时间",
							type: "dateTime",
							fillType: "actFill",
						},
						yjghsj: {
							label: "预计归还时间",
							type: "dateTime",
							fillType: "actFill",
						},
						dwzs: {
							label: "动物种属",
							type: "select",
							fillType: "actFill",
							otherCode: "dwzsOther",
							options: this.getDictOptions('business_dwzs'),
						},
						dwpjtz: {
							label: "动物平均体重",
							type: "input",
							fillType: "actFill",
							subType: "select",
							subFillType: "actFill",
							subKey: "dwtzUnit",
							subOptions: this.getDictOptions('business_dwtz'),
						},
						dwsl: {
							label: "动物数量",
							type: "input",
							fillType: "actFill",
							subType: "select",
							subFillType: "actFill",
							subKey: "dwzsUnit",
							otherCode: "dwslOther",
							subOptions: this.getDictOptions('business_dwsl'),
						},

					}
				},
			]
		},
	},
	data() {
		return {
			syId:null,
			depId:null,
			sdId:null,
			public_studyList:public_studyList,
			searchForm: {
				name: {
					label:this.$t('page.business.study.study.name'),
				},
				sn: {
					label:this.$t('page.business.study.study.sn'),
				},
				leaderName: {
					label:this.$t('page.business.study.study.leader'),
				},
			},
			columns:[
                {
                    prop: 'name',
                    label: 'page.business.study.study.name',
                },
                {
                    prop: 'sn',
                    label: 'page.business.study.study.sn',
                },
                {
                    prop: 'status',
                    label: 'page.business.study.study.status',
                },
                {
                    prop: 'leaderName',
                    label: 'page.business.study.study.leader',
                },
                {
                    prop: 'createTime',
                    label: 'page.business.study.study.createDate',
                }
            ]
		};
	},
	mounted() {
	},
	methods: {
		onDialogSubmit(selectedId,currentRow){
			this.$refs.baseInfoRef.batchUpdateFormData({
				syNo: currentRow.sn,
				SD: currentRow.leaderName,
			});
			// this.syId='' todo
			// this.depId=''
			// this.sdId=''
			console.log(currentRow,"currentRow")
			this.$refs.selectReagentDialogRef.onCancel()
		},
		// 试验编号或部门名称点击事件
		onClickSybh() {
			this.$refs.selectReagentDialogRef.show()
			// this.$refs.baseInfoRef.setClickable("syNo", true);
		},
		//获取已填写的表单数据
		getFilledFormData(){
			return this.getFilledFormDataByRefs(["baseInfoRef", "storageConditionRef", "stepFormPackageRef", "stepRef", "remarkRef"])
		},
		async getFormData() {
			let content = await this.validFormFields(["baseInfoRef","remarkRef"]);
			content.syId=this.syId
			content.depId=this.depId
			content.sdId=this.sdId
			return content;
		},
		async onSave() {
			const formData = await this.getFormData();
			// const formData = await this.$refs.stepTableRef.getFormData();
			console.log(formData, "formData")
		},
	}
};
</script>
<style rel="stylesheet/scss" lang="scss">
.mt-20 {
	margin-top: 20px;
}

</style>