跟换菜品控件

This commit is contained in:
huangdeliang 2021-03-19 17:08:21 +08:00
parent 5f7e4c45db
commit 144e3550aa
4 changed files with 668 additions and 561 deletions

View File

@ -0,0 +1,131 @@
<template>
<div>
<el-form
:model="queryParams"
ref="queryForm"
:inline="true"
label-width="68px"
>
<el-form-item label="名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入食材名称"
clearable
size="mini"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="类别" prop="type">
<el-select
v-model="queryParams.type"
placeholder="请选择食材类别"
clearable
size="mini"
>
<el-option
v-for="dict in typeOptions"
: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-table
v-loading="loading"
border
:data="ingredientList"
:cell-style="{ padding: 0 }"
:header-cell-style="{ padding: 0, height: 'unset' }"
@current-change="handleCurrentChange"
>
<el-table-column label="食材名称" align="center" prop="name" />
<el-table-column
label="食材类别"
align="center"
prop="type"
:formatter="typeFormat"
/>
<el-table-column prop="proteinRatio" label="蛋白质/100g" align="center" />
<el-table-column prop="fatRatio" label="脂肪/100g" align="center" />
<el-table-column prop="carbonRatio" label="碳水/100g" align="center" />
</el-table>
<pagination
v-show="total > 0"
:background="false"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
layout="total, prev, pager, next"
/>
</div>
</template>
<script>
import { listIngredient } from "@/api/custom/ingredient";
export default {
name: "IngredientListView",
data() {
return {
loading: false,
total: 0,
ingredientList: [],
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
type: null,
area: null,
reviewStatus: "yes",
},
};
},
props: ["typeOptions", "visible"],
watch: {},
methods: {
getList() {
this.loading = true;
listIngredient(this.queryParams).then((response) => {
this.ingredientList = response.rows;
this.total = response.total;
this.loading = false;
});
},
reset() {
this.resetForm("queryForm");
},
//
typeFormat(row, column) {
return this.selectDictLabel(this.typeOptions, row.type);
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
handleCurrentChange(data) {
this.$emit("onSelect", data);
},
},
};
</script>

View File

@ -0,0 +1,507 @@
<template>
<el-drawer
:title="title"
:visible.sync="open"
:wrapperClosable="false"
:before-close="handleClose"
size="50%"
:close-on-press-escape="false"
>
<div class="edit_dishes_drawer_wrapper">
<el-row class="content_detail" v-loading="entireLoading">
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-col :span="12">
<el-form-item label="菜品名称" prop="name">
<el-input v-model="form.name" placeholder="请输入菜品名称" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="审核状态" prop="reviewStatus">
<el-select
v-model="form.reviewStatus"
placeholder="请选择审核状态"
clearable
>
<el-option
v-for="dict in reviewStatusOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="菜品种类" prop="dishClass">
<el-cascader
filterable
v-model="form.dishClass"
:options="dishClassOptions"
:props="{ expandTrigger: 'hover' }"
placeholder="请选择菜品种类"
></el-cascader>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="菜品类型" prop="type">
<el-select
v-model="form.type"
placeholder="请选择菜品类型"
multiple
>
<el-option
v-for="dict in typeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="是否主食" prop="isMain">
<el-radio-group v-model="form.isMain">
<el-radio :label="0"></el-radio>
<el-radio :label="1"></el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="待选食材">
<IngredientListView
ref="igdRef"
:typeOptions="ingTypeOptions"
@onSelect="handleOnIgdSelect"
/>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="已选食材" prop="igdList">
<el-table
:data="form.igdList"
border
show-summary
:cell-style="{ padding: 0 }"
:header-cell-style="{ padding: 0, height: 'unset' }"
:summary-method="getSummaries"
>
<el-table-column prop="name" label="食材" align="center" />
<el-table-column label="通俗计量" align="center">
<template slot-scope="scope">
<span class="cus-unit">
<el-select size="mini" v-model="scope.row.cusWeight">
<el-option
v-for="dict in cusWeightOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="parseInt(dict.dictValue)"
/>
</el-select>
<el-select size="mini" v-model="scope.row.cusUnit">
<el-option
v-for="dict in cusUnitOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="parseInt(dict.dictValue)"
/>
</el-select>
</span>
</template>
</el-table-column>
<el-table-column prop="weight" label="重量(g)" align="center">
<template slot-scope="scope">
<el-input-number
class="weight"
v-model="scope.row.weight"
size="mini"
controls-position="right"
:min="0"
:step="5"
/>
</template>
</el-table-column>
<el-table-column
prop="proteinRatio"
label="蛋白质/100g"
align="center"
/>
<el-table-column
prop="fatRatio"
label="脂肪/100g"
align="center"
/>
<el-table-column
prop="carbonRatio"
label="碳水/100g"
align="center"
/>
<el-table-column label="热量(kcal)" align="center">
<template slot-scope="scope">
{{
`${(
((scope.row.proteinRatio * scope.row.weight) / 100) *
4 +
((scope.row.fatRatio * scope.row.weight) / 100) * 9 +
((scope.row.carbonRatio * scope.row.weight) / 100) * 4
).toFixed(1)}`
}}
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template slot-scope="scope">
<el-button type="text" @click="handleOnDelete(scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="推荐人群" v-if="!!selRec.length">
<el-tag
style="margin-right: 4px"
v-for="rec in selRec"
:key="rec"
type="success"
>
{{ rec }}
</el-tag>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="忌口人群" v-if="!!selNotRec.length">
<el-tag
style="margin-right: 4px"
v-for="notRec in selNotRec"
:key="notRec"
type="danger"
>
{{ notRec }}
</el-tag>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="做法" prop="methods">
<el-input
v-model="form.methods"
type="textarea"
placeholder="请输入内容"
rows="4"
/>
</el-form-item>
</el-col>
</el-form>
</el-row>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</div>
</el-drawer>
</template>
<script>
import { addDishes, updateDishes, getDishes } from "@/api/custom/dishes";
import IngredientListView from "./IngredientListView";
export default {
name: "EditDishesDrawer",
components: {
IngredientListView,
},
created() {
this.getDicts("cus_ing_type").then((response) => {
this.ingTypeOptions = response.data;
});
this.getDicts("cus_cus_unit").then((response) => {
this.cusUnitOptions = response.data;
});
this.getDicts("cus_cus_weight").then((response) => {
this.cusWeightOptions = response.data;
});
},
data() {
return {
//
title: "",
//
open: false,
//
cusUnitOptions: [],
//
cusWeightOptions: [],
//
ingTypeOptions: [],
//
form: {},
//
rules: {
name: [
{ required: true, message: "菜品名称不能为空", trigger: "blur" },
],
type: [
{ required: true, message: "菜品类型不能为空", trigger: "blur" },
],
igdList: [{ required: true, message: "食材不能为空", trigger: "blur" }],
},
//
entireLoading: false,
//
//
selRec: [],
selNotRec: [],
};
},
props: [
"typeOptions",
"reviewStatusOptions",
"dishClassBigOptions",
"dishClassOptions",
"dishClassSmallOptions",
],
watch: {
"form.igdList": function (val) {
const selRec = [];
const selNotRec = [];
val.forEach((obj) => {
if (obj.rec) {
obj.rec.split(",").forEach((rec) => {
if (!selRec.includes(rec)) {
selRec.push(rec);
}
});
}
if (obj.notRec) {
obj.notRec.split(",").forEach((notRec) => {
if (!selNotRec.includes(notRec)) {
selNotRec.push(notRec);
}
});
}
});
this.selRec = selRec;
this.selNotRec = selNotRec;
},
showNotRec() {
return !!this.selNotRec.length;
},
},
methods: {
showDrawer(id) {
this.open = true;
this.title = id ? "修改菜品" : "新建菜品";
this.reset();
if (id) {
this.fetchDishesDetail(id);
}
this.$nextTick(() => {
this.$refs.igdRef.getList();
});
},
fetchDishesDetail(id) {
getDishes(id).then((response) => {
this.form = response.data;
this.form.dishClass = [this.form.bigClass, this.form.smallClass];
this.form.type = this.form.type ? this.form.type.split(",") : [];
});
},
handleOnIgdSelect(data) {
if (this.form.igdList.some((obj) => obj.id === data.id)) {
this.$message.error(`已存在食材${data.name}`);
return;
}
this.form.igdList.push({
...data,
weight: 100,
cusUnit: 1,
cusWeight: 1,
});
},
handleOnDelete(data) {
this.form.igdList = this.form.igdList.filter((obj) => obj.id !== data.id);
},
cusUnitFormat(row, column) {
return this.selectDictLabel(this.cusUnitOptions, row.type);
},
cusWeightFormat(row, column) {
return this.selectDictLabel(this.cusWeightOptions, row.cusWeight);
},
//
cancel() {
this.open = false;
},
//
reset() {
this.form = {
id: null,
name: null,
type: [],
dishClass: [],
methods: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
igdList: [],
isMain: 1,
};
this.selRec = [];
this.selNotRec = [];
this.resetForm("form");
this.$nextTick(() => {
this.$refs.igdRef.reset();
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate((valid) => {
if (valid) {
const data = JSON.parse(JSON.stringify(this.form));
// console.log({ data });
data.type = data.type.join(",");
if (data.id != null) {
updateDishes(data).then((response) => {
if (response.code === 200) {
this.msgSuccess("修改成功");
this.open = false;
this.$emit("onSuccess");
}
});
} else {
addDishes(data).then((response) => {
if (response.code === 200) {
this.msgSuccess("新增成功");
this.open = false;
this.$emit("onSuccess");
}
});
}
}
});
},
getSummaries(param) {
const { columns, data } = param;
// console.log(data);
return columns.reduce(
(arr, cur, idx) => {
if (idx > 1 && idx !== 7) {
if (idx === 6) {
arr[6] = (arr[3] * 4 + arr[4] * 9 + arr[5] * 4).toFixed(1);
} else {
arr[idx] = data.reduce((acc, dAcc) => {
if (idx === 2) {
return acc + parseFloat(dAcc.weight);
}
return parseFloat(
(
acc +
(dAcc[cur.property] * parseFloat(dAcc.weight)) / 100
).toFixed(1)
);
}, 0);
}
}
return arr;
},
["合计"]
);
},
handleClose(done) {
this.reset();
done();
},
},
};
</script>
<style lang="scss" scoped>
.edit_dishes_drawer_wrapper {
height: 100%;
display: flex;
flex-direction: column;
.content_detail {
flex: 1 1 0;
padding: 12px;
overflow: auto;
}
.dialog-footer {
flex: 0 0 45px;
display: inline-flex;
align-items: center;
justify-content: flex-end;
padding: 0 12px;
}
}
</style>
<style lang="scss">
#el-drawer__title {
& > span:focus {
outline: 0;
}
}
.el-transfer-panel__filter {
margin: 2px;
}
.el-transfer-panel__list.is-filterable {
padding-bottom: 28px;
}
.cus-unit {
display: inline-flex;
.el-input-number--mini {
width: 38px;
}
.el-input-number {
.el-input-number__decrease {
display: none;
}
.el-input-number__increase {
display: none;
}
.el-input {
width: 38px;
}
.el-input .el-input__inner {
padding: 0;
border-radius: 0;
border: unset;
border-bottom: 1px solid #dcdfe6;
}
}
.el-select {
.el-input__suffix {
display: none;
}
.el-input__inner {
padding: 0 4px;
/* border: unset; */
text-align: center;
}
}
}
.weight {
width: 70px;
.el-input .el-input__inner {
padding: 0 32px 0 4px;
}
}
.pagination-container {
margin-top: 0;
}
</style>

View File

@ -97,11 +97,7 @@
@queryTable="getList" @queryTable="getList"
></right-toolbar> ></right-toolbar>
</el-row> </el-row>
<el-table <el-table v-loading="loading" :data="dishesList">
v-loading="loading"
:data="dishesList"
@selection-change="handleSelectionChange"
>
<el-table-column label="审核状态" align="center" width="80"> <el-table-column label="审核状态" align="center" width="80">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag <el-tag
@ -177,247 +173,28 @@
/> />
<!-- 添加或修改菜品对话框 --> <!-- 添加或修改菜品对话框 -->
<el-drawer <EditDishesDrawer
:title="title" ref="dishesDrawerRef"
:visible.sync="open" :typeOptions="typeOptions"
:wrapperClosable="false" :reviewStatusOptions="reviewStatusOptions"
size="50%" :dishClassBigOptions="dishClassBigOptions"
:close-on-press-escape="false" :dishClassSmallOptions="dishClassSmallOptions"
> :dishClassOptions="dishClassOptions"
<div class="drawer_content"> @onSuccess="getList"
<el-row class="content_detail"> />
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-col :span="24">
<el-form-item label="菜品名称" prop="name">
<el-input v-model="form.name" placeholder="请输入菜品名称" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="菜品种类" prop="dishClass">
<el-cascader
filterable
v-model="form.dishClass"
:options="dishClassOptions"
:props="{ expandTrigger: 'hover' }"
placeholder="请选择菜品种类"
></el-cascader>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="菜品类型" prop="type">
<el-select
v-model="form.type"
placeholder="请选择菜品类型"
multiple
>
<el-option
v-for="dict in typeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="是否主食" prop="isMain">
<el-radio-group v-model="form.isMain">
<el-radio :label="0"></el-radio>
<el-radio :label="1"></el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="食材" prop="ingIds">
<el-transfer
style="text-align: left; display: inline-block"
v-model="selIngIds"
size="mini"
filterable
:titles="['备选', '已选']"
:button-texts="['', '']"
:format="{
noChecked: '${total}',
hasChecked: '${checked}/${total}',
}"
@change="handleChange"
:data="ingDataList"
>
<el-select
class="transfer-footer"
slot="left-footer"
size="small"
filterable
v-model="ingType"
@change="handleOnTypeChange"
>
<el-option
v-for="dict in ingTypeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
<div
class="transfer-footer"
slot="right-footer"
size="small"
/>
</el-transfer>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="分量" prop="weight">
<el-table
:data="selTableData"
border
show-summary
size="mini"
:summary-method="getSummaries"
style="width: 100%"
>
<el-table-column prop="name" label="食材" align="center" />
<el-table-column label="通俗计量" align="center">
<template slot-scope="scope">
<span class="cus-unit">
<el-select size="mini" v-model="scope.row.cusWeight">
<el-option
v-for="dict in cusWeightOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="parseInt(dict.dictValue)"
/>
</el-select>
<el-select size="mini" v-model="scope.row.cusUnit">
<el-option
v-for="dict in cusUnitOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="parseInt(dict.dictValue)"
/>
</el-select>
</span>
</template>
</el-table-column>
<el-table-column prop="weight" label="重量(g)" align="center">
<template slot-scope="scope">
<el-input-number
class="weight"
v-model="scope.row.weight"
size="mini"
controls-position="right"
:min="0"
:step="5"
/>
</template>
</el-table-column>
<el-table-column
prop="proteinRatio"
label="蛋白质/100g"
align="center"
/>
<el-table-column
prop="fatRatio"
label="脂肪/100g"
align="center"
/>
<el-table-column
prop="carbonRatio"
label="碳水/100g"
align="center"
/>
<el-table-column label="热量" align="center">
<template slot-scope="scope">
{{
`${(
((scope.row.proteinRatio * scope.row.weight) / 100) *
4 +
((scope.row.fatRatio * scope.row.weight) / 100) * 9 +
((scope.row.carbonRatio * scope.row.weight) / 100) * 4
).toFixed(1)} kcal`
}}
</template>
</el-table-column>
</el-table>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="推荐人群">
<el-tag
style="margin-right: 4px"
v-for="rec in selRec"
:key="rec"
type="success"
>
{{ rec }}
</el-tag>
</el-form-item>
</el-col>
<el-col :span="24">
<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-col>
<el-col :span="24">
<el-form-item label="审核状态" prop="reviewStatus">
<el-select
v-model="form.reviewStatus"
placeholder="请选择审核状态"
clearable
>
<el-option
v-for="dict in reviewStatusOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="做法" prop="methods">
<el-input
v-model="form.methods"
type="textarea"
placeholder="请输入内容"
rows="4"
/>
</el-form-item>
</el-col>
</el-form>
</el-row>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</div>
</el-drawer>
</div> </div>
</template> </template>
<script> <script>
import { import { delDishes, exportDishes, listDishes } from "@/api/custom/dishes";
addDishes,
delDishes,
exportDishes,
getDishes,
listDishes,
updateDishes,
} from "@/api/custom/dishes";
import { listAllIngredient } from "@/api/custom/ingredient";
import AutoHideInfo from "@/components/AutoHideInfo"; import AutoHideInfo from "@/components/AutoHideInfo";
import EditDishesDrawer from "./EditDishesDrawer";
export default { export default {
name: "Dishes", name: "Dishes",
components: { components: {
autohideinfo: AutoHideInfo, autohideinfo: AutoHideInfo,
EditDishesDrawer,
}, },
data() { data() {
return { return {
@ -425,10 +202,6 @@ export default {
loading: true, loading: true,
// //
ids: [], ids: [],
//
single: true,
//
multiple: true,
// //
showSearch: true, showSearch: true,
// //
@ -437,13 +210,7 @@ export default {
dishesList: [], dishesList: [],
// //
reviewStatusOptions: [], reviewStatusOptions: [],
//
title: "",
//
open: false,
ingType: "1",
//
ingTypeOptions: [],
// //
oriDataList: [], oriDataList: [],
// //
@ -456,14 +223,10 @@ export default {
selNotRec: [], selNotRec: [],
// id // id
selIngIds: [], selIngIds: [],
//
selTableData: [],
// //
typeOptions: [], typeOptions: [],
//
cusUnitOptions: [],
//
cusWeightOptions: [],
dishClassOptions: [], dishClassOptions: [],
dishClassBigOptions: [], dishClassBigOptions: [],
dishClassSmallOptions: [], dishClassSmallOptions: [],
@ -476,10 +239,6 @@ export default {
bigClass: null, bigClass: null,
smallClass: null, smallClass: null,
}, },
//
form: {},
//
rules: {},
// //
dishClassQueryParam: [], dishClassQueryParam: [],
}; };
@ -489,15 +248,7 @@ export default {
this.getDicts("cus_dishes_type").then((response) => { this.getDicts("cus_dishes_type").then((response) => {
this.typeOptions = response.data; this.typeOptions = response.data;
}); });
this.getDicts("cus_ing_type").then((response) => {
this.ingTypeOptions = response.data;
});
this.getDicts("cus_cus_unit").then((response) => {
this.cusUnitOptions = response.data;
});
this.getDicts("cus_cus_weight").then((response) => {
this.cusWeightOptions = response.data;
});
this.getDicts("cus_review_status").then((response) => { this.getDicts("cus_review_status").then((response) => {
this.reviewStatusOptions = response.data; this.reviewStatusOptions = response.data;
}); });
@ -582,12 +333,7 @@ export default {
.split(",") .split(",")
.map((type) => this.selectDictLabel(this.typeOptions, type)); .map((type) => this.selectDictLabel(this.typeOptions, type));
}, },
cusUnitFormat(row, column) {
return this.selectDictLabel(this.cusUnitOptions, row.type);
},
cusWeightFormat(row, column) {
return this.selectDictLabel(this.cusWeightOptions, row.cusWeight);
},
// //
reviewStatusFormat(row, column) { reviewStatusFormat(row, column) {
return this.selectDictLabel(this.reviewStatusOptions, row.area); return this.selectDictLabel(this.reviewStatusOptions, row.area);
@ -607,35 +353,6 @@ export default {
} }
return ""; return "";
}, },
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
name: null,
type: [],
dishClass: [],
methods: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
igdList: [],
isMain: 1,
};
this.selIngIds = [];
this.selIngList = [];
this.selTableData = [];
this.oriDataList = [];
this.selRec = [];
this.selNotRec = [];
this.ingType = "1";
this.resetForm("form");
},
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {
this.queryParams.pageNum = 1; this.queryParams.pageNum = 1;
@ -647,101 +364,13 @@ export default {
this.dishClassQueryParam = []; this.dishClassQueryParam = [];
this.handleQuery(); this.handleQuery();
}, },
//
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.id);
this.single = selection.length !== 1;
this.multiple = !selection.length;
},
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.reset(); this.$refs.dishesDrawerRef.showDrawer();
listAllIngredient({ type: this.ingType }).then((response) => {
this.open = true;
this.title = "添加菜品";
this.oriDataList = response.rows;
this.ingDataList = this.oriDataList.map((obj) => ({
key: obj.id,
label: obj.name,
}));
});
}, },
/** 修改按钮操作 */ /** 修改按钮操作 */
handleUpdate(row) { handleUpdate(row) {
this.reset(); this.$refs.dishesDrawerRef.showDrawer(row.id);
const id = row.id || this.ids;
getDishes(id).then((response) => {
this.form = response.data;
this.form.dishClass = [this.form.bigClass, this.form.smallClass];
this.form.type = this.form.type ? this.form.type.split(",") : null;
this.form.igdList.forEach((obj) => {
this.selIngIds.push(obj.id);
this.selIngList.push({
key: obj.id,
label: obj.name,
});
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) => {
this.open = true;
this.title = "修改菜品";
this.oriDataList = res.rows.concat(this.form.igdList);
this.ingDataList = this.oriDataList.reduce((arr, cur) => {
if (!arr.some(({ key }) => key === cur.id)) {
arr.push({
key: cur.id,
label: cur.name,
});
}
return arr;
}, []);
});
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate((valid) => {
if (valid) {
if (!this.selTableData.length) {
this.$message.error("食材不能为空");
return;
}
const data = JSON.parse(JSON.stringify(this.form));
data.igdList = this.selTableData;
data.type = data.type.join(",");
if (data.id != null) {
updateDishes(data).then((response) => {
if (response.code === 200) {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
}
});
} else {
addDishes(data).then((response) => {
if (response.code === 200) {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
}
});
}
}
});
}, },
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
@ -776,178 +405,8 @@ export default {
}) })
.catch(function () {}); .catch(function () {});
}, },
handleChange(value, direction, movedKeys) {
// console.log({
// oriIgdList: this.oriDataList,
// selIgdList: this.form.igdList,
// ingDataList: this.ingDataList,
// value,
// ingType: this.ingType,
// });
const newTableData = [];
this.selRec = [];
this.selNotRec = [];
this.selIngList = value.map((id) => {
// table
let tmpTableObj = this.selTableData.find((obj) => obj.id === id);
if (tmpTableObj) {
newTableData.push(tmpTableObj);
} else {
//
tmpTableObj = this.oriDataList.find((obj) => obj.id === id);
if (tmpTableObj) {
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);
return tarObj;
});
this.selTableData = newTableData;
},
handleOnTypeChange(value) {
listAllIngredient({ type: value }).then((res) => {
this.oriDataList = res.rows.concat(this.form.igdList);
this.ingDataList = this.oriDataList.reduce((arr, cur) => {
if (!arr.some(({ key }) => key === cur.id)) {
arr.push({
key: cur.id,
label: cur.name,
});
}
return arr;
}, []);
});
},
getSummaries(param) {
const { columns, data } = param;
// console.log(data);
return columns.reduce(
(arr, cur, idx) => {
if (idx > 1) {
if (idx === 6) {
arr[6] = arr[3] * 4 + arr[4] * 9 + arr[5] * 4 + " kcal";
} else {
arr[idx] = data.reduce((acc, dAcc) => {
if (idx === 2) {
return acc + parseFloat(dAcc.weight);
}
return parseFloat(
(
acc +
(dAcc[cur.property] * parseFloat(dAcc.weight)) / 100
).toFixed(1)
);
}, 0);
}
}
return arr;
},
["合计"]
);
},
}, },
}; };
</script> </script>
<style rel="stylesheet/scss" lang="scss"> <style rel="stylesheet/scss" lang="scss">
#el-drawer__title {
& > span:focus {
outline: 0;
}
}
.el-transfer-panel__filter {
margin: 2px;
}
.el-transfer-panel__list.is-filterable {
padding-bottom: 28px;
}
.cus-unit {
display: inline-flex;
.el-input-number--mini {
width: 38px;
}
.el-input-number {
.el-input-number__decrease {
display: none;
}
.el-input-number__increase {
display: none;
}
.el-input {
width: 38px;
}
.el-input .el-input__inner {
padding: 0;
border-radius: 0;
border: unset;
border-bottom: 1px solid #dcdfe6;
}
}
.el-select {
.el-input__suffix {
display: none;
}
.el-input__inner {
padding: 0 4px;
/* border: unset; */
text-align: center;
}
}
}
.weight {
width: 70px;
.el-input .el-input__inner {
padding: 0 32px 0 4px;
}
}
.drawer_content {
height: 100%;
display: flex;
flex-direction: column;
.content_detail {
flex: 1 1 0;
padding: 12px;
overflow: auto;
}
.dialog-footer {
flex: 0 0 45px;
display: inline-flex;
align-items: center;
justify-content: flex-end;
padding: 0 12px;
}
}
</style> </style>

View File

@ -146,6 +146,16 @@
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="图片" align="center" width="100">
<template slot-scope="scope">
<img
width="100"
height="auto"
:src="scope.row.imgList[0] ? scope.row.imgList[0].previewUrl : ''"
:alt="scope.row.imgList[0] ? scope.row.imgList[0].name : ''"
/>
</template>
</el-table-column>
<el-table-column <el-table-column
label="食材名称" label="食材名称"
align="center" align="center"