This commit is contained in:
lzc 2025-04-02 17:32:17 +08:00
commit 8fc195de39
4 changed files with 55 additions and 33 deletions

View File

@ -3,7 +3,7 @@
* @Author: zenghua.wang * @Author: zenghua.wang
* @Date: 2022-02-23 21:12:37 * @Date: 2022-02-23 21:12:37
* @LastEditors: zenghua.wang * @LastEditors: zenghua.wang
* @LastEditTime: 2025-03-28 14:18:58 * @LastEditTime: 2025-04-02 14:21:56
*/ */
import lodash from 'lodash'; import lodash from 'lodash';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@ -138,12 +138,12 @@ export const setPropDisplay = (column, fields) => {
* @param {*} tree * @param {*} tree
* @returns * @returns
*/ */
export const flattenTree = (tree) => { export const flattenTree = (tree, children = 'children') => {
const result = []; const result = [];
function traverse(node) { function traverse(node) {
result.push(node); result.push(node);
if (node.children && node.children.length > 0) { if (node[children] && node[children].length > 0) {
node.children.forEach((child) => traverse(child)); node[children].forEach((child) => traverse(child));
} }
} }
if (Array.isArray(tree)) { if (Array.isArray(tree)) {
@ -276,6 +276,7 @@ export const getTree = (data, id = 'id', parentId = 'parentId', children = 'chil
const map = {}; const map = {};
data.forEach((item) => { data.forEach((item) => {
item.level = 0;
map[item[id]] = item; map[item[id]] = item;
}); });
@ -283,9 +284,11 @@ export const getTree = (data, id = 'id', parentId = 'parentId', children = 'chil
data.forEach((item) => { data.forEach((item) => {
const parent = map[item[parentId]]; const parent = map[item[parentId]];
if (parent) { if (parent) {
item.level = parent.level + 1;
parent[children] = parent[children] || []; parent[children] = parent[children] || [];
parent[children].push(item); parent[children].push(item);
} else { } else {
item.level = 0;
tree.push(item); tree.push(item);
} }
}); });

View File

@ -34,20 +34,18 @@
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, reactive, onMounted } from 'vue'; import { ref, reactive } from 'vue';
import { useRouter } from 'vue-router';
import { useApp } from '@/hooks'; import { useApp } from '@/hooks';
import { useUserStore } from '@/store/modules/user'; import { useUserStore } from '@/store/modules/user';
import { CRUD_OPTIONS } from '@/config'; import { CRUD_OPTIONS } from '@/config';
import { isEmpty, setDicData, debounce } from '@/utils'; import { isEmpty, setDicData, debounce } from '@/utils';
import { CommonDicData } from '@/apis'; // import { CommonDicData } from '@/apis';
import { getLandsList } from '@/apis/land'; import { getLandsList } from '@/apis/land';
import { GetEntityList, AddEntity, UpdateEntity, DeleteEntity, UpdateStatus } from '@/apis/plantingAndBreeding/base'; import { GetEntityList, AddEntity, UpdateEntity, DeleteEntity, UpdateStatus } from '@/apis/plantingAndBreeding/base';
const { VITE_APP_BASE_API } = import.meta.env; const { VITE_APP_BASE_API } = import.meta.env;
const app = useApp(); const app = useApp();
const UserStore = useUserStore(); const UserStore = useUserStore();
const router = useRouter();
const crudRef = ref(null); const crudRef = ref(null);
const state = reactive({ const state = reactive({
loading: false, loading: false,
@ -142,9 +140,15 @@ const state = reactive({
{ {
label: '区域面积', label: '区域面积',
prop: 'area', prop: 'area',
width: 100, width: 150,
overHidden: true,
disabled: true, disabled: true,
labelTip: '请先选择地块!', labelTip: '请先选择地块!',
formatter: (row) => {
// const item = state.unitList.find((v) => v.dictValue == row.unit);
// return row.area + (!isEmpty(item) ? item.dictLabel : '');
return row.area + (!isEmpty(row.unit) ? row.unit : '平方米');
},
}, },
{ {
label: '状态', label: '状态',
@ -238,18 +242,18 @@ const state = reactive({
}); });
// //
const getUnit = async () => { // const getUnit = async () => {
CommonDicData('sys_unit_type') // CommonDicData('sys_unit_type')
.then((res) => { // .then((res) => {
console.log(250, res); // console.log(250, res);
if (res.code === 200) { // if (res.code === 200) {
state.unitList = res.data; // state.unitList = res.data;
} // }
}) // })
.catch((err) => { // .catch((err) => {
app.$message.error(err.msg); // app.$message.error(err.msg);
}); // });
}; // };
const loadData = async () => { const loadData = async () => {
state.loading = true; state.loading = true;
@ -276,9 +280,9 @@ const loadData = async () => {
loadData(); loadData();
onMounted(() => { // onMounted(() => {
getUnit(); // getUnit();
}); // });
// //
const currentChange = (current) => { const currentChange = (current) => {
@ -412,7 +416,7 @@ const remoteLandList = async (val) => {
// //
const selectedChange = ({ item, value, dic }) => { const selectedChange = ({ item, value, dic }) => {
// console.log(390, value, item); // console.log(390, value, item);
crudRef.value.tableForm.landId = item?.id; crudRef.value.tableForm.landId = value;
crudRef.value.tableForm.landName = item?.landName; crudRef.value.tableForm.landName = item?.landName;
crudRef.value.tableForm.address = item?.address; crudRef.value.tableForm.address = item?.address;
crudRef.value.tableForm.area = item?.area; crudRef.value.tableForm.area = item?.area;

View File

@ -51,13 +51,16 @@ const state = reactive({
selection: [], selection: [],
options: { options: {
...CRUD_OPTIONS, ...CRUD_OPTIONS,
addBtnText: '添加网格', // addBtnText: '',
column: [ column: [
{ {
label: '网格区', label: '网格区',
prop: 'gridArea', prop: 'gridArea',
search: true, search: true,
width: 200, width: 200,
addDisplay: false,
editDisplay: false,
viewDisplay: true,
rules: { rules: {
required: true, required: true,
message: '请输入', message: '请输入',
@ -93,6 +96,11 @@ const state = reactive({
addDisplay: true, addDisplay: true,
editDisplay: true, editDisplay: true,
viewDisplay: false, viewDisplay: false,
// multiple: true,
// checkStrictly: true,
// collapseTags: true,
// emitPath: false,
// checkDescendants: false,
props: { props: {
label: 'areaName', label: 'areaName',
value: 'areaCode', value: 'areaCode',
@ -261,7 +269,6 @@ const selectionChange = (rows) => {
// //
const rowView = (row) => { const rowView = (row) => {
// state.currentRow = row;
crudRef.value.rowView(row); crudRef.value.rowView(row);
}; };
@ -271,7 +278,8 @@ const setCity = (row) => {
row.cityCode = row?.cities[1] ?? null; row.cityCode = row?.cities[1] ?? null;
row.gridAreaCode = row?.cities[2] ?? null; row.gridAreaCode = row?.cities[2] ?? null;
row.townCode = row?.cities[3] ?? null; row.townCode = row?.cities[3] ?? null;
row.village = row?.cities[3] ?? null; row.village = row?.cities[4] ?? null;
// row.village = row?.cities.join(',');
} }
}; };
@ -296,7 +304,8 @@ const rowSave = (row, done, loading) => {
// //
const rowEdit = (row) => { const rowEdit = (row) => {
row.cities = compact([row.provinceCode, row.cityCode, row.gridAreaCode ?? '', row.townCode ?? '', row.village ?? '']); const village = !isEmpty(row.village) ? row.village : [];
row.cities = compact([row.provinceCode, row.cityCode, row.gridAreaCode ?? '', row.townCode ?? '', ...village]);
crudRef.value.rowEdit(row); crudRef.value.rowEdit(row);
}; };
const rowUpdate = (row, index, done, loading) => { const rowUpdate = (row, index, done, loading) => {
@ -331,7 +340,6 @@ const rowDel = (row, index, done) => {
.then((res) => { .then((res) => {
if (res.code === 200) { if (res.code === 200) {
app.$message.success('删除成功!'); app.$message.success('删除成功!');
done();
loadData(); loadData();
} }
}) })

View File

@ -84,7 +84,7 @@ const state = reactive({
selection: [], selection: [],
options: { options: {
...CRUD_OPTIONS, ...CRUD_OPTIONS,
addBtnText: '添加信息', // addBtnText: '',
column: [ column: [
{ {
label: '溯源码', label: '溯源码',
@ -236,6 +236,12 @@ const state = reactive({
}, },
{ {
label: '乡镇', label: '乡镇',
prop: 'town',
hide: true,
display: false,
},
{
label: '村',
prop: 'village', prop: 'village',
hide: true, hide: true,
display: false, display: false,
@ -455,7 +461,8 @@ const setCity = (row) => {
row.province = row?.cities[0] ?? null; row.province = row?.cities[0] ?? null;
row.city = row?.cities[1] ?? null; row.city = row?.cities[1] ?? null;
row.county = row?.cities[2] ?? null; row.county = row?.cities[2] ?? null;
row.village = row?.cities[3] ?? null; row.town = row?.cities[3] ?? null;
row.village = row?.cities[4] ?? null;
} }
}; };
@ -509,7 +516,7 @@ const rowSave = (row, done, loading) => {
// //
const rowEdit = (row) => { const rowEdit = (row) => {
row.base64 = row.productUrl; row.base64 = row.productUrl;
row.cities = compact([row.province, row.city, row.county ?? '', row.village ?? '']); row.cities = compact([row.province, row.city, row.county ?? '', row.town ?? '', row.village ?? '']);
crudRef.value.rowEdit(row); crudRef.value.rowEdit(row);
}; };
const rowUpdate = (row, index, done, loading) => { const rowUpdate = (row, index, done, loading) => {