2025-07-26 11:44:09 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div class="p-2">
|
|
|
|
|
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
|
|
|
|
<div v-show="showSearch" class="mb-[10px]">
|
|
|
|
|
<el-card shadow="hover">
|
|
|
|
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="110px">
|
|
|
|
|
<el-form-item label="地块编号" prop="landCode">
|
|
|
|
|
<el-input v-model="queryParams.landCode" placeholder="请输入地块编号" clearable @keyup.enter="handleQuery" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="地块名称" prop="landName">
|
|
|
|
|
<el-input v-model="queryParams.landName" placeholder="请输入地块名称" clearable @keyup.enter="handleQuery" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="所属村委会" prop="villageCommittee">
|
|
|
|
|
<el-input v-model="queryParams.villageCommittee" placeholder="请输入所属村委会" clearable @keyup.enter="handleQuery" />
|
|
|
|
|
</el-form-item>
|
2025-08-09 18:02:32 +08:00
|
|
|
|
<el-form-item label="设计面积(亩)" prop="designArea">
|
2025-08-14 01:58:00 +08:00
|
|
|
|
<el-input v-model="queryParams.designArea" type="number" placeholder="请输入设计面积" clearable @keyup.enter="handleQuery" />
|
2025-07-26 11:44:09 +08:00
|
|
|
|
</el-form-item>
|
2025-08-09 18:02:32 +08:00
|
|
|
|
<el-form-item label="地块数(块)" prop="blockCount">
|
|
|
|
|
<el-input v-model="queryParams.blockCount" type="number" placeholder="请输入地块数" clearable @keyup.enter="handleQuery" />
|
2025-07-26 11:44:09 +08:00
|
|
|
|
</el-form-item>
|
2025-08-09 18:02:32 +08:00
|
|
|
|
<el-form-item label="农户数(户)" prop="farmerCount">
|
|
|
|
|
<el-input v-model="queryParams.farmerCount" type="number" placeholder="请输入农户数" clearable @keyup.enter="handleQuery" />
|
2025-07-26 11:44:09 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item>
|
|
|
|
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
|
|
|
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</el-card>
|
|
|
|
|
</div>
|
|
|
|
|
</transition>
|
|
|
|
|
<el-card shadow="never">
|
|
|
|
|
<template #header>
|
|
|
|
|
<el-row :gutter="10" class="mb8">
|
|
|
|
|
<el-col :span="1.5">
|
|
|
|
|
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['land:landBlock:add']">新增</el-button>
|
|
|
|
|
</el-col>
|
2025-08-25 19:58:42 +08:00
|
|
|
|
<el-col :span="1.5">
|
|
|
|
|
<el-button type="success" plain icon="Plus" @click="downloadTemplate" v-hasPermi="['land:enterRoad:import']">模板下载</el-button>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="1.5">
|
|
|
|
|
<el-upload ref="uploadRef" class="upload-demo" :http-request="handleImport" :show-file-list="false">
|
2025-08-27 19:50:22 +08:00
|
|
|
|
<template #trigger>
|
2025-08-30 08:18:27 +08:00
|
|
|
|
<el-button plain type="primary" icon="upload">导入excel</el-button>
|
2025-08-27 19:50:22 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-upload>
|
2025-07-26 11:44:09 +08:00
|
|
|
|
</el-col>
|
2025-08-30 08:18:27 +08:00
|
|
|
|
<el-col :span="1.5">
|
|
|
|
|
<el-button type="success" plain icon="Download" @click="exportFile">导出模版</el-button>
|
|
|
|
|
</el-col>
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
|
|
|
|
</el-row>
|
|
|
|
|
</template>
|
|
|
|
|
<el-table draggable v-loading="loading" :data="landBlockList" @selection-change="handleSelectionChange">
|
2025-08-27 19:50:22 +08:00
|
|
|
|
<el-table-column type="index" label="序号" width="55" align="center" />
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<el-table-column label="地块编号" align="center" prop="landCode" />
|
|
|
|
|
<el-table-column label="地块名称" align="center" prop="landName" />
|
|
|
|
|
<el-table-column label="方阵" align="center" prop="unit" />
|
|
|
|
|
<el-table-column label="所属村委会" align="center" prop="villageCommittee" />
|
2025-08-09 18:02:32 +08:00
|
|
|
|
<el-table-column label="设计面积(亩)" align="center" prop="designArea" />
|
|
|
|
|
<el-table-column label="地块数(块)" align="center" prop="blockCount" />
|
|
|
|
|
<el-table-column label="农户数(户)" align="center" prop="farmerCount" />
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<el-table-column label="备注" align="center" prop="remark" />
|
|
|
|
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
<el-tooltip content="修改" placement="top">
|
|
|
|
|
<el-button link type="primary" @click="handleUpdate(scope.row)" v-hasPermi="['land:landBlock:edit']">编辑</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
<el-tooltip content="删除" placement="top">
|
|
|
|
|
<el-button link type="primary" @click="handleDelete(scope.row)" v-hasPermi="['land:landBlock:remove']">删除</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
<el-tooltip content="关联方阵" placement="top">
|
|
|
|
|
<el-button type="primary" link @click="handleView(scope.row)">关联方阵</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
|
|
|
|
|
</el-card>
|
2025-09-02 09:52:36 +08:00
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
<!-- 地块表单弹窗 -->
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<el-dialog draggable :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
|
|
|
|
<el-form ref="landBlockFormRef" :model="form" :rules="rules" label-width="100px">
|
|
|
|
|
<el-form-item label="地块名称" prop="landName">
|
|
|
|
|
<el-input v-model="form.landName" placeholder="请输入地块名称" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="所属村委会" prop="villageCommittee">
|
|
|
|
|
<el-input v-model="form.villageCommittee" placeholder="请输入所属村委会" />
|
|
|
|
|
</el-form-item>
|
2025-08-09 18:02:32 +08:00
|
|
|
|
<el-form-item label="设计面积(亩)" prop="designArea">
|
|
|
|
|
<el-input type="number" v-model="form.designArea" placeholder="请输入设计面积" />
|
2025-07-26 11:44:09 +08:00
|
|
|
|
</el-form-item>
|
2025-08-09 18:02:32 +08:00
|
|
|
|
<el-form-item label="地块数(块)" prop="blockCount">
|
|
|
|
|
<el-input type="number" v-model="form.blockCount" placeholder="请输入地块数" />
|
2025-07-26 11:44:09 +08:00
|
|
|
|
</el-form-item>
|
2025-08-09 18:02:32 +08:00
|
|
|
|
<el-form-item label="农户数(户)" prop="farmerCount">
|
|
|
|
|
<el-input type="number" v-model="form.farmerCount" placeholder="请输入农户数" />
|
2025-07-26 11:44:09 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="备注" prop="remark">
|
|
|
|
|
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<div class="dialog-footer">
|
2025-08-29 19:54:27 +08:00
|
|
|
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm" v-hasPermi="['land:landBlock:add']">确 定</el-button>
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<el-button @click="cancel">取 消</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
2025-09-02 09:52:36 +08:00
|
|
|
|
|
|
|
|
|
<!-- 关联方阵弹窗(核心修复区域) -->
|
2025-08-27 19:50:22 +08:00
|
|
|
|
<el-dialog draggable :title="dialogMatrix.title" v-model="dialogMatrix.visible" width="900px" append-to-body>
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<el-button type="primary" plain icon="Plus" @click="addUnitBoItem" style="margin-bottom: 15px">添加</el-button>
|
2025-09-02 09:52:36 +08:00
|
|
|
|
<!-- 修复1:表单模型绑定formM(根模型),确保嵌套字段校验生效 -->
|
2025-08-27 19:50:22 +08:00
|
|
|
|
<el-form ref="landBlockFormMatrixRef" :model="formM" label-width="100px">
|
2025-09-02 09:52:36 +08:00
|
|
|
|
<!-- 修复2:循环formM.unitBoList(而非独立ref),保证数据双向绑定 -->
|
2025-09-02 19:00:50 +08:00
|
|
|
|
<el-row v-for="(item, i) of formM.unitBoList" :key="i" class="mb-4">
|
2025-09-02 09:52:36 +08:00
|
|
|
|
<!-- 方阵选择:修复校验规则(移除min:2,改为min:1,适配单层级选择) -->
|
2025-08-27 19:50:22 +08:00
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item
|
|
|
|
|
label="方阵"
|
|
|
|
|
:prop="`unitBoList[${i}].unitProjectId`"
|
|
|
|
|
:rules="[
|
|
|
|
|
{ required: true, message: '请选择方阵', trigger: 'change' },
|
2025-09-02 09:52:36 +08:00
|
|
|
|
{ type: 'array', min: 1, message: '请选择完整的方阵', trigger: 'change' }
|
2025-08-27 19:50:22 +08:00
|
|
|
|
]"
|
|
|
|
|
>
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<el-cascader
|
|
|
|
|
:options="fangzhenList"
|
2025-08-27 19:50:22 +08:00
|
|
|
|
placeholder="请选择方阵"
|
2025-07-26 11:44:09 +08:00
|
|
|
|
filterable
|
|
|
|
|
:props="{ value: 'matrixId', label: 'name' }"
|
|
|
|
|
v-model="item.unitProjectId"
|
|
|
|
|
clearable
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
2025-09-02 09:52:36 +08:00
|
|
|
|
<!-- 所属工区:保留原有规则 -->
|
2025-08-27 19:50:22 +08:00
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item
|
|
|
|
|
label="所属工区"
|
|
|
|
|
:prop="`unitBoList[${i}].unitProjectArea`"
|
|
|
|
|
:rules="{ required: true, message: '请输入所属工区', trigger: 'blur' }"
|
|
|
|
|
>
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<el-input v-model="item.unitProjectArea" placeholder="请输入所属工区" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
2025-09-02 09:52:36 +08:00
|
|
|
|
<!-- 方阵状态:保留原有规则 -->
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<el-col :span="6">
|
2025-08-27 19:50:22 +08:00
|
|
|
|
<el-form-item
|
|
|
|
|
label="方阵状态"
|
|
|
|
|
:prop="`unitBoList[${i}].unitProjectStatus`"
|
|
|
|
|
:rules="{ required: true, message: '请输入方阵状态', trigger: 'blur' }"
|
|
|
|
|
>
|
2025-07-26 11:44:09 +08:00
|
|
|
|
<el-input v-model="item.unitProjectStatus" placeholder="请输入方阵状态" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
2025-09-02 09:52:36 +08:00
|
|
|
|
<!-- 删除按钮:禁用逻辑优化(至少保留1项) -->
|
2025-08-27 19:50:22 +08:00
|
|
|
|
<el-col :span="1" style="margin-left: 15px; display: flex; align-items: flex-end">
|
2025-09-02 09:52:36 +08:00
|
|
|
|
<el-button
|
|
|
|
|
style="margin-bottom: 18px"
|
|
|
|
|
type="danger"
|
|
|
|
|
icon="Delete"
|
|
|
|
|
@click="removeUnitBoItem(i)"
|
|
|
|
|
:disabled="formM.unitBoList.length <= 1"
|
|
|
|
|
></el-button>
|
2025-07-26 11:44:09 +08:00
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<div class="dialog-footer">
|
|
|
|
|
<el-button type="primary" @click="submitFormMatrix">确 定</el-button>
|
|
|
|
|
<el-button @click="cancelMatrix">取 消</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup name="LandBlock" lang="ts">
|
2025-08-27 19:50:22 +08:00
|
|
|
|
import {
|
|
|
|
|
listLandBlock,
|
|
|
|
|
getLandBlock,
|
|
|
|
|
delLandBlock,
|
|
|
|
|
LandUnit,
|
|
|
|
|
addLandBlock,
|
|
|
|
|
updateLandBlock,
|
|
|
|
|
subMatrix,
|
|
|
|
|
importLandBlock
|
|
|
|
|
} from '@/api/system/landTransfer/landBlock';
|
2025-07-26 11:44:09 +08:00
|
|
|
|
import { LandBlockVO, LandBlockQuery, LandBlockForm } from '@/api/system/landTransfer/landBlock/types';
|
|
|
|
|
import { useUserStoreHook } from '@/store/modules/user';
|
2025-09-02 09:52:36 +08:00
|
|
|
|
import { getCurrentInstance, ComponentInternalInstance, onMounted, onUnmounted, watch, reactive, ref, toRefs, computed } from 'vue';
|
|
|
|
|
import { ElFormInstance } from 'element-plus';
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 类型定义补充
|
2025-08-27 19:50:22 +08:00
|
|
|
|
interface DialogOption {
|
|
|
|
|
visible: boolean;
|
|
|
|
|
title: string;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 方阵级联选择器选项类型
|
|
|
|
|
interface FangzhenOption {
|
|
|
|
|
matrixId: string | number;
|
|
|
|
|
name: string;
|
|
|
|
|
children?: FangzhenOption[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 方阵表单项类型
|
2025-08-27 19:50:22 +08:00
|
|
|
|
interface UnitBoItem {
|
|
|
|
|
unitProjectArea: string;
|
|
|
|
|
unitProjectStatus: string;
|
|
|
|
|
unitProjectId: (string | number)[]; // 级联选择值(数组)
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 方阵表单根模型类型(关键:显式声明unitBoList)
|
|
|
|
|
interface MatrixForm {
|
|
|
|
|
landId?: string | number; // 关联的地块ID
|
|
|
|
|
unitBoList: UnitBoItem[]; // 方阵列表
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
// 基础实例与Store
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
|
|
|
const userStore = useUserStoreHook();
|
|
|
|
|
const currentProject = computed(() => userStore.selectedProject);
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
// 响应式数据
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const landBlockList = ref<LandBlockVO[]>([]);
|
2025-09-02 09:52:36 +08:00
|
|
|
|
const fangzhenList = ref<FangzhenOption[]>([]);
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const buttonLoading = ref(false);
|
|
|
|
|
const loading = ref(true);
|
|
|
|
|
const showSearch = ref(true);
|
2025-09-02 09:52:36 +08:00
|
|
|
|
const uploadRef = ref<any>(null);
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 方阵表单模型(核心修复:使用reactive并显式声明结构)
|
2025-09-04 17:56:01 +08:00
|
|
|
|
const formM = ref<MatrixForm>({
|
2025-09-02 09:52:36 +08:00
|
|
|
|
landId: undefined,
|
|
|
|
|
unitBoList: [{ unitProjectArea: '', unitProjectStatus: '', unitProjectId: [] }]
|
|
|
|
|
});
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
// 表格选择相关
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const ids = ref<Array<string | number>>([]);
|
|
|
|
|
const single = ref(true);
|
|
|
|
|
const multiple = ref(true);
|
|
|
|
|
const total = ref(0);
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
// 表单Ref
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const queryFormRef = ref<ElFormInstance>();
|
|
|
|
|
const landBlockFormRef = ref<ElFormInstance>();
|
|
|
|
|
const landBlockFormMatrixRef = ref<ElFormInstance>();
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
// 弹窗配置
|
|
|
|
|
const dialog = reactive<DialogOption>({ visible: false, title: '' });
|
|
|
|
|
const dialogMatrix = reactive<DialogOption>({ visible: false, title: '选择方阵' });
|
2025-07-26 11:44:09 +08:00
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
// 初始表单数据
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const initFormData: LandBlockForm = {
|
|
|
|
|
id: undefined,
|
2025-08-14 01:58:00 +08:00
|
|
|
|
projectId: currentProject.value?.id,
|
2025-07-26 11:44:09 +08:00
|
|
|
|
landCode: undefined,
|
|
|
|
|
landName: undefined,
|
|
|
|
|
villageCommittee: undefined,
|
|
|
|
|
designArea: undefined,
|
|
|
|
|
blockCount: undefined,
|
|
|
|
|
farmerCount: undefined,
|
|
|
|
|
remark: undefined
|
|
|
|
|
};
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
// 核心数据(含表单规则)
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const data = reactive({
|
|
|
|
|
form: { ...initFormData },
|
|
|
|
|
queryParams: {
|
|
|
|
|
pageNum: 1,
|
|
|
|
|
pageSize: 10,
|
2025-08-14 01:58:00 +08:00
|
|
|
|
projectId: currentProject.value?.id,
|
2025-07-26 11:44:09 +08:00
|
|
|
|
landCode: undefined,
|
|
|
|
|
landName: undefined,
|
|
|
|
|
villageCommittee: undefined,
|
|
|
|
|
designArea: undefined,
|
|
|
|
|
blockCount: undefined,
|
|
|
|
|
farmerCount: undefined,
|
|
|
|
|
params: {}
|
|
|
|
|
},
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 地块表单规则
|
2025-07-26 11:44:09 +08:00
|
|
|
|
rules: {
|
|
|
|
|
id: [{ required: true, message: '主键ID不能为空', trigger: 'blur' }],
|
|
|
|
|
projectId: [{ required: true, message: '项目ID不能为空', trigger: 'blur' }],
|
|
|
|
|
landCode: [{ required: true, message: '地块编号不能为空', trigger: 'blur' }],
|
|
|
|
|
landName: [{ required: true, message: '地块名称不能为空', trigger: 'blur' }]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-09-02 19:00:50 +08:00
|
|
|
|
const { queryParams, form, rules } = toRefs(data);
|
2025-07-26 11:44:09 +08:00
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 查询地块列表 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const getList = async () => {
|
|
|
|
|
loading.value = true;
|
2025-08-27 19:50:22 +08:00
|
|
|
|
try {
|
|
|
|
|
const res = await listLandBlock(queryParams.value);
|
|
|
|
|
landBlockList.value = res.rows;
|
|
|
|
|
total.value = res.total;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
proxy?.$modal.msgError('获取地块列表失败');
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
2025-07-26 11:44:09 +08:00
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 地块表单取消 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const cancel = () => {
|
|
|
|
|
reset();
|
|
|
|
|
dialog.visible = false;
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 地块表单重置 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const reset = () => {
|
|
|
|
|
form.value = { ...initFormData };
|
|
|
|
|
landBlockFormRef.value?.resetFields();
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 搜索提交 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const handleQuery = () => {
|
|
|
|
|
queryParams.value.pageNum = 1;
|
|
|
|
|
getList();
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 搜索重置 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const resetQuery = () => {
|
|
|
|
|
queryFormRef.value?.resetFields();
|
|
|
|
|
handleQuery();
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 表格选择变化 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const handleSelectionChange = (selection: LandBlockVO[]) => {
|
|
|
|
|
ids.value = selection.map((item) => item.id);
|
2025-08-27 19:50:22 +08:00
|
|
|
|
single.value = selection.length !== 1;
|
|
|
|
|
multiple.value = selection.length === 0;
|
2025-07-26 11:44:09 +08:00
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 新增地块 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const handleAdd = () => {
|
|
|
|
|
reset();
|
|
|
|
|
dialog.visible = true;
|
|
|
|
|
dialog.title = '添加地块信息';
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 编辑地块 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const handleUpdate = async (row?: LandBlockVO) => {
|
|
|
|
|
reset();
|
|
|
|
|
const _id = row?.id || ids.value[0];
|
2025-08-27 19:50:22 +08:00
|
|
|
|
if (!_id) return proxy?.$modal.msgWarning('请选择要编辑的地块');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await getLandBlock(_id);
|
|
|
|
|
Object.assign(form.value, res.data);
|
|
|
|
|
dialog.visible = true;
|
|
|
|
|
dialog.title = '修改地块信息';
|
|
|
|
|
} catch (err) {
|
|
|
|
|
proxy?.$modal.msgError('获取地块详情失败');
|
|
|
|
|
}
|
2025-07-26 11:44:09 +08:00
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 提交地块表单 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const submitForm = () => {
|
|
|
|
|
landBlockFormRef.value?.validate(async (valid: boolean) => {
|
2025-08-27 19:50:22 +08:00
|
|
|
|
if (!valid) return;
|
|
|
|
|
|
|
|
|
|
buttonLoading.value = true;
|
|
|
|
|
try {
|
2025-07-26 11:44:09 +08:00
|
|
|
|
if (form.value.id) {
|
2025-08-27 19:50:22 +08:00
|
|
|
|
await updateLandBlock(form.value);
|
2025-07-26 11:44:09 +08:00
|
|
|
|
} else {
|
2025-08-27 19:50:22 +08:00
|
|
|
|
await addLandBlock(form.value);
|
2025-07-26 11:44:09 +08:00
|
|
|
|
}
|
|
|
|
|
proxy?.$modal.msgSuccess('操作成功');
|
|
|
|
|
dialog.visible = false;
|
|
|
|
|
await getList();
|
2025-08-27 19:50:22 +08:00
|
|
|
|
} catch (err) {
|
|
|
|
|
proxy?.$modal.msgError(form.value.id ? '修改失败' : '新增失败');
|
|
|
|
|
} finally {
|
|
|
|
|
buttonLoading.value = false;
|
2025-07-26 11:44:09 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 删除地块 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const handleDelete = async (row?: LandBlockVO) => {
|
|
|
|
|
const _ids = row?.id || ids.value;
|
2025-08-27 19:50:22 +08:00
|
|
|
|
if (!_ids.length) return proxy?.$modal.msgWarning('请选择要删除的地块');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await proxy?.$modal.confirm(`是否确认删除地块信息编号为"${_ids}"的数据项?`);
|
|
|
|
|
await delLandBlock(_ids);
|
|
|
|
|
proxy?.$modal.msgSuccess('删除成功');
|
|
|
|
|
await getList();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// 取消确认时不提示错误
|
|
|
|
|
if (err !== 'cancel') proxy?.$modal.msgError('删除失败');
|
|
|
|
|
}
|
2025-07-26 11:44:09 +08:00
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 获取方阵列表 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const getfangzhenList = async () => {
|
2025-08-27 19:50:22 +08:00
|
|
|
|
if (!currentProject.value?.id) return;
|
|
|
|
|
|
2025-07-26 11:44:09 +08:00
|
|
|
|
loading.value = true;
|
2025-08-27 19:50:22 +08:00
|
|
|
|
try {
|
|
|
|
|
const res = await subMatrix(currentProject.value.id);
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 处理方阵数据(级联选择需父子结构)
|
2025-08-27 19:50:22 +08:00
|
|
|
|
res.data.forEach((item: any) => {
|
|
|
|
|
item.children?.forEach((item2: any) => {
|
2025-09-02 09:52:36 +08:00
|
|
|
|
item2.matrixId = `${item2.name}_${item2.matrixId}`;
|
2025-08-27 19:50:22 +08:00
|
|
|
|
});
|
2025-07-26 11:44:09 +08:00
|
|
|
|
});
|
2025-08-27 19:50:22 +08:00
|
|
|
|
fangzhenList.value = res.data;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
proxy?.$modal.msgError('获取方阵列表失败');
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
2025-07-26 11:44:09 +08:00
|
|
|
|
};
|
|
|
|
|
|
2025-09-02 09:52:36 +08:00
|
|
|
|
/** 关联方阵 */
|
2025-08-27 19:50:22 +08:00
|
|
|
|
const handleView = async (row: LandBlockVO) => {
|
|
|
|
|
if (!row?.id) return proxy?.$modal.msgWarning('请选择有效的地块');
|
2025-09-04 17:56:01 +08:00
|
|
|
|
console.log('🚀 ~ handleView ~ row:', row);
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 重置方阵表单
|
2025-08-27 19:50:22 +08:00
|
|
|
|
resetMatrix();
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 绑定当前地块ID
|
2025-09-04 17:56:01 +08:00
|
|
|
|
formM.value.landId = row.id;
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 打开弹窗
|
2025-07-26 11:44:09 +08:00
|
|
|
|
dialogMatrix.visible = true;
|
2025-09-02 19:09:43 +08:00
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
dialogMatrix.title = `关联方阵(地块:${row.landName || row.landCode})`;
|
2025-07-26 11:44:09 +08:00
|
|
|
|
};
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
/** 新增方阵表单项 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const addUnitBoItem = () => {
|
2025-09-04 17:56:01 +08:00
|
|
|
|
formM.value.unitBoList.push({
|
2025-07-26 11:44:09 +08:00
|
|
|
|
unitProjectArea: '',
|
|
|
|
|
unitProjectStatus: '',
|
2025-09-02 09:52:36 +08:00
|
|
|
|
unitProjectId: []
|
2025-07-26 11:44:09 +08:00
|
|
|
|
});
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 重置校验状态
|
|
|
|
|
landBlockFormMatrixRef.value?.clearValidate();
|
2025-07-26 11:44:09 +08:00
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 删除方阵表单项 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const removeUnitBoItem = (index: number) => {
|
2025-09-04 17:56:01 +08:00
|
|
|
|
if (formM.value.unitBoList.length <= 1) {
|
2025-08-27 19:50:22 +08:00
|
|
|
|
return proxy?.$modal.msgWarning('至少保留一项方阵配置');
|
2025-07-26 11:44:09 +08:00
|
|
|
|
}
|
2025-09-04 17:56:01 +08:00
|
|
|
|
formM.value.unitBoList.splice(index, 1);
|
2025-08-27 19:50:22 +08:00
|
|
|
|
landBlockFormMatrixRef.value?.clearValidate();
|
2025-07-26 11:44:09 +08:00
|
|
|
|
};
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
2025-09-02 09:52:36 +08:00
|
|
|
|
/** 提交方阵关联表单(核心修复:数据处理逻辑) */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const submitFormMatrix = () => {
|
|
|
|
|
landBlockFormMatrixRef.value?.validate(async (valid: boolean) => {
|
2025-08-27 19:50:22 +08:00
|
|
|
|
if (!valid) return;
|
2025-09-04 17:56:01 +08:00
|
|
|
|
if (!formM.value.landId) return proxy?.$modal.msgWarning('地块ID异常,请重新选择地块');
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
try {
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 处理方阵数据(修复ID拆分逻辑)
|
2025-09-04 17:56:01 +08:00
|
|
|
|
const unitBoListParams = formM.value.unitBoList.map((item) => {
|
2025-09-02 09:52:36 +08:00
|
|
|
|
// 取级联选择的最后一层值
|
|
|
|
|
const lastLevelValue = item.unitProjectId[item.unitProjectId.length - 1];
|
|
|
|
|
if (!lastLevelValue) throw new Error('请选择完整的方阵');
|
|
|
|
|
|
|
|
|
|
// 拆分名称和ID
|
|
|
|
|
const [unitProjectName, unitProjectId] = String(lastLevelValue).split('_');
|
|
|
|
|
if (!unitProjectId) throw new Error('方阵ID解析失败,请重新选择');
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
unitProjectArea: item.unitProjectArea.trim(),
|
|
|
|
|
unitProjectStatus: item.unitProjectStatus.trim(),
|
2025-09-02 09:52:36 +08:00
|
|
|
|
unitProjectId: unitProjectId,
|
|
|
|
|
unitProjectName: unitProjectName
|
2025-08-27 19:50:22 +08:00
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 调用关联接口
|
|
|
|
|
const res = await LandUnit({
|
2025-09-04 17:56:01 +08:00
|
|
|
|
landId: formM.value.landId,
|
2025-08-27 19:50:22 +08:00
|
|
|
|
unitBoList: unitBoListParams
|
2025-07-26 11:44:09 +08:00
|
|
|
|
});
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
proxy?.$modal.msgSuccess('关联方阵成功');
|
2025-07-26 11:44:09 +08:00
|
|
|
|
dialogMatrix.visible = false;
|
2025-09-02 09:52:36 +08:00
|
|
|
|
await getList();
|
2025-07-26 11:44:09 +08:00
|
|
|
|
} else {
|
2025-08-27 19:50:22 +08:00
|
|
|
|
proxy?.$modal.msgError(res.msg || '关联失败');
|
2025-07-26 11:44:09 +08:00
|
|
|
|
}
|
2025-08-27 19:50:22 +08:00
|
|
|
|
} catch (err: any) {
|
|
|
|
|
proxy?.$modal.msgError(err.msg || '关联过程异常');
|
2025-07-26 11:44:09 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
/** 方阵表单取消 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const cancelMatrix = () => {
|
|
|
|
|
resetMatrix();
|
|
|
|
|
dialogMatrix.visible = false;
|
|
|
|
|
};
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
2025-09-02 09:52:36 +08:00
|
|
|
|
/** 方阵表单重置 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const resetMatrix = () => {
|
2025-08-27 19:50:22 +08:00
|
|
|
|
if (landBlockFormMatrixRef.value) {
|
|
|
|
|
landBlockFormMatrixRef.value.resetFields();
|
|
|
|
|
landBlockFormMatrixRef.value.clearValidate();
|
|
|
|
|
}
|
2025-09-04 17:56:01 +08:00
|
|
|
|
formM.value.landId = undefined;
|
|
|
|
|
formM.value.unitBoList = [{ unitProjectArea: '', unitProjectStatus: '', unitProjectId: [] }];
|
2025-07-26 11:44:09 +08:00
|
|
|
|
};
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
/** 监听项目变化,刷新数据 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
const listeningProject = watch(
|
2025-08-14 01:58:00 +08:00
|
|
|
|
() => currentProject.value?.id,
|
2025-08-27 19:50:22 +08:00
|
|
|
|
(newId) => {
|
|
|
|
|
if (newId) {
|
|
|
|
|
queryParams.value.projectId = newId;
|
2025-09-02 09:52:36 +08:00
|
|
|
|
getfangzhenList();
|
|
|
|
|
getList();
|
2025-08-27 19:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2025-09-02 09:52:36 +08:00
|
|
|
|
{ immediate: true }
|
2025-07-26 11:44:09 +08:00
|
|
|
|
);
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 导入Excel */
|
|
|
|
|
const handleImport = (options: { file: File }) => {
|
|
|
|
|
if (!currentProject.value?.id) return proxy?.$modal.msgWarning('请先选择项目');
|
|
|
|
|
if (!options.file) return proxy?.$modal.msgWarning('请选择Excel文件');
|
|
|
|
|
|
2025-08-25 19:58:42 +08:00
|
|
|
|
loading.value = true;
|
2025-08-27 19:50:22 +08:00
|
|
|
|
const formData = new FormData();
|
2025-08-25 19:58:42 +08:00
|
|
|
|
formData.append('file', options.file);
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
importLandBlock(currentProject.value.id, formData)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
proxy?.$modal.msgSuccess(res.msg || '导入成功');
|
|
|
|
|
getList();
|
|
|
|
|
getfangzhenList();
|
|
|
|
|
} else {
|
|
|
|
|
proxy?.$modal.msgError(res.msg || '导入失败');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
proxy?.$modal.msgError(err.msg || '导入接口异常');
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
});
|
2025-08-25 19:58:42 +08:00
|
|
|
|
};
|
2025-09-02 09:52:36 +08:00
|
|
|
|
|
|
|
|
|
/** 导出模板 */
|
2025-08-30 08:18:27 +08:00
|
|
|
|
const exportFile = () => {
|
|
|
|
|
try {
|
|
|
|
|
const link = document.createElement('a');
|
|
|
|
|
link.href = '/dikuai.xlsx';
|
|
|
|
|
link.download = '地块信息导入模版.xlsx';
|
|
|
|
|
document.body.appendChild(link);
|
|
|
|
|
link.click();
|
|
|
|
|
document.body.removeChild(link);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
alert('下载失败,请重试');
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-09-02 09:52:36 +08:00
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 下载导入模板 */
|
2025-08-25 19:58:42 +08:00
|
|
|
|
const downloadTemplate = () => {
|
|
|
|
|
try {
|
|
|
|
|
const link = document.createElement('a');
|
2025-09-02 09:52:36 +08:00
|
|
|
|
link.href = '/landBlock.xlsx';
|
|
|
|
|
link.download = '地块信息导入模板.xlsx';
|
2025-08-25 19:58:42 +08:00
|
|
|
|
document.body.appendChild(link);
|
2025-09-02 09:52:36 +08:00
|
|
|
|
link.click();
|
2025-08-27 19:50:22 +08:00
|
|
|
|
} catch (err) {
|
|
|
|
|
proxy?.$modal.msgError('模板下载失败,请重试');
|
|
|
|
|
} finally {
|
2025-09-02 09:52:36 +08:00
|
|
|
|
const link = document.querySelector('a[download="地块信息导入模板.xlsx"]');
|
|
|
|
|
if (link) document.body.removeChild(link);
|
2025-08-25 19:58:42 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 19:50:22 +08:00
|
|
|
|
/** 生命周期:组件卸载时清理监听 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
listeningProject();
|
|
|
|
|
});
|
2025-08-27 19:50:22 +08:00
|
|
|
|
|
|
|
|
|
/** 生命周期:组件挂载时初始化数据 */
|
2025-07-26 11:44:09 +08:00
|
|
|
|
onMounted(() => {
|
|
|
|
|
getList();
|
|
|
|
|
getfangzhenList();
|
|
|
|
|
});
|
|
|
|
|
</script>
|