2025-03-07 14:36:54 +08:00
|
|
|
<template>
|
2025-03-27 15:56:05 +08:00
|
|
|
<section class="custom-page">
|
2025-03-14 17:33:44 +08:00
|
|
|
<h2>肥料基本信息</h2>
|
2025-03-27 15:56:05 +08:00
|
|
|
<TypeMenu v-if="materialTypes[1].length > 1" v-model:type="_type" :types="materialTypes['2']" />
|
2025-03-14 17:33:44 +08:00
|
|
|
<br />
|
2025-03-27 15:56:05 +08:00
|
|
|
<avue-crud
|
|
|
|
ref="crud"
|
|
|
|
v-model:page="pageData"
|
|
|
|
v-model:search="searchCondition"
|
|
|
|
:data="data"
|
|
|
|
:table-loading="_loading"
|
|
|
|
:option="option"
|
2025-03-31 09:03:19 +08:00
|
|
|
:before-close="handleCloseDialog"
|
|
|
|
@search-change="
|
|
|
|
(form, done) => {
|
|
|
|
getData(1);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
"
|
|
|
|
@refresh-change="getData"
|
|
|
|
@search-reset="getData(1)"
|
2025-03-27 15:56:05 +08:00
|
|
|
@current-change="getData"
|
|
|
|
@size-change="getData(1)"
|
|
|
|
@row-save="handleRowSave"
|
|
|
|
>
|
|
|
|
<template #menu="{ row }">
|
2025-03-31 09:03:19 +08:00
|
|
|
<el-button @click="handleInfo(row)">详情</el-button>
|
2025-03-27 15:56:05 +08:00
|
|
|
</template>
|
|
|
|
<template #photoUrl-form="{ type }">
|
|
|
|
<Attrs v-model:attrs="attrs" :type="type == 'add' ? 'add' : 'view'" :limit="2" />
|
|
|
|
</template>
|
|
|
|
<template #_productSpecification-form="{ value, type }">
|
|
|
|
<NumberSelect v-if="type == 'add'" v-model:value="productSpecification" :options="goodsUnitOptions" />
|
|
|
|
<span v-if="type == 'view'">{{ value }}</span>
|
|
|
|
</template>
|
|
|
|
<template #_suggest-form="{ value, type }">
|
|
|
|
<NumberSelect v-if="type == 'add'" v-model:value="useDosage" :options="useDosageUnit" />
|
|
|
|
<span v-if="type == 'view'">{{ value }}</span>
|
|
|
|
</template>
|
|
|
|
</avue-crud>
|
|
|
|
</section>
|
2025-03-07 14:36:54 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2025-03-27 15:56:05 +08:00
|
|
|
import { ref, watch, onMounted } from 'vue';
|
2025-03-14 17:33:44 +08:00
|
|
|
import TypeMenu from '../../common/TypeMenu.vue';
|
2025-03-27 15:56:05 +08:00
|
|
|
import { CRUD_OPTIONS, customRules } from '@/config';
|
|
|
|
import { useBasicInfo } from '@/views/inputSuppliesManage/hooks/useBasicInfo';
|
|
|
|
import inputSuppliesApi from '@/apis/inputSuppliesApi';
|
|
|
|
import Attrs from '@/views/inputSuppliesManage/common/Attrs.vue';
|
|
|
|
import NumberSelect from '@/views/inputSuppliesManage/common/NumberSelect.vue';
|
2025-03-31 09:03:19 +08:00
|
|
|
import { ElMessage } from 'element-plus';
|
2025-03-07 14:36:54 +08:00
|
|
|
|
2025-03-27 15:56:05 +08:00
|
|
|
const { getFertilizreList, addFertilizer } = inputSuppliesApi;
|
2025-03-31 09:03:19 +08:00
|
|
|
const { loadFinish, materialTypes, materialTwoLevel, targetName, goodsUnitOptions, useDosageUnit, handleShowName, handleNumUnit } = useBasicInfo();
|
2025-03-27 15:56:05 +08:00
|
|
|
|
|
|
|
onMounted(getData);
|
|
|
|
watch(
|
|
|
|
() => loadFinish.value,
|
|
|
|
(bol) => {
|
|
|
|
if (bol) {
|
|
|
|
option.value.column[5].dicData = materialTypes['2'].filter((v, i) => i > 0) ?? [];
|
|
|
|
option.value.column[12].dicData = materialTwoLevel?.['1']?.['3'] ?? [];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deep: true,
|
|
|
|
}
|
|
|
|
);
|
2025-03-07 14:36:54 +08:00
|
|
|
/* --------------- data --------------- */
|
|
|
|
// #region
|
2025-03-27 15:56:05 +08:00
|
|
|
const _type = ref('');
|
2025-03-14 17:33:44 +08:00
|
|
|
watch(
|
2025-03-27 15:56:05 +08:00
|
|
|
() => _type.value,
|
2025-03-14 17:33:44 +08:00
|
|
|
() => {
|
2025-03-27 15:56:05 +08:00
|
|
|
getData(1);
|
2025-03-14 17:33:44 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
deep: true,
|
|
|
|
}
|
|
|
|
);
|
2025-03-07 14:36:54 +08:00
|
|
|
|
2025-03-14 17:33:44 +08:00
|
|
|
const crud = ref();
|
2025-03-27 15:56:05 +08:00
|
|
|
const _loading = ref(false);
|
2025-03-14 17:33:44 +08:00
|
|
|
const data = ref([]);
|
2025-03-27 15:56:05 +08:00
|
|
|
const searchCondition = ref({
|
|
|
|
keywords: '',
|
|
|
|
});
|
2025-03-14 17:33:44 +08:00
|
|
|
const pageData = ref({
|
|
|
|
total: 0,
|
|
|
|
currentPage: 1,
|
2025-03-27 15:56:05 +08:00
|
|
|
size: 10,
|
2025-03-14 17:33:44 +08:00
|
|
|
});
|
|
|
|
const option = ref({
|
2025-03-27 15:56:05 +08:00
|
|
|
...CRUD_OPTIONS,
|
2025-03-14 17:33:44 +08:00
|
|
|
selection: false,
|
|
|
|
column: [
|
2025-03-26 13:37:24 +08:00
|
|
|
{
|
2025-03-27 15:56:05 +08:00
|
|
|
hide: true,
|
2025-03-26 13:37:24 +08:00
|
|
|
prop: 'keywords',
|
|
|
|
label: '关键字',
|
2025-03-27 15:56:05 +08:00
|
|
|
addDisplay: false,
|
|
|
|
viewDisplay: false,
|
|
|
|
search: true,
|
|
|
|
searchPlaceholder: '输入肥料名称',
|
2025-03-26 13:37:24 +08:00
|
|
|
},
|
2025-03-14 17:33:44 +08:00
|
|
|
{
|
2025-03-27 15:56:05 +08:00
|
|
|
prop: 'fertilizeName',
|
2025-03-14 17:33:44 +08:00
|
|
|
label: '名称',
|
2025-03-27 15:56:05 +08:00
|
|
|
rules: customRules({ msg: '请输入肥料名称' }),
|
2025-03-14 17:33:44 +08:00
|
|
|
},
|
|
|
|
{
|
2025-03-27 15:56:05 +08:00
|
|
|
prop: 'manufacturer',
|
2025-03-14 17:33:44 +08:00
|
|
|
label: '厂家',
|
2025-03-27 15:56:05 +08:00
|
|
|
rules: customRules({ msg: '请输入厂家名称' }),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
prop: 'photoUrl',
|
|
|
|
label: '肥料图片',
|
|
|
|
hide: true,
|
|
|
|
editDisplay: false,
|
2025-03-14 17:33:44 +08:00
|
|
|
},
|
|
|
|
{
|
2025-03-27 15:56:05 +08:00
|
|
|
prop: 'distributor',
|
2025-03-14 17:33:44 +08:00
|
|
|
label: '经销商',
|
|
|
|
},
|
|
|
|
{
|
2025-03-31 09:03:19 +08:00
|
|
|
prop: '_classifyId',
|
2025-03-27 15:56:05 +08:00
|
|
|
label: '分类',
|
|
|
|
type: 'cascader',
|
|
|
|
clearable: false,
|
|
|
|
dicData: () => [],
|
|
|
|
rules: customRules({ msg: '请选择肥料分类' }),
|
2025-03-31 09:03:19 +08:00
|
|
|
expandTrigger: 'click',
|
|
|
|
render: ({ row }) => {
|
|
|
|
return row.classifyName;
|
|
|
|
},
|
2025-03-27 15:56:05 +08:00
|
|
|
},
|
|
|
|
{
|
2025-03-31 09:03:19 +08:00
|
|
|
prop: 'mainComponent',
|
2025-03-14 17:33:44 +08:00
|
|
|
label: '化学成分',
|
2025-03-27 15:56:05 +08:00
|
|
|
rules: customRules({ msg: '请输入化学成分' }),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
prop: 'adaptCrops',
|
|
|
|
label: '适用作物',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
hide: true,
|
|
|
|
prop: '_productSpecification',
|
|
|
|
label: '产品规格',
|
|
|
|
viewDisplay: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
hide: true,
|
|
|
|
prop: '_suggest',
|
2025-03-31 09:03:19 +08:00
|
|
|
label: '建议用量1',
|
|
|
|
viewDisplay: false,
|
2025-03-14 17:33:44 +08:00
|
|
|
},
|
|
|
|
{
|
2025-03-27 15:56:05 +08:00
|
|
|
prop: 'productSpecification',
|
2025-03-14 17:33:44 +08:00
|
|
|
label: '产品规格',
|
2025-03-27 15:56:05 +08:00
|
|
|
addDisplay: false,
|
|
|
|
editDisplay: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
prop: 'suggest',
|
|
|
|
label: '建议用量',
|
|
|
|
addDisplay: false,
|
|
|
|
editDisplay: false,
|
2025-03-14 17:33:44 +08:00
|
|
|
},
|
|
|
|
{
|
2025-03-31 09:03:19 +08:00
|
|
|
hide: true,
|
2025-03-27 15:56:05 +08:00
|
|
|
prop: '_produceDosage',
|
|
|
|
label: '剂型',
|
|
|
|
type: 'cascader',
|
|
|
|
dicData: [],
|
2025-03-31 09:03:19 +08:00
|
|
|
viewDisplay: false,
|
|
|
|
expandTrigger: 'click',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
prop: 'produceDosage',
|
|
|
|
label: '剂型',
|
|
|
|
addDisplay: false,
|
|
|
|
editDisplay: false,
|
|
|
|
render: ({ row }) => {
|
|
|
|
return row.produceDosage;
|
|
|
|
},
|
2025-03-27 15:56:05 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
prop: 'expiryDate',
|
2025-03-14 17:33:44 +08:00
|
|
|
label: '保质期',
|
|
|
|
},
|
2025-03-27 15:56:05 +08:00
|
|
|
{
|
|
|
|
hide: true,
|
|
|
|
prop: 'usageMethod',
|
|
|
|
label: '使用方法',
|
|
|
|
type: 'textarea',
|
|
|
|
span: 24,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
hide: true,
|
|
|
|
prop: 'precautions',
|
|
|
|
label: '注意事项',
|
|
|
|
type: 'textarea',
|
|
|
|
span: 24,
|
|
|
|
},
|
2025-03-14 17:33:44 +08:00
|
|
|
],
|
|
|
|
});
|
2025-03-27 15:56:05 +08:00
|
|
|
const attrs = ref([]);
|
|
|
|
const productSpecification = ref({
|
|
|
|
num: 1,
|
|
|
|
type: '1',
|
|
|
|
});
|
|
|
|
const useDosage = ref({
|
|
|
|
num: 1,
|
|
|
|
type: '1',
|
|
|
|
});
|
2025-03-07 14:36:54 +08:00
|
|
|
// #endregion
|
|
|
|
|
|
|
|
/* --------------- methods --------------- */
|
|
|
|
// #region
|
2025-03-27 15:56:05 +08:00
|
|
|
async function getData(reset) {
|
|
|
|
_loading.value = true;
|
|
|
|
reset == 1 && (pageData.value.currentPage = 1);
|
|
|
|
let params = {
|
|
|
|
current: pageData.value.currentPage,
|
|
|
|
size: pageData.value.size,
|
|
|
|
fertilizeName: searchCondition.value.keywords,
|
|
|
|
};
|
|
|
|
_type.value != '0' && (params.classifyId = _type.value);
|
|
|
|
let res = await getFertilizreList(params);
|
|
|
|
_loading.value = false;
|
|
|
|
if (res.code == 200) {
|
|
|
|
data.value = res.data.records.map((v) => {
|
2025-03-31 09:03:19 +08:00
|
|
|
v.productSpecification = handleNumUnit({ num1: v.productSpecification, unit1: v.productUnit, type: 1 });
|
|
|
|
v.suggest = handleNumUnit({ unit1: v.productUnit, num2: v.suggestDosage, unit2: v.suggestUnit, type: -1 });
|
|
|
|
v.produceDosage = handleShowName(v.produceDosage);
|
2025-03-27 15:56:05 +08:00
|
|
|
return v;
|
|
|
|
});
|
|
|
|
pageData.value.total = res.data.total;
|
|
|
|
}
|
|
|
|
}
|
2025-03-31 09:03:19 +08:00
|
|
|
async function handleRowSave(form, done, loading) {
|
2025-03-27 15:56:05 +08:00
|
|
|
let data = {
|
|
|
|
fertilizeName: form.fertilizeName,
|
|
|
|
manufacturer: form.manufacturer,
|
|
|
|
distributor: form.distributor,
|
2025-03-31 09:03:19 +08:00
|
|
|
classifyId: form._classifyId[0],
|
|
|
|
classifyName: targetName(option.value.column[5].dicData, form._classifyId, ''),
|
|
|
|
mainComponent: form.mainComponent,
|
2025-03-27 15:56:05 +08:00
|
|
|
productSpecification: productSpecification.value.num,
|
|
|
|
productUnit: productSpecification.value.type,
|
|
|
|
suggestDosage: useDosage.value.num,
|
|
|
|
suggestUnit: useDosage.value.type,
|
|
|
|
usageMethod: form.usageMethod,
|
|
|
|
precautions: form.precautions,
|
|
|
|
expiryDate: form.expiryDate,
|
|
|
|
adaptCrops: form.adaptCrops,
|
|
|
|
};
|
|
|
|
if (attrs.value.length) {
|
|
|
|
data.photoUrl = attrs.value.map((v) => v.url).join();
|
|
|
|
}
|
|
|
|
if (form._produceDosage.length) {
|
|
|
|
let names = [];
|
|
|
|
form._produceDosage.forEach((item) => {
|
2025-03-31 09:03:19 +08:00
|
|
|
names.push(targetName(option.value.column[12].dicData, item, ''));
|
2025-03-27 15:56:05 +08:00
|
|
|
});
|
|
|
|
data.produceDosage = JSON.stringify(form._produceDosage) + '|' + JSON.stringify(names);
|
|
|
|
}
|
2025-03-31 09:03:19 +08:00
|
|
|
let res = await addFertilizer(data);
|
2025-03-27 15:56:05 +08:00
|
|
|
loading();
|
2025-03-31 09:03:19 +08:00
|
|
|
if (res.code == 200) {
|
|
|
|
ElMessage.success('添加成功');
|
|
|
|
resetOtherInfo();
|
|
|
|
getData();
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function handleInfo(row) {
|
|
|
|
if (row.photoUrl) {
|
|
|
|
attrs.value = row.photoUrl.split(',').map((v, i) => {
|
|
|
|
return { url: v, uid: `photo_${i}_${Date.now()}` };
|
|
|
|
});
|
|
|
|
}
|
|
|
|
crud.value.rowView(row);
|
|
|
|
for (let i = 0; i < option.value.column.length; i++) {
|
|
|
|
option.value.column[i].span = 24;
|
|
|
|
if (option.value.column[i].prop == 'photoUrl') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function resetOtherInfo() {
|
|
|
|
attrs.value = [];
|
|
|
|
productSpecification.value = { num: 1, type: '1' };
|
|
|
|
useDosage.value = { num: 1, type: '1' };
|
|
|
|
}
|
|
|
|
function handleCloseDialog(done) {
|
|
|
|
resetOtherInfo();
|
|
|
|
done();
|
|
|
|
for (let i = 0; i < option.value.column.length; i++) {
|
|
|
|
delete option.value.column[i].span;
|
|
|
|
if (option.value.column[i].prop == 'photoUrl') return;
|
|
|
|
}
|
2025-03-27 15:56:05 +08:00
|
|
|
}
|
2025-03-07 14:36:54 +08:00
|
|
|
// #endregion
|
|
|
|
</script>
|
|
|
|
|
2025-03-14 17:33:44 +08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
h2 {
|
|
|
|
font-size: 24px;
|
|
|
|
font-weight: bold;
|
|
|
|
font-family: '黑体';
|
|
|
|
}
|
|
|
|
</style>
|