order.vue 11 KB

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