klzhangweiya 1 month ago
parent
commit
373d40c1f9
1 changed files with 61 additions and 102 deletions
  1. 61 102
      UI/VB.VUE/src/views/common/modal/sopSelectModal.vue

+ 61 - 102
UI/VB.VUE/src/views/common/modal/sopSelectModal.vue

@@ -11,10 +11,11 @@ const props = withDefaults(
 		// batchNum: ""
 	}
 )
-// const sopType = ref("feed")
-// const batchNumber = ref("")
-// const bindType = ref("batch") // 'batch' | 'chicken'
+const sopType = ref(1)
+const batchNumber = ref("")
+const bindType = ref("batch") // 'batch' | 'chicken'
 const chickenId = ref(0) // 鸡只ID列表,逗号分隔
+const gender = ref<number>(1)
 const emits = defineEmits<{
 	(e: "confirm", v: any): void
 }>()
@@ -22,7 +23,7 @@ const emits = defineEmits<{
 const tableRef = ref()
 const modalRef = ref()
 
-const baseColumns = [
+const columns = [
 	{ field: "id", name: "ID", visible: true, isSort: false, width: 100, tooltip: true },
 	{ field: "sopName", name: "名称", visible: true, isSort: false, width: "auto", tooltip: true },
 	{
@@ -35,7 +36,36 @@ const baseColumns = [
 	}
 ]
 
-const baseSearchFormItems = [
+const searchFormItems = [
+	{
+		field: "gender",
+		label: "家禽性别",
+		class: "w-100",
+		required: false,
+		component: "Dict",
+		props: {
+			placeholder: "请选择家禽性别",
+			dictType: "chicken_gender",
+			valueIsNumber: 1,
+			type: "select"
+		},
+		listeners: {
+			change: (val: any) => {
+				gender.value = val
+				handleQuery()
+			}
+		}
+	},
+	{
+		field: "CURRNET_BIND",
+		label: "当前绑定sop",
+		class: "w-100",
+		required: false,
+		component: "slot",
+		props: {
+			placeholder: "请输入名称"
+		}
+	},
 	{
 		field: "sopName",
 		label: "名称",
@@ -48,90 +78,21 @@ const baseSearchFormItems = [
 	}
 ]
 
-// 根据SOP类型获取配置
-const getConfig = (sopType: number = 1, bindingType: string = "batch", gender: number = 1) => {
-	// const typeConfigs = {
-	// 	feed: {
-	// 		title: "选择喂养SOP",
-	// 		api: apis.base.feedSopApi,
-	// 		bindApi:
-	// 			bindingType === "batch"
-	// 				? apis.breeding.batchFeedApi.bind
-	// 				: apis.breeding.chickenFeedApi.bind,
-	// 		queryParams: { ...baseQueryParams },
-	// 		columns: [
-	// 			...baseColumns.slice(0, 2),
-	// 			{
-	// 				field: "gender",
-	// 				name: "家禽性别",
-	// 				visible: true,
-	// 				isSort: false,
-	// 				width: 100,
-	// 				tooltip: true
-	// 			},
-	// 			baseColumns[2]
-	// 		],
-	// 		searchFormItems: baseSearchFormItems
-	// 	},
-	// 	drug: {
-	// 		title: "选择药物SOP",
-	// 		api: apis.base.drugSopApi,
-	// 		bindApi:
-	// 			bindingType === "batch"
-	// 				? apis.breeding.batchDrugApi.bind
-	// 				: apis.breeding.chickenDrugApi.bind,
-	// 		queryParams: baseQueryParams,
-	// 		columns: baseColumns,
-	// 		searchFormItems: baseSearchFormItems
-	// 	},
-	// 	vaccine: {
-	// 		title: "选择疫苗SOP",
-	// 		api: apis.base.vaccineSopApi,
-	// 		bindApi:
-	// 			bindingType === "batch"
-	// 				? apis.breeding.batchVaccineApi.bind
-	// 				: apis.breeding.chickenVaccineApi.bind,
-	// 		queryParams: baseQueryParams,
-	// 		columns: baseColumns,
-	// 		searchFormItems: baseSearchFormItems
-	// 	}
-	// }
-	// return (
-	// 	typeConfigs[type] || {
-	// 		title: "选择SOP",
-	// 		api: apis.base.feedSopApi,
-	// 		bindApi:
-	// 			bindingType === "batch"
-	// 				? apis.breeding.batchFeedApi.bind
-	// 				: apis.breeding.chickenFeedApi.bind,
-	// 		queryParams: {},
-	// 		columns: [],
-	// 		searchFormItems: []
-	// 	}
-	// )
-	return {
-		title: `选择${sopType === 1 ? "喂养" : sopType === 2 ? "药物" : "疫苗"}SOP`,
-		//api: apis.base.feedSopApi,
-		bindingType: bindingType,
-		//bindApi: apis.breeding.batchFeedApi.bind,
-		queryParams: { sopName: "", gender: gender, sopType: sopType }
-	}
-}
-
-//const currentConfig = computed(() => getConfig(sopType.value))
-const currentConfig = ref(getConfig())
+const title = computed(
+	() => `选择${sopType.value === 1 ? "喂养" : sopType.value === 2 ? "药物" : "疫苗"}SOP`
+)
 
-const queryParams = ref(currentConfig.value.queryParams)
+const queryParams = ref({ sopName: "", gender: undefined, sopType: undefined })
 
 function handleQuery() {
-	tableRef.value?.query(currentConfig.value.queryParams)
+	tableRef.value?.query({ sopName: "", gender: gender.value, sopType: sopType.value })
 }
 
 function resetQuery() {
 	queryParams.value = {
 		sopName: "",
-		gender: currentConfig.value.queryParams.gender,
-		sopType: currentConfig.value.queryParams.sopType
+		gender: gender.value,
+		sopType: sopType.value
 	}
 	tableRef.value?.query(queryParams.value)
 }
@@ -139,26 +100,21 @@ function resetQuery() {
 function confirm() {
 	const selectedRows = tableRef.value?.getSelecteds() || []
 	if (selectedRows.length === 0) {
-		ElMessage.warning(`请选择${currentConfig.value.title.replace("选择", "")}`)
+		ElMessage.warning(`请${title.value}`)
 		return
 	}
 
 	const selectedSop = selectedRows[0]
-	let bindData
+	let bindData: any = { sopId: selectedSop.id, gender: gender.value, sopType: sopType.value }
 	if (bindType.value === "batch") {
-		bindData = {
-			batchNum: batchNumber.value,
-			sopId: selectedSop.id
-		}
+		bindData.batchNum = batchNumber.value
 	} else {
-		bindData = {
-			chickenId: chickenId.value,
-			sopId: selectedSop.id
-		}
+		bindData.chickenId = chickenId.value
 	}
-	message.confirm(`确定绑定${currentConfig.value.title.replace("选择", "")}吗?`).then(() => {
-		apis.breeding.batchFeedApi
-			.bind(bindData)
+	message.confirm(`确定绑定${title.value.replace("选择", "")}吗?`).then(() => {
+		;(bindType.value === "batch"
+			? apis.breeding.sopBindApi.bindBatch
+			: apis.breeding.sopBindApi.bindChicken)(bindData)
 			.then(() => {
 				message.msgSuccess("绑定成功")
 				emits("confirm", selectedSop)
@@ -176,17 +132,17 @@ function open(
 	type: number,
 	batchNumOrChickenId: string,
 	bindingType: string = "batch",
-	gender: number = 1
+	_gender: number = 1
 ) {
 	sopType.value = type
 	bindType.value = bindingType
+	gender.value = _gender
 	if (bindingType === "batch") {
 		batchNumber.value = batchNumOrChickenId
 	} else {
 		chickenId.value = Number(batchNumOrChickenId)
 	}
-	currentConfig.value = getConfig(type, bindingType, gender)
-	console.log(currentConfig.value)
+
 	modalRef.value?.show()
 	nextTick(() => {
 		handleQuery()
@@ -194,7 +150,7 @@ function open(
 }
 
 function close() {
-	queryParams.value = { sopName: "" }
+	queryParams.value = { sopName: "", gender: gender.value, sopType: sopType.value }
 	modalRef.value?.hide()
 	tableRef.value.clearSelecteds()
 }
@@ -208,7 +164,7 @@ defineExpose({
 <template>
 	<VbModal
 		v-model:modal="modalRef"
-		:title="currentConfig.title"
+		:title="title"
 		modal-dialog-style="max-width:1200px;"
 		modal-body-class="pt-0"
 		:save-auto-close="false"
@@ -218,9 +174,9 @@ defineExpose({
 				ref="tableRef"
 				tableBoxHeight="290px"
 				v-model:query-params="queryParams"
-				:search-form-items="currentConfig.searchFormItems"
-				:columns="currentConfig.columns"
-				:remote-fun="currentConfig.api.list"
+				:search-form-items="searchFormItems"
+				:columns="columns"
+				:remote-fun="apis.base.feedSopApi"
 				:check-multiple="false"
 				:has-checkbox="true"
 				:reset-search-form-fun="resetQuery"
@@ -235,6 +191,9 @@ defineExpose({
 				<template #status="{ row }">
 					<DictTag type="sop_status" :value-is-number="1" :value="row.status"></DictTag>
 				</template>
+				<template #tool-form_CURRNET_BIND>
+					<span>{{}}</span>
+				</template>
 			</VbDataTable>
 		</template>
 	</VbModal>