weekFoods.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <div class="main-data data-weeks-foods">
  3. <div class="title-area">周菜谱</div>
  4. <!-- 选择日期 -->
  5. <div class="choose-area choose-week">
  6. <el-select v-model="week" placeholder="请选择" @change="changeWeek">
  7. <el-option
  8. v-for="item in weeks"
  9. :key="item"
  10. :label="item"
  11. :value="item"
  12. >
  13. </el-option>
  14. </el-select>
  15. </div>
  16. <!-- 选择早中晚 -->
  17. <div class="choose-area">
  18. <el-select v-model="food" placeholder="请选择" @change="changeFoods">
  19. <el-option
  20. v-for="item in foods"
  21. :key="item"
  22. :label="item"
  23. :value="item"
  24. >
  25. </el-option>
  26. </el-select>
  27. </div>
  28. <div class="close-btn" @click="close"></div>
  29. <div class="content-area">
  30. <div class="content">
  31. <div class="data-list">
  32. <div v-for="(item, index) in list" :key="index" class="data-item">
  33. <img :src="item.img" @error="errorImg(item)" />
  34. <span class="name">{{ item.name }}</span>
  35. </div>
  36. <div v-if="list.length == 0" class="no-data">暂无数据</div>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import { getFoodsList } from "@/api/screen/service";
  44. import pinyin from "../data/pinyin.js";
  45. export default {
  46. name: "WeekFoods",
  47. props: {
  48. week: {
  49. type: String,
  50. default: "",
  51. },
  52. appOrg: {
  53. type: String,
  54. default: "10001",
  55. },
  56. },
  57. data() {
  58. return {
  59. dataList: [],
  60. weeks: ["周一", "周二", "周三", "周四", "周五"],
  61. list: [],
  62. foodsList: [],
  63. food: "早餐",
  64. foods: ["早餐", "中餐", "晚餐"],
  65. lists: [],
  66. appOrgs:['10001','1D001','1K003','1J001','1E001','1J003','1K002','1J002','1K001','1A001']
  67. };
  68. },
  69. created() {
  70. this.getFoodsList();
  71. },
  72. destroyed() {},
  73. beforeDestroy() {},
  74. mounted() {},
  75. methods: {
  76. //获取数据概况
  77. getFoodsList() {
  78. let appOrg = this.$props.appOrg == '0000' ? '10001' : this.$props.appOrg;
  79. if(this.appOrgs.indexOf(appOrg) == -1){
  80. appOrg = "1J001";
  81. }
  82. getFoodsList(appOrg).then((res) => {
  83. if (Number(res.code) === 200) {
  84. let foodsList = JSON.parse(res.data.foodInfo);
  85. // 转换后的数据
  86. const transformedData = {};
  87. // 映射关系
  88. const dayMap = {"monday": "1","tuesday": "2","wednesday": "3","thursday": "4","friday": "5"};
  89. const mealTypeMap = {"breakfast": "1", "lunch": "2", "dinner": "3"};
  90. // 遍历原始数据并转换
  91. for (const day in foodsList) {
  92. if (foodsList.hasOwnProperty(day)) {
  93. const dayNumber = dayMap[day];
  94. transformedData[dayNumber] = [];
  95. for (const mealTypeKey in foodsList[day]) {
  96. if (foodsList[day].hasOwnProperty(mealTypeKey)) {
  97. const mealTypeNumber = mealTypeMap[mealTypeKey];
  98. foodsList[day][mealTypeKey].forEach(meal => {
  99. if (meal.name) {
  100. const newDishes = [
  101. {"name": meal.name, "type": mealTypeNumber},
  102. ];
  103. transformedData[dayNumber] = transformedData[dayNumber].concat(newDishes);
  104. }
  105. });
  106. }
  107. }
  108. }
  109. }
  110. this.foodsList = JSON.parse(JSON.stringify(transformedData));
  111. let index = parseInt(this.weeks.indexOf(this.$props.week)) + 1;
  112. let lists = JSON.parse(JSON.stringify(transformedData[index]));
  113. this.lists = lists;
  114. let list = [];
  115. let type = parseInt(this.foods.indexOf(this.food)) + 1;
  116. let that = this;
  117. lists.forEach((item) => {
  118. if (item.type == type && item.name) { // 再次检查'name'字段是否为空
  119. //处理图片
  120. // item.img = require('../../../assets/caidanImgs/'+ pinyin.chineseToPinYin(item.name) +'.jpg');
  121. that.loadImage(item);
  122. list.push(item);
  123. }
  124. });
  125. this.list = list;
  126. }
  127. });
  128. },
  129. //选择周几
  130. changeWeek(e) {
  131. let index = parseInt(this.weeks.indexOf(e)) + 1;
  132. let lists = this.foodsList[index];
  133. this.lists = lists;
  134. //联动选择早中晚
  135. this.food = '早餐';
  136. this.changeFoods('早餐');
  137. },
  138. //选择菜品
  139. changeFoods(e) {
  140. let type = parseInt(this.foods.indexOf(e)) + 1;
  141. let lists = this.lists;
  142. let list = [];
  143. let that = this;
  144. lists.forEach((item) => {
  145. if (item.type == type) {
  146. //处理图片
  147. that.loadImage(item);
  148. list.push(item);
  149. }
  150. });
  151. this.list = list;
  152. // console.log(list,'菜品');
  153. },
  154. //默认显示暂无菜品
  155. errorImg(item) {
  156. item.img = require("@/assets/caidanImgs/no-data.jpg");
  157. },
  158. loadImage(item) {
  159. try {
  160. // 尝试加载图片
  161. item.img = require("@/assets/caidanImgs/" +
  162. pinyin.chineseToPinYin(item.name) +
  163. ".jpg");
  164. } catch (e) {
  165. // 处理图片不存在的情况
  166. item.img = require("@/assets/caidanImgs/no-data.jpg"); // 使用默认图片
  167. }
  168. },
  169. //选择周日
  170. choose() {
  171. this.$emit("chooseFoods", this.week);
  172. },
  173. close() {
  174. this.$emit("closeFoods");
  175. },
  176. },
  177. };
  178. </script>
  179. <style lang="scss">
  180. .el-scrollbar {
  181. background: #15696b;
  182. border: 1px solid #00ffff;
  183. ul {
  184. li {
  185. color: #fff;
  186. }
  187. }
  188. }
  189. .el-select-dropdown__item.hover,
  190. .el-select-dropdown__item:hover {
  191. background: #15696b;
  192. color: #00ffff;
  193. }
  194. .el-select-dropdown__item.selected {
  195. color: #00ffff;
  196. }
  197. .el-select .el-input .el-select__caret {
  198. display: none;
  199. }
  200. .data-weeks-foods {
  201. position: relative;
  202. width: 985px !important;
  203. height: 576px;
  204. background: url("../../../assets/images/main/dialog-bg.png") no-repeat;
  205. background-size: cover;
  206. .close-btn {
  207. position: absolute;
  208. right: 0;
  209. top: 0;
  210. width: 50px;
  211. height: 50px;
  212. cursor: pointer;
  213. }
  214. .choose-area {
  215. position: absolute;
  216. right: 100px;
  217. top: 7px;
  218. width: 80.05px;
  219. height: 30px;
  220. line-height: 30px;
  221. padding-left: 15px;
  222. font-size: 14px;
  223. color: #00ffff;
  224. background: url("../../../assets/images/main/choose_short.png") no-repeat;
  225. cursor: pointer;
  226. }
  227. .choose-area.choose-week{
  228. right: 200px;
  229. }
  230. .content-area {
  231. display: flex;
  232. flex-direction: column;
  233. padding: 15px 20px 0 15px;
  234. }
  235. .content {
  236. width: 100%;
  237. display: flex;
  238. flex-direction: row;
  239. align-items: center;
  240. .data-list {
  241. // background: radial-gradient(
  242. // 190% 71% at 50% 49%,
  243. // rgba(21, 105, 107, 0.54) 0%,
  244. // rgba(27, 95, 97, 0) 100%
  245. // );
  246. background: #0b0a0a;
  247. opacity: 0.9;
  248. width: 100%;
  249. height: 492px;
  250. padding: 20px;
  251. overflow: auto;
  252. white-space: pre-wrap;
  253. .data-item {
  254. display: inline-block;
  255. color: #00ffff;
  256. font-weight: bold;
  257. margin: 0 10px 10px 10px;
  258. font-size: 14px;
  259. img {
  260. width: 160px;
  261. height: 48px;
  262. object-fit: cover;
  263. }
  264. .name {
  265. width: 160px;
  266. display: block;
  267. white-space: nowrap;
  268. overflow: hidden;
  269. text-overflow: ellipsis;
  270. text-align: center;
  271. position: relative;
  272. top: -40px;
  273. font-size: 15px;
  274. }
  275. }
  276. }
  277. }
  278. .title-format {
  279. display: flex;
  280. flex-direction: row;
  281. align-items: center;
  282. img {
  283. width: 6px;
  284. height: 24px;
  285. margin-right: 6px;
  286. }
  287. .title-info {
  288. display: flex;
  289. flex-direction: column;
  290. font-size: 12px;
  291. color: #ffffff;
  292. .title-en {
  293. font-size: 8px;
  294. color: #ffffff;
  295. opacity: 0.4;
  296. }
  297. }
  298. }
  299. .choose-area {
  300. .el-select {
  301. width: 90%;
  302. }
  303. .el-input {
  304. input {
  305. background: rgba(255, 255, 255, 0);
  306. color: #00ffff;
  307. border: none;
  308. padding: 0;
  309. width: 30px;
  310. }
  311. }
  312. }
  313. .no-data{
  314. text-align: center;
  315. color: #62ffe5;
  316. font-size: 25px;
  317. margin-top: 150px;
  318. }
  319. ::-webkit-scrollbar {
  320. width: 3px;
  321. height: 3px;
  322. }
  323. ::-webkit-scrollbar-thumb {
  324. //滑块部分
  325. // border-radius: 5px;
  326. background-color: #58cbbb;
  327. }
  328. ::-webkit-scrollbar-track {
  329. //轨道部分
  330. // box-shadow: inset 0 0 5px #ddd;
  331. background: #ddd;
  332. // border-radius: 5px;
  333. }
  334. }
  335. </style>