262 lines
6.6 KiB
Vue
Raw Normal View History

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"
@current-change="getData"
@size-change="getData(1)"
@row-save="handleRowSave"
>
<template #menu="{ row }">
aa
<!-- <el-button type="primary" @click="handleEdit(row)">上传报告</el-button> -->
<!-- <el-button @click="handleInfo(row)">详情</el-button> -->
</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-07 14:36:54 +08:00
2025-03-27 15:56:05 +08:00
const { getFertilizreList, addFertilizer } = inputSuppliesApi;
const { loadFinish, materialTypes, materialTwoLevel, targetName, goodsUnitOptions, useDosageUnit, handleNumUnit } = useBasicInfo();
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-27 15:56:05 +08:00
hide: true,
prop: 'keywords',
label: '关键字',
2025-03-27 15:56:05 +08:00
addDisplay: false,
viewDisplay: false,
search: true,
searchPlaceholder: '输入肥料名称',
},
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-27 15:56:05 +08:00
prop: 'classifyName',
label: '分类',
type: 'cascader',
clearable: false,
dicData: () => [],
rules: customRules({ msg: '请选择肥料分类' }),
},
{
prop: 'mainComponents',
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',
label: '建议用量',
viewDisplay: true,
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-27 15:56:05 +08:00
prop: '_produceDosage',
label: '剂型',
type: 'cascader',
dicData: [],
},
{
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);
console.log('params --- ', params, res);
_loading.value = false;
if (res.code == 200) {
data.value = res.data.records.map((v) => {
console.log('v', v);
v.productSpecification = handleNumUnit(v.productSpecification, v.productUnit, 1);
v.suggest = handleNumUnit(v.suggestDosage, v.suggestUnit, 2);
return v;
});
pageData.value.total = res.data.total;
}
}
function handleRowSave(form, done, loading) {
console.log('form', form);
let data = {
fertilizeName: form.fertilizeName,
manufacturer: form.manufacturer,
distributor: form.distributor,
classifyId: form.classifyName,
mainComponents: form.mainComponents,
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) => {
names.push(targetName(option.value.column, item, ''));
});
data.produceDosage = JSON.stringify(form._produceDosage) + '|' + JSON.stringify(names);
}
console.log('data', data);
loading();
}
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>