完善菜品功能

This commit is contained in:
huangdeliang 2021-01-04 09:32:37 +08:00
parent d77e7505be
commit 39e5183366

View File

@ -11,7 +11,7 @@
/> />
</el-form-item> </el-form-item>
<el-form-item label="菜品类型" prop="type"> <el-form-item label="菜品类型" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择菜品类型" clearable size="small"> <el-select v-model="queryParams.type" multiple placeholder="请选择菜品类型" clearable size="small">
<el-option <el-option
v-for="dict in typeOptions" v-for="dict in typeOptions"
:key="dict.dictValue" :key="dict.dictValue"
@ -55,6 +55,30 @@
<!-- <el-table-column label="id" align="center" prop="id" />--> <!-- <el-table-column label="id" align="center" prop="id" />-->
<el-table-column label="菜品名称" align="center" prop="name"/> <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="type" :formatter="typeFormat"/>
<el-table-column label="包含食材" align="center">
<template slot-scope="scope">
<div v-for="igd in scope.row.igdList"
:key="igd.id">
{{igd.name}}
</div>
</template>
</el-table-column>
<el-table-column label="推荐人群" align="center">
<template slot-scope="scope">
<div v-for="tag in scope.row.recTags"
:key="tag">
{{tag}}
</div>
</template>
</el-table-column>
<el-table-column label="忌口人群" align="center">
<template slot-scope="scope">
<div v-for="tag in scope.row.notRecTags"
:key="tag">
{{tag}}
</div>
</template>
</el-table-column>
<el-table-column label="做法" align="center" prop="methods"/> <el-table-column label="做法" align="center" prop="methods"/>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
@ -87,71 +111,71 @@
/> />
<!-- 添加或修改菜品对话框 --> <!-- 添加或修改菜品对话框 -->
<el-dialog :title="title" :visible.sync="open" width="720px" append-to-body> <el-drawer :title="title" :visible.sync="open" size="50%">
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <div class="drawer_content">
<el-form-item label="菜品名称" prop="name"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-input v-model="form.name" placeholder="请输入菜品名称"/> <el-form-item label="菜品名称" prop="name">
</el-form-item> <el-input v-model="form.name" placeholder="请输入菜品名称"/>
<el-form-item label="菜品类型" prop="type"> </el-form-item>
<el-select v-model="form.type" placeholder="请选择菜品类型"> <el-form-item label="菜品类型" prop="type">
<el-option <el-select v-model="form.type" placeholder="请选择菜品类型">
v-for="dict in typeOptions" <el-option
:key="dict.dictValue" v-for="dict in typeOptions"
:label="dict.dictLabel" :key="dict.dictValue"
:value="dict.dictValue" :label="dict.dictLabel"
></el-option> :value="dict.dictValue"
</el-select> ></el-option>
</el-form-item> </el-select>
<el-form-item label="食材" prop="ingIds"> </el-form-item>
<el-transfer <el-form-item label="食材" prop="ingIds">
style="text-align: left; display: inline-block" <el-transfer
v-model="selIngIds" style="text-align: left; display: inline-block"
size="mini" v-model="selIngIds"
filterable size="mini"
:titles="['备选', '已选']" filterable
:button-texts="['', '']" :titles="['备选', '已选']"
:format="{ :button-texts="['', '']"
:format="{
noChecked: '${total}', noChecked: '${total}',
hasChecked: '${checked}/${total}', hasChecked: '${checked}/${total}',
}" }"
@change="handleChange" @change="handleChange"
:data="ingDataList" :data="ingDataList"
> >
<el-select <el-select
class="transfer-footer" class="transfer-footer"
slot="left-footer" slot="left-footer"
size="small" size="small"
filterable filterable
v-model="ingType" v-model="ingType"
@change="handleOnTypeChange"> @change="handleOnTypeChange">
<el-option <el-option
v-for="dict in ingTypeOptions" v-for="dict in ingTypeOptions"
:key="dict.dictValue" :key="dict.dictValue"
:label="dict.dictLabel" :label="dict.dictLabel"
:value="dict.dictValue"/> :value="dict.dictValue"/>
</el-select> </el-select>
<div class="transfer-footer" slot="right-footer" size="small"/> <div class="transfer-footer" slot="right-footer" size="small"/>
</el-transfer> </el-transfer>
</el-form-item> </el-form-item>
<el-form-item label="分量" prop="weight"> <el-form-item label="分量" prop="weight">
<el-table <el-table
:data="selTableData" :data="selTableData"
border border
show-summary show-summary
size="mini" size="mini"
:summary-method="getSummaries" :summary-method="getSummaries"
style="width: 100%"> style="width: 100%">
<el-table-column <el-table-column
prop="name" prop="name"
label="食材"> label="食材">
</el-table-column> </el-table-column>
<el-table-column label="通俗计量"> <el-table-column label="通俗计量">
<template slot-scope="scope"> <template slot-scope="scope">
<span class="cus-unit"> <span class="cus-unit">
<el-input-number <el-input-number
v-model="scope.row.cusWeight" v-model="scope.row.cusWeight"
size="small" size="small"
type="number"
controls-position="right" controls-position="right"
step="0.5" step="0.5"
:min="0.5"/> :min="0.5"/>
@ -167,46 +191,64 @@
/> />
</el-select> </el-select>
</span> </span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="weight" prop="weight"
label="重量(g)"> label="重量(g)">
<template slot-scope="scope"> <template slot-scope="scope">
<el-input-number <el-input-number
class="weight" class="weight"
v-model="scope.row.weight" v-model="scope.row.weight"
size="mini" size="mini"
controls-position="right" controls-position="right"
@change="handleInputChange" @change="handleInputChange"
type="number"
:min="0" :min="0"
step="50"/> step="50"/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="proteinRatio" prop="proteinRatio"
label="P/100g"> label="P/100g">
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="fatRatio" prop="fatRatio"
label="F/100g"> label="F/100g">
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="carbonRatio" prop="carbonRatio"
label="C/100g"> label="C/100g">
</el-table-column> </el-table-column>
</el-table> </el-table>
</el-form-item> </el-form-item>
<el-form-item label="做法" prop="methods"> <el-form-item label="推荐人群">
<el-input v-model="form.methods" type="textarea" placeholder="请输入内容"/> <el-tag
</el-form-item> style="margin-right: 4px"
</el-form> v-for="rec in selRec"
<div slot="footer" class="dialog-footer"> :key="rec"
<el-button type="primary" @click="submitForm"> </el-button> type="success">
<el-button @click="cancel"> </el-button> {{rec}}
</el-tag>
</el-form-item>
<el-form-item label="忌口人群">
<el-tag
style="margin-right: 4px"
v-for="notRec in selNotRec"
:key="notRec"
type="danger">
{{notRec}}
</el-tag>
</el-form-item>
<el-form-item label="做法" prop="methods">
<el-input v-model="form.methods" type="textarea" placeholder="请输入内容" rows="4"/>
</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>
</div> </div>
</el-dialog> </el-drawer>
</div> </div>
</template> </template>
@ -245,6 +287,10 @@
ingDataList: [], ingDataList: [],
// //
selIngList: [], selIngList: [],
//
selRec: [],
//
selNotRec: [],
// id // id
selIngIds: [], selIngIds: [],
// //
@ -283,7 +329,31 @@
getList() { getList() {
this.loading = true; this.loading = true;
listDishes(this.queryParams).then(response => { listDishes(this.queryParams).then(response => {
this.dishesList = response.rows; this.dishesList = response.rows.map(d => {
const recTags = [], notRecTags = [];
d.igdList.forEach(igd => {
if (igd.rec) {
igd.rec.split(',').forEach(rec => {
if (!recTags.includes(rec)) {
recTags.push(rec)
}
})
}
if (igd.notRec) {
igd.notRec.split(',').forEach(notRec => {
if (!notRecTags.includes(notRec)) {
notRecTags.push(notRec)
}
})
}
})
return {
...d,
recTags,
notRecTags
}
});
console.log(this.dishesList)
this.total = response.total; this.total = response.total;
this.loading = false; this.loading = false;
}); });
@ -317,6 +387,8 @@
this.selIngList = []; this.selIngList = [];
this.selTableData = []; this.selTableData = [];
this.oriDataList = []; this.oriDataList = [];
this.selRec = [];
this.selNotRec = [];
this.ingType = '1'; this.ingType = '1';
this.resetForm("form"); this.resetForm("form");
}, },
@ -362,6 +434,20 @@
label: obj.name label: obj.name
}); });
this.selTableData.push(obj) this.selTableData.push(obj)
if (obj.rec) {
obj.rec.split(',').forEach(rec => {
if (!this.selRec.includes(rec)) {
this.selRec.push(rec)
}
})
}
if (obj.notRec) {
obj.notRec.split(',').forEach(notRec => {
if (!this.selNotRec.includes(notRec)) {
this.selNotRec.push(notRec)
}
})
}
}) })
listAllIngredient({type: this.ingType}).then(res => { listAllIngredient({type: this.ingType}).then(res => {
this.open = true; this.open = true;
@ -436,6 +522,8 @@
handleChange(value, direction, movedKeys) { handleChange(value, direction, movedKeys) {
// console.log({oriIgdList: this.oriDataList, selIgdList: this.form.igdList}); // console.log({oriIgdList: this.oriDataList, selIgdList: this.form.igdList});
const newTableData = []; const newTableData = [];
this.selRec = [];
this.selNotRec = [];
this.selIngList = value.map(id => { this.selIngList = value.map(id => {
// table // table
let tmpTableObj = this.selTableData.find(obj => obj.id === id); let tmpTableObj = this.selTableData.find(obj => obj.id === id);
@ -448,6 +536,22 @@
newTableData.push({...tmpTableObj, weight: 100, cusWeight: 1, cusUnit: 1}) newTableData.push({...tmpTableObj, weight: 100, cusWeight: 1, cusUnit: 1})
} }
} }
if (tmpTableObj) {
if (tmpTableObj.rec) {
tmpTableObj.rec.split(',').forEach(rec => {
if (!this.selRec.includes(rec)) {
this.selRec.push(rec)
}
})
}
if (tmpTableObj.notRec) {
tmpTableObj.notRec.split(',').forEach(notRec => {
if (!this.selNotRec.includes(notRec)) {
this.selNotRec.push(notRec)
}
})
}
}
const tarObj = this.ingDataList.find(({key}) => key === id); const tarObj = this.ingDataList.find(({key}) => key === id);
return tarObj return tarObj
}); });
@ -536,4 +640,25 @@
.weight .el-input .el-input__inner { .weight .el-input .el-input__inner {
padding: 0 32px 0 4px; padding: 0 32px 0 4px;
} }
.drawer_content {
height: 100%;
display: flex;
flex-direction: column;
}
.drawer_content .el-form {
/*height: calc(100% - 45px);*/
flex: 1 1 0;
padding: 12px;
overflow: auto;
}
.drawer_content > div {
flex: 0 0 45px;
display: inline-flex;
align-items: center;
justify-content: flex-end;
padding: 0 12px;
}
</style> </style>