feat:肥料管理表格展示数据处理

This commit is contained in:
李想 2025-03-26 13:37:24 +08:00
parent 13d7bd86c9
commit eb757a2e35
7 changed files with 209 additions and 51 deletions

View File

@ -10,4 +10,4 @@ VITE_APP_SUB_GSS = '//localhost:9529/sub-government-screen-service/'
VITE_APP_BASE_API = '/apis' VITE_APP_BASE_API = '/apis'
VITE_APP_BASE_URL = 'http://192.168.18.99:8080' VITE_APP_BASE_URL = 'http://192.168.18.99:8080'
VITE_APP_UPLOAD_API = '/uploadApis' VITE_APP_UPLOAD_API = '/uploadApis'
VITE_APP_UPLOAD_URL = 'http://192.168.18.99:9300' VITE_APP_UPLOAD_URL = 'http://192.168.18.99:8080'

View File

@ -39,7 +39,7 @@ export default defineConfig(({ command, mode }) => {
[VITE_APP_UPLOAD_API]: { [VITE_APP_UPLOAD_API]: {
target: VITE_APP_UPLOAD_URL, target: VITE_APP_UPLOAD_URL,
changeOrigin: true, changeOrigin: true,
rewrite: (path) => path.replace(/^\/uploadApis/, ''), // rewrite: (path) => path.replace(/^\/uploadApis/, ''),
}, },
}, },
}, },

View File

@ -12,3 +12,10 @@ export function getPesticideList(params) {
params, params,
}); });
} }
/* 新增农药 */
export function addPesticide(data) {
return request('/inputGoods/pesticide/save', {
method: 'POST',
data,
});
}

View File

@ -1,5 +1,5 @@
<template> <template>
<el-menu mode="horizontal" class="input_supplies_type_menu_" @select="handleTypeSelect"> <el-menu mode="horizontal" class="input_supplies_type_menu_" :default-active="ac" @select="handleTypeSelect">
<template v-for="item in types" :key="`type_menu_${item.value}`"> <template v-for="item in types" :key="`type_menu_${item.value}`">
<el-menu-item v-if="!item.children" :index="item.value">{{ item.label }}</el-menu-item> <el-menu-item v-if="!item.children" :index="item.value">{{ item.label }}</el-menu-item>
<SubMenu v-else :types="item" /> <SubMenu v-else :types="item" />
@ -8,6 +8,7 @@
</template> </template>
<script setup> <script setup>
import { ref } from 'vue';
import SubMenu from './SubMenu.vue'; import SubMenu from './SubMenu.vue';
const emit = defineEmits(['update:type']); const emit = defineEmits(['update:type']);
@ -59,7 +60,12 @@ const props = defineProps({
}, },
], ],
}, },
type: {
type: String,
default: '0',
},
}); });
const ac = ref(props.type);
function handleTypeSelect(key) { function handleTypeSelect(key) {
emit('update:type', key); emit('update:type', key);
} }

View File

@ -10,6 +10,7 @@ export function useBasicInfo(set = {}) {
}, },
set set
); );
/* ------ data ------ */ /* ------ data ------ */
// #region // #region
const materialTypes = reactive({ const materialTypes = reactive({
@ -19,6 +20,7 @@ export function useBasicInfo(set = {}) {
4: [{ value: '0', label: '全部' }], 4: [{ value: '0', label: '全部' }],
5: [{ value: '0', label: '全部' }], 5: [{ value: '0', label: '全部' }],
}); });
/* 不包含顶级 */
const materialTwoLevel = ref({}); const materialTwoLevel = ref({});
/* ------ 农药 ------ */ /* ------ 农药 ------ */
@ -37,19 +39,26 @@ export function useBasicInfo(set = {}) {
// #endregion // #endregion
// #endregion // #endregion
/* ------ ------ */
// #region
/* 获取物资类型 */
async function getmaterialType(_set = {}) { async function getmaterialType(_set = {}) {
let params = Object.assign(searchCondition, _set); let params = Object.assign(searchCondition, _set);
let res = await getMaterailTypes(params); let res = await getMaterailTypes(params);
console.log('two --- ', res);
if (res && res?.code == 200) { if (res && res?.code == 200) {
res.data.forEach((item) => { res.data.forEach((item) => {
const { moduleType, children } = item; const { moduleType, children } = item;
materialTypes[moduleType].push(...handleTypes(children)); materialTypes[moduleType].push(...handleTypes(children));
// materialTwoLevel.value[moduleType] = handleTypes(children);
handleTwoLevel(); handleTwoLevel();
}); });
console.log('materialTypes --- ', materialTypes);
console.log('materialTwoLevel --- ', materialTwoLevel.value);
} }
loadFinish.value = true; loadFinish.value = true;
} }
/* 将所有的数据处理成value label格式方便其他地方指直接使用 */
function handleTypes(arr) { function handleTypes(arr) {
arr.forEach((item) => { arr.forEach((item) => {
item.value = item.id; item.value = item.id;
@ -60,6 +69,7 @@ export function useBasicInfo(set = {}) {
}); });
return arr; return arr;
} }
/* 处理二级及以下的联动数据 */
function handleTwoLevel() { function handleTwoLevel() {
for (let key in materialTypes) { for (let key in materialTypes) {
materialTwoLevel.value[key] = {}; materialTwoLevel.value[key] = {};
@ -70,6 +80,22 @@ export function useBasicInfo(set = {}) {
}); });
} }
} }
/* 获取标签的名字 */
function targetName(arr, ids, _name) {
let _ids = JSON.parse(JSON.stringify(ids));
let name = '';
if (!arr || !arr.length || _ids.length < 1) {
return;
} else {
let obj = arr.find((v) => v.value == _ids[0]) || { value: '', label: '', children: [] };
name = _name + (_name ? '/' : '') + obj.label;
_ids.splice(0, 1);
if (_ids.length > 0) {
name = targetName(obj.children, _ids, name);
}
}
return name;
}
function filterTypes(_set = {}) { function filterTypes(_set = {}) {
let filterType = Object.assign( let filterType = Object.assign(
{ {
@ -81,7 +107,6 @@ export function useBasicInfo(set = {}) {
let all = materialTypes[filterType.moduleType]; let all = materialTypes[filterType.moduleType];
let _arr = []; let _arr = [];
all.forEach((item) => { all.forEach((item) => {
console.log('item', item);
if (filterType.dataType == item.dataType) { if (filterType.dataType == item.dataType) {
_arr = item.children; _arr = item.children;
} }
@ -89,6 +114,7 @@ export function useBasicInfo(set = {}) {
return _arr; return _arr;
} }
// #endregion
onMounted(getmaterialType); onMounted(getmaterialType);
return { return {
@ -98,6 +124,7 @@ export function useBasicInfo(set = {}) {
goodsUnitOptions, goodsUnitOptions,
useDosageUnit, useDosageUnit,
getmaterialType, getmaterialType,
targetName,
filterTypes, filterTypes,
}; };
} }

View File

@ -37,12 +37,16 @@ const option = ref({
CRUD_OPTIONS, CRUD_OPTIONS,
selection: false, selection: false,
column: [ column: [
{
prop: 'keywords',
label: '关键字',
},
{ {
prop: '', prop: '',
label: '编号', label: '编号',
}, },
{ {
prop: '', prop: 'xxxName',
label: '名称', label: '名称',
}, },
{ {

View File

@ -1,16 +1,26 @@
<template> <template>
<CustomCard> <CustomCard>
<h2>农药基本信息</h2> <h2>农药基本信息</h2>
<TypeMenu v-if="materialTypes.length > 1" v-model:type="_type" :types="materialTypes['1']" /> <TypeMenu v-if="materialTypes[1].length > 1" v-model:type="_type" :types="materialTypes['1']" />
<br /> <br />
<avue-crud <avue-crud
ref="crud" ref="crud"
v-model:page="pageData" v-model:page="pageData"
v-model:search="searchCondition"
:table-loading="_loading" :table-loading="_loading"
:data="data" :data="data"
:option="option" :option="option"
:before-close="handleCloseDialog" :before-close="handleCloseDialog"
@search-change="
(form, done) => {
getData(1);
done();
}
"
@search-reset="getData(1)"
@refresh-change="getData" @refresh-change="getData"
@current-change="getData"
@size-change="getData(1)"
@row-save="handleRowSave" @row-save="handleRowSave"
@row-update="handleRowUpdate" @row-update="handleRowUpdate"
> >
@ -45,35 +55,34 @@
</template> </template>
<script setup> <script setup>
import { reactive, ref, watch, onMounted, h, computed } from 'vue'; import { reactive, ref, watch, onMounted, h } from 'vue';
import CustomCard from '@/components/CustomCard.vue'; import CustomCard from '@/components/CustomCard.vue';
import TypeMenu from '../../common/TypeMenu.vue'; import TypeMenu from '../../common/TypeMenu.vue';
import { CRUD_OPTIONS } from '@/config'; import { CRUD_OPTIONS, customRules } from '@/config';
import { useBasicInfo } from '@/views/inputSuppliesManage/hooks/useBasicInfo'; import { useBasicInfo } from '@/views/inputSuppliesManage/hooks/useBasicInfo';
import Attrs from '@/views/inputSuppliesManage/common/Attrs.vue'; import Attrs from '@/views/inputSuppliesManage/common/Attrs.vue';
import NumberSelect from '@/views/inputSuppliesManage/common/NumberSelect.vue'; import NumberSelect from '@/views/inputSuppliesManage/common/NumberSelect.vue';
import inputSuppliesApi from '@/apis/inputSuppliesApi'; import inputSuppliesApi from '@/apis/inputSuppliesApi';
import { ElMessage } from 'element-plus';
const { loadFinish, materialTypes, materialTwoLevel, goodsUnitOptions, useDosageUnit, filterTypes } = useBasicInfo({ const { loadFinish, materialTypes, materialTwoLevel, goodsUnitOptions, useDosageUnit, targetName, filterTypes } = useBasicInfo({
moduleType: '1', moduleType: '1',
}); });
const { getPesticideList } = inputSuppliesApi; const { getPesticideList, addPesticide } = inputSuppliesApi;
onMounted(getData); onMounted(getData);
/* --------------- data --------------- */ /* --------------- data --------------- */
// #region // #region
const _type = ref(''); const _type = ref('0');
watch( watch(
() => _type.value, () => _type.value,
() => { () => getData(1),
console.log(_type.value);
},
{ {
deep: true, deep: true,
} }
); );
const searchCondition = ref({ const searchCondition = ref({
pesticideName: '', keywords: '',
}); });
const crud = ref(); const crud = ref();
const _loading = ref(false); const _loading = ref(false);
@ -83,6 +92,24 @@ const pageData = ref({
currentPage: 1, currentPage: 1,
size: 10, size: 10,
}); });
const dicDatas = ref({
_targetPests: {
one: '1',
two: '1',
dic: [],
},
_mainComponent: {
one: '1',
two: '2',
dic: [],
},
_produceDosage: {
one: '1',
two: '3',
dic: [],
},
});
const option = ref({ const option = ref({
...CRUD_OPTIONS, ...CRUD_OPTIONS,
selection: false, selection: false,
@ -95,6 +122,7 @@ const option = ref({
{ {
hide: true, hide: true,
label: '关键字', label: '关键字',
prop: 'keywords',
search: true, search: true,
addDisplay: false, addDisplay: false,
editDisplay: false, editDisplay: false,
@ -109,6 +137,7 @@ const option = ref({
prop: 'pesticideName', prop: 'pesticideName',
label: '名称', label: '名称',
editDisplay: false, editDisplay: false,
rules: customRules({ msg: '请输入农药名称' }),
}, },
{ {
hide: true, hide: true,
@ -116,6 +145,7 @@ const option = ref({
label: '产品标准证号', label: '产品标准证号',
viewDisplay: false, viewDisplay: false,
editDisplay: false, editDisplay: false,
rules: customRules({ msg: '请输入产品标准证号' }),
}, },
{ {
hide: true, hide: true,
@ -129,11 +159,13 @@ const option = ref({
label: '农药登记证号', label: '农药登记证号',
viewDisplay: false, viewDisplay: false,
editDisplay: false, editDisplay: false,
rules: customRules({ msg: '请输登记证号' }),
}, },
{ {
prop: 'manufacturer', prop: 'manufacturer',
label: '生产厂家', label: '生产厂家',
editDisplay: false, editDisplay: false,
rules: customRules({ msg: '请输入生产厂家' }),
}, },
{ {
prop: 'distributor', prop: 'distributor',
@ -144,55 +176,80 @@ const option = ref({
prop: 'productSpecification', prop: 'productSpecification',
label: '产品规格', label: '产品规格',
editDisplay: false, editDisplay: false,
render: ({ row }) => {
return `${row.productSpecification}${goodsUnitOptions.find((v) => v.value == row.productUnit).label}`;
},
}, },
{ {
prop: 'toxicityLevel', prop: 'toxicityLevel',
label: '毒性', label: '毒性',
editDisplay: false, editDisplay: false,
value: '无毒',
}, },
{ {
prop: 'dosage', prop: 'dosage',
label: '建议用量', label: '建议用量',
editDisplay: false, editDisplay: false,
render: ({ row }) => {
return `${row.suggestDosage}${useDosageUnit.find((v) => v.value == row.suggestUnit).label}`;
},
}, },
{ {
prop: 'validity', prop: 'expiryDate',
label: '保质期', label: '保质期',
editDisplay: false, editDisplay: false,
}, },
{ {
prop: 'preventTargets', prop: 'targetPests',
label: '防治对象', label: '防治对象',
type: 'cascader',
checkStrictly: true,
multiple: true,
dicData: [],
span: 24,
editDisplay: false,
}, },
{ {
prop: 'mainComponents', prop: 'mainComponent',
label: '化学成分', label: '化学成分',
type: 'cascader',
checkStrictly: true,
multiple: true,
dicData: materialTwoLevel.value?.['1']?.['2'] ?? [],
span: 24,
editDisplay: false,
}, },
{ {
prop: 'dosageForm', prop: 'produceDosage',
label: '加工剂型', label: '加工剂型',
type: 'cascader',
checkStrictly: true,
multiple: true,
dicData: materialTwoLevel.value?.['1']?.['3'] ?? [],
span: 24,
editDisplay: false,
}, },
{ {
hide: true, hide: true,
prop: 'useMethods', prop: '_targetPests',
label: '防治对象',
type: 'cascader',
multiple: true,
dicData: [],
value: [],
span: 24,
editDisplay: false,
rules: customRules({ msg: '请选择防治对象' }),
},
{
hide: true,
prop: '_mainComponent',
label: '化学成分',
type: 'cascader',
multiple: true,
dicData: [],
value: [],
span: 24,
editDisplay: false,
rules: customRules({ msg: '请选择主要成分' }),
},
{
hide: true,
prop: '_produceDosage',
label: '加工剂型',
type: 'cascader',
multiple: true,
dicData: [],
value: [],
span: 24,
editDisplay: false,
rules: customRules({ msg: '加工剂型' }),
},
{
hide: true,
prop: 'usageMethod',
label: '使用方法', label: '使用方法',
type: 'textarea', type: 'textarea',
span: 24, span: 24,
@ -201,7 +258,7 @@ const option = ref({
}, },
{ {
hide: true, hide: true,
prop: 'tips', prop: 'precautions',
label: '注意事项', label: '注意事项',
type: 'textarea', type: 'textarea',
span: 24, span: 24,
@ -287,18 +344,15 @@ watch(
() => loadFinish.value, () => loadFinish.value,
() => { () => {
if (loadFinish.value) { if (loadFinish.value) {
let newDicName = [ for (let key in dicDatas.value) {
{ key: '', one: '1', two: '1' },
{ key: '', one: '1', two: '2' },
{ key: '', one: '1', two: '3' },
];
newDicName.forEach((v) => {
option.value.column.forEach((item) => { option.value.column.forEach((item) => {
if (item.prop === v.key) { if (item.prop === key) {
item.dicData = materialTwoLevel?.[v.one]?.[v.two] ?? []; let dic = materialTwoLevel.value?.[dicDatas.value[key].one]?.[dicDatas.value[key].two] ?? [];
dicDatas.value[key].dic = dic;
item.dicData = dic;
} }
}); });
}); }
} }
} }
); );
@ -323,8 +377,9 @@ async function getData(reset) {
let params = { let params = {
current: pageData.value.currentPage, current: pageData.value.currentPage,
size: pageData.value.size, size: pageData.value.size,
...searchCondition.value, pesticideName: searchCondition.value.keywords,
}; };
_type.value != '0' && (params.classifyId = _type.value);
let res = await getPesticideList(params); let res = await getPesticideList(params);
console.log('res --- ', res); console.log('res --- ', res);
_loading.value = false; _loading.value = false;
@ -334,14 +389,68 @@ async function getData(reset) {
} }
} }
function handleCloseDialog(done) { function handleCloseDialog(done) {
resetOtherInfo();
handleCheckInfoChange(); handleCheckInfoChange();
done(); done();
} }
function handleRowSave(form, done, loading) { async function handleRowSave(form, done, loading) {
console.log('handleRowSave', form); console.log('handleRowSave', form);
let data = {
pesticideName: form.pesticideName,
productStandCode: form.productStandCode,
pesticideRegistCode: form.pesticideRegistCode,
manufacturer: form.manufacturer,
distributor: form.distributor,
toxicityLevel: form.toxicityLevel,
usageMethod: form.usageMethod,
precautions: form.precautions,
expiryDate: form.expiryDate,
productSpecification: productSpecification.value.num,
productUnit: productSpecification.value.type,
suggestDosage: useDosage.value.num,
suggestUnit: useDosage.value.type,
};
if (attrs.value.length) {
data.pesticidePhoto = attrs.value.map((v) => v.url).join();
}
if (form._targetPests.length) {
let names = [];
form._targetPests.forEach((item) => {
names.push(targetName(dicDatas.value._targetPests.dic, item, ''));
});
data.targetPests = JSON.stringify(form._targetPests) + '|' + JSON.stringify(names);
}
if (form._mainComponent.length) {
let names = [];
form._mainComponent.forEach((item) => {
names.push(targetName(dicDatas.value._mainComponent.dic, item, ''));
});
data.mainComponent = JSON.stringify(form._mainComponent) + '|' + JSON.stringify(names);
}
if (form._produceDosage.length) {
let names = [];
form._produceDosage.forEach((item) => {
names.push(targetName(dicDatas.value._produceDosage.dic, item, ''));
});
data.produceDosage = JSON.stringify(form._produceDosage) + '|' + JSON.stringify(names);
}
let res = await addPesticide(data);
if (res.code == 200) {
ElMessage.success('保存成功');
getData();
// resetOtherInfo();
// done();
}
loading(); loading();
} }
function resetOtherInfo() {
let obj = { num: 1, type: '1' };
attrs.value = [];
productSpecification.value = obj;
useDosage.value = obj;
}
function handleEdit(row) { function handleEdit(row) {
console.log('handleEdit', row); console.log('handleEdit', row);
handleCheckInfoChange('open'); handleCheckInfoChange('open');
@ -389,6 +498,11 @@ async function handleRowUpdate(form, done, loading) {
console.log('update from -- ', form); console.log('update from -- ', form);
loading(); loading();
} }
function handleShowName(text = '') {
if (!text || text.includes('|')) return false;
let names = text.split('|')[1];
console.log('names', names);
}
// #endregion // #endregion
</script> </script>