MyNutrition.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div class="page-content">
  3. <div class="left-content">
  4. <div class="item-left score-content">
  5. <div class="score-title-box">
  6. <div class="score-title">营养评分</div>
  7. <img @click="show.showMaskQA = true" class="inquiry" src="@/assets/icon_action_help.png" alt="">
  8. </div>
  9. <div class="score-box">
  10. <img class="score-level-img" src="@/assets/Purple.png" alt="">
  11. <div class="echarts_box">
  12. <div class="echarts">
  13. <Score size="120px" />
  14. <div>蛋白质</div>
  15. </div>
  16. <div class="echarts">
  17. <Score size="120px" :name="'良好'" :color="'#FFA900'" :value="76.8" />
  18. <div>脂肪</div>
  19. </div>
  20. <div class="echarts">
  21. <Score size="120px" :name="'及格'" :color="'#FD6C3B'" :value="10" />
  22. <div>碳水化合物</div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="dish_items">
  28. <div class="item-left dish_item" v-for="(itemFood, index) in selectedFoods" :key="itemFood.type">
  29. <div class="breakfast_top">
  30. <img :src="itemFood.icon" alt="">
  31. <div>{{itemFood.name}}</div>
  32. </div>
  33. <div class="item-container" ref="box">
  34. <div class="draggable-item-horizontal selected-item" v-for="item in itemFood.items">
  35. <div class="selected-item-content">
  36. <img class="selected-item-img" :src="item.img" :alt="item.data">
  37. <span>{{item.data}}</span>
  38. </div>
  39. </div>
  40. <div :class="['container-selected-item',itemFood.items.length > 0 ? '':'no-items']" :style="{border:isEnter?'2px dashed red':'6px dashed #F0F0F0',position:'relative'}">
  41. <Container
  42. behaviour="contain"
  43. group-name="1"
  44. :get-child-payload="getChildPayload2(itemFood.type)"
  45. @drop="onDrop($event, index)"
  46. @drag-enter="onEnter"
  47. @drag-leave="onLeave"
  48. @drag-end="onEnd"
  49. drag-class="card-ghost">
  50. <div
  51. :style="{
  52. color: itemFood.items.length || isEnter > 0 ? '#00000000' : '#00000038' ,
  53. height:itemFood.items.length > 0 ? '80px':'150px',
  54. lineHeight:itemFood.items.length > 0 ? '80px':'160px',
  55. top:0,left:0,
  56. textAlign:'center',
  57. width:'100%'}">
  58. {{ itemFood.items.length > 0 ? '1':'从右边可拖入菜品' }}
  59. </div>
  60. </Container>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="right-content">
  67. <div class="dish_select_list">
  68. <Container
  69. :drag-begin-delay="20"
  70. behaviour="copy"
  71. group-name="1"
  72. :get-child-payload="getChildPayload1"
  73. drag-class="card-ghost">
  74. <Draggable v-for="item in items1">
  75. <div class="draggable-item">
  76. <div class="selected-item-content">
  77. <img class="selected-item-img" :src="item.img" :alt="item.data">
  78. <span>{{item.data}}</span>
  79. </div>
  80. </div>
  81. </Draggable>
  82. </Container>
  83. </div>
  84. </div>
  85. </div>
  86. </template>
  87. <script>
  88. import { Container, Draggable } from 'vue3-smooth-dnd'
  89. import Score from '@/components/Echarts/Score.vue'
  90. const applyDrag = (arr, dragResult) => {
  91. const { removedIndex, addedIndex, payload } = dragResult
  92. if (removedIndex === null && addedIndex === null) return arr
  93. const result = [...arr]
  94. let itemToAdd = payload
  95. if (removedIndex !== null) {
  96. itemToAdd = result.splice(removedIndex, 1)[0]
  97. }
  98. if (addedIndex !== null) {
  99. result.splice(addedIndex, 0, itemToAdd)
  100. }
  101. return result
  102. }
  103. export default {
  104. name: 'Copy',
  105. components: {Container, Draggable,Score},
  106. data () {
  107. return {
  108. isEnter: false,
  109. selectedFoods:[{
  110. name:'早餐',
  111. type:'1',
  112. icon:require('@/assets/Dinner_breakfas.png'),
  113. items:[],
  114. },{
  115. name:'中餐',
  116. type:'2',
  117. icon: require('@/assets/Dinner_lunch.png'),
  118. items:[],
  119. },{
  120. name:'晚餐',
  121. type:'3',
  122. icon: require('@/assets/Dinner_supper.png'),
  123. items:[],
  124. }],
  125. items2:[],
  126. items1: [{
  127. id:1,
  128. data:'xx_drag_1',
  129. img:'https://do-while.oss-cn-beijing.aliyuncs.com/exhibition/1635177107%281%29.jpg'
  130. },{
  131. id:2,
  132. data:'xx_drag_2',
  133. img:'https://do-while.oss-cn-beijing.aliyuncs.com/exhibition/1635175644%281%29.jpg'
  134. }]
  135. }
  136. },
  137. methods: {
  138. onDrop (dropResult,index) {
  139. const { removedIndex, addedIndex, payload } = dropResult
  140. let itemToAdd = payload
  141. if(addedIndex == null && removedIndex == null) return
  142. this.selectedFoods[index].items.splice(this.selectedFoods[index].items.length, 0, itemToAdd)
  143. },
  144. getChildPayload1 (index) {
  145. return this.items1[index]
  146. },
  147. getChildPayload2 (type) {
  148. return this.selectedFoods[type-1].items
  149. },
  150. getChildPayload3 (index) {
  151. return this.items3[index]
  152. },
  153. onEnter(e){
  154. console.log(e)
  155. this.isEnter = true
  156. },
  157. onLeave(e){
  158. this.isEnter = false
  159. },
  160. onEnd(){
  161. this.isEnter = false
  162. this.$nextTick(()=>{
  163. this.$refs.box.scrollLeft = this.$refs.box.scrollWidth
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="less">
  170. *::-webkit-scrollbar {
  171. display: none !important;
  172. }
  173. .dish_items{
  174. flex: 1;
  175. overflow-y: scroll;
  176. }
  177. .page-content{
  178. display: flex;
  179. margin: 0 auto;
  180. width: 96%;
  181. height: 100%;
  182. overflow: hidden;
  183. }
  184. .left-content{
  185. flex: 1;
  186. display: flex;
  187. flex-direction: column;
  188. padding-top: 15px;
  189. margin-right: 26px;
  190. }
  191. .right-content{
  192. width: 342px;
  193. padding-top: 15px;
  194. }
  195. .horizontal{
  196. width: 100% !important;
  197. display: flex;
  198. text-align: left;
  199. }
  200. .smooth-dnd-container.horizontal > .smooth-dnd-draggable-wrapper{
  201. display: inline-block;
  202. margin-left: 20px;
  203. }
  204. .draggable-item{
  205. display: inline;
  206. }
  207. .dish_select_list .smooth-dnd-container{
  208. display: flex;
  209. flex-direction: column;
  210. }
  211. .dish_select_list .smooth-dnd-container .smooth-dnd-draggable-wrapper{
  212. display: inline-block;
  213. width: 57px;
  214. }
  215. .item-container{
  216. height: 175px;
  217. max-width: 610px;
  218. overflow-x: scroll;
  219. white-space: nowrap; /* 内容超出不换行 */
  220. }
  221. .container-selected-item{
  222. width: 80px;
  223. height: 80px;
  224. border-radius: 10px;
  225. display: inline-block;
  226. }
  227. .no-items{
  228. width: 600px !important;
  229. height: 160px !important;
  230. }
  231. .selected-item {
  232. height: 160px;
  233. width: 90px;
  234. display: inline-block;
  235. }
  236. .smooth-dnd-disable-touch-action *{
  237. touch-action: auto;
  238. }
  239. .dish_item{
  240. margin-top: 24px;
  241. display: flex;
  242. flex-direction: column;
  243. }
  244. .selected-item-content{
  245. display: flex;
  246. flex-direction: column;
  247. justify-content: center;
  248. align-items: center;
  249. }
  250. .selected-item-img{
  251. width: 40px;
  252. height: 40px;
  253. }
  254. .echarts_box {
  255. display: flex;
  256. background: #FAFAFC;
  257. flex: 1;
  258. height: 170px;
  259. align-items: center;
  260. border-radius: 16px;
  261. justify-content: space-around;
  262. }
  263. .echarts {
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. }
  268. .score-box{
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. }
  273. .score-level-img{
  274. margin: 0 40px;
  275. width: 140px;
  276. height: 140px;
  277. }
  278. .score-title-box{
  279. display: flex;
  280. align-items: center;
  281. margin: 0 30px 30px 30px;
  282. }
  283. .inquiry {
  284. width: 2rem;
  285. height: 2rem;
  286. }
  287. .score-title{
  288. font-size: 24px;
  289. margin-right: 11px;
  290. font-weight: 600;
  291. }
  292. .score-space{
  293. width: 32px;
  294. height: 1px;
  295. }
  296. .item-left{
  297. background: white;
  298. padding: 20px;
  299. border-radius: 16px;
  300. align-items: start;
  301. }
  302. .breakfast_top {
  303. display: flex;
  304. align-items: center;
  305. padding: 25px 0;
  306. img {
  307. width: 3.3rem;
  308. height: 3.3rem;
  309. }
  310. div {
  311. margin-left: 1.1rem;
  312. font-size: 1.8em;
  313. font-weight: bold;
  314. }
  315. }
  316. </style>