Merge branch 'bonus-houqin' of http://192.168.0.75:3000/bonus/bonus-ui into bonus-houqin
This commit is contained in:
commit
28019a4f7b
|
|
@ -0,0 +1,92 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
// 原料类别
|
||||
export function systemMaterialTreeApi(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v1/menumaterialcategory/tree/list',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"merchant-id":"378915229716713472",
|
||||
},
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 系统区域权限树
|
||||
export function systemAreaTreeApi(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v2/alloc/area/system-auth/tree',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"merchant-id":"378915229716713472",
|
||||
},
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 查询区域列表
|
||||
export function getMaterialListApi(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v1/menumaterial/page',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"merchant-id":"378915229716713472",
|
||||
},
|
||||
data: data
|
||||
})
|
||||
}
|
||||
// 根据区域id,查询区域名称
|
||||
export function getMaterialNameApi(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v2/alloc/area/get-area-name',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"merchant-id":"378915229716713472",
|
||||
},
|
||||
data: data
|
||||
})
|
||||
}
|
||||
// 查询区域(食堂,档口,餐线)编号
|
||||
export function getMaterialNumApi(data) {
|
||||
return request({
|
||||
url: 'smart-canteen/api/v2/alloc/canteen/get-canteen-num',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"merchant-id":"378915229716713472",
|
||||
},
|
||||
data: data
|
||||
})
|
||||
}
|
||||
// 新增区域
|
||||
export function addMaterialApi(data) {
|
||||
return request({
|
||||
url: 'smart-canteen/api/v2/alloc/area/add',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"merchant-id":"378915229716713472",
|
||||
},
|
||||
data: data
|
||||
})
|
||||
}
|
||||
//修改区域
|
||||
export function updateMaterialApi(data) {
|
||||
return request({
|
||||
url: 'smart-canteen/api/v2/alloc/area/update',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"merchant-id":"378915229716713472",
|
||||
},
|
||||
data: data
|
||||
})
|
||||
}
|
||||
//删除区域
|
||||
export function removeMaterialApi(data) {
|
||||
return request({
|
||||
url: 'smart-canteen/api/v2/alloc/area/remove',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"merchant-id":"378915229716713472",
|
||||
},
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
// 查询获取所有食材营养信息
|
||||
export function listNutrition(query) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v1/menunutrition/getMenuNutritionPage',
|
||||
method: 'post',
|
||||
data: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询详细
|
||||
export function getNutrition(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v1/menunutrition/oneMaterial',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 新增
|
||||
export function addMenuNutrition(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v1/menunutrition/addMenuNutrition',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改
|
||||
export function updateNutrition(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v1/menunutrition/updateMenuNutrition',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除
|
||||
export function delNutrition(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v1/menunutrition/remove',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 获取所有食材类别
|
||||
export function typeList(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/api/v1/menunutrition/all/type/list',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,492 @@
|
|||
<template>
|
||||
<el-dialog
|
||||
:title="title + ' - 原料'"
|
||||
:visible.sync="visible"
|
||||
width="1000px"
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
:destroy-on-close="true"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-tabs v-model="activeTab">
|
||||
<el-tab-pane label="基础信息" name="basic">
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="原料名称" prop="materialName">
|
||||
<el-input
|
||||
v-model="form.materialName"
|
||||
placeholder="请输入原料名称"
|
||||
maxlength="40"
|
||||
show-word-limit
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="所属区域" prop="region">
|
||||
<el-select v-model="form.region" placeholder="请选择所属区域" style="width: 100%">
|
||||
<el-option label="宏源大厦" value="宏源大厦" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="原料类别" prop="materialType">
|
||||
<el-select v-model="form.materialType" placeholder="请选择原料类别" style="width: 100%">
|
||||
<el-option label="蔬菜类-宏源大厦" value="蔬菜类-宏源大厦" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="计量类型" prop="measureType">
|
||||
<el-select v-model="form.measureType" placeholder="请选择计量类型" style="width: 100%">
|
||||
<el-option label="按份" value="按份" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="原料单位" prop="unit">
|
||||
<el-select v-model="form.unit" placeholder="请选择原料单位" style="width: 100%">
|
||||
<el-option label="条" value="条" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="原料进价" prop="purchasePrice">
|
||||
<el-input
|
||||
v-model="form.purchasePrice"
|
||||
placeholder="请输入原料进价"
|
||||
@input="handleNumericInput('purchasePrice', $event)"
|
||||
@blur="formatNumericValue('purchasePrice')"
|
||||
>
|
||||
<template slot="append">元</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="条码" prop="barcode">
|
||||
<el-input
|
||||
v-model="form.barcode"
|
||||
placeholder="请输入条码"
|
||||
maxlength="20"
|
||||
show-word-limit
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="营养信息类别" prop="phoneticType">
|
||||
<el-select v-model="form.phoneticType" placeholder="请选择营养信息类别" style="width: 100%">
|
||||
<el-option label="植物油/植物油" value="植物油/植物油" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="营养信息" prop="phoneticInfo">
|
||||
<el-select v-model="form.phoneticInfo" placeholder="请选择营养信息" style="width: 100%">
|
||||
<el-option label="辣椒油" value="辣椒油" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="保质期" prop="shelfLife">
|
||||
<el-input-number
|
||||
v-model="form.shelfLife"
|
||||
:min="0"
|
||||
:max="999"
|
||||
style="width: 120px"
|
||||
/>
|
||||
<el-select v-model="form.shelfLifeUnit" style="width: 100px; margin-left: 10px">
|
||||
<el-option label="按年" value="年" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="采购上限价格" prop="maxPrice">
|
||||
<el-input
|
||||
v-model="form.maxPrice"
|
||||
placeholder="请输入采购上限价格"
|
||||
@input="handleNumericInput('maxPrice', $event)"
|
||||
@blur="formatNumericValue('maxPrice')"
|
||||
>
|
||||
<template slot="append">元</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="是否需要检测" prop="needInspection">
|
||||
<el-select v-model="form.needInspection" placeholder="请选择是否需要检测" style="width: 100%">
|
||||
<el-option label="是" value="是" />
|
||||
<el-option label="否" value="否" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="供应资格证书" prop="qualificationCert">
|
||||
<el-select v-model="form.qualificationCert" placeholder="请选择供应资格证书" style="width: 100%">
|
||||
<el-option label="请选择供应资格证书" value="" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="要求检测机构" prop="inspectionOrg">
|
||||
<el-select v-model="form.inspectionOrg" placeholder="请选择要求检测机构" style="width: 100%">
|
||||
<el-option label="自检" value="自检" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="要求检测项目" prop="inspectionItems">
|
||||
<el-select v-model="form.inspectionItems" placeholder="请选择要求检测项目" style="width: 100%">
|
||||
<el-option label="农残" value="农残" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="加工方法" prop="processingMethods">
|
||||
<div class="method-input-group">
|
||||
<div v-for="(method, index) in form.processingMethods" :key="index" class="method-input-item">
|
||||
<el-input
|
||||
v-model="form.processingMethods[index]"
|
||||
:placeholder="'请输入加工方法' + (index + 1)"
|
||||
>
|
||||
<template slot="append">
|
||||
<el-button v-if="index === form.processingMethods.length - 1" @click="addProcessingMethod">增加</el-button>
|
||||
<el-button v-else @click="removeProcessingMethod(index)" type="danger">删除</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="切配方法" prop="cuttingMethods">
|
||||
<div class="method-input-group">
|
||||
<div v-for="(method, index) in form.cuttingMethods" :key="index" class="method-input-item">
|
||||
<el-input
|
||||
v-model="form.cuttingMethods[index]"
|
||||
:placeholder="'请输入切配方法' + (index + 1)"
|
||||
>
|
||||
<template slot="append">
|
||||
<el-button v-if="index === form.cuttingMethods.length - 1" @click="addCuttingMethod">增加</el-button>
|
||||
<el-button v-else @click="removeCuttingMethod(index)" type="danger">删除</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<h3>营养信息</h3>
|
||||
<el-row :gutter="20" class="nutrition-info">
|
||||
<el-col :span="12" v-for="(item, index) in nutritionFields" :key="index">
|
||||
<el-form-item :label="item.label" :prop="'nutrition.' + item.prop">
|
||||
<el-input
|
||||
v-model="form.nutrition[item.prop]"
|
||||
:placeholder="'请输入' + item.label"
|
||||
@input="handleNumericInput('nutrition.' + item.prop, $event)"
|
||||
@blur="formatNumericValue('nutrition.' + item.prop)"
|
||||
>
|
||||
<template slot="append">{{item.unit}}</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="原料识别注册图" name="image">
|
||||
<!-- 这里添加图片上传组件 -->
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "MaterialDialog",
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
default: '新增'
|
||||
},
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
activeTab: 'basic',
|
||||
form: {
|
||||
materialName: '',
|
||||
region: '',
|
||||
materialType: '',
|
||||
measureType: '',
|
||||
unit: '',
|
||||
barcode: '',
|
||||
purchasePrice: '',
|
||||
phoneticType: '',
|
||||
phoneticInfo: '',
|
||||
shelfLife: 0,
|
||||
shelfLifeUnit: '年',
|
||||
maxPrice: '',
|
||||
needInspection: '是',
|
||||
qualificationCert: '',
|
||||
inspectionOrg: '',
|
||||
inspectionItems: '',
|
||||
processingMethods: [''],
|
||||
cuttingMethods: [''],
|
||||
nutrition: {
|
||||
ediblePart: '',
|
||||
water: '',
|
||||
heat: '',
|
||||
protein: '',
|
||||
fat: '',
|
||||
carbohydrate: '',
|
||||
dietaryFiber: '',
|
||||
cholesterol: '',
|
||||
ash: '',
|
||||
vitaminA: '',
|
||||
carotene: '',
|
||||
retinol: '',
|
||||
thiamine: '',
|
||||
riboflavin: '',
|
||||
niacin: '',
|
||||
vitaminC: '',
|
||||
vitaminE: '',
|
||||
calcium: '',
|
||||
phosphorus: '',
|
||||
potassium: '',
|
||||
sodium: '',
|
||||
magnesium: '',
|
||||
iron: '',
|
||||
zinc: '',
|
||||
selenium: '',
|
||||
copper: '',
|
||||
manganese: '',
|
||||
iodine: ''
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
materialName: [{ required: true, message: '请输入原料名称', trigger: 'blur' }],
|
||||
region: [{ required: true, message: '请选择所属区域', trigger: 'change' }],
|
||||
materialType: [{ required: true, message: '请选择原料类别', trigger: 'change' }]
|
||||
},
|
||||
nutritionFields: [
|
||||
{ label: '可食部分', prop: 'ediblePart', unit: 'g/100g' },
|
||||
{ label: '水分', prop: 'water', unit: 'g/100g' },
|
||||
{ label: '热量', prop: 'heat', unit: '千卡/100g' },
|
||||
{ label: '蛋白质', prop: 'protein', unit: 'g/100g' },
|
||||
{ label: '脂肪', prop: 'fat', unit: 'g/100g' },
|
||||
{ label: '碳水化合物', prop: 'carbohydrate', unit: 'g/100g' },
|
||||
{ label: '膳食纤维', prop: 'dietaryFiber', unit: 'g/100g' },
|
||||
{ label: '胆固醇', prop: 'cholesterol', unit: 'mg/100g' },
|
||||
{ label: '灰分', prop: 'ash', unit: 'g/100g' },
|
||||
{ label: '维生素A', prop: 'vitaminA', unit: 'μg/100g' },
|
||||
{ label: '胡萝卜素', prop: 'carotene', unit: 'μg/100g' },
|
||||
{ label: '视黄醇', prop: 'retinol', unit: 'μg/100g' },
|
||||
{ label: '硫胺素', prop: 'thiamine', unit: 'mg/100g' },
|
||||
{ label: '核黄素', prop: 'riboflavin', unit: 'mg/100g' },
|
||||
{ label: '烟酸/尼克酸', prop: 'niacin', unit: 'mg/100g' },
|
||||
{ label: '维生素C', prop: 'vitaminC', unit: 'mg/100g' },
|
||||
{ label: '维生素E', prop: 'vitaminE', unit: 'mg/100g' },
|
||||
{ label: '钙', prop: 'calcium', unit: 'mg/100g' },
|
||||
{ label: '磷', prop: 'phosphorus', unit: 'mg/100g' },
|
||||
{ label: '钾', prop: 'potassium', unit: 'mg/100g' },
|
||||
{ label: '钠', prop: 'sodium', unit: 'mg/100g' },
|
||||
{ label: '镁', prop: 'magnesium', unit: 'mg/100g' },
|
||||
{ label: '铁', prop: 'iron', unit: 'mg/100g' },
|
||||
{ label: '锌', prop: 'zinc', unit: 'mg/100g' },
|
||||
{ label: '硒', prop: 'selenium', unit: 'μg/100g' },
|
||||
{ label: '铜', prop: 'copper', unit: 'mg/100g' },
|
||||
{ label: '锰', prop: 'manganese', unit: 'mg/100g' },
|
||||
{ label: '碘', prop: 'iodine', unit: 'μg/100g' }
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// Remove dialogVisible computed property
|
||||
},
|
||||
methods: {
|
||||
handleNumericInput(field, event) {
|
||||
const value = event.target.value;
|
||||
// 只允许输入数字和小数点
|
||||
let newValue = value.replace(/[^\d.]/g, '');
|
||||
|
||||
// 确保只有一个小数点
|
||||
const parts = newValue.split('.');
|
||||
if (parts.length > 2) {
|
||||
newValue = parts[0] + '.' + parts.slice(1).join('');
|
||||
}
|
||||
|
||||
// 限制小数点后最多两位
|
||||
if (parts.length === 2 && parts[1].length > 2) {
|
||||
newValue = parts[0] + '.' + parts[1].substring(0, 2);
|
||||
}
|
||||
|
||||
// 设置字段值
|
||||
if (field.includes('.')) {
|
||||
const [obj, prop] = field.split('.');
|
||||
this.form[obj][prop] = newValue;
|
||||
} else {
|
||||
this.form[field] = newValue;
|
||||
}
|
||||
},
|
||||
|
||||
formatNumericValue(field) {
|
||||
let value;
|
||||
if (field.includes('.')) {
|
||||
const [obj, prop] = field.split('.');
|
||||
value = this.form[obj][prop];
|
||||
} else {
|
||||
value = this.form[field];
|
||||
}
|
||||
|
||||
if (!value || value === '' || value === '.') {
|
||||
value = '0.00';
|
||||
} else {
|
||||
value = parseFloat(value).toFixed(2);
|
||||
}
|
||||
|
||||
if (field.includes('.')) {
|
||||
const [obj, prop] = field.split('.');
|
||||
this.form[obj][prop] = value;
|
||||
} else {
|
||||
this.form[field] = value;
|
||||
}
|
||||
},
|
||||
|
||||
addProcessingMethod() {
|
||||
this.form.processingMethods.push('');
|
||||
},
|
||||
|
||||
removeProcessingMethod(index) {
|
||||
this.form.processingMethods.splice(index, 1);
|
||||
},
|
||||
|
||||
addCuttingMethod() {
|
||||
this.form.cuttingMethods.push('');
|
||||
},
|
||||
|
||||
removeCuttingMethod(index) {
|
||||
this.form.cuttingMethods.splice(index, 1);
|
||||
},
|
||||
|
||||
submitForm() {
|
||||
this.$refs.form.validate(valid => {
|
||||
if (valid) {
|
||||
this.$emit('submit', this.form);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
handleClose() {
|
||||
this.$emit('update:visible', false);
|
||||
this.$nextTick(() => {
|
||||
this.reset();
|
||||
});
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.$emit('update:visible', false);
|
||||
this.$nextTick(() => {
|
||||
this.reset();
|
||||
});
|
||||
},
|
||||
|
||||
reset() {
|
||||
this.form = {
|
||||
materialName: '',
|
||||
region: '',
|
||||
materialType: '',
|
||||
measureType: '',
|
||||
unit: '',
|
||||
barcode: '',
|
||||
purchasePrice: '',
|
||||
phoneticType: '',
|
||||
phoneticInfo: '',
|
||||
shelfLife: 0,
|
||||
shelfLifeUnit: '年',
|
||||
maxPrice: '',
|
||||
needInspection: '是',
|
||||
qualificationCert: '',
|
||||
inspectionOrg: '',
|
||||
inspectionItems: '',
|
||||
processingMethods: [''],
|
||||
cuttingMethods: [''],
|
||||
nutrition: {
|
||||
ediblePart: '',
|
||||
water: '',
|
||||
heat: '',
|
||||
protein: '',
|
||||
fat: '',
|
||||
carbohydrate: '',
|
||||
dietaryFiber: '',
|
||||
cholesterol: '',
|
||||
ash: '',
|
||||
vitaminA: '',
|
||||
carotene: '',
|
||||
retinol: '',
|
||||
thiamine: '',
|
||||
riboflavin: '',
|
||||
niacin: '',
|
||||
vitaminC: '',
|
||||
vitaminE: '',
|
||||
calcium: '',
|
||||
phosphorus: '',
|
||||
potassium: '',
|
||||
sodium: '',
|
||||
magnesium: '',
|
||||
iron: '',
|
||||
zinc: '',
|
||||
selenium: '',
|
||||
copper: '',
|
||||
manganese: '',
|
||||
iodine: ''
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
||||
|
|
@ -0,0 +1,733 @@
|
|||
<template>
|
||||
<!-- 类型管理 -->
|
||||
<div class="app-container" id="toolsType">
|
||||
<el-row :gutter="20">
|
||||
<!--树数据-->
|
||||
<el-col :span="5" :xs="24">
|
||||
<div class="head-container">
|
||||
原料类别
|
||||
<el-input
|
||||
v-model="materialName"
|
||||
placeholder="请输入关键字进行搜索"
|
||||
clearable
|
||||
maxlength="50"
|
||||
size="small"
|
||||
prefix-icon="el-icon-search"
|
||||
style="margin-bottom: 20px"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="head-container" style>
|
||||
<el-tree
|
||||
style="height: 700px; overflow: scroll"
|
||||
:data="treeOptions"
|
||||
:props="defaultProps"
|
||||
:expand-on-click-node="false"
|
||||
:filter-node-method="filterNode"
|
||||
ref="tree"
|
||||
node-key="id"
|
||||
:default-expand-all="false"
|
||||
highlight-current
|
||||
@node-click="handleNodeClick"
|
||||
>
|
||||
<span
|
||||
class="custom-tree-node"
|
||||
slot-scope="{ node, data }"
|
||||
@mousemove="onMousemove(data)"
|
||||
@mouseleave="onMouseleave()"
|
||||
>
|
||||
<span v-if="isMousemoveId === data.id && node.label.length > 10">{{
|
||||
node.label.slice(0, 10) + "..."
|
||||
}}</span>
|
||||
<span v-else>{{ node.label }}</span>
|
||||
|
||||
<span class="btn-items" v-if="isMousemoveId === data.id">
|
||||
<el-button
|
||||
type="text"
|
||||
size="mini"
|
||||
icon="el-icon-plus"
|
||||
@click.stop="() => appendTreeNode(data)"
|
||||
>
|
||||
</el-button>
|
||||
<el-button
|
||||
type="text"
|
||||
size="mini"
|
||||
icon="el-icon-edit-outline"
|
||||
style="color: #67c23a"
|
||||
v-if="data.id !== 0"
|
||||
@click.stop="() => editTreeNode(data)"
|
||||
>
|
||||
</el-button>
|
||||
<el-button
|
||||
type="text"
|
||||
size="mini"
|
||||
icon="el-icon-delete"
|
||||
style="color: #f56c6c"
|
||||
v-if="data.parentId != '-1'"
|
||||
@click.stop="() => removeTreeNode(data)"
|
||||
>
|
||||
</el-button>
|
||||
</span>
|
||||
</span>
|
||||
</el-tree>
|
||||
</div>
|
||||
</el-col>
|
||||
<!--用户数据-->
|
||||
<el-col :span="19" :xs="24">
|
||||
<el-form
|
||||
:model="queryParams"
|
||||
ref="queryForm"
|
||||
size="small"
|
||||
:inline="true"
|
||||
v-show="showSearch"
|
||||
label-width="68px"
|
||||
>
|
||||
|
||||
<el-form-item label="原料名称" prop="keyword">
|
||||
<el-input
|
||||
v-model="queryParams.keyword"
|
||||
placeholder="请输入原料名称"
|
||||
clearable
|
||||
style="width: 240px"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="条码" prop="keyword">
|
||||
<el-input
|
||||
v-model="queryParams.keyword"
|
||||
placeholder="请输入条码"
|
||||
clearable
|
||||
style="width: 240px"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="el-icon-search"
|
||||
size="mini"
|
||||
@click="handleQuery"
|
||||
>查询</el-button
|
||||
>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
|
||||
>重置</el-button
|
||||
>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
icon="el-icon-plus"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
v-hasPermi="['dish:material:add']"
|
||||
>新增</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="typeList" border>
|
||||
<el-table-column label="序号" align="center" width="80" type="index">
|
||||
<template slot-scope="scope">
|
||||
<span>{{(queryParams.pageNum - 1) * 10 + scope.$index + 1}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="原料编码" align="center" key="materialNum" prop="materialNum" show-overflow-tooltip/>
|
||||
<el-table-column label="所属区域" align="center" key="region" prop="region" show-overflow-tooltip/>
|
||||
<el-table-column label="原料类别" align="center" key="materialType" prop="materialType" show-overflow-tooltip/>
|
||||
<el-table-column label="原料名称" align="center" key="materialName" prop="materialName" show-overflow-tooltip/>
|
||||
<el-table-column label="营养信息名称" align="center" key="nutritionName" prop="nutritionName" show-overflow-tooltip/>
|
||||
<el-table-column label="单位" align="center" key="unit" prop="unit" show-overflow-tooltip/>
|
||||
<el-table-column label="条码" align="center" key="barcode" prop="barcode" show-overflow-tooltip/>
|
||||
<el-table-column label="原料进价(元)" align="center" key="purchasePrice" prop="purchasePrice" show-overflow-tooltip/>
|
||||
<el-table-column label="最近进价(元)" align="center" key="recentPrice" prop="recentPrice" show-overflow-tooltip/>
|
||||
<el-table-column label="最近入库时间" align="center" key="lastStockTime" prop="lastStockTime" show-overflow-tooltip/>
|
||||
<el-table-column label="月度均价(元)" align="center" key="monthlyAvgPrice" prop="monthlyAvgPrice" show-overflow-tooltip/>
|
||||
<el-table-column label="操作" align="center" width="180">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total > 0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 添加或修改原料类别对话框 -->
|
||||
<el-dialog
|
||||
:title="title+'-原料类别'"
|
||||
:visible.sync="open"
|
||||
width="500px"
|
||||
append-to-body
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
|
||||
|
||||
|
||||
<el-form-item label="所属区域" prop="areaNameStr">
|
||||
<el-cascader
|
||||
v-model="form.areaNameStr" :show-all-levels="false" :filterable="true"
|
||||
:options="treeAreaOptions" :props="treeProps" collapse-tags
|
||||
@change="handleTreeChange"></el-cascader>
|
||||
</el-form-item>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="原料类别" prop="categoryName">
|
||||
<el-input
|
||||
v-model="form.categoryName"
|
||||
placeholder="请输入原料类别"
|
||||
maxlength="30"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="原类别父节点" prop="superAreaName">
|
||||
<el-input
|
||||
v-model="form.superAreaName"
|
||||
disabled
|
||||
placeholder="原类别父节点"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-form-item label="新类别父节点" prop="areaNameStr">
|
||||
<el-cascader
|
||||
v-model="form.areaNameStr" :show-all-levels="false" :filterable="true"
|
||||
:options="treeAreaOptions" :props="treeProps" collapse-tags
|
||||
@change="handleTreeChange"></el-cascader>
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="handleSubmit">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 添加或修改用户配置对话框 -->
|
||||
<material-dialog
|
||||
:visible.sync="dialogVisible"
|
||||
:title="title"
|
||||
@submit="handleDialogSubmit"
|
||||
ref="materialDialog"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Treeselect from "@riophae/vue-treeselect";
|
||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||
import { systemMaterialTreeApi,systemAreaTreeApi,getMaterialListApi,getMaterialNameApi,getMaterialNumApi,addMaterialApi,updateMaterialApi,removeMaterialApi } from "@/api/dish/material";
|
||||
import MaterialDialog from './components/MaterialDialog.vue';
|
||||
|
||||
export default {
|
||||
name: "Material",
|
||||
components: {
|
||||
Treeselect,
|
||||
MaterialDialog
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 树选项
|
||||
treeOptions: undefined,
|
||||
treeTemp: [],
|
||||
isMousemoveId: null,
|
||||
defaultProps: {
|
||||
children: "children",
|
||||
label: "categoryName",
|
||||
},
|
||||
materialName:"",
|
||||
materialId:"",
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
},
|
||||
// 总条数
|
||||
total: 0,
|
||||
//列表数据
|
||||
typeList: undefined,
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
dialogVisible: false,
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 表单参数
|
||||
form: {
|
||||
categoryName: "",
|
||||
parentId: "",
|
||||
superAreaName: "",
|
||||
categoryCode: "",
|
||||
description: ""
|
||||
},
|
||||
// 表单校验
|
||||
rules: {
|
||||
categoryName: [
|
||||
{
|
||||
required: true,
|
||||
message: "类别名称不能为空",
|
||||
trigger: "blur",
|
||||
},
|
||||
],
|
||||
categoryCode: [
|
||||
{
|
||||
required: true,
|
||||
message: "类别编码不能为空",
|
||||
trigger: "blur",
|
||||
},
|
||||
]
|
||||
},
|
||||
parentId: undefined,
|
||||
|
||||
treeAreaOptions:[],//区域树
|
||||
treeProps:{
|
||||
multiple: true,
|
||||
value:"id",
|
||||
label:"treeName",
|
||||
children:"children",
|
||||
},
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
// 根据名称筛选部门树
|
||||
materialName(val) {
|
||||
this.$refs.tree.filter(val);
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.getTreeData();
|
||||
this.getAreaTreeData();
|
||||
},
|
||||
methods: {
|
||||
// 筛选节点 - 左侧树
|
||||
filterNode(value, data) {
|
||||
if (!value) return true;
|
||||
return data.categoryName.indexOf(value) !== -1;
|
||||
},
|
||||
/** 查询新增页面-上级类型下拉树结构 */
|
||||
getTreeData() {
|
||||
systemMaterialTreeApi({}).then((response) => {
|
||||
this.treeOptions = response.data;
|
||||
console.log("this.treeOptions",this.treeOptions)
|
||||
if(this.treeOptions && this.treeOptions.length > 0){
|
||||
// 确保树节点数据格式正确
|
||||
this.treeOptions = this.treeOptions.map(node => ({
|
||||
...node,
|
||||
categoryName: node.categoryName || node.treeName || node.label || '未命名'
|
||||
}));
|
||||
this.materialId = this.treeOptions[0].id;
|
||||
this.getList();
|
||||
} else {
|
||||
this.materialId = "";
|
||||
this.getList();
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1;
|
||||
this.getList();
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
this.resetForm("queryForm");
|
||||
this.queryParams.pageNum = 1;
|
||||
this.queryParams.pageSize = 10;
|
||||
this.$refs.tree.setCurrentKey(null);
|
||||
this.handleQuery();
|
||||
},
|
||||
/** 查询列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
let params= {
|
||||
"materialName":this.materialName,
|
||||
"materialId":this.materialId,
|
||||
"size": this.queryParams.pageSize,
|
||||
"current": this.queryParams.pageNum
|
||||
}
|
||||
getMaterialListApi(params).then((response) => {
|
||||
this.typeList = response.records;
|
||||
this.total = Number(response.total);
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
// 节点单击事件 - 左侧树
|
||||
async handleNodeClick(data, node) {
|
||||
console.log(data)
|
||||
this.materialId = data.id;
|
||||
this.handleQuery();
|
||||
},
|
||||
|
||||
// 节点单击事件 - 左侧树
|
||||
async getMaterialName(data) {
|
||||
let params= {
|
||||
"materialId":data.id
|
||||
}
|
||||
const res = await getMaterialNameApi(params);
|
||||
this.$set(this.form,"superMaterialName",res.msg)
|
||||
},
|
||||
// 节点单击事件 - 左侧树
|
||||
async getMaterialNum(data) {
|
||||
let params= {
|
||||
"superId":data.id||""
|
||||
}
|
||||
if(data.parentId=="-1"){
|
||||
params.canteenTreeType=-1
|
||||
}else{
|
||||
params.canteenTreeType=0
|
||||
}
|
||||
const res = await getMaterialNumApi(params);
|
||||
this.$set(this.form,"materialNum",res.data)
|
||||
},
|
||||
|
||||
|
||||
/* 树节点增加 */
|
||||
appendTreeNode(data) {
|
||||
this.reset();
|
||||
if(data.parentId=="-1"){
|
||||
this.$set(this.form,"superAreaName",data.categoryName)
|
||||
}else{
|
||||
this.$set(this.form,"superAreaName",data.categoryName)
|
||||
}
|
||||
this.$set(this.form,"parentId",data.id)
|
||||
this.open = true;
|
||||
this.title = "新增";
|
||||
},
|
||||
/* 树节点删除 */
|
||||
removeTreeNode(data) {
|
||||
console.log(data, "删除时的数据源--");
|
||||
this.$modal
|
||||
.confirm("是否确认删除数据项?")
|
||||
.then(function () {
|
||||
return removeMaterialApi({"materialId":data.id});
|
||||
})
|
||||
.then(() => {
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
this.getList();
|
||||
this.getTreeData();
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
/* 树节点修改 */
|
||||
editTreeNode(data) {
|
||||
this.reset();
|
||||
this.form = {
|
||||
...data,
|
||||
superAreaName: data.parentId === "-1" ? "" : this.getParentCategoryName(data.parentId)
|
||||
};
|
||||
this.open = true;
|
||||
this.title = "修改";
|
||||
},
|
||||
onMousemove(data) {
|
||||
this.isMousemoveId = data.id;
|
||||
},
|
||||
onMouseleave() {
|
||||
this.isMousemoveId = null;
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.dialogVisible = false;
|
||||
this.reset();
|
||||
},
|
||||
// 表单重置
|
||||
reset() {
|
||||
this.form = {};
|
||||
this.resetForm("form");
|
||||
},
|
||||
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.dialogVisible = true;
|
||||
this.title = "新增";
|
||||
},
|
||||
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
this.dialogVisible = true;
|
||||
this.title = "修改";
|
||||
// 在显示对话框后,可以通过 $refs 访问子组件方法设置表单数据
|
||||
this.$nextTick(() => {
|
||||
// 假设子组件提供了 setFormData 方法
|
||||
this.$refs.materialDialog.setFormData(row);
|
||||
});
|
||||
},
|
||||
|
||||
/** 处理对话框提交 */
|
||||
handleDialogSubmit(formData) {
|
||||
if (this.title === "新增") {
|
||||
addMaterialApi(formData).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.dialogVisible = false;
|
||||
this.getList();
|
||||
this.getTreeData();
|
||||
});
|
||||
} else {
|
||||
updateMaterialApi(formData).then(response => {
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
this.dialogVisible = false;
|
||||
this.getList();
|
||||
this.getTreeData();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
this.$modal
|
||||
.confirm("是否确认删除数据项?")
|
||||
.then(function () {
|
||||
return removeMaterialApi({"materialId":row.materialId});
|
||||
})
|
||||
.then(() => {
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
this.getList();
|
||||
this.getTreeData();
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
|
||||
|
||||
|
||||
getParentName(list, id) {
|
||||
try {
|
||||
list.forEach((e) => {
|
||||
if (e.id == id) {
|
||||
this.form.label = e.label;
|
||||
throw new Error();
|
||||
} else {
|
||||
if (e.children && e.children.length > 0) {
|
||||
this.getParentName(e.children, id);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {}
|
||||
},
|
||||
|
||||
/** 表单提交 */
|
||||
handleSubmit() {
|
||||
this.$refs.form.validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.id != undefined) {
|
||||
updateMaterialApi(this.form).then(response => {
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
} else {
|
||||
addMaterialApi(this.form).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 获取父节点的类别名称
|
||||
getParentCategoryName(parentId) {
|
||||
const findNode = (nodes) => {
|
||||
for (let node of nodes) {
|
||||
if (node.id === parentId) {
|
||||
return node.categoryName;
|
||||
}
|
||||
if (node.children) {
|
||||
const result = findNode(node.children);
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
};
|
||||
return findNode(this.treeOptions);
|
||||
},
|
||||
|
||||
handleTreeChange(e){
|
||||
console.log(e)
|
||||
},
|
||||
|
||||
//区域树
|
||||
getAreaTreeData() {
|
||||
systemAreaTreeApi({}).then((response) => {
|
||||
this.treeAreaOptions = response;
|
||||
console.log(this.treeAreaOptions)
|
||||
});
|
||||
},
|
||||
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
::v-deep.el-table .fixed-width .el-button--mini {
|
||||
width: 60px !important;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
::v-deep .btn-items .el-button + .el-button {
|
||||
margin-left: 6px;
|
||||
}
|
||||
.btn-items {
|
||||
margin-left: 4px;
|
||||
.el-button--text {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
::v-deep .el-tree .el-tree-node__expand-icon.expanded {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
::v-deep .el-tree .el-icon-caret-right:before {
|
||||
content: "\e783";
|
||||
font-size: 16px;
|
||||
}
|
||||
::v-deep
|
||||
.el-tree
|
||||
.el-tree-node__expand-icon.expanded.el-icon-caret-right:before {
|
||||
content: "\e781";
|
||||
font-size: 16px;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
::v-deep .el-tree-node__content > .el-tree-node__expand-icon {
|
||||
color: #1890ff !important;
|
||||
}
|
||||
::v-deep .el-tree-node__expand-icon.is-leaf {
|
||||
color: transparent !important;
|
||||
}
|
||||
|
||||
::v-deep
|
||||
.el-tree--highlight-current
|
||||
.el-tree-node.is-current
|
||||
> .el-tree-node__content {
|
||||
background-color: #8decf1;
|
||||
}
|
||||
|
||||
::v-deep .el-dialog .material-dialog {
|
||||
// 表单标签文字样式
|
||||
.el-form-item__label {
|
||||
font-size: 14px;
|
||||
color: #606266;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
// 输入框文字样式
|
||||
.el-input__inner {
|
||||
font-size: 14px;
|
||||
color: #303133;
|
||||
|
||||
&::placeholder {
|
||||
font-size: 13px;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
}
|
||||
|
||||
// 单位文字样式
|
||||
span {
|
||||
font-size: 14px;
|
||||
// color: #606266;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
// 下拉选择框文字样式
|
||||
.el-select {
|
||||
.el-input__inner {
|
||||
font-size: 14px;
|
||||
color: #303133;
|
||||
}
|
||||
}
|
||||
|
||||
// 只读输入框样式
|
||||
.el-input.is-disabled .el-input__inner {
|
||||
background-color: #f5f7fa;
|
||||
border-color: #e4e7ed;
|
||||
color: #606266;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
// 表格内文字样式
|
||||
::v-deep .el-table {
|
||||
font-size: 14px;
|
||||
|
||||
th {
|
||||
font-weight: 500;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
td {
|
||||
color: #606266;
|
||||
}
|
||||
}
|
||||
|
||||
// 按钮文字样式
|
||||
::v-deep .el-button {
|
||||
font-size: 14px;
|
||||
|
||||
&--text {
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
// 树节点文字样式
|
||||
::v-deep .el-tree-node__label {
|
||||
font-size: 14px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
// 搜索框文字样式
|
||||
::v-deep .el-input--small {
|
||||
.el-input__inner {
|
||||
font-size: 13px;
|
||||
|
||||
&::placeholder {
|
||||
font-size: 13px;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* 级联选择器相关方法
|
||||
*/
|
||||
export const cascaderMixin = {
|
||||
methods: {
|
||||
/**
|
||||
* 更新级联选择器选项
|
||||
* @returns {void}
|
||||
*/
|
||||
updateCascaderOptions() {
|
||||
this.cascaderOptions = this.cascaderOptionsMethod();
|
||||
},
|
||||
|
||||
/**
|
||||
* 生成级联选择器的选项数据
|
||||
* @returns {Array<{value: string, label: string, children: Array<{value: string, label: string}>}>}
|
||||
*/
|
||||
cascaderOptionsMethod() {
|
||||
if (!this.queryParams.status) {
|
||||
return [];
|
||||
}
|
||||
return this.queryParams.status.map(item => ({
|
||||
value: item.bigType,
|
||||
label: item.bigType,
|
||||
children: item.littleTypeList.map(subItem => ({
|
||||
value: subItem,
|
||||
label: subItem
|
||||
}))
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理级联选择器值变化
|
||||
* @param {Array<string>} value - 选中的值数组
|
||||
*/
|
||||
handleChange(value) {
|
||||
if (value && value.length >= 2) {
|
||||
this.queryParams.bigType = value[0];
|
||||
this.queryParams.littleType = value[1];
|
||||
} else {
|
||||
this.queryParams.bigType = undefined;
|
||||
this.queryParams.littleType = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,805 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
|
||||
<el-form-item label="营养信息类别" prop="status" >
|
||||
<el-cascader
|
||||
v-model="selectedOptions"
|
||||
:options="cascaderOptions"
|
||||
@change="handleChange"
|
||||
></el-cascader>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="食材编码" prop="nutritionCode">
|
||||
<el-input
|
||||
v-model="queryParams.nutritionCode"
|
||||
placeholder="请输入食材编码"
|
||||
clearable
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="营养信息名称" prop="nutritionName">
|
||||
<el-input
|
||||
v-model="queryParams.nutritionName"
|
||||
placeholder="请输入营养信息名称"
|
||||
clearable
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
icon="el-icon-plus"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
v-hasPermi="['dish:nutritionInfo:add']"
|
||||
>新增</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="menuNutritionList" >
|
||||
<el-table-column type="index" label="序号" width="50" align="center" />
|
||||
<el-table-column label="食材编码" align="center" prop="nutritionCode" />
|
||||
<el-table-column label="营养信息名称" align="center" prop="nutritionName" />
|
||||
<el-table-column label="食材大类" align="center" prop="bigType" />
|
||||
<el-table-column label="食材小类" align="center" prop="littleType" />
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
v-hasPermi="['dish:nutritionInfo:edit']"
|
||||
>修改</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
v-hasPermi="['dish:nutritionInfo:remove']"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.current"
|
||||
:limit.sync="queryParams.size"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
<!-- 添加或修改岗位对话框 -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="190px">
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="营养信息类别" prop="nutritionCategory" required>
|
||||
<el-cascader
|
||||
v-model="form.nutritionCategory"
|
||||
:options="cascaderOptions"
|
||||
:props="{
|
||||
checkStrictly: false,
|
||||
emitPath: true
|
||||
}"
|
||||
placeholder="请选择营养信息类别"
|
||||
clearable
|
||||
style="width: 100%;"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="营养信息名称" prop="nutritionName" required>
|
||||
<el-input
|
||||
v-model="form.nutritionName"
|
||||
placeholder="请输入营养信息名称"
|
||||
maxlength="30"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="食材编码" prop="nutritionCode" required>
|
||||
<el-input
|
||||
v-model="form.nutritionCode"
|
||||
placeholder="请输入食材编码"
|
||||
maxlength="30"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="加工时间(min)">
|
||||
<el-input
|
||||
v-model="form.processingTime"
|
||||
@input="handleNumericInput('processingTime')"
|
||||
@blur="formatNumericValue('processingTime')"
|
||||
placeholder="请输入加工时间"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="可食部分(g/100g)" prop="edible">
|
||||
<el-input
|
||||
v-model="form.edible"
|
||||
@input="handleNumericInput('edible')"
|
||||
@blur="formatNumericValue('edible')"
|
||||
placeholder="请输入可食部分"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="水分(g/100g)" prop="water">
|
||||
<el-input
|
||||
v-model="form.water"
|
||||
@input="handleNumericInput('water')"
|
||||
@blur="formatNumericValue('water')"
|
||||
placeholder="请输入水分"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="热量(千卡/100g)" prop="calories">
|
||||
<el-input
|
||||
v-model="form.calories"
|
||||
@input="handleNumericInput('calories')"
|
||||
@blur="formatNumericValue('calories')"
|
||||
placeholder="请输入热量"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="蛋白质(g/100g)" prop="protein">
|
||||
<el-input
|
||||
v-model="form.protein"
|
||||
@input="handleNumericInput('protein')"
|
||||
@blur="formatNumericValue('protein')"
|
||||
placeholder="请输入蛋白质"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="脂肪(g/100g)" prop="fat">
|
||||
<el-input
|
||||
v-model="form.fat"
|
||||
@input="handleNumericInput('fat')"
|
||||
@blur="formatNumericValue('fat')"
|
||||
placeholder="请输入脂肪"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="碳水化合物(g/100g)" prop="carbohydrate">
|
||||
<el-input
|
||||
v-model="form.carbohydrate"
|
||||
@input="handleNumericInput('carbohydrate')"
|
||||
@blur="formatNumericValue('carbohydrate')"
|
||||
placeholder="请输入碳水化合物"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="膳食纤维(g/100g)" prop="dietaryFiber">
|
||||
<el-input
|
||||
v-model="form.dietaryFiber"
|
||||
@input="handleNumericInput('dietaryFiber')"
|
||||
@blur="formatNumericValue('dietaryFiber')"
|
||||
placeholder="请输入膳食纤维"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="胆固醇(mg/100g)" prop="cholesterol">
|
||||
<el-input
|
||||
v-model="form.cholesterol"
|
||||
@input="handleNumericInput('cholesterol')"
|
||||
@blur="formatNumericValue('cholesterol')"
|
||||
placeholder="请输入胆固醇"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="灰分(g/100g)" prop="ash">
|
||||
<el-input
|
||||
v-model="form.ash"
|
||||
@input="handleNumericInput('ash')"
|
||||
@blur="formatNumericValue('ash')"
|
||||
placeholder="请输入灰分"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="维生素A(μg/100g)" prop="vitaminA">
|
||||
<el-input
|
||||
v-model="form.vitaminA"
|
||||
@input="handleNumericInput('vitaminA')"
|
||||
@blur="formatNumericValue('vitaminA')"
|
||||
placeholder="请输入维生素A"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="胡萝卜素(μg/100g)" prop="carotene">
|
||||
<el-input
|
||||
v-model="form.carotene"
|
||||
@input="handleNumericInput('carotene')"
|
||||
@blur="formatNumericValue('carotene')"
|
||||
placeholder="请输入胡萝卜素"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="视黄醇(μg/100g)" prop="retinol">
|
||||
<el-input
|
||||
v-model="form.retinol"
|
||||
@input="handleNumericInput('retinol')"
|
||||
@blur="formatNumericValue('retinol')"
|
||||
placeholder="请输入视黄醇"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="硫胺素(mg/100g)" prop="thiamine">
|
||||
<el-input
|
||||
v-model="form.thiamine"
|
||||
@input="handleNumericInput('thiamine')"
|
||||
@blur="formatNumericValue('thiamine')"
|
||||
placeholder="请输入硫胺素"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="核黄素(mg/100g)" prop="riboflavin">
|
||||
<el-input
|
||||
v-model="form.riboflavin"
|
||||
@input="handleNumericInput('riboflavin')"
|
||||
@blur="formatNumericValue('riboflavin')"
|
||||
placeholder="请输入核黄素"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label=" 烟酸/尼克酸(mg/100g)" prop="niacin">
|
||||
<el-input
|
||||
v-model="form.niacin"
|
||||
@input="handleNumericInput('niacin')"
|
||||
@blur="formatNumericValue('niacin')"
|
||||
placeholder="请输入烟酸/尼克酸"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="维生素C(mg/100g)" prop="vitaminC">
|
||||
<el-input
|
||||
v-model="form.vitaminC"
|
||||
@input="handleNumericInput('vitaminC')"
|
||||
@blur="formatNumericValue('vitaminC')"
|
||||
placeholder="请输入维生素C"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="维生素D(μg/100g)" prop="vitaminD">
|
||||
<el-input
|
||||
v-model="form.vitaminD"
|
||||
@input="handleNumericInput('vitaminD')"
|
||||
@blur="formatNumericValue('vitaminD')"
|
||||
placeholder="请输入维生素D"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="维生素E(mg/100g)" prop="vitaminE">
|
||||
<el-input
|
||||
v-model="form.vitaminE"
|
||||
@input="handleNumericInput('vitaminE')"
|
||||
@blur="formatNumericValue('vitaminE')"
|
||||
placeholder="请输入维生素E"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="钙(mg/100g)" prop="calcium">
|
||||
<el-input
|
||||
v-model="form.calcium"
|
||||
@input="handleNumericInput('calcium')"
|
||||
@blur="formatNumericValue('calcium')"
|
||||
placeholder="请输入钙"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="磷(mg/100g)" prop="phosphorus">
|
||||
<el-input
|
||||
v-model="form.phosphorus"
|
||||
@input="handleNumericInput('phosphorus')"
|
||||
@blur="formatNumericValue('phosphorus')"
|
||||
placeholder="请输入磷"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label=" 钾(mg/100g)" prop="kalium">
|
||||
<el-input
|
||||
v-model="form.kalium"
|
||||
@input="handleNumericInput('kalium')"
|
||||
@blur="formatNumericValue('kalium')"
|
||||
placeholder="请输入钾"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="钠 (mg/100g)" prop="sodium">
|
||||
<el-input
|
||||
v-model="form.sodium"
|
||||
@input="handleNumericInput('sodium')"
|
||||
@blur="formatNumericValue('sodium')"
|
||||
placeholder="请输入钠"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label=" 镁(mg/100g)" prop="magnesium">
|
||||
<el-input
|
||||
v-model="form.magnesium"
|
||||
@input="handleNumericInput('magnesium')"
|
||||
@blur="formatNumericValue('magnesium')"
|
||||
placeholder="请输入镁"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="铁 (mg/100g)" prop="iron">
|
||||
<el-input
|
||||
v-model="form.iron"
|
||||
@input="handleNumericInput('iron')"
|
||||
@blur="formatNumericValue('iron')"
|
||||
placeholder="请输入铁"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item label="锌(mg/100g)" prop="zinc">
|
||||
<el-input
|
||||
v-model="form.zinc"
|
||||
@input="handleNumericInput('zinc')"
|
||||
@blur="formatNumericValue('zinc')"
|
||||
placeholder="请输入锌"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="硒(μg/100g)" prop="selenium">
|
||||
<el-input
|
||||
v-model="form.selenium"
|
||||
@input="handleNumericInput('selenium')"
|
||||
@blur="formatNumericValue('selenium')"
|
||||
placeholder="请输入硒"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
|
||||
</el-row>
|
||||
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listNutrition, getNutrition, delNutrition, addMenuNutrition, updateNutrition, typeList } from "@/api/dish/nutritionInfo";
|
||||
import { cascaderMixin } from './cascaderMixin';
|
||||
|
||||
export default {
|
||||
name: "NutritionInfo",
|
||||
mixins: [cascaderMixin],
|
||||
/** @type {import('vue').ComponentOptions} */
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 岗位表格数据
|
||||
menuNutritionList: [],
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
current: 1,
|
||||
size: 10,
|
||||
nutritionCode: undefined,
|
||||
nutritionName: undefined,
|
||||
status: undefined,
|
||||
bigType: undefined,
|
||||
littleType: undefined
|
||||
},
|
||||
// 表单参数
|
||||
form: {
|
||||
nutritionCategory: [], // 营养信息类别
|
||||
nutritionName: undefined, // 营养信息名称
|
||||
nutritionCode: undefined, // 食材编码
|
||||
processingTime: undefined, // 加工时间
|
||||
edible: undefined, // 可食部分
|
||||
water: undefined, // 水分
|
||||
calories: undefined, // 热量
|
||||
protein: undefined, // 蛋白质
|
||||
fat: undefined, // 脂肪
|
||||
carbohydrate: undefined, // 碳水化合物
|
||||
dietaryFiber: undefined, // 膳食纤维
|
||||
cholesterol: undefined, // 胆固醇
|
||||
ash: undefined, // 灰分
|
||||
vitaminA: undefined, // 维生素A
|
||||
carotene: undefined, // 胡萝卜素
|
||||
retinol: undefined, // 视黄醇
|
||||
thiamine: undefined, // 硫胺素
|
||||
riboflavin: undefined, // 核黄素
|
||||
niacin: undefined, // 烟酸/尼克酸
|
||||
vitaminC: undefined, // 维生素C
|
||||
vitaminD: undefined, // 维生素D
|
||||
vitaminE: undefined, // 维生素E
|
||||
calcium: undefined, // 钙
|
||||
phosphorus: undefined, // 磷
|
||||
kalium: undefined, // 钾
|
||||
sodium: undefined, // 钠
|
||||
magnesium: undefined, // 镁
|
||||
iron: undefined, // 铁
|
||||
zinc: undefined, // 锌
|
||||
selenium: undefined, // 硒
|
||||
},
|
||||
// 表单校验
|
||||
rules: {
|
||||
nutritionCategory: [
|
||||
{ required: true, message: "请选择营养信息类别", trigger: "change" }
|
||||
],
|
||||
nutritionName: [
|
||||
{ required: true, message: "营养信息名称不能为空", trigger: "blur" }
|
||||
],
|
||||
nutritionCode: [
|
||||
{ required: true, message: "食材编码不能为空", trigger: "blur" }
|
||||
]
|
||||
},
|
||||
|
||||
selectedOptions: [], // 级联选择器的选中值
|
||||
cascaderOptions: [] // 级联选择器的选项
|
||||
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
created() {
|
||||
this.getFoodType();
|
||||
this.getList();
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 获取所有食材类别
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
getFoodType() {
|
||||
typeList().then(response => {
|
||||
this.queryParams.status = response.data;
|
||||
this.updateCascaderOptions(); // 在获取数据后更新级联选择器选项
|
||||
}).catch(error => {
|
||||
console.error("Failed to fetch food types:", error);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新级联选择器选项
|
||||
* @returns {void}
|
||||
*/
|
||||
updateCascaderOptions() {
|
||||
this.cascaderOptions = this.cascaderOptionsMethod();
|
||||
},
|
||||
|
||||
/**
|
||||
* 生成级联选择器的选项数据
|
||||
* @returns {Array<{value: string, label: string, children: Array<{value: string, label: string}>}>}
|
||||
*/
|
||||
cascaderOptionsMethod() {
|
||||
if (!this.queryParams.status) {
|
||||
return [];
|
||||
}
|
||||
return this.queryParams.status.map(item => ({
|
||||
value: item.bigType,
|
||||
label: item.bigType,
|
||||
children: item.littleTypeList.map(subItem => ({
|
||||
value: subItem,
|
||||
label: subItem
|
||||
}))
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理级联选择器值变化
|
||||
* @param {Array<string>} value - 选中的值数组
|
||||
*/
|
||||
handleChange(value) {
|
||||
if (value && value.length >= 2) {
|
||||
this.queryParams.bigType = value[0];
|
||||
this.queryParams.littleType = value[1];
|
||||
} else {
|
||||
this.queryParams.bigType = undefined;
|
||||
this.queryParams.littleType = undefined;
|
||||
}
|
||||
},
|
||||
|
||||
/** 查询岗位列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listNutrition(this.queryParams).then(response => {
|
||||
this.menuNutritionList = response.data.records;
|
||||
this.total = Number(response.data.total);
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.open = false;
|
||||
this.reset();
|
||||
},
|
||||
// 表单重置
|
||||
reset() {
|
||||
this.form = {
|
||||
nutritionCategory: [], // 营养信息类别
|
||||
nutritionName: undefined, // 营养信息名称
|
||||
nutritionCode: undefined, // 食材编码
|
||||
processingTime: undefined, // 加工时间
|
||||
edible: undefined, // 可食部分
|
||||
water: undefined, // 水分
|
||||
calories: undefined, // 热量
|
||||
protein: undefined, // 蛋白质
|
||||
fat: undefined, // 脂肪
|
||||
carbohydrate: undefined, // 碳水化合物
|
||||
dietaryFiber: undefined, // 膳食纤维
|
||||
cholesterol: undefined, // 胆固醇
|
||||
ash: undefined, // 灰分
|
||||
vitaminA: undefined, // 维生素A
|
||||
carotene: undefined, // 胡萝卜素
|
||||
retinol: undefined, // 视黄醇
|
||||
thiamine: undefined, // 硫胺素
|
||||
riboflavin: undefined, // 核黄素
|
||||
niacin: undefined, // 烟酸/尼克酸
|
||||
vitaminC: undefined, // 维生素C
|
||||
vitaminD: undefined, // 维生素D
|
||||
vitaminE: undefined, // 维生素E
|
||||
calcium: undefined, // 钙
|
||||
phosphorus: undefined, // 磷
|
||||
kalium: undefined, // 钾
|
||||
sodium: undefined, // 钠
|
||||
magnesium: undefined, // 镁
|
||||
iron: undefined, // 铁
|
||||
zinc: undefined, // 锌
|
||||
selenium: undefined, // 硒
|
||||
};
|
||||
this.resetForm("form");
|
||||
},
|
||||
/**
|
||||
* 搜索按钮操作
|
||||
* @method handleQuery
|
||||
* @description 重置页码为1并获取列表数据
|
||||
*/
|
||||
handleQuery() {
|
||||
this.queryParams.current = 1;
|
||||
this.getList();
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
this.resetForm("queryForm");
|
||||
this.selectedOptions = []; // 清空级联选择器的选中值
|
||||
this.queryParams.bigType = undefined;
|
||||
this.queryParams.littleType = undefined;
|
||||
this.handleQuery();
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.open = true;
|
||||
this.title = "添加营养信息";
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const id = row.nutritionId;
|
||||
var data = {
|
||||
nutritionId: id
|
||||
}
|
||||
getNutrition(data).then(response => {
|
||||
this.form = response.data;
|
||||
// 如果后端返回的是分开的大类小类,需要组合成数组
|
||||
if (response.data.bigType && response.data.littleType) {
|
||||
this.form.nutritionCategory = [response.data.bigType, response.data.littleType];
|
||||
}
|
||||
this.open = true;
|
||||
this.title = "修改营养信息";
|
||||
});
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm: function() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (valid) {
|
||||
const formData = { ...this.form };
|
||||
// 处理营养信息类别,转换为后端需要的格式
|
||||
if (formData.nutritionCategory && formData.nutritionCategory.length >= 2) {
|
||||
formData.bigType = formData.nutritionCategory[0];
|
||||
formData.littleType = formData.nutritionCategory[1];
|
||||
}
|
||||
delete formData.nutritionCategory; // 删除多余的字段
|
||||
|
||||
if (formData.id != undefined) {
|
||||
updateNutrition(formData).then(response => {
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
} else {
|
||||
addMenuNutrition(formData).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const nutritionIds = row.nutritionId;
|
||||
var data = {
|
||||
nutritionId:nutritionIds
|
||||
}
|
||||
this.$modal.confirm('是否确认删除数据项?').then(function() {
|
||||
return delNutrition(data);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
}).catch(() => {});
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理数值输入
|
||||
* @param {string} field - 字段名
|
||||
* @param {Event} event - 输入事件
|
||||
*/
|
||||
handleNumericInput(field, event) {
|
||||
const value = event.target.value;
|
||||
// 只允许输入数字和小数点
|
||||
let newValue = value.replace(/[^\d.]/g, '');
|
||||
|
||||
// 确保只有一个小数点
|
||||
const parts = newValue.split('.');
|
||||
if (parts.length > 2) {
|
||||
newValue = parts[0] + '.' + parts.slice(1).join('');
|
||||
}
|
||||
|
||||
// 限制小数点后最多两位
|
||||
if (parts.length === 2 && parts[1].length > 2) {
|
||||
newValue = parts[0] + '.' + parts[1].substring(0, 2);
|
||||
}
|
||||
|
||||
// 限制最大值为100
|
||||
if (parseFloat(newValue) > 100) {
|
||||
newValue = '100.00';
|
||||
}
|
||||
|
||||
this.form[field] = newValue;
|
||||
},
|
||||
|
||||
/**
|
||||
* 格式化数值
|
||||
* @param {string} field - 字段名
|
||||
*/
|
||||
formatNumericValue(field) {
|
||||
let value = this.form[field];
|
||||
|
||||
if (!value || value === '' || value === '.') {
|
||||
this.form[field] = '0.00';
|
||||
return;
|
||||
}
|
||||
|
||||
value = parseFloat(value);
|
||||
if (isNaN(value)) {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
// 限制最大值为100
|
||||
if (value > 100) {
|
||||
value = 100;
|
||||
}
|
||||
|
||||
// 格式化为两位小数
|
||||
this.form[field] = value.toFixed(2);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
::v-deep .el-dialog__body {
|
||||
max-height: calc(90vh - 120px);
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue