新增食材管理

This commit is contained in:
huangdeliang 2020-12-15 21:11:45 +08:00
parent a3fc7d7da7
commit 27bf41b006
11 changed files with 1123 additions and 6 deletions

View File

@ -826,10 +826,6 @@ create table sys_ingredient(
protein_ratio decimal(10,3) comment '蛋白质比例', protein_ratio decimal(10,3) comment '蛋白质比例',
fat_ratio decimal(10,3) comment '脂肪比例', fat_ratio decimal(10,3) comment '脂肪比例',
carbon_ratio decimal(10,3) comment '碳水比例', carbon_ratio decimal(10,3) comment '碳水比例',
protein_mass_ratio decimal(10,3) comment '蛋白质质量比',
fat_mass decimal(10,3) comment '脂肪质量',
carbon_mass decimal(10,3) comment '碳水质量',
heat decimal(10,3) comment '热量',
remark varchar(500) comment '备注', remark varchar(500) comment '备注',
area varchar(20) comment '地域', area varchar(20) comment '地域',
not_rec varchar(500) comment '忌口', not_rec varchar(500) comment '忌口',

View File

@ -0,0 +1,103 @@
package com.stdiet.web.controller.custom;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.stdiet.common.annotation.Log;
import com.stdiet.common.core.controller.BaseController;
import com.stdiet.common.core.domain.AjaxResult;
import com.stdiet.common.enums.BusinessType;
import com.stdiet.custom.domain.SysIngredient;
import com.stdiet.custom.service.ISysIngredientService;
import com.stdiet.common.utils.poi.ExcelUtil;
import com.stdiet.common.core.page.TableDataInfo;
/**
* 食材Controller
*
* @author wonder
* @date 2020-12-15
*/
@RestController
@RequestMapping("/custom/ingredient")
public class SysIngredientController extends BaseController
{
@Autowired
private ISysIngredientService sysIngredientService;
/**
* 查询食材列表
*/
@PreAuthorize("@ss.hasPermi('custom:ingredient:list')")
@GetMapping("/list")
public TableDataInfo list(SysIngredient sysIngredient)
{
startPage();
List<SysIngredient> list = sysIngredientService.selectSysIngredientList(sysIngredient);
return getDataTable(list);
}
/**
* 导出食材列表
*/
@PreAuthorize("@ss.hasPermi('custom:ingredient:export')")
@Log(title = "食材", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(SysIngredient sysIngredient)
{
List<SysIngredient> list = sysIngredientService.selectSysIngredientList(sysIngredient);
ExcelUtil<SysIngredient> util = new ExcelUtil<SysIngredient>(SysIngredient.class);
return util.exportExcel(list, "ingredient");
}
/**
* 获取食材详细信息
*/
@PreAuthorize("@ss.hasPermi('custom:ingredient:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(sysIngredientService.selectSysIngredientById(id));
}
/**
* 新增食材
*/
@PreAuthorize("@ss.hasPermi('custom:ingredient:add')")
@Log(title = "食材", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody SysIngredient sysIngredient)
{
return toAjax(sysIngredientService.insertSysIngredient(sysIngredient));
}
/**
* 修改食材
*/
@PreAuthorize("@ss.hasPermi('custom:ingredient:edit')")
@Log(title = "食材", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SysIngredient sysIngredient)
{
return toAjax(sysIngredientService.updateSysIngredient(sysIngredient));
}
/**
* 删除食材
*/
@PreAuthorize("@ss.hasPermi('custom:ingredient:remove')")
@Log(title = "食材", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(sysIngredientService.deleteSysIngredientByIds(ids));
}
}

View File

@ -0,0 +1,197 @@
package com.stdiet.custom.domain;
import java.math.BigDecimal;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.stdiet.common.annotation.Excel;
import com.stdiet.common.core.domain.BaseEntity;
/**
* 食材对象 sys_ingredient
*
* @author wonder
* @date 2020-12-15
*/
public class SysIngredient extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** id */
private Long id;
/** 食材名称 */
@Excel(name = "食材名称")
private String name;
/** 食材类别 */
@Excel(name = "食材类别")
private String type;
/** 推荐分量估算 */
@Excel(name = "推荐分量估算")
private Long recEstimation;
/** 推荐分量估算单位id */
@Excel(name = "推荐分量估算单位id")
private Long recEstUnit;
/** 推荐分量 */
@Excel(name = "推荐分量")
private Long recPortion;
/** 蛋白质比例 */
@Excel(name = "蛋白质比例")
private BigDecimal proteinRatio;
/** 脂肪比例 */
@Excel(name = "脂肪比例")
private BigDecimal fatRatio;
/** 碳水比例 */
@Excel(name = "碳水比例")
private BigDecimal carbonRatio;
/** 地域 */
@Excel(name = "地域")
private String area;
/** 忌口 */
@Excel(name = "忌口")
private String notRec;
/** 推荐 */
@Excel(name = "推荐")
private String recommend;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setType(String type)
{
this.type = type;
}
public String getType()
{
return type;
}
public void setRecEstimation(Long recEstimation)
{
this.recEstimation = recEstimation;
}
public Long getRecEstimation()
{
return recEstimation;
}
public void setRecEstUnit(Long recEstUnit)
{
this.recEstUnit = recEstUnit;
}
public Long getRecEstUnit()
{
return recEstUnit;
}
public void setRecPortion(Long recPortion)
{
this.recPortion = recPortion;
}
public Long getRecPortion()
{
return recPortion;
}
public void setProteinRatio(BigDecimal proteinRatio)
{
this.proteinRatio = proteinRatio;
}
public BigDecimal getProteinRatio()
{
return proteinRatio;
}
public void setFatRatio(BigDecimal fatRatio)
{
this.fatRatio = fatRatio;
}
public BigDecimal getFatRatio()
{
return fatRatio;
}
public void setCarbonRatio(BigDecimal carbonRatio)
{
this.carbonRatio = carbonRatio;
}
public BigDecimal getCarbonRatio()
{
return carbonRatio;
}
public void setArea(String area)
{
this.area = area;
}
public String getArea()
{
return area;
}
public void setNotRec(String notRec)
{
this.notRec = notRec;
}
public String getNotRec()
{
return notRec;
}
public void setRecommend(String recommend)
{
this.recommend = recommend;
}
public String getRecommend()
{
return recommend;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("name", getName())
.append("type", getType())
.append("recEstimation", getRecEstimation())
.append("recEstUnit", getRecEstUnit())
.append("recPortion", getRecPortion())
.append("proteinRatio", getProteinRatio())
.append("fatRatio", getFatRatio())
.append("carbonRatio", getCarbonRatio())
.append("remark", getRemark())
.append("area", getArea())
.append("notRec", getNotRec())
.append("recommend", getRecommend())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.toString();
}
}

View File

@ -0,0 +1,61 @@
package com.stdiet.custom.mapper;
import java.util.List;
import com.stdiet.custom.domain.SysIngredient;
/**
* 食材Mapper接口
*
* @author wonder
* @date 2020-12-15
*/
public interface SysIngredientMapper
{
/**
* 查询食材
*
* @param id 食材ID
* @return 食材
*/
public SysIngredient selectSysIngredientById(Long id);
/**
* 查询食材列表
*
* @param sysIngredient 食材
* @return 食材集合
*/
public List<SysIngredient> selectSysIngredientList(SysIngredient sysIngredient);
/**
* 新增食材
*
* @param sysIngredient 食材
* @return 结果
*/
public int insertSysIngredient(SysIngredient sysIngredient);
/**
* 修改食材
*
* @param sysIngredient 食材
* @return 结果
*/
public int updateSysIngredient(SysIngredient sysIngredient);
/**
* 删除食材
*
* @param id 食材ID
* @return 结果
*/
public int deleteSysIngredientById(Long id);
/**
* 批量删除食材
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteSysIngredientByIds(Long[] ids);
}

View File

@ -0,0 +1,61 @@
package com.stdiet.custom.service;
import java.util.List;
import com.stdiet.custom.domain.SysIngredient;
/**
* 食材Service接口
*
* @author wonder
* @date 2020-12-15
*/
public interface ISysIngredientService
{
/**
* 查询食材
*
* @param id 食材ID
* @return 食材
*/
public SysIngredient selectSysIngredientById(Long id);
/**
* 查询食材列表
*
* @param sysIngredient 食材
* @return 食材集合
*/
public List<SysIngredient> selectSysIngredientList(SysIngredient sysIngredient);
/**
* 新增食材
*
* @param sysIngredient 食材
* @return 结果
*/
public int insertSysIngredient(SysIngredient sysIngredient);
/**
* 修改食材
*
* @param sysIngredient 食材
* @return 结果
*/
public int updateSysIngredient(SysIngredient sysIngredient);
/**
* 批量删除食材
*
* @param ids 需要删除的食材ID
* @return 结果
*/
public int deleteSysIngredientByIds(Long[] ids);
/**
* 删除食材信息
*
* @param id 食材ID
* @return 结果
*/
public int deleteSysIngredientById(Long id);
}

View File

@ -0,0 +1,96 @@
package com.stdiet.custom.service.impl;
import java.util.List;
import com.stdiet.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.stdiet.custom.mapper.SysIngredientMapper;
import com.stdiet.custom.domain.SysIngredient;
import com.stdiet.custom.service.ISysIngredientService;
/**
* 食材Service业务层处理
*
* @author wonder
* @date 2020-12-15
*/
@Service
public class SysIngredientServiceImpl implements ISysIngredientService
{
@Autowired
private SysIngredientMapper sysIngredientMapper;
/**
* 查询食材
*
* @param id 食材ID
* @return 食材
*/
@Override
public SysIngredient selectSysIngredientById(Long id)
{
return sysIngredientMapper.selectSysIngredientById(id);
}
/**
* 查询食材列表
*
* @param sysIngredient 食材
* @return 食材
*/
@Override
public List<SysIngredient> selectSysIngredientList(SysIngredient sysIngredient)
{
return sysIngredientMapper.selectSysIngredientList(sysIngredient);
}
/**
* 新增食材
*
* @param sysIngredient 食材
* @return 结果
*/
@Override
public int insertSysIngredient(SysIngredient sysIngredient)
{
sysIngredient.setCreateTime(DateUtils.getNowDate());
return sysIngredientMapper.insertSysIngredient(sysIngredient);
}
/**
* 修改食材
*
* @param sysIngredient 食材
* @return 结果
*/
@Override
public int updateSysIngredient(SysIngredient sysIngredient)
{
sysIngredient.setUpdateTime(DateUtils.getNowDate());
return sysIngredientMapper.updateSysIngredient(sysIngredient);
}
/**
* 批量删除食材
*
* @param ids 需要删除的食材ID
* @return 结果
*/
@Override
public int deleteSysIngredientByIds(Long[] ids)
{
return sysIngredientMapper.deleteSysIngredientByIds(ids);
}
/**
* 删除食材信息
*
* @param id 食材ID
* @return 结果
*/
@Override
public int deleteSysIngredientById(Long id)
{
return sysIngredientMapper.deleteSysIngredientById(id);
}
}

View File

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stdiet.custom.mapper.SysIngredientMapper">
<resultMap type="SysIngredient" id="SysIngredientResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="type" column="type" />
<result property="recEstimation" column="rec_estimation" />
<result property="recEstUnit" column="rec_est_unit" />
<result property="recPortion" column="rec_portion" />
<result property="proteinRatio" column="protein_ratio" />
<result property="fatRatio" column="fat_ratio" />
<result property="carbonRatio" column="carbon_ratio" />
<result property="remark" column="remark" />
<result property="area" column="area" />
<result property="notRec" column="not_rec" />
<result property="recommend" column="recommend" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectSysIngredientVo">
select id, name, type, rec_estimation, rec_est_unit, rec_portion, protein_ratio, fat_ratio, carbon_ratio, remark, area, not_rec, recommend, create_by, create_time, update_by, update_time from sys_ingredient
</sql>
<select id="selectSysIngredientList" parameterType="SysIngredient" resultMap="SysIngredientResult">
<include refid="selectSysIngredientVo"/>
<where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="area != null and area != ''"> and area = #{area}</if>
<if test="notRec != null and notRec != ''"> and not_rec like concat('%', #{notRec}, '%')</if>
<if test="recommend != null and recommend != ''"> and recommend like concat('%', #{recommend}, '%')</if>
</where>
</select>
<select id="selectSysIngredientById" parameterType="Long" resultMap="SysIngredientResult">
<include refid="selectSysIngredientVo"/>
where id = #{id}
</select>
<insert id="insertSysIngredient" parameterType="SysIngredient" useGeneratedKeys="true" keyProperty="id">
insert into sys_ingredient
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">name,</if>
<if test="type != null">type,</if>
<if test="recEstimation != null">rec_estimation,</if>
<if test="recEstUnit != null">rec_est_unit,</if>
<if test="recPortion != null">rec_portion,</if>
<if test="proteinRatio != null">protein_ratio,</if>
<if test="fatRatio != null">fat_ratio,</if>
<if test="carbonRatio != null">carbon_ratio,</if>
<if test="remark != null">remark,</if>
<if test="area != null">area,</if>
<if test="notRec != null">not_rec,</if>
<if test="recommend != null">recommend,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
<if test="type != null">#{type},</if>
<if test="recEstimation != null">#{recEstimation},</if>
<if test="recEstUnit != null">#{recEstUnit},</if>
<if test="recPortion != null">#{recPortion},</if>
<if test="proteinRatio != null">#{proteinRatio},</if>
<if test="fatRatio != null">#{fatRatio},</if>
<if test="carbonRatio != null">#{carbonRatio},</if>
<if test="remark != null">#{remark},</if>
<if test="area != null">#{area},</if>
<if test="notRec != null">#{notRec},</if>
<if test="recommend != null">#{recommend},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateSysIngredient" parameterType="SysIngredient">
update sys_ingredient
<trim prefix="SET" suffixOverrides=",">
<if test="name != null">name = #{name},</if>
<if test="type != null">type = #{type},</if>
<if test="recEstimation != null">rec_estimation = #{recEstimation},</if>
<if test="recEstUnit != null">rec_est_unit = #{recEstUnit},</if>
<if test="recPortion != null">rec_portion = #{recPortion},</if>
<if test="proteinRatio != null">protein_ratio = #{proteinRatio},</if>
<if test="fatRatio != null">fat_ratio = #{fatRatio},</if>
<if test="carbonRatio != null">carbon_ratio = #{carbonRatio},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="area != null">area = #{area},</if>
<if test="notRec != null">not_rec = #{notRec},</if>
<if test="recommend != null">recommend = #{recommend},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteSysIngredientById" parameterType="Long">
delete from sys_ingredient where id = #{id}
</delete>
<delete id="deleteSysIngredientByIds" parameterType="String">
delete from sys_ingredient where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -0,0 +1,53 @@
import request from '@/utils/request'
// 查询食材列表
export function listIngredient(query) {
return request({
url: '/custom/ingredient/list',
method: 'get',
params: query
})
}
// 查询食材详细
export function getIngredient(id) {
return request({
url: '/custom/ingredient/' + id,
method: 'get'
})
}
// 新增食材
export function addIngredient(data) {
return request({
url: '/custom/ingredient',
method: 'post',
data: data
})
}
// 修改食材
export function updateIngredient(data) {
return request({
url: '/custom/ingredient',
method: 'put',
data: data
})
}
// 删除食材
export function delIngredient(id) {
return request({
url: '/custom/ingredient/' + id,
method: 'delete'
})
}
// 导出食材
export function exportIngredient(query) {
return request({
url: '/custom/ingredient/export',
method: 'get',
params: query
})
}

View File

@ -1,7 +1,7 @@
<template> <template>
<el-breadcrumb class="app-breadcrumb" separator="/"> <el-breadcrumb class="app-breadcrumb" separator="/">
<transition-group name="breadcrumb"> <transition-group name="breadcrumb">
<el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path"> <el-breadcrumb-item v-for="(item,index) in levelList" :key="item.key">
<span v-if="item.redirect==='noRedirect'||index==levelList.length-1" class="no-redirect">{{ item.meta.title }}</span> <span v-if="item.redirect==='noRedirect'||index==levelList.length-1" class="no-redirect">{{ item.meta.title }}</span>
<a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a> <a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
</el-breadcrumb-item> </el-breadcrumb-item>
@ -40,7 +40,10 @@ export default {
matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched) matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched)
} }
this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false) this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false).map(obj => ({
...obj,
key: Math.floor(Math.random() * 1000)
}))
}, },
isDashboard(route) { isDashboard(route) {
const name = route && route.name const name = route && route.name

View File

@ -0,0 +1,424 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="食材名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入食材名称"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="食材类别" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择食材类别" clearable size="small">
<el-option
v-for="dict in typeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item label="地域" prop="area">
<el-select v-model="queryParams.area" placeholder="请选择地域" clearable size="small">
<el-option
v-for="dict in areaOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="cyan" 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"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['custom:ingredient:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['custom:ingredient:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['custom:ingredient:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['custom:ingredient:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="ingredientList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="id" align="center" prop="id" />
<el-table-column label="食材名称" align="center" prop="name" />
<el-table-column label="食材类别" align="center" prop="type" :formatter="typeFormat" />
<el-table-column label="推荐分量" align="center" prop="recEstimation" />
<el-table-column label="推荐分量单位" align="center" prop="recEstUnit" :formatter="recEstUnitFormat" />
<el-table-column label="推荐分量" align="center" prop="recPortion" />
<el-table-column label="蛋白质比例" align="center" prop="proteinRatio" />
<el-table-column label="脂肪比例" align="center" prop="fatRatio" />
<el-table-column label="碳水比例" align="center" prop="carbonRatio" />
<el-table-column label="地域" align="center" prop="area" :formatter="areaFormat" />
<el-table-column label="忌口人群" align="center" prop="notRec" :formatter="notRecFormat" />
<el-table-column label="推荐人群" align="center" prop="recommend" :formatter="recommendFormat" />
<el-table-column label="备注" align="center" prop="remark" />
<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="['custom:ingredient:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['custom:ingredient:remove']"
>删除</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-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="食材名称" prop="name">
<el-input v-model="form.name" placeholder="请输入食材名称" />
</el-form-item>
<el-form-item label="食材类别" prop="type">
<el-select v-model="form.type" placeholder="请选择食材类别">
<el-option
v-for="dict in typeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="推荐分量" prop="recEstimation">
<el-input v-model="form.recEstimation" placeholder="请输入推荐分量" />
</el-form-item>
<el-form-item label="推荐分量单位" prop="recEstUnit">
<el-select v-model="form.recEstUnit" placeholder="请选择推荐分量单位">
<el-option
v-for="dict in recEstUnitOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="parseInt(dict.dictValue)"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="推荐分量" prop="recPortion">
<el-input v-model="form.recPortion" placeholder="请输入推荐分量" />
</el-form-item>
<el-form-item label="蛋白质比例" prop="proteinRatio">
<el-input v-model="form.proteinRatio" placeholder="请输入蛋白质比例" />
</el-form-item>
<el-form-item label="脂肪比例" prop="fatRatio">
<el-input v-model="form.fatRatio" placeholder="请输入脂肪比例" />
</el-form-item>
<el-form-item label="碳水比例" prop="carbonRatio">
<el-input v-model="form.carbonRatio" placeholder="请输入碳水比例" />
</el-form-item>
<el-form-item label="地域" prop="area">
<el-select v-model="form.area" placeholder="请选择地域">
<el-option
v-for="dict in areaOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="忌口人群">
<el-checkbox-group v-model="form.notRec">
<el-checkbox
v-for="dict in notRecOptions"
:key="dict.dictValue"
:label="dict.dictValue">
{{dict.dictLabel}}
</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item label="推荐人群">
<el-checkbox-group v-model="form.recommend">
<el-checkbox
v-for="dict in recommendOptions"
:key="dict.dictValue"
:label="dict.dictValue">
{{dict.dictLabel}}
</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
</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 { listIngredient, getIngredient, delIngredient, addIngredient, updateIngredient, exportIngredient } from "@/api/custom/ingredient";
export default {
name: "Ingredient",
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
ingredientList: [],
//
title: "",
//
open: false,
//
typeOptions: [],
//
recEstUnitOptions: [],
//
areaOptions: [],
//
notRecOptions: [],
//
recommendOptions: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
type: null,
area: null,
notRec: null,
recommend: null,
},
//
form: {},
//
rules: {
}
};
},
created() {
this.getList();
this.getDicts("cus_ing_type").then(response => {
this.typeOptions = response.data;
});
this.getDicts("cus_cus_unit").then(response => {
this.recEstUnitOptions = response.data;
});
this.getDicts("cus_area").then(response => {
this.areaOptions = response.data;
});
this.getDicts("cus_not_rec_group").then(response => {
this.notRecOptions = response.data;
});
this.getDicts("cus_rec_group").then(response => {
this.recommendOptions = response.data;
});
},
methods: {
/** 查询食材列表 */
getList() {
this.loading = true;
listIngredient(this.queryParams).then(response => {
this.ingredientList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
typeFormat(row, column) {
return this.selectDictLabel(this.typeOptions, row.type);
},
//
recEstUnitFormat(row, column) {
return this.selectDictLabel(this.recEstUnitOptions, row.recEstUnit);
},
//
areaFormat(row, column) {
return this.selectDictLabel(this.areaOptions, row.area);
},
//
notRecFormat(row, column) {
return this.selectDictLabels(this.notRecOptions, row.notRec);
},
//
recommendFormat(row, column) {
return this.selectDictLabels(this.recommendOptions, row.recommend);
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
name: null,
type: null,
recEstimation: null,
recEstUnit: null,
recPortion: null,
proteinRatio: null,
fatRatio: null,
carbonRatio: null,
area: null,
notRec: [],
recommend: [],
remark: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加食材";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getIngredient(id).then(response => {
this.form = response.data;
this.form.notRec = this.form.notRec.split(",");
this.form.recommend = this.form.recommend.split(",");
this.open = true;
this.title = "修改食材";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
this.form.notRec = this.form.notRec.join(",");
this.form.recommend = this.form.recommend.join(",");
if (this.form.id != null) {
updateIngredient(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
}
});
} else {
addIngredient(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
}
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除食材编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delIngredient(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(function() {});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有食材数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return exportIngredient(queryParams);
}).then(response => {
this.download(response.msg);
}).catch(function() {});
}
}
};
</script>

View File

@ -524,6 +524,8 @@
// //
open: false, open: false,
// //
totalAmount: 0,
//
review: 'no', review: 'no',
// //
daterange: [beginTime, endTime], daterange: [beginTime, endTime],