<!-- 麻醉/精神药品配制/领取申请单 -->
<template>
	<div>
		<div class="detail-container">
			<div class="detail-title"><img src="@/assets/images/detail-title.png">{{ formData.bdmc ||
				$t('template.gsp.MJYLQSQD.title') }}<img src="@/assets/images/detail-title.png" /></div>
			<div class="detail-content">
				<div class="content">
					<LineLabel label="template.gsp.MJYLQSQD.jbxx" />
					<div class="template-form-item">
						<BaseInfoFormPcakge @clickable="onClickSybh" ref="baseInfoRef" :formConfig="baseInfoFormConfig"
							:formData="formData" />
					</div>
					<BaseInfoFormPcakge label="template.common.remark" ref="remarkRef" :formConfig="remarkConig" :formData="formData" />
				</div>
			</div>
		</div>
		<SelectReagentDialog type="MJYLQSQD" selectedCode="sn" title="template.gsp.MJYLQSQD.qxzsyhbm" :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: "template.common.remarkPlaceholder",
							maxlength: 1000,
							rows: 5
						}
					}
				}
			]
		},
		// 试验基本信息表单配置
		baseInfoFormConfig() {
			return [
				{
					type: "step",
					config: {
						syNo: {
							label: "template.gsp.MJYLQSQD.sybhhbmmc",
							type: "clickable",
							fillType: "actFill",
						},
						SD: {
							label: "template.gsp.MJYLQSQD.sd",
							type: "input",
							fillType: "actFill",
						},
						sywzmc: {
							label: "template.gsp.MJYLQSQD.sywzmc",
							type: "select",
							fillType: "actFill",
							otherCode: "sywzmcOther",
							options: this.getDictOptions('business_sywzmc'),
						},
						gyjl: {
							label: "template.gsp.MJYLQSQD.gyjl",
							type: "select",
							fillType: "actFill",
							otherCode: "gyjlOther",
							options: this.getDictOptions('business_gyjl'),
						},
						xynd: {
							label: "template.gsp.MJYLQSQD.xynd",
							type: "select",
							fillType: "actFill",
							otherCode: "xyndOther",
							options: this.getDictOptions('business_gynd'),
						},
						xyl: {
							label: "template.gsp.MJYLQSQD.xyl",
							type: "inputNumber",
							fillType: "actFill",
						},
						xysj: {
							label: "template.gsp.MJYLQSQD.xysj",
							type: "dateTime",
							fillType: "actFill",
						},
						yjghsj: {
							label: "template.gsp.MJYLQSQD.yjghsj",
							type: "dateTime",
							fillType: "actFill",
						},
						dwzs: {
							label: "template.gsp.MJYLQSQD.dwzs",
							type: "select",
							fillType: "actFill",
							otherCode: "dwzsOther",
							options: this.getDictOptions('business_dwzs'),
						},
						dwpjtz: {
							label: "template.gsp.MJYLQSQD.dwpjtz",
							type: "input",
							fillType: "actFill",
							subType: "select",
							subFillType: "actFill",
							subKey: "dwtzUnit",
							subOptions: this.getDictOptions('business_dwtz'),
						},
						dwsl: {
							label: "template.gsp.MJYLQSQD.dwsl",
							type: "input",
							fillType: "actFill",
							subType: "select",
							subFillType: "actFill",
							subKey: "dwslUnit",
							otherCode: "dwslOther",
							subOptions: this.getDictOptions('business_dwsl'),
						},

					}
				},
			]
		},
	},
	data() {
		return {
			syId: null,
			bmId: 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) {
			console.log(JSON.stringify(currentRow))
			//试验
			if (currentRow.type == 1) {
				this.$refs.baseInfoRef.batchUpdateFormData({
					syNo: currentRow.sn,
					SD: currentRow.leaderName,
				});
				this.syId = currentRow.id
				this.bmId = currentRow.deptId
				this.sdId = currentRow.leader
			}
			//部门
			if (currentRow.type == 2) {
				this.$refs.baseInfoRef.batchUpdateFormData({
					syNo: currentRow.deptName,
					SD: currentRow.nickName,
				});
				this.syId = ''
				this.bmId = currentRow.deptId
				this.sdId = currentRow.userId
			}
			this.$refs.selectReagentDialogRef.onCancel()
		},
		// 试验编号或部门名称点击事件
		onClickSybh() {
			this.$refs.selectReagentDialogRef.show()
			// this.$refs.baseInfoRef.setClickable("syNo", true);
		},
		//获取已填写的表单数据
		getFilledFormData() {
			let content = this.getFilledFormDataByRefs(["baseInfoRef", "storageConditionRef", "stepFormPackageRef", "stepRef", "remarkRef"])
			content.syId = this.syId
			content.bmId = this.bmId
			content.sdId = this.sdId
			return content;
		},
		async getFormData() {
			let content = await this.validFormFields(["baseInfoRef", "remarkRef"]);
			content.syId = this.syId
			content.bmId = this.bmId
			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>