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_URL = 'http://192.168.18.99:8080'
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]: {
target: VITE_APP_UPLOAD_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/uploadApis/, ''),
// rewrite: (path) => path.replace(/^\/uploadApis/, ''),
},
},
},

View File

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

View File

@ -1,5 +1,5 @@
<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}`">
<el-menu-item v-if="!item.children" :index="item.value">{{ item.label }}</el-menu-item>
<SubMenu v-else :types="item" />
@ -8,6 +8,7 @@
</template>
<script setup>
import { ref } from 'vue';
import SubMenu from './SubMenu.vue';
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) {
emit('update:type', key);
}

View File

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

View File

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

View File

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