order.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <view>
  3. <!-- <view > -->
  4. <!-- <swiper class="screen-swiper round-dot" :indicator-dots="true" :circular="true" :autoplay="true" interval="5000"
  5. duration="500"> -->
  6. <!-- <swiper-item v-for="(item,index) in 4" :key="index"> -->
  7. <image src="./top.png" mode="aspectFit" style="height: 20vh; width: 100%;margin-top: 2vh;"></image>
  8. <!-- </swiper-item> -->
  9. <!-- </swiper> -->
  10. <!-- </view> -->
  11. <view class="aside-main" >
  12. <scroll-view scroll-y class="scroll-Y1" style="max-height: 71vh;" scroll-with-animation>
  13. <view :class="num==index?'active':'active2'" v-for="(item,index) in asideList" :key="index"
  14. @click="asid(index)">{{item.title}}
  15. </view>
  16. </scroll-view>
  17. <!-- 右侧滑动区 -->
  18. <scroll-view scroll-y class="scroll-Y2" style="max-height: 71vh;background-color: whitesmoke;" :scroll-into-view="rightview"
  19. scroll-with-animation @scroll="scrollright" @scrolltoupper="scrolltop" @scrolltolower="scrollbuttom">
  20. <!-- 功能区节点 -->
  21. <view v-for="(item,index) in asideList" :key="index" class="min" :id="'rightIndex'+index" :style="{marginTop:index!=0?'10px':0}">
  22. <span class="title">{{item.title}}</span>
  23. <view v-for="(i,j) in item.list" :key="j" class="minmi" >
  24. <image class="imgPic" :src="i.url" mode=""></image>
  25. <view class="rightContainer">
  26. <view class="foodName">
  27. {{i.name}}
  28. </view>
  29. <view class="foodPrice">
  30. <view class="priceflex">
  31. <text class="zero">¥</text>
  32. {{i.price}}
  33. </view>
  34. <view class="shopCar iconfont-themeColor-write" v-show="i.num == 0" @tap="addcart(i)">
  35. <text class="lg text-white cuIcon-add" ></text>
  36. </view>
  37. <view class="" v-if="i.num > 0" >
  38. <!-- <text class="lg text-white cuIcon-minus" @tap="addcart(i)" ></text> -->
  39. <uni-number-box :min="0" :max="100" :step="1" v-model="i.num" @tap="chengeCart(i)" />
  40. <!-- {{ i.num }} -->
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. <view class="cu-bar bg-white tabbar border shop" style="padding-bottom: 0;max-height: 5vh;">
  49. <view class="bg-orange submit" @click="toggle()">
  50. <view class="cuIcon-cartfill" style="font-size: 30px;">
  51. <!-- <view class="cu-tag badge">{{nowCart.length}}</view> -->
  52. </view>
  53. <view style="margin-left: 20px;">
  54. <view class="">合计: ¥{{nowCartPrice}}</view>
  55. <view class="">菜品: {{nowCartList.length}}道</view>
  56. </view>
  57. </view>
  58. <view class="bg-red submit">立即下单</view>
  59. </view>
  60. <uni-popup ref="popup" background-color="#fff" type="bottom" >
  61. <view style="height: 40vh;">
  62. <view class="cu-bar bg-white ">
  63. <view class="action">
  64. <text class="cuIcon-titles text-orange"></text> 购物车
  65. </view>
  66. </view>
  67. <view style="height: 30vh;overflow-y: auto;">
  68. <view v-for="(i,j) in nowCartList" :key="j" class="minmi" style="width: 100vw;" >
  69. <image class="imgPic" :src="i.url" mode=""></image>
  70. <view class="rightContainer">
  71. <view class="foodName">
  72. {{i.name}}
  73. </view>
  74. <view class="foodPrice">
  75. <view class="priceflex">
  76. <text class="zero">¥</text>
  77. {{i.price}}
  78. </view>
  79. <view class="shopCar iconfont-themeColor-write" v-show="i.num == 0" @tap="addcart(i)">
  80. <text class="lg text-white cuIcon-add" ></text>
  81. </view>
  82. <view class="" v-if="i.num > 0" >
  83. <!-- <text class="lg text-white cuIcon-minus" @tap="addcart(i)" ></text> -->
  84. <!-- <uni-number-box :min="0" :max="100" :step="1" v-model="i.num" @tap="chengeCart(i)" /> -->
  85. <text>{{ i.num }}</text>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. <button class="bg-red submit">立即下单</button>
  92. </view>
  93. </uni-popup>
  94. </view>
  95. </template>
  96. <script setup>
  97. import goodsApi from '@/sheep/api/restaurant/goods'
  98. import uniNumberBox from '@/uni_modules/uni-number-box/components/uni-number-box/uni-number-box.vue';
  99. import { onShow } from '@dcloudio/uni-app';
  100. import {
  101. ref,
  102. onMounted,
  103. getCurrentInstance
  104. } from 'vue'
  105. const popup = ref(null);
  106. const nowCartList = ref([])
  107. const nowCartPrice = ref(0)
  108. const mainH = ref('350')
  109. const num = ref(0)
  110. const leftview = ref('')
  111. const rightview = ref('')
  112. const nodes = ref([])
  113. const shopchecked = ref('自取')
  114. const checkedmode = (e) => {
  115. shopchecked.value = e
  116. }
  117. const asideList = ref([])
  118. const getAideList = ref([])
  119. const toggle = () =>{
  120. popup.value.open()
  121. }
  122. // 分类数据
  123. const categorizeItems = (items) => {
  124. asideList.value = {};
  125. items.forEach(item => {
  126. if (!asideList.value[item.goodsTypeid]) {
  127. asideList.value[item.goodsTypeid] ={
  128. title: item.goodsTypeName,
  129. list: []
  130. };
  131. }
  132. asideList.value[item.goodsTypeid].list.push(
  133. { url:item.goodsIcon,
  134. name: item.goodsName,
  135. price: item.goodsPrice,
  136. // id: item.goodsId
  137. num : 0
  138. });
  139. });
  140. console.log('asideList', asideList.value,'items',items);
  141. };
  142. onShow(async () => {
  143. // [{
  144. // title: "双人套餐",
  145. // list: new Array(10).fill({
  146. // url: "https://q9.itc.cn/q_70/images01/20240419/ab185a39af90465cbe8cda9e81ec7e71.jpeg",
  147. // name: '双人套餐',
  148. // price: 32
  149. // })
  150. // }, ]
  151. getAideList.value =(await goodsApi.getAll()).data;
  152. categorizeItems(getAideList.value)
  153. });
  154. onMounted(() => {
  155. uni.getSystemInfo({
  156. success: (res) => {
  157. mainH.value = res.windowHeight - uni.upx2px(88) + 'px'
  158. }
  159. })
  160. coordinate()
  161. })
  162. const addcart = (item)=>{
  163. console.log('item',item)
  164. item.num=1
  165. nowCartList.value.push(item)
  166. // nowCartPrice.value = nowCartPrice.value+item.price
  167. countprice()
  168. console.log('nowCartList',nowCartList.value);
  169. }
  170. const countprice = ()=>{
  171. let totalprice = 0
  172. nowCartList.value.forEach(element => {
  173. totalprice = totalprice +element.price*element.num
  174. });
  175. nowCartPrice.value = totalprice
  176. // console.log('nowCartList',nowCartList.value);
  177. }
  178. const chengeCart = (item)=>{
  179. if(item.num == 0){
  180. nowCartList.value = nowCartList.value.filter(element=>element.num!==0)
  181. }
  182. console.log('item',item)
  183. countprice()
  184. console.log('nowCartList',nowCartList.value);
  185. // item.num=1
  186. }
  187. const asid = (index) => {
  188. num.value = index
  189. rightview.value = 'rightIndex' + index
  190. }
  191. const scrolltop = () => {
  192. num.value = 0
  193. }
  194. const scrollbuttom = () => {
  195. num.value = nodes.value.length - 1
  196. }
  197. const scrollright = (e) => {
  198. console.log( nodes.value);
  199. for (let i = 0; i < nodes.value.length - 1; i++) { // 从0开始循环,并且减去1以避免越界
  200. if (e.detail.scrollTop + nodes.value[0] >= nodes.value[i] && e.detail.scrollTop + nodes.value[0] < nodes
  201. .value[i + 1]) {
  202. num.value = i;
  203. break; // 找到对应的索引后,退出循环
  204. }
  205. }
  206. // 处理边界情况
  207. if (e.detail.scrollTop + nodes.value[0] <= nodes.value[0]) {
  208. num.value = 0;
  209. } else if (e.detail.scrollTop + nodes.value[0] >= nodes.value[nodes.value.length - 1]) {
  210. num.value = nodes.value.length - 1;
  211. }
  212. console.log(num.value);
  213. }
  214. const coordinate = () => {
  215. const instance = getCurrentInstance(); // 获取组件实例
  216. const query = uni.createSelectorQuery().in(instance)
  217. console.log('query',query);
  218. query.selectAll(".min").boundingClientRect((data) => {
  219. console.log('data',data);
  220. for (let i = 0; i < data.length; i++) {
  221. nodes.value.push(data[i].top)
  222. }
  223. }).exec()
  224. }
  225. </script>
  226. <style lang="scss">
  227. .title{
  228. width: 99%;
  229. text-align: left;
  230. padding-left: 10px;
  231. border-left: 5px solid red;
  232. font-size: 18px;
  233. margin-left: 20px;
  234. margin-top: 10px;
  235. font-weight: 800;
  236. }
  237. .active {
  238. font-size: 30upx;
  239. color: #F9BE3E;
  240. }
  241. .active2 {
  242. font-size: 30upx;
  243. }
  244. .min {
  245. display: flex;
  246. flex-direction: row;
  247. justify-content: space-around;
  248. flex-wrap: wrap;
  249. // margin: 20px 0;
  250. background-color: white;
  251. padding-bottom: 20px;
  252. }
  253. .minmi {
  254. display: flex;
  255. width: 592upx;
  256. margin-left: 25upx;
  257. padding-top: 51upx;
  258. .imgPic {
  259. width: 208upx;
  260. height: 167upx;
  261. border-radius: 10upx;
  262. margin-left: 20upx;
  263. }
  264. .rightContainer {
  265. display: flex;
  266. flex-direction: column;
  267. height: 167upx;
  268. box-sizing: border-box;
  269. justify-content: space-between;
  270. align-items: flex-start;
  271. padding-left: 18upx;
  272. padding-right: 18upx;
  273. padding-top: 18upx;
  274. // padding-bottom: 18upx;
  275. flex: 1;
  276. .foodName {
  277. font-weight: 700;
  278. font-size: 25upx;
  279. }
  280. .foodPrice {
  281. display: flex;
  282. justify-content: space-between;
  283. width: 375upx;
  284. color: #F9BE3E;
  285. .priceflex {
  286. display: flex;
  287. align-items: center;
  288. .zero {
  289. font-size: 15upx;
  290. }
  291. }
  292. .shopCar {
  293. background-color: #F9BE3E;
  294. border-radius: 45upx;
  295. width: 112upx;
  296. height: 45upx;
  297. font-size: 25upx;
  298. text-align: center;
  299. line-height: 46upx;
  300. }
  301. }
  302. }
  303. }
  304. .aside-main {
  305. width: 100%;
  306. display: flex;
  307. flex-direction: row;
  308. justify-content: space-between;
  309. box-sizing: border-box;
  310. }
  311. .scroll-Y1 {
  312. flex: 1;
  313. box-sizing: border-box;
  314. }
  315. .scroll-Y1 view {
  316. text-align: center;
  317. padding-top: 33upx;
  318. // padding-bottom: 33upx;
  319. }
  320. .scroll-Y2 {
  321. flex: 3;
  322. box-sizing: border-box;
  323. // padding-bottom: 170upx;
  324. }
  325. .scroll-Y2 view {
  326. text-align: center;
  327. /* margin:20upx; */
  328. }
  329. .icon {
  330. width: 50upx;
  331. height: 50upx;
  332. margin-top: 10upx;
  333. }
  334. .icon1 {
  335. width: 30upx;
  336. height: 30upx;
  337. position: absolute;
  338. top: 15upx;
  339. left: 10upx;
  340. }
  341. .btn {
  342. width: 140upx;
  343. height: 60upx;
  344. line-height: 60upx;
  345. margin: 0;
  346. padding: 0;
  347. font-size: 30upx;
  348. }
  349. .serch {
  350. height: 60upx;
  351. flex: 2;
  352. margin-left: 20upx;
  353. margin-right: 20upx;
  354. box-sizing: border-box;
  355. border: solid 1upx #ccc;
  356. border-radius: 10upx;
  357. position: relative;
  358. }
  359. .serch input {
  360. height: 60upx;
  361. margin-left: 60upx;
  362. }
  363. </style>