123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <template>
- <div class="main-data data-weeks-foods">
- <div class="title-area">周菜谱</div>
- <!-- 选择日期 -->
- <div class="choose-area choose-week">
- <el-select v-model="week" placeholder="请选择" @change="changeWeek">
- <el-option
- v-for="item in weeks"
- :key="item"
- :label="item"
- :value="item"
- >
- </el-option>
- </el-select>
- </div>
- <!-- 选择早中晚 -->
- <div class="choose-area">
- <el-select v-model="food" placeholder="请选择" @change="changeFoods">
- <el-option
- v-for="item in foods"
- :key="item"
- :label="item"
- :value="item"
- >
- </el-option>
- </el-select>
- </div>
- <div class="close-btn" @click="close"></div>
- <div class="content-area">
- <div class="content">
- <div class="data-list">
- <div v-for="(item, index) in list" :key="index" class="data-item">
- <img :src="item.img" @error="errorImg(item)" />
- <span class="name">{{ item.name }}</span>
- </div>
- <div v-if="list.length == 0" class="no-data">暂无数据</div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import { getFoodsList } from "@/api/screen/service";
- import pinyin from "../data/pinyin.js";
- export default {
- name: "WeekFoods",
- props: {
- week: {
- type: String,
- default: "",
- },
- appOrg: {
- type: String,
- default: "10001",
- },
- },
- data() {
- return {
- dataList: [],
- weeks: ["周一", "周二", "周三", "周四", "周五"],
- list: [],
- foodsList: [],
- food: "早餐",
- foods: ["早餐", "中餐", "晚餐"],
- lists: [],
- appOrgs:['10001','1D001','1K003','1J001','1E001','1J003','1K002','1J002','1K001','1A001']
- };
- },
- created() {
- this.getFoodsList();
- },
-
- destroyed() {},
- beforeDestroy() {},
- mounted() {},
- methods: {
- //获取数据概况
- getFoodsList() {
- let appOrg = this.$props.appOrg == '0000' ? '10001' : this.$props.appOrg;
- if(this.appOrgs.indexOf(appOrg) == -1){
- appOrg = "1J001";
- }
- getFoodsList(appOrg).then((res) => {
- if (Number(res.code) === 200) {
- let foodsList = JSON.parse(res.data.foodInfo);
- // 转换后的数据
- const transformedData = {};
- // 映射关系
- const dayMap = {"monday": "1","tuesday": "2","wednesday": "3","thursday": "4","friday": "5"};
- const mealTypeMap = {"breakfast": "1", "lunch": "2", "dinner": "3"};
- // 遍历原始数据并转换
- for (const day in foodsList) {
- if (foodsList.hasOwnProperty(day)) {
- const dayNumber = dayMap[day];
- transformedData[dayNumber] = [];
- for (const mealTypeKey in foodsList[day]) {
- if (foodsList[day].hasOwnProperty(mealTypeKey)) {
- const mealTypeNumber = mealTypeMap[mealTypeKey];
- foodsList[day][mealTypeKey].forEach(meal => {
- if (meal.name) {
- const newDishes = [
- {"name": meal.name, "type": mealTypeNumber},
- ];
- transformedData[dayNumber] = transformedData[dayNumber].concat(newDishes);
- }
- });
- }
- }
- }
- }
- this.foodsList = JSON.parse(JSON.stringify(transformedData));
- let index = parseInt(this.weeks.indexOf(this.$props.week)) + 1;
- let lists = JSON.parse(JSON.stringify(transformedData[index]));
- this.lists = lists;
- let list = [];
- let type = parseInt(this.foods.indexOf(this.food)) + 1;
- let that = this;
- lists.forEach((item) => {
- if (item.type == type && item.name) { // 再次检查'name'字段是否为空
- //处理图片
- // item.img = require('../../../assets/caidanImgs/'+ pinyin.chineseToPinYin(item.name) +'.jpg');
- that.loadImage(item);
- list.push(item);
- }
- });
- this.list = list;
- }
- });
- },
- //选择周几
- changeWeek(e) {
- let index = parseInt(this.weeks.indexOf(e)) + 1;
- let lists = this.foodsList[index];
- this.lists = lists;
- //联动选择早中晚
- this.food = '早餐';
- this.changeFoods('早餐');
- },
- //选择菜品
- changeFoods(e) {
- let type = parseInt(this.foods.indexOf(e)) + 1;
- let lists = this.lists;
- let list = [];
- let that = this;
- lists.forEach((item) => {
- if (item.type == type) {
- //处理图片
- that.loadImage(item);
- list.push(item);
- }
- });
- this.list = list;
- // console.log(list,'菜品');
- },
- //默认显示暂无菜品
- errorImg(item) {
- item.img = require("@/assets/caidanImgs/no-data.jpg");
- },
- loadImage(item) {
- try {
- // 尝试加载图片
- item.img = require("@/assets/caidanImgs/" +
- pinyin.chineseToPinYin(item.name) +
- ".jpg");
- } catch (e) {
- // 处理图片不存在的情况
- item.img = require("@/assets/caidanImgs/no-data.jpg"); // 使用默认图片
- }
- },
- //选择周日
- choose() {
- this.$emit("chooseFoods", this.week);
- },
- close() {
- this.$emit("closeFoods");
- },
- },
- };
- </script>
- <style lang="scss">
- .el-scrollbar {
- background: #15696b;
- border: 1px solid #00ffff;
- ul {
- li {
- color: #fff;
- }
- }
- }
- .el-select-dropdown__item.hover,
- .el-select-dropdown__item:hover {
- background: #15696b;
- color: #00ffff;
- }
- .el-select-dropdown__item.selected {
- color: #00ffff;
- }
- .el-select .el-input .el-select__caret {
- display: none;
- }
- .data-weeks-foods {
- position: relative;
- width: 985px !important;
- height: 576px;
- background: url("../../../assets/images/main/dialog-bg.png") no-repeat;
- background-size: cover;
- .close-btn {
- position: absolute;
- right: 0;
- top: 0;
- width: 50px;
- height: 50px;
- cursor: pointer;
- }
- .choose-area {
- position: absolute;
- right: 100px;
- top: 7px;
- width: 80.05px;
- height: 30px;
- line-height: 30px;
- padding-left: 15px;
- font-size: 14px;
- color: #00ffff;
- background: url("../../../assets/images/main/choose_short.png") no-repeat;
- cursor: pointer;
- }
- .choose-area.choose-week{
- right: 200px;
- }
- .content-area {
- display: flex;
- flex-direction: column;
- padding: 15px 20px 0 15px;
- }
- .content {
- width: 100%;
- display: flex;
- flex-direction: row;
- align-items: center;
- .data-list {
- // background: radial-gradient(
- // 190% 71% at 50% 49%,
- // rgba(21, 105, 107, 0.54) 0%,
- // rgba(27, 95, 97, 0) 100%
- // );
- background: #0b0a0a;
- opacity: 0.9;
- width: 100%;
- height: 492px;
- padding: 20px;
- overflow: auto;
- white-space: pre-wrap;
- .data-item {
- display: inline-block;
- color: #00ffff;
- font-weight: bold;
- margin: 0 10px 10px 10px;
- font-size: 14px;
- img {
- width: 160px;
- height: 48px;
- object-fit: cover;
- }
- .name {
- width: 160px;
- display: block;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- text-align: center;
- position: relative;
- top: -40px;
- font-size: 15px;
- }
- }
- }
- }
- .title-format {
- display: flex;
- flex-direction: row;
- align-items: center;
- img {
- width: 6px;
- height: 24px;
- margin-right: 6px;
- }
- .title-info {
- display: flex;
- flex-direction: column;
- font-size: 12px;
- color: #ffffff;
- .title-en {
- font-size: 8px;
- color: #ffffff;
- opacity: 0.4;
- }
- }
- }
- .choose-area {
- .el-select {
- width: 90%;
- }
- .el-input {
- input {
- background: rgba(255, 255, 255, 0);
- color: #00ffff;
- border: none;
- padding: 0;
- width: 30px;
- }
- }
- }
- .no-data{
- text-align: center;
- color: #62ffe5;
- font-size: 25px;
- margin-top: 150px;
- }
- ::-webkit-scrollbar {
- width: 3px;
- height: 3px;
- }
- ::-webkit-scrollbar-thumb {
- //滑块部分
- // border-radius: 5px;
- background-color: #58cbbb;
- }
- ::-webkit-scrollbar-track {
- //轨道部分
- // box-shadow: inset 0 0 5px #ddd;
- background: #ddd;
- // border-radius: 5px;
- }
- }
- </style>
|