order.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <s-layout>
  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="https://www.rshunfandian.cn/prod-api/admin-api/infra/file/24/get/829355650921a542a491d6b901fce0a11b261e749778fb68688fed23d1b31fc5.png" mode="aspectFit" style="height: 15vh; width: 100%;"></image>
  8. <!-- </swiper-item> -->
  9. <!-- </swiper> -->
  10. <!-- </view> -->
  11. <view class="aside-main" >
  12. <scroll-view scroll-y class="scroll-Y1" style="max-height: 66vh;" 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: 66vh;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.priceVisable}}
  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" @click="toggle()">立即下单</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.priceVisable}}
  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" @click="handleOk()">立即下单</button>
  92. </view>
  93. </uni-popup>
  94. </s-layout>
  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 sheep from '@/sheep';
  101. import {
  102. ref,
  103. onMounted,
  104. getCurrentInstance
  105. } from 'vue'
  106. const cart = sheep.$store('cart');
  107. const popup = ref(null);
  108. const nowCartList = ref([])
  109. const nowCartPrice = ref(0)
  110. const mainH = ref('350')
  111. const num = ref(0)
  112. const leftview = ref('')
  113. const rightview = ref('')
  114. const nodes = ref([])
  115. const shopchecked = ref('自取')
  116. const checkedmode = (e) => {
  117. shopchecked.value = e
  118. }
  119. const asideList = ref([])
  120. const getAideList = ref([])
  121. const toggle = () =>{
  122. popup.value.open()
  123. }
  124. const handleOk = ()=>{
  125. if (nowCartList.value.length === 0) {
  126. sheep.$helper.toast('请选择商品');
  127. return;
  128. }
  129. cart.list = nowCartList.value
  130. // store.commit('setParam',nowCartList );
  131. uni.navigateTo({ url: '/pages/restaurant/confirmOrder' });
  132. }
  133. // 分类数据
  134. const categorizeItems = (items) => {
  135. asideList.value = {};
  136. items.forEach(item => {
  137. if (!asideList.value[item.goodsTypeid]) {
  138. asideList.value[item.goodsTypeid] ={
  139. title: item.goodsTypeName,
  140. list: []
  141. };
  142. }
  143. asideList.value[item.goodsTypeid].list.push(
  144. { url:item.goodsIcon,
  145. name: item.goodsName,
  146. price: item.goodsPrice,
  147. priceVisable:item.priceVisable,
  148. goodsId: item.id,
  149. num : 0
  150. });
  151. });
  152. console.log('asideList', asideList.value,'items',items);
  153. };
  154. onShow(async () => {
  155. // [{
  156. // title: "双人套餐",
  157. // list: new Array(10).fill({
  158. // url: "https://q9.itc.cn/q_70/images01/20240419/ab185a39af90465cbe8cda9e81ec7e71.jpeg",
  159. // name: '双人套餐',
  160. // price: 32
  161. // })
  162. // }, ]
  163. getAideList.value =(await goodsApi.getAll()).data;
  164. categorizeItems(getAideList.value)
  165. });
  166. onMounted(() => {
  167. uni.getSystemInfo({
  168. success: (res) => {
  169. mainH.value = res.windowHeight - uni.upx2px(88) + 'px'
  170. }
  171. })
  172. coordinate()
  173. })
  174. const addcart = (item)=>{
  175. console.log('item',item.id)
  176. item.num=1
  177. nowCartList.value.push(item)
  178. // nowCartPrice.value = nowCartPrice.value+item.price
  179. countprice()
  180. console.log('nowCartList',nowCartList.value);
  181. }
  182. const countprice = ()=>{
  183. let totalprice = 0
  184. nowCartList.value.forEach(element => {
  185. totalprice = totalprice +element.priceVisable*element.num
  186. });
  187. nowCartPrice.value = totalprice
  188. // console.log('nowCartList',nowCartList.value);
  189. }
  190. const chengeCart = (item)=>{
  191. if(item.num == 0){
  192. nowCartList.value = nowCartList.value.filter(element=>element.num!==0)
  193. }
  194. console.log('item',item)
  195. countprice()
  196. console.log('nowCartList',nowCartList.value);
  197. // item.num=1
  198. }
  199. const asid = (index) => {
  200. num.value = index
  201. rightview.value = 'rightIndex' + index
  202. }
  203. const scrolltop = () => {
  204. num.value = 0
  205. }
  206. const scrollbuttom = () => {
  207. num.value = nodes.value.length - 1
  208. }
  209. const scrollright = (e) => {
  210. console.log( nodes.value);
  211. for (let i = 0; i < nodes.value.length - 1; i++) { // 从0开始循环,并且减去1以避免越界
  212. if (e.detail.scrollTop + nodes.value[0] >= nodes.value[i] && e.detail.scrollTop + nodes.value[0] < nodes
  213. .value[i + 1]) {
  214. num.value = i;
  215. break; // 找到对应的索引后,退出循环
  216. }
  217. }
  218. // 处理边界情况
  219. if (e.detail.scrollTop + nodes.value[0] <= nodes.value[0]) {
  220. num.value = 0;
  221. } else if (e.detail.scrollTop + nodes.value[0] >= nodes.value[nodes.value.length - 1]) {
  222. num.value = nodes.value.length - 1;
  223. }
  224. console.log(num.value);
  225. }
  226. const coordinate = () => {
  227. const instance = getCurrentInstance(); // 获取组件实例
  228. const query = uni.createSelectorQuery().in(instance)
  229. console.log('query',query);
  230. query.selectAll(".min").boundingClientRect((data) => {
  231. console.log('data',data);
  232. for (let i = 0; i < data.length; i++) {
  233. nodes.value.push(data[i].top)
  234. }
  235. }).exec()
  236. }
  237. </script>
  238. <style lang="scss">
  239. .title{
  240. width: 99%;
  241. text-align: left;
  242. padding-left: 10px;
  243. border-left: 5px solid red;
  244. font-size: 18px;
  245. margin-left: 20px;
  246. margin-top: 10px;
  247. font-weight: 800;
  248. }
  249. .active {
  250. font-size: 30upx;
  251. color: #F9BE3E;
  252. }
  253. .active2 {
  254. font-size: 30upx;
  255. }
  256. .min {
  257. display: flex;
  258. flex-direction: row;
  259. justify-content: space-around;
  260. flex-wrap: wrap;
  261. // margin: 20px 0;
  262. background-color: white;
  263. padding-bottom: 20px;
  264. }
  265. .minmi {
  266. display: flex;
  267. width: 592upx;
  268. margin-left: 25upx;
  269. padding-top: 51upx;
  270. .imgPic {
  271. width: 208upx;
  272. height: 167upx;
  273. border-radius: 10upx;
  274. margin-left: 20upx;
  275. }
  276. .rightContainer {
  277. display: flex;
  278. flex-direction: column;
  279. height: 167upx;
  280. box-sizing: border-box;
  281. justify-content: space-between;
  282. align-items: flex-start;
  283. padding-left: 18upx;
  284. padding-right: 18upx;
  285. padding-top: 18upx;
  286. // padding-bottom: 18upx;
  287. flex: 1;
  288. .foodName {
  289. font-weight: 700;
  290. font-size: 25upx;
  291. }
  292. .foodPrice {
  293. display: flex;
  294. justify-content: space-between;
  295. width: 375upx;
  296. color: #F9BE3E;
  297. .priceflex {
  298. display: flex;
  299. align-items: center;
  300. .zero {
  301. font-size: 15upx;
  302. }
  303. }
  304. .shopCar {
  305. background-color: #F9BE3E;
  306. border-radius: 45upx;
  307. width: 112upx;
  308. height: 45upx;
  309. font-size: 25upx;
  310. text-align: center;
  311. line-height: 46upx;
  312. }
  313. }
  314. }
  315. }
  316. .aside-main {
  317. width: 100%;
  318. display: flex;
  319. flex-direction: row;
  320. justify-content: space-between;
  321. box-sizing: border-box;
  322. }
  323. .scroll-Y1 {
  324. flex: 1;
  325. box-sizing: border-box;
  326. }
  327. .scroll-Y1 view {
  328. text-align: center;
  329. padding-top: 33upx;
  330. // padding-bottom: 33upx;
  331. }
  332. .scroll-Y2 {
  333. flex: 3;
  334. box-sizing: border-box;
  335. // padding-bottom: 170upx;
  336. }
  337. .scroll-Y2 view {
  338. text-align: center;
  339. /* margin:20upx; */
  340. }
  341. .icon {
  342. width: 50upx;
  343. height: 50upx;
  344. margin-top: 10upx;
  345. }
  346. .icon1 {
  347. width: 30upx;
  348. height: 30upx;
  349. position: absolute;
  350. top: 15upx;
  351. left: 10upx;
  352. }
  353. .btn {
  354. width: 140upx;
  355. height: 60upx;
  356. line-height: 60upx;
  357. margin: 0;
  358. padding: 0;
  359. font-size: 30upx;
  360. }
  361. .serch {
  362. height: 60upx;
  363. flex: 2;
  364. margin-left: 20upx;
  365. margin-right: 20upx;
  366. box-sizing: border-box;
  367. border: solid 1upx #ccc;
  368. border-radius: 10upx;
  369. position: relative;
  370. }
  371. .serch input {
  372. height: 60upx;
  373. margin-left: 60upx;
  374. }
  375. </style>