5.项目代码

5.1.前端代码

5.1.1.Index组件

注意点:

  1. 修改图片路径,包括css中背景图片路径
  2. style中添加scoped。
  3. 将静态工程中的 icon.css内容添加到style中。
  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <div class="icon-location-box">
  6. <div class="icon-location"></div>
  7. </div>
  8. <div class="location-text">沈阳市规划大厦<i class="fa fa-caret-down"></i></div>
  9. </header>
  10. <!-- search部分 -->
  11. <!--
  12. 搜索框部分(此块与search-fixed-top块宽度高度一致,用于当
  13. search-fixed-top块固定后,挡住下面块不要窜上去)
  14. -->
  15. <div class="search">
  16. <!-- 当滚动条超过上面的定位块时,search-fixed-top块变成固定在顶部。 -->
  17. <div class="search-fixed-top" ref="fixedBox">
  18. <!-- 搜索框部分中间的白框 -->
  19. <div class="search-box">
  20. <i class="fa fa-search"></i>搜索饿了么商家、商品名称
  21. </div>
  22. </div>
  23. </div>
  24. <!-- 点餐分类部分 -->
  25. <ul class="foodtype">
  26. <li @click="toBusinessList(1)">
  27. <img src="../assets/dcfl01.png">
  28. <p>美食</p>
  29. </li>
  30. <li @click="toBusinessList(2)">
  31. <img src="../assets/dcfl02.png">
  32. <p>早餐</p>
  33. </li>
  34. <li @click="toBusinessList(3)">
  35. <img src="../assets/dcfl03.png">
  36. <p>跑腿代购</p>
  37. </li>
  38. <li @click="toBusinessList(4)">
  39. <img src="../assets/dcfl04.png">
  40. <p>汉堡披萨</p>
  41. </li>
  42. <li @click="toBusinessList(5)">
  43. <img src="../assets/dcfl05.png">
  44. <p>甜品饮品</p>
  45. </li>
  46. <li @click="toBusinessList(6)">
  47. <img src="../assets/dcfl06.png">
  48. <p>速食简餐</p>
  49. </li>
  50. <li @click="toBusinessList(7)">
  51. <img src="../assets/dcfl07.png">
  52. <p>地方小吃</p>
  53. </li>
  54. <li @click="toBusinessList(8)">
  55. <img src="../assets/dcfl08.png">
  56. <p>米粉面馆</p>
  57. </li>
  58. <li @click="toBusinessList(9)">
  59. <img src="../assets/dcfl09.png">
  60. <p>包子粥铺</p>
  61. </li>
  62. <li @click="toBusinessList(10)">
  63. <img src="../assets/dcfl10.png">
  64. <p>炸鸡炸串</p>
  65. </li>
  66. </ul>
  67. <!-- 横幅广告部分(注意:此处有背景图片) -->
  68. <div class="banner">
  69. <h3>品质套餐</h3>
  70. <p>搭配齐全吃得好</p>
  71. <a>立即抢购 &gt;</a>
  72. </div>
  73. <!-- 超级会员部分 -->
  74. <div class="supermember">
  75. <div class="left">
  76. <img src="../assets/super_member.png">
  77. <h3>超级会员</h3>
  78. <p>&#8226; 每月享超值权益</p>
  79. </div>
  80. <div class="right">
  81. 立即开通 &gt;
  82. </div>
  83. </div>
  84. <!-- 推荐商家部分 -->
  85. <div class="recommend">
  86. <div class="recommend-line"></div>
  87. <p>推荐商家</p>
  88. <div class="recommend-line"></div>
  89. </div>
  90. <!-- 推荐方式部分 -->
  91. <ul class="recommendtype">
  92. <li>综合排序<i class="fa fa-caret-down"></i></li>
  93. <li>距离最近</li>
  94. <li>销量最高</li>
  95. <li>筛选<i class="fa fa-filter"></i></li>
  96. </ul>
  97. <!-- 推荐商家列表部分 -->
  98. <ul class="business">
  99. <li>
  100. <img src="../assets/sj01.png">
  101. <div class="business-info">
  102. <div class="business-info-h">
  103. <h3>万家饺子(软件园E18店)</h3>
  104. <div class="business-info-like">&#8226;</div>
  105. </div>
  106. <div class="business-info-star">
  107. <div class="business-info-star-left">
  108. <i class="fa fa-star"></i>
  109. <i class="fa fa-star"></i>
  110. <i class="fa fa-star"></i>
  111. <i class="fa fa-star"></i>
  112. <i class="fa fa-star"></i>
  113. <p>4.9 月售345单</p>
  114. </div>
  115. <div class="business-info-star-right">
  116. 蜂鸟专送
  117. </div>
  118. </div>
  119. <div class="business-info-delivery">
  120. <p>&#165;15起送 | &#165;3配送</p>
  121. <p>3.22km | 30分钟</p>
  122. </div>
  123. <div class="business-info-explain">
  124. <div>各种饺子</div>
  125. </div>
  126. <div class="business-info-promotion">
  127. <div class="business-info-promotion-left">
  128. <div class="business-info-promotion-left-incon"></div>
  129. <p>饿了么新用户首单立减9元</p>
  130. </div>
  131. <div class="business-info-promotion-right">
  132. <p>2个活动</p>
  133. <i class="fa fa-caret-down"></i>
  134. </div>
  135. </div>
  136. <div class="business-info-promotion">
  137. <div class="business-info-promotion-left">
  138. <div class="business-info-promotion-left-incon" style="background-color: #F1884F;"></div>
  139. <p>特价商品5元起</p>
  140. </div>
  141. </div>
  142. </div>
  143. </li>
  144. <li>
  145. <img src="../assets/sj02.png">
  146. <div class="business-info">
  147. <div class="business-info-h">
  148. <h3>小锅饭豆腐馆(全运店)</h3>
  149. <div class="business-info-like">&#8226;</div>
  150. </div>
  151. <div class="business-info-star">
  152. <div class="business-info-star-left">
  153. <i class="fa fa-star"></i>
  154. <i class="fa fa-star"></i>
  155. <i class="fa fa-star"></i>
  156. <i class="fa fa-star"></i>
  157. <i class="fa fa-star"></i>
  158. <p>4.9 月售345单</p>
  159. </div>
  160. <div class="business-info-star-right">
  161. 蜂鸟专送
  162. </div>
  163. </div>
  164. <div class="business-info-delivery">
  165. <p>&#165;15起送 | &#165;3配送</p>
  166. <p>3.22km | 30分钟</p>
  167. </div>
  168. <div class="business-info-explain">
  169. <div>各种饺子</div>
  170. </div>
  171. <div class="business-info-promotion">
  172. <div class="business-info-promotion-left">
  173. <div class="business-info-promotion-left-incon"></div>
  174. <p>饿了么新用户首单立减9元</p>
  175. </div>
  176. <div class="business-info-promotion-right">
  177. <p>2个活动</p>
  178. <i class="fa fa-caret-down"></i>
  179. </div>
  180. </div>
  181. <div class="business-info-promotion">
  182. <div class="business-info-promotion-left">
  183. <div class="business-info-promotion-left-incon"></div>
  184. <p>特价商品5元起</p>
  185. </div>
  186. </div>
  187. </div>
  188. </li>
  189. <li>
  190. <img src="../assets/sj03.png">
  191. <div class="business-info">
  192. <div class="business-info-h">
  193. <h3>麦当劳麦乐送(全运路店)</h3>
  194. <div class="business-info-like">&#8226;</div>
  195. </div>
  196. <div class="business-info-star">
  197. <div class="business-info-star-left">
  198. <i class="fa fa-star"></i>
  199. <i class="fa fa-star"></i>
  200. <i class="fa fa-star"></i>
  201. <i class="fa fa-star"></i>
  202. <i class="fa fa-star"></i>
  203. <p>4.9 月售345单</p>
  204. </div>
  205. <div class="business-info-star-right">
  206. 蜂鸟专送
  207. </div>
  208. </div>
  209. <div class="business-info-delivery">
  210. <p>&#165;15起送 | &#165;3配送</p>
  211. <p>3.22km | 30分钟</p>
  212. </div>
  213. <div class="business-info-explain">
  214. <div>各种饺子</div>
  215. </div>
  216. <div class="business-info-promotion">
  217. <div class="business-info-promotion-left">
  218. <div class="business-info-promotion-left-incon"></div>
  219. <p>饿了么新用户首单立减9元</p>
  220. </div>
  221. <div class="business-info-promotion-right">
  222. <p>2个活动</p>
  223. <i class="fa fa-caret-down"></i>
  224. </div>
  225. </div>
  226. <div class="business-info-promotion">
  227. <div class="business-info-promotion-left">
  228. <div class="business-info-promotion-left-incon"></div>
  229. <p>特价商品5元起</p>
  230. </div>
  231. </div>
  232. </div>
  233. </li>
  234. <li>
  235. <img src="../assets/sj04.png">
  236. <div class="business-info">
  237. <div class="business-info-h">
  238. <h3>米村拌饭(浑南店)</h3>
  239. <div class="business-info-like">&#8226;</div>
  240. </div>
  241. <div class="business-info-star">
  242. <div class="business-info-star-left">
  243. <i class="fa fa-star"></i>
  244. <i class="fa fa-star"></i>
  245. <i class="fa fa-star"></i>
  246. <i class="fa fa-star"></i>
  247. <i class="fa fa-star"></i>
  248. <p>4.9 月售345单</p>
  249. </div>
  250. <div class="business-info-star-right">
  251. 蜂鸟专送
  252. </div>
  253. </div>
  254. <div class="business-info-delivery">
  255. <p>&#165;15起送 | &#165;3配送</p>
  256. <p>3.22km | 30分钟</p>
  257. </div>
  258. <div class="business-info-explain">
  259. <div>各种饺子</div>
  260. </div>
  261. <div class="business-info-promotion">
  262. <div class="business-info-promotion-left">
  263. <div class="business-info-promotion-left-incon"></div>
  264. <p>饿了么新用户首单立减9元</p>
  265. </div>
  266. <div class="business-info-promotion-right">
  267. <p>2个活动</p>
  268. <i class="fa fa-caret-down"></i>
  269. </div>
  270. </div>
  271. <div class="business-info-promotion">
  272. <div class="business-info-promotion-left">
  273. <div class="business-info-promotion-left-incon"></div>
  274. <p>特价商品5元起</p>
  275. </div>
  276. </div>
  277. </div>
  278. </li>
  279. <li>
  280. <img src="../assets/sj05.png">
  281. <div class="business-info">
  282. <div class="business-info-h">
  283. <h3>申记串道(中海康城店)</h3>
  284. <div class="business-info-like">&#8226;</div>
  285. </div>
  286. <div class="business-info-star">
  287. <div class="business-info-star-left">
  288. <i class="fa fa-star"></i>
  289. <i class="fa fa-star"></i>
  290. <i class="fa fa-star"></i>
  291. <i class="fa fa-star"></i>
  292. <i class="fa fa-star"></i>
  293. <p>4.9 月售345单</p>
  294. </div>
  295. <div class="business-info-star-right">
  296. 蜂鸟专送
  297. </div>
  298. </div>
  299. <div class="business-info-delivery">
  300. <p>&#165;15起送 | &#165;3配送</p>
  301. <p>3.22km | 30分钟</p>
  302. </div>
  303. <div class="business-info-explain">
  304. <div>各种饺子</div>
  305. </div>
  306. <div class="business-info-promotion">
  307. <div class="business-info-promotion-left">
  308. <div class="business-info-promotion-left-incon"></div>
  309. <p>饿了么新用户首单立减9元</p>
  310. </div>
  311. <div class="business-info-promotion-right">
  312. <p>2个活动</p>
  313. <i class="fa fa-caret-down"></i>
  314. </div>
  315. </div>
  316. <div class="business-info-promotion">
  317. <div class="business-info-promotion-left">
  318. <div class="business-info-promotion-left-incon"></div>
  319. <p>特价商品5元起</p>
  320. </div>
  321. </div>
  322. </div>
  323. </li>
  324. </ul>
  325. <!-- 底部菜单部分 -->
  326. <Footer></Footer>
  327. </div>
  328. </template>
  329. <script>
  330. //导入共通组件
  331. import Footer from '../components/Footer.vue';
  332. export default {
  333. name: 'Index',
  334. mounted() {
  335. document.onscroll = ()=> {
  336. //获取滚动条位置
  337. let s1 = document.documentElement.scrollTop;
  338. let s2 = document.body.scrollTop;
  339. let scroll = s1 == 0 ? s2 : s1;
  340. //获取视口宽度
  341. let width = document.documentElement.clientWidth;
  342. //获取顶部固定块
  343. let search = this.$refs.fixedBox;
  344. //判断滚动条超过视口宽度的12%时,搜索块变固定定位
  345. if (scroll > width * 0.12) {
  346. search.style.position = 'fixed';
  347. search.style.left = '0';
  348. search.style.top = '0';
  349. } else {
  350. search.style.position = 'static';
  351. }
  352. }
  353. },
  354. destroyed() {
  355. //当切换到其他组件时,就不需要document滚动条事件,所以将此事件去掉
  356. document.onscroll = null;
  357. },
  358. components:{
  359. Footer
  360. },
  361. methods:{
  362. toBusinessList(orderTypeId){
  363. this.$router.push({path:'/businessList',query:{orderTypeId:orderTypeId}});
  364. }
  365. }
  366. }
  367. </script>
  368. <style scoped>
  369. /****************** 总容器 ******************/
  370. .wrapper {
  371. width: 100%;
  372. height: 100%;
  373. }
  374. /****************** header ******************/
  375. .wrapper header {
  376. width: 100%;
  377. height: 12vw;
  378. background-color: #0097FF;
  379. display: flex;
  380. align-items: center;
  381. }
  382. .wrapper header .icon-location-box {
  383. width: 3.5vw;
  384. height: 3.5vw;
  385. margin: 0 1vw 0 3vw;
  386. }
  387. .wrapper header .location-text {
  388. font-size: 4.5vw;
  389. font-weight: 700;
  390. color: #fff;
  391. }
  392. .wrapper header .location-text .fa-caret-down {
  393. margin-left: 1vw;
  394. }
  395. /****************** search ******************/
  396. .wrapper .search {
  397. width: 100%;
  398. height: 13vw;
  399. }
  400. .wrapper .search .search-fixed-top {
  401. width: 100%;
  402. height: 13vw;
  403. background-color: #0097FF;
  404. display: flex;
  405. justify-content: center;
  406. align-items: center;
  407. }
  408. .wrapper .search .search-fixed-top .search-box {
  409. width: 90%;
  410. height: 9vw;
  411. background-color: #fff;
  412. border-radius: 2px;
  413. display: flex;
  414. justify-content: center;
  415. align-items: center;
  416. font-size: 3.5vw;
  417. color: #AEAEAE;
  418. font-family: "宋体";
  419. /*此样式是让文本选中状态无效*/
  420. user-select: none;
  421. }
  422. .wrapper .search .search-fixed-top .search-box .fa-search {
  423. margin-right: 1vw;
  424. }
  425. /****************** 点餐分类部分 ******************/
  426. .wrapper .foodtype {
  427. width: 100%;
  428. height: 48vw;
  429. display: flex;
  430. flex-wrap: wrap;
  431. justify-content: space-around;
  432. /*要使用align-content。10个子元素将自动换行为两行,而且两行作为一个整体垂直居中*/
  433. align-content: center;
  434. }
  435. .wrapper .foodtype li {
  436. /*一共10个子元素,通过计算,子元素宽度在16.7 ~ 20 之间,才能保证换两行*/
  437. width: 18vw;
  438. height: 20vw;
  439. display: flex;
  440. /*弹性盒子主轴方向设为column,然后仍然是垂直水平方向居中*/
  441. flex-direction: column;
  442. justify-content: center;
  443. align-items: center;
  444. user-select: none;
  445. cursor: pointer;
  446. }
  447. .wrapper .foodtype li img {
  448. width: 12vw;
  449. /*视频讲解时高度设置为12vw,实际上设置为10.3vw更佳*/
  450. height: 10.3vw;
  451. }
  452. .wrapper .foodtype li p {
  453. font-size: 3.2vw;
  454. color: #666;
  455. }
  456. /****************** 横幅广告部分 ******************/
  457. .wrapper .banner {
  458. /**
  459. * 设置容器宽度95%,然后水平居中,这样两边留白;
  460. * 这里不能用padding,因为背景图片也会覆盖padding
  461. */
  462. width: 95%;
  463. margin: 0 auto;
  464. height: 29vw;
  465. /*此三个样式组合,可以保证背景图片充满整个容器*/
  466. background-image: url(../assets/index_banner.png);
  467. background-repeat: no-repeat;
  468. background-size: cover;
  469. box-sizing: border-box;
  470. padding: 2vw 6vw;
  471. }
  472. .wrapper .banner h3 {
  473. font-size: 4.2vw;
  474. margin-bottom: 1.2vw;
  475. }
  476. .wrapper .banner p {
  477. font-size: 3.4vw;
  478. color: #666;
  479. margin-bottom: 2.4vw;
  480. }
  481. .wrapper .banner a {
  482. font-size: 3vw;
  483. color: #C79060;
  484. font-weight: 700;
  485. }
  486. /****************** 超级会员部分 ******************/
  487. .wrapper .supermember {
  488. /*这里也设置容器宽度95%,不能用padding,因为背景色也会充满padding*/
  489. width: 95%;
  490. margin: 0 auto;
  491. height: 11.5vw;
  492. background-color: #FEEDC1;
  493. margin-top: 1.3vw;
  494. border-radius: 2px;
  495. color: #644F1B;
  496. display: flex;
  497. justify-content: space-between;
  498. align-items: center;
  499. }
  500. .wrapper .supermember .left {
  501. display: flex;
  502. align-items: center;
  503. margin-left: 4vw;
  504. user-select: none;
  505. }
  506. .wrapper .supermember .left img {
  507. width: 6vw;
  508. height: 6vw;
  509. margin-right: 2vw;
  510. }
  511. .wrapper .supermember .left h3 {
  512. font-size: 4vw;
  513. margin-right: 2vw;
  514. }
  515. .wrapper .supermember .left p {
  516. font-size: 3vw;
  517. }
  518. .wrapper .supermember .right {
  519. font-size: 3vw;
  520. margin-right: 4vw;
  521. cursor: pointer;
  522. }
  523. /****************** 推荐商家部分 ******************/
  524. .wrapper .recommend {
  525. width: 100%;
  526. height: 14vw;
  527. display: flex;
  528. justify-content: center;
  529. align-items: center;
  530. }
  531. .wrapper .recommend .recommend-line {
  532. width: 6vw;
  533. height: 0.2vw;
  534. background-color: #888;
  535. }
  536. .wrapper .recommend p {
  537. font-size: 4vw;
  538. margin: 0 4vw;
  539. }
  540. /****************** 推荐方式部分 ******************/
  541. .wrapper .recommendtype {
  542. width: 100%;
  543. height: 5vw;
  544. margin-bottom: 5vw;
  545. display: flex;
  546. justify-content: space-around;
  547. align-items: center;
  548. }
  549. .wrapper .recommendtype li {
  550. font-size: 3.5vw;
  551. color: #555;
  552. }
  553. /****************** 推荐商家列表部分 ******************/
  554. .wrapper .business {
  555. width: 100%;
  556. margin-bottom: 14vw;
  557. }
  558. .wrapper .business li {
  559. width: 100%;
  560. box-sizing: border-box;
  561. padding: 2.5vw;
  562. user-select: none;
  563. border-bottom: solid 1px #DDD;
  564. display: flex;
  565. }
  566. .wrapper .business li img {
  567. width: 18vw;
  568. height: 18vw;
  569. }
  570. .wrapper .business li .business-info {
  571. width: 100%;
  572. box-sizing: border-box;
  573. padding-left: 3vw;
  574. }
  575. .wrapper .business li .business-info .business-info-h {
  576. display: flex;
  577. justify-content: space-between;
  578. align-items: center;
  579. margin-bottom: 2vw;
  580. }
  581. .wrapper .business li .business-info .business-info-h h3 {
  582. font-size: 4vw;
  583. color: #333;
  584. }
  585. .wrapper .business li .business-info .business-info-h .business-info-like {
  586. width: 1.6vw;
  587. height: 3.4vw;
  588. background-color: #666;
  589. color: #fff;
  590. font-size: 4vw;
  591. margin-right: 4vw;
  592. display: flex;
  593. justify-content: center;
  594. align-items: center;
  595. }
  596. .wrapper .business li .business-info .business-info-star {
  597. display: flex;
  598. justify-content: space-between;
  599. align-items: center;
  600. margin-bottom: 2vw;
  601. font-size: 3.1vw;
  602. }
  603. .wrapper .business li .business-info .business-info-star .business-info-star-left {
  604. display: flex;
  605. align-items: center;
  606. }
  607. .wrapper .business li .business-info .business-info-star .business-info-star-left .fa-star {
  608. color: #FEC80E;
  609. margin-right: 0.5vw;
  610. }
  611. .wrapper .business li .business-info .business-info-star .business-info-star-left p {
  612. color: #666;
  613. margin-left: 1vw;
  614. }
  615. .wrapper .business li .business-info .business-info-star .business-info-star-right {
  616. background-color: #0097FF;
  617. color: #fff;
  618. font-size: 2.4vw;
  619. border-radius: 2px;
  620. padding: 0 0.6vw;
  621. }
  622. .wrapper .business li .business-info .business-info-delivery {
  623. display: flex;
  624. justify-content: space-between;
  625. align-items: center;
  626. margin-bottom: 2vw;
  627. color: #666;
  628. font-size: 3.1vw;
  629. }
  630. .wrapper .business li .business-info .business-info-explain {
  631. display: flex;
  632. align-items: center;
  633. margin-bottom: 3vw;
  634. }
  635. .wrapper .business li .business-info .business-info-explain div {
  636. border: solid 1px #DDD;
  637. font-size: 2.8vw;
  638. color: #666;
  639. border-radius: 3px;
  640. padding: 0 0.1vw;
  641. }
  642. .wrapper .business li .business-info .business-info-promotion {
  643. display: flex;
  644. justify-content: space-between;
  645. align-items: center;
  646. margin-bottom: 1.8vw;
  647. }
  648. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-left {
  649. display: flex;
  650. align-items: center;
  651. }
  652. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-left .business-info-promotion-left-incon {
  653. width: 4vw;
  654. height: 4vw;
  655. background-color: #70BC46;
  656. border-radius: 3px;
  657. font-size: 3vw;
  658. color: #fff;
  659. display: flex;
  660. justify-content: center;
  661. align-items: center;
  662. }
  663. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-left p {
  664. color: #666;
  665. font-size: 3vw;
  666. margin-left: 2vw;
  667. }
  668. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-right {
  669. display: flex;
  670. align-items: center;
  671. font-size: 2.5vw;
  672. color: #999;
  673. }
  674. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-right p {
  675. margin-right: 2vw;
  676. }
  677. </style>

5.1.2.BusinessList组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>商家列表</p>
  6. </header>
  7. <!-- 商家列表部分 -->
  8. <ul class="business">
  9. <li v-for="item in businessArr" @click="toBusinessInfo(item.businessId)">
  10. <div class="business-img">
  11. <img :src="item.businessImg">
  12. <div class="business-img-quantity" v-show="item.quantity>0">{{item.quantity}}</div>
  13. </div>
  14. <div class="business-info">
  15. <h3>{{item.businessName}}</h3>
  16. <p>&#165;{{item.starPrice}}起送 | &#165;{{item.deliveryPrice}}配送</p>
  17. <p>{{item.businessExplain}}</p>
  18. </div>
  19. </li>
  20. </ul>
  21. <!-- 底部菜单部分 -->
  22. <Footer></Footer>
  23. </div>
  24. </template>
  25. <script>
  26. import Footer from '../components/Footer.vue';
  27. export default{
  28. name:'BusinessList',
  29. data(){
  30. return {
  31. orderTypeId: this.$route.query.orderTypeId,
  32. businessArr:[],
  33. user:{}
  34. }
  35. },
  36. created() {
  37. this.user = this.$getSessionStorage('user');
  38. //根据orderTypeId查询商家信息
  39. this.$axios.post('BusinessController/listBusinessByOrderTypeId',this.$qs.stringify({
  40. orderTypeId:this.orderTypeId
  41. })).then(response=>{
  42. this.businessArr = response.data;
  43. //判断是否登录
  44. if(this.user!=null){
  45. this.listCart();
  46. }
  47. }).catch(error=>{
  48. console.error(error);
  49. });
  50. },
  51. components:{
  52. Footer
  53. },
  54. methods:{
  55. listCart(){
  56. this.$axios.post('CartController/listCart',this.$qs.stringify({
  57. userId:this.user.userId
  58. })).then(response=>{
  59. let cartArr = response.data;
  60. //遍历所有食品列表
  61. for(let businessItem of this.businessArr){
  62. businessItem.quantity = 0;
  63. for(let cartItem of cartArr){
  64. if(cartItem.businessId==businessItem.businessId){
  65. businessItem.quantity += cartItem.quantity;
  66. }
  67. }
  68. }
  69. this.businessArr.sort();
  70. }).catch(error=>{
  71. console.error(error);
  72. });
  73. },
  74. toBusinessInfo(businessId){
  75. this.$router.push({path:'/businessInfo',query:{businessId:businessId}});
  76. }
  77. }
  78. }
  79. </script>
  80. <style scoped>
  81. /****************** 总容器 ******************/
  82. .wrapper {
  83. width: 100%;
  84. height: 100%;
  85. }
  86. /****************** header部分 ******************/
  87. .wrapper header {
  88. width: 100%;
  89. height: 12vw;
  90. background-color: #0097FF;
  91. color: #fff;
  92. font-size: 4.8vw;
  93. position: fixed;
  94. left: 0;
  95. top: 0;
  96. z-index: 1000;
  97. display: flex;
  98. justify-content: center;
  99. align-items: center;
  100. }
  101. /****************** 商家列表部分 ******************/
  102. .wrapper .business {
  103. width: 100%;
  104. margin-top: 12vw;
  105. margin-bottom: 14vw;
  106. }
  107. .wrapper .business li {
  108. width: 100%;
  109. box-sizing: border-box;
  110. padding: 2.5vw;
  111. border-bottom: solid 1px #DDD;
  112. user-select: none;
  113. cursor: pointer;
  114. display: flex;
  115. align-items: center;
  116. }
  117. .wrapper .business li .business-img {
  118. /*这里设置为相当定位,成为business-img-quantity元素的父元素*/
  119. position: relative;
  120. }
  121. .wrapper .business li .business-img img {
  122. width: 20vw;
  123. height: 20vw;
  124. }
  125. .wrapper .business li .business-img .business-img-quantity {
  126. width: 5vw;
  127. height: 5vw;
  128. background-color: red;
  129. color: #fff;
  130. font-size: 3.6vw;
  131. border-radius: 2.5vw;
  132. display: flex;
  133. justify-content: center;
  134. align-items: center;
  135. /*设置成绝对定位,不占文档流空间*/
  136. position: absolute;
  137. right: -1.5vw;
  138. top: -1.5vw;
  139. }
  140. .wrapper .business li .business-info {
  141. margin-left: 3vw;
  142. }
  143. .wrapper .business li .business-info h3 {
  144. font-size: 3.8vw;
  145. color: #555;
  146. }
  147. .wrapper .business li .business-info p {
  148. font-size: 3vw;
  149. color: #888;
  150. margin-top: 2vw;
  151. }
  152. </style>

5.1.3.BusinessInfo组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>商家信息</p>
  6. </header>
  7. <!-- 商家logo部分 -->
  8. <div class="business-logo">
  9. <img :src="business.businessImg">
  10. </div>
  11. <!-- 商家信息部分 -->
  12. <div class="business-info">
  13. <h1>{{business.businessName}}</h1>
  14. <p>&#165;{{business.starPrice}}起送 &#165;{{business.deliveryPrice}}配送</p>
  15. <p>{{business.businessExplain}}</p>
  16. </div>
  17. <!-- 食品列表部分 -->
  18. <ul class="food">
  19. <li v-for="(item,index) in foodArr">
  20. <div class="food-left">
  21. <img :src="item.foodImg">
  22. <div class="food-left-info">
  23. <h3>{{item.foodName}}</h3>
  24. <p>{{item.foodExplain}}</p>
  25. <p>&#165;{{item.foodPrice}}</p>
  26. </div>
  27. </div>
  28. <div class="food-right">
  29. <div>
  30. <i class="fa fa-minus-circle" @click="minus(index)" v-show="item.quantity!=0"></i>
  31. </div>
  32. <p><span v-show="item.quantity!=0">{{item.quantity}}</span></p>
  33. <div>
  34. <i class="fa fa-plus-circle" @click="add(index)"></i>
  35. </div>
  36. </div>
  37. </li>
  38. </ul>
  39. <!-- 购物车部分 -->
  40. <div class="cart">
  41. <div class="cart-left">
  42. <div class="cart-left-icon" :style="totalQuantity==0?'background-color:#505051;':'background-color:#3190E8;'">
  43. <i class="fa fa-shopping-cart"></i>
  44. <div class="cart-left-icon-quantity" v-show="totalQuantity!=0">{{totalQuantity}}</div>
  45. </div>
  46. <div class="cart-left-info">
  47. <p>&#165;{{totalPrice}}</p>
  48. <p>另需配送费{{business.deliveryPrice}}元</p>
  49. </div>
  50. </div>
  51. <div class="cart-right">
  52. <!-- 不够起送费 -->
  53. <div class="cart-right-item" v-show="totalSettle<business.starPrice" style="background-color: #535356;cursor: default;">
  54. &#165;{{business.starPrice}}起送
  55. </div>
  56. <!-- 达到起送费 -->
  57. <div class="cart-right-item" @click="toOrder" v-show="totalSettle>=business.starPrice">
  58. 去结算
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. export default {
  66. name: 'BusinessInfo',
  67. data() {
  68. return {
  69. businessId: this.$route.query.businessId,
  70. business: {},
  71. foodArr: [],
  72. user: {}
  73. }
  74. },
  75. created() {
  76. this.user = this.$getSessionStorage('user');
  77. //根据businessId查询商家信息
  78. this.$axios.post('BusinessController/getBusinessById', this.$qs.stringify({
  79. businessId: this.businessId
  80. })).then(response => {
  81. this.business = response.data;
  82. }).catch(error => {
  83. console.error(error);
  84. });
  85. //根据businessId查询所属食品信息
  86. this.$axios.post('FoodController/listFoodByBusinessId', this.$qs.stringify({
  87. businessId: this.businessId
  88. })).then(response => {
  89. this.foodArr = response.data;
  90. for (let i = 0; i < this.foodArr.length; i++) {
  91. this.foodArr[i].quantity = 0;
  92. }
  93. //如果已登录,那么需要去查询购物车中是否已经选购了某个食品
  94. if (this.user != null) {
  95. this.listCart();
  96. }
  97. }).catch(error => {
  98. console.error(error);
  99. });
  100. },
  101. methods: {
  102. listCart() {
  103. this.$axios.post('CartController/listCart', this.$qs.stringify({
  104. businessId: this.businessId,
  105. userId: this.user.userId
  106. })).then(response => {
  107. let cartArr = response.data;
  108. //遍历所有食品列表
  109. for (let foodItem of this.foodArr) {
  110. foodItem.quantity = 0;
  111. for (let cartItem of cartArr) {
  112. if (cartItem.foodId == foodItem.foodId) {
  113. foodItem.quantity = cartItem.quantity;
  114. }
  115. }
  116. }
  117. this.foodArr.sort();
  118. }).catch(error => {
  119. console.error(error);
  120. });
  121. },
  122. add(index) {
  123. //首先做登录验证
  124. if (this.user == null) {
  125. this.$router.push({
  126. path: '/login'
  127. });
  128. return;
  129. }
  130. if (this.foodArr[index].quantity == 0) {
  131. //做insert
  132. this.savaCart(index);
  133. } else {
  134. //做update
  135. this.updateCart(index, 1);
  136. }
  137. },
  138. minus(index) {
  139. //首先做登录验证
  140. if (this.user == null) {
  141. this.$router.push({
  142. path: '/login'
  143. });
  144. return;
  145. }
  146. if (this.foodArr[index].quantity > 1) {
  147. //做update
  148. this.updateCart(index, -1);
  149. } else {
  150. //做delete
  151. this.removeCart(index);
  152. }
  153. },
  154. savaCart(index) {
  155. this.$axios.post('CartController/saveCart', this.$qs.stringify({
  156. businessId: this.businessId,
  157. userId: this.user.userId,
  158. foodId: this.foodArr[index].foodId
  159. })).then(response => {
  160. if (response.data == 1) {
  161. //此食品数量要更新为1;
  162. this.foodArr[index].quantity = 1;
  163. this.foodArr.sort();
  164. } else {
  165. alert('向购物车中添加食品失败!');
  166. }
  167. }).catch(error => {
  168. console.error(error);
  169. });
  170. },
  171. updateCart(index, num) {
  172. this.$axios.post('CartController/updateCart', this.$qs.stringify({
  173. businessId: this.businessId,
  174. userId: this.user.userId,
  175. foodId: this.foodArr[index].foodId,
  176. quantity: this.foodArr[index].quantity + num
  177. })).then(response => {
  178. if (response.data == 1) {
  179. //此食品数量要更新为1或-1;
  180. this.foodArr[index].quantity += num;
  181. this.foodArr.sort();
  182. } else {
  183. alert('向购物车中更新食品失败!');
  184. }
  185. }).catch(error => {
  186. console.error(error);
  187. });
  188. },
  189. removeCart(index) {
  190. this.$axios.post('CartController/removeCart', this.$qs.stringify({
  191. businessId: this.businessId,
  192. userId: this.user.userId,
  193. foodId: this.foodArr[index].foodId
  194. })).then(response => {
  195. if (response.data == 1) {
  196. //此食品数量要更新为0;视图的减号和数量要消失
  197. this.foodArr[index].quantity = 0;
  198. this.foodArr.sort();
  199. } else {
  200. alert('从购物车中删除食品失败!');
  201. }
  202. }).catch(error => {
  203. console.error(error);
  204. });
  205. },
  206. toOrder() {
  207. this.$router.push({
  208. path: '/orders',
  209. query: {
  210. businessId: this.business.businessId
  211. }
  212. });
  213. }
  214. },
  215. computed: {
  216. //食品总价格
  217. totalPrice() {
  218. let total = 0;
  219. for (let item of this.foodArr) {
  220. total += item.foodPrice * item.quantity;
  221. }
  222. return total;
  223. },
  224. //食品总数量
  225. totalQuantity() {
  226. let quantity = 0;
  227. for (let item of this.foodArr) {
  228. quantity += item.quantity;
  229. }
  230. return quantity;
  231. },
  232. //结算总价格
  233. totalSettle() {
  234. return this.totalPrice + this.business.deliveryPrice;
  235. }
  236. }
  237. }
  238. </script>
  239. <style scoped>
  240. /****************** 总容器 ******************/
  241. .wrapper {
  242. width: 100%;
  243. height: 100%;
  244. }
  245. /****************** header部分 ******************/
  246. .wrapper header {
  247. width: 100%;
  248. height: 12vw;
  249. background-color: #0097FF;
  250. color: #fff;
  251. font-size: 4.8vw;
  252. position: fixed;
  253. left: 0;
  254. top: 0;
  255. z-index: 1000;
  256. display: flex;
  257. justify-content: center;
  258. align-items: center;
  259. }
  260. /****************** 商家logo部分 ******************/
  261. .wrapper .business-logo {
  262. width: 100%;
  263. height: 35vw;
  264. /*使用上外边距避开header部分*/
  265. margin-top: 12vw;
  266. display: flex;
  267. justify-content: center;
  268. align-items: center;
  269. }
  270. .wrapper .business-logo img {
  271. width: 40vw;
  272. height: 30vw;
  273. border-radius: 5px;
  274. }
  275. /****************** 商家信息部分 ******************/
  276. .wrapper .business-info {
  277. width: 100%;
  278. height: 20vw;
  279. display: flex;
  280. flex-direction: column;
  281. justify-content: center;
  282. align-items: center;
  283. }
  284. .wrapper .business-info h1 {
  285. font-size: 5vw;
  286. }
  287. .wrapper .business-info p {
  288. font-size: 3vw;
  289. color: #666;
  290. margin-top: 1vw;
  291. }
  292. /****************** 食品列表部分 ******************/
  293. .wrapper .food {
  294. width: 100%;
  295. /*使用下外边距避开footer部分*/
  296. margin-bottom: 14vw;
  297. }
  298. .wrapper .food li {
  299. width: 100%;
  300. box-sizing: border-box;
  301. padding: 2.5vw;
  302. user-select: none;
  303. display: flex;
  304. justify-content: space-between;
  305. align-items: center;
  306. }
  307. .wrapper .food li .food-left {
  308. display: flex;
  309. align-items: center;
  310. }
  311. .wrapper .food li .food-left img {
  312. width: 20vw;
  313. height: 20vw;
  314. }
  315. .wrapper .food li .food-left .food-left-info {
  316. margin-left: 3vw;
  317. }
  318. .wrapper .food li .food-left .food-left-info h3 {
  319. font-size: 3.8vw;
  320. color: #555;
  321. }
  322. .wrapper .food li .food-left .food-left-info p {
  323. font-size: 3vw;
  324. color: #888;
  325. margin-top: 2vw;
  326. }
  327. .wrapper .food li .food-right {
  328. width: 16vw;
  329. display: flex;
  330. justify-content: space-between;
  331. align-items: center;
  332. }
  333. .wrapper .food li .food-right .fa-minus-circle {
  334. font-size: 5.5vw;
  335. color: #999;
  336. cursor: pointer;
  337. }
  338. .wrapper .food li .food-right p {
  339. font-size: 3.6vw;
  340. color: #333;
  341. }
  342. .wrapper .food li .food-right .fa-plus-circle {
  343. font-size: 5.5vw;
  344. color: #0097EF;
  345. cursor: pointer;
  346. }
  347. /****************** 购物车部分 ******************/
  348. .wrapper .cart {
  349. width: 100%;
  350. height: 14vw;
  351. position: fixed;
  352. left: 0;
  353. bottom: 0;
  354. display: flex;
  355. }
  356. .wrapper .cart .cart-left {
  357. flex: 2;
  358. background-color: #505051;
  359. display: flex;
  360. }
  361. .wrapper .cart .cart-left .cart-left-icon {
  362. width: 16vw;
  363. height: 16vw;
  364. box-sizing: border-box;
  365. border: solid 1.6vw #444;
  366. border-radius: 8vw;
  367. background-color: #3190E8;
  368. font-size: 7vw;
  369. color: #fff;
  370. display: flex;
  371. justify-content: center;
  372. align-items: center;
  373. margin-top: -4vw;
  374. margin-left: 3vw;
  375. position: relative;
  376. }
  377. .wrapper .cart .cart-left .cart-left-icon-quantity {
  378. width: 5vw;
  379. height: 5vw;
  380. border-radius: 2.5vw;
  381. background-color: red;
  382. color: #fff;
  383. font-size: 3.6vw;
  384. display: flex;
  385. justify-content: center;
  386. align-items: center;
  387. position: absolute;
  388. right: -1.5vw;
  389. top: -1.5vw;
  390. }
  391. .wrapper .cart .cart-left .cart-left-info p:first-child {
  392. font-size: 4.5vw;
  393. color: #fff;
  394. margin-top: 1vw;
  395. }
  396. .wrapper .cart .cart-left .cart-left-info p:last-child {
  397. font-size: 2.8vw;
  398. color: #AAA;
  399. }
  400. .wrapper .cart .cart-right {
  401. flex: 1;
  402. }
  403. /*达到起送费时的样式*/
  404. .wrapper .cart .cart-right .cart-right-item {
  405. width: 100%;
  406. height: 100%;
  407. background-color: #38CA73;
  408. color: #fff;
  409. font-size: 4.5vw;
  410. font-weight: 700;
  411. user-select: none;
  412. cursor: pointer;
  413. display: flex;
  414. justify-content: center;
  415. align-items: center;
  416. }
  417. /*不够起送费时的样式(只有背景色和鼠标样式的区别)*/
  418. /*
  419. .wrapper .cart .cart-right .cart-right-item{
  420. width: 100%;
  421. height: 100%;
  422. background-color: #535356;
  423. color: #fff;
  424. font-size: 4.5vw;
  425. font-weight: 700;
  426. user-select: none;
  427. display: flex;
  428. justify-content: center;
  429. align-items: center;
  430. }
  431. */
  432. </style>

5.1.4.Order组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>确认订单</p>
  6. </header>
  7. <!-- 订单信息部分 -->
  8. <div class="order-info">
  9. <h5>订单配送至:</h5>
  10. <div class="order-info-address" @click="toUserAddress">
  11. <p>{{deliveryaddress!=null?deliveryaddress.address:'请选择送货地址'}}</p>
  12. <i class="fa fa-angle-right"></i>
  13. </div>
  14. <p>{{user.userName}}{{user.userSex | sexFilter}} {{user.userId}}</p>
  15. </div>
  16. <h3>{{business.businessName}}</h3>
  17. <!-- 订单明细部分 -->
  18. <ul class="order-detailed">
  19. <li v-for="item in cartArr">
  20. <div class="order-detailed-left">
  21. <img :src="item.food.foodImg">
  22. <p>{{item.food.foodName}} x {{item.quantity}}</p>
  23. </div>
  24. <p>&#165;{{item.food.foodPrice*item.quantity}}</p>
  25. </li>
  26. </ul>
  27. <div class="order-deliveryfee">
  28. <p>配送费</p>
  29. <p>&#165;{{business.deliveryPrice}}</p>
  30. </div>
  31. <!-- 合计部分 -->
  32. <div class="total">
  33. <div class="total-left">
  34. &#165;{{totalPrice}}
  35. </div>
  36. <div class="total-right" @click="toPayment">
  37. 去支付
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. export default{
  44. name:'Orders',
  45. data(){
  46. return {
  47. businessId:this.$route.query.businessId,
  48. business:{},
  49. user:{},
  50. cartArr:[],
  51. deliveryaddress:{}
  52. }
  53. },
  54. created() {
  55. this.user = this.$getSessionStorage('user');
  56. this.deliveryaddress = this.$getLocalStorage(this.user.userId);
  57. //查询当前商家
  58. this.$axios.post('BusinessController/getBusinessById',this.$qs.stringify({
  59. businessId:this.businessId
  60. })).then(response=>{
  61. this.business = response.data;
  62. }).catch(error=>{
  63. console.error(error);
  64. });
  65. //查询当前用户在购物车中的当前商家食品列表
  66. this.$axios.post('CartController/listCart',this.$qs.stringify({
  67. userId:this.user.userId,
  68. businessId:this.businessId
  69. })).then(response=>{
  70. this.cartArr = response.data;
  71. }).catch(error=>{
  72. console.error(error);
  73. });
  74. },
  75. computed:{
  76. totalPrice(){
  77. let totalPrice = 0;
  78. for(let cartItem of this.cartArr){
  79. totalPrice += cartItem.food.foodPrice*cartItem.quantity;
  80. }
  81. totalPrice += this.business.deliveryPrice;
  82. return totalPrice;
  83. }
  84. },
  85. filters:{
  86. sexFilter(value){
  87. return value==1?'先生':'女士';
  88. }
  89. },
  90. methods:{
  91. toUserAddress(){
  92. this.$router.push({path:'/userAddress',query:{businessId:this.businessId}});
  93. },
  94. toPayment(){
  95. if(this.deliveryaddress==null){
  96. alert('请选择送货地址!');
  97. return;
  98. }
  99. //创建订单
  100. this.$axios.post('OrdersController/createOrders',this.$qs.stringify({
  101. userId:this.user.userId,
  102. businessId:this.businessId,
  103. daId:this.deliveryaddress.daId,
  104. orderTotal:this.totalPrice
  105. })).then(response=>{
  106. let orderId = response.data;
  107. if(orderId>0){
  108. this.$router.push({path:'/payment',query:{orderId:orderId}});
  109. }else{
  110. alert('创建订单失败!');
  111. }
  112. }).catch(error=>{
  113. console.error(error);
  114. });
  115. }
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. /****************** 总容器 ******************/
  121. .wrapper {
  122. width: 100%;
  123. height: 100%;
  124. }
  125. /****************** header部分 ******************/
  126. .wrapper header {
  127. width: 100%;
  128. height: 12vw;
  129. background-color: #0097FF;
  130. color: #fff;
  131. font-size: 4.8vw;
  132. position: fixed;
  133. left: 0;
  134. top: 0;
  135. z-index: 1000;
  136. display: flex;
  137. justify-content: center;
  138. align-items: center;
  139. }
  140. /****************** 订单信息部分 ******************/
  141. .wrapper .order-info {
  142. /*注意这里,不设置高,靠内容撑开。因为地址有可能折行*/
  143. width: 100%;
  144. margin-top: 12vw;
  145. background-color: #0097EF;
  146. box-sizing: border-box;
  147. padding: 2vw;
  148. color: #fff;
  149. }
  150. .wrapper .order-info h5 {
  151. font-size: 3vw;
  152. font-weight: 300;
  153. }
  154. .wrapper .order-info .order-info-address {
  155. width: 100%;
  156. display: flex;
  157. justify-content: space-between;
  158. align-items: center;
  159. font-weight: 700;
  160. user-select: none;
  161. cursor: pointer;
  162. margin: 1vw 0;
  163. }
  164. .wrapper .order-info .order-info-address p {
  165. width: 90%;
  166. font-size: 5vw;
  167. }
  168. .wrapper .order-info .order-info-address i {
  169. font-size: 6vw;
  170. }
  171. .wrapper .order-info p {
  172. font-size: 3vw;
  173. }
  174. .wrapper h3 {
  175. box-sizing: border-box;
  176. padding: 3vw;
  177. font-size: 4vw;
  178. color: #666;
  179. border-bottom: solid 1px #DDD;
  180. }
  181. /****************** 订单明细部分 ******************/
  182. .wrapper .order-detailed {
  183. width: 100%;
  184. }
  185. .wrapper .order-detailed li {
  186. width: 100%;
  187. height: 16vw;
  188. box-sizing: border-box;
  189. padding: 3vw;
  190. color: #666;
  191. display: flex;
  192. justify-content: space-between;
  193. align-items: center;
  194. }
  195. .wrapper .order-detailed li .order-detailed-left {
  196. display: flex;
  197. align-items: center;
  198. }
  199. .wrapper .order-detailed li .order-detailed-left img {
  200. width: 10vw;
  201. height: 10vw;
  202. }
  203. .wrapper .order-detailed li .order-detailed-left p {
  204. font-size: 3.5vw;
  205. margin-left: 3vw;
  206. }
  207. .wrapper .order-detailed li p {
  208. font-size: 3.5vw;
  209. }
  210. .wrapper .order-deliveryfee {
  211. width: 100%;
  212. height: 16vw;
  213. box-sizing: border-box;
  214. padding: 3vw;
  215. color: #666;
  216. display: flex;
  217. justify-content: space-between;
  218. align-items: center;
  219. font-size: 3.5vw;
  220. }
  221. /****************** 订单合计部分 ******************/
  222. .wrapper .total {
  223. width: 100%;
  224. height: 14vw;
  225. position: fixed;
  226. left: 0;
  227. bottom: 0;
  228. display: flex;
  229. }
  230. .wrapper .total .total-left {
  231. flex: 2;
  232. background-color: #505051;
  233. color: #fff;
  234. font-size: 4.5vw;
  235. font-weight: 700;
  236. user-select: none;
  237. display: flex;
  238. justify-content: center;
  239. align-items: center;
  240. }
  241. .wrapper .total .total-right {
  242. flex: 1;
  243. background-color: #38CA73;
  244. color: #fff;
  245. font-size: 4.5vw;
  246. font-weight: 700;
  247. user-select: none;
  248. cursor: pointer;
  249. display: flex;
  250. justify-content: center;
  251. align-items: center;
  252. }
  253. </style>

5.1.5.Payment组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>在线支付</p>
  6. </header>
  7. <!-- 订单信息部分 -->
  8. <h3>订单信息:</h3>
  9. <div class="order-info">
  10. <p>
  11. {{orders.business.businessName}}
  12. <i class="fa fa-caret-down" @click="detailetShow"></i>
  13. </p>
  14. <p>&#165;{{orders.orderTotal}}</p>
  15. </div>
  16. <!-- 订单明细部分 -->
  17. <ul class="order-detailet" v-show="isShowDetailet">
  18. <li v-for="item in orders.list">
  19. <p>{{item.food.foodName}} x {{item.quantity}}</p>
  20. <p>&#165;{{item.food.foodPrice*item.quantity}}</p>
  21. </li>
  22. <li>
  23. <p>配送费</p>
  24. <p>&#165;{{orders.business.deliveryPrice}}</p>
  25. </li>
  26. </ul>
  27. <!-- 支付方式部分 -->
  28. <ul class="payment-type">
  29. <li>
  30. <img src="../assets/alipay.png">
  31. <i class="fa fa-check-circle"></i>
  32. </li>
  33. <li>
  34. <img src="../assets/wechat.png">
  35. </li>
  36. </ul>
  37. <div class="payment-button">
  38. <button>确认支付</button>
  39. </div>
  40. <!-- 底部菜单部分 -->
  41. <Footer></Footer>
  42. </div>
  43. </template>
  44. <script>
  45. import Footer from '../components/Footer.vue';
  46. export default {
  47. name: 'Payment',
  48. data(){
  49. return {
  50. orderId:this.$route.query.orderId,
  51. orders:{
  52. business:{}
  53. },
  54. isShowDetailet:false
  55. }
  56. },
  57. created() {
  58. this.$axios.post('OrdersController/getOrdersById',this.$qs.stringify({
  59. orderId:this.orderId
  60. })).then(response=>{
  61. this.orders = response.data;
  62. }).catch(error=>{
  63. console.error(error);
  64. });
  65. },
  66. mounted() {
  67. //这里的代码是实现:一旦路由到在线支付组件,就不能回到订单确认组件。
  68. //先将当前url添加到history对象中
  69. history.pushState(null,null,document.URL);
  70. //popstate事件能够监听history对象的变化
  71. window.onpopstate = () => {
  72. this.$router.push({path:'/index'});
  73. }
  74. },
  75. destroyed() {
  76. window.onpopstate = null;
  77. },
  78. methods:{
  79. detailetShow(){
  80. this.isShowDetailet = !this.isShowDetailet;
  81. }
  82. },
  83. components: {
  84. Footer
  85. }
  86. }
  87. </script>
  88. <style scoped>
  89. /****************** 总容器 ******************/
  90. .wrapper {
  91. width: 100%;
  92. height: 100%;
  93. }
  94. /****************** header部分 ******************/
  95. .wrapper header {
  96. width: 100%;
  97. height: 12vw;
  98. background-color: #0097FF;
  99. color: #fff;
  100. font-size: 4.8vw;
  101. position: fixed;
  102. left: 0;
  103. top: 0;
  104. z-index: 1000;
  105. display: flex;
  106. justify-content: center;
  107. align-items: center;
  108. }
  109. /****************** 订单信息部分 ******************/
  110. .wrapper h3 {
  111. margin-top: 12vw;
  112. box-sizing: border-box;
  113. padding: 4vw 4vw 0;
  114. font-size: 4vw;
  115. font-weight: 300;
  116. color: #999;
  117. }
  118. .wrapper .order-info {
  119. box-sizing: border-box;
  120. padding: 4vw;
  121. font-size: 4vw;
  122. color: #666;
  123. display: flex;
  124. justify-content: space-between;
  125. align-items: center;
  126. }
  127. .wrapper .order-info p:last-child {
  128. color: orangered;
  129. }
  130. /****************** 订单明细部分 ******************/
  131. .wrapper .order-detailet {
  132. width: 100%;
  133. }
  134. .wrapper .order-detailet li {
  135. width: 100%;
  136. box-sizing: border-box;
  137. padding: 1vw 4vw;
  138. display: flex;
  139. justify-content: space-between;
  140. align-items: center;
  141. }
  142. .wrapper .order-detailet li p {
  143. font-size: 3vw;
  144. color: #666;
  145. }
  146. /****************** 支付方式部分 ******************/
  147. .wrapper .payment-type {
  148. width: 100%;
  149. }
  150. .wrapper .payment-type li {
  151. width: 100%;
  152. box-sizing: border-box;
  153. padding: 4vw;
  154. display: flex;
  155. justify-content: space-between;
  156. align-items: center;
  157. }
  158. .wrapper .payment-type li img {
  159. width: 33vw;
  160. height: 8.9vw;
  161. }
  162. .wrapper .payment-type li .fa-check-circle {
  163. font-size: 5vw;
  164. color: #38CA73;
  165. }
  166. .wrapper .payment-button {
  167. width: 100%;
  168. box-sizing: border-box;
  169. padding: 4vw;
  170. }
  171. .wrapper .payment-button button {
  172. width: 100%;
  173. height: 10vw;
  174. border: none;
  175. /*去掉外轮廓线*/
  176. outline: none;
  177. border-radius: 4px;
  178. background-color: #38CA73;
  179. color: #fff;
  180. }
  181. </style>

5.1.6.UserAddress组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>地址管理</p>
  6. </header>
  7. <!-- 地址列表部分 -->
  8. <ul class="addresslist">
  9. <li v-for="item in deliveryAddressArr">
  10. <div class="addresslist-left" @click="setDeliveryAddress(item)">
  11. <h3>{{item.contactName}}{{item.contactSex | sexFilter}} {{item.contactTel}}</h3>
  12. <p>{{item.address}}</p>
  13. </div>
  14. <div class="addresslist-right">
  15. <i class="fa fa-edit" @click="editUserAddress(item.daId)"></i>
  16. <i class="fa fa-remove" @click="removeUserAddress(item.daId)"></i>
  17. </div>
  18. </li>
  19. </ul>
  20. <!-- 新增地址部分 -->
  21. <div class="addbtn" @click="toAddUserAddress">
  22. <i class="fa fa-plus-circle"></i>
  23. <p>新增收货地址</p>
  24. </div>
  25. <!-- 底部菜单部分 -->
  26. <Footer></Footer>
  27. </div>
  28. </template>
  29. <script>
  30. import Footer from '../components/Footer.vue';
  31. export default{
  32. name:'UserAddress',
  33. data(){
  34. return {
  35. businessId:this.$route.query.businessId,
  36. user:{},
  37. deliveryAddressArr:[]
  38. }
  39. },
  40. created() {
  41. this.user = this.$getSessionStorage('user');
  42. this.listDeliveryAddressByUserId();
  43. },
  44. components:{
  45. Footer
  46. },
  47. filters:{
  48. sexFilter(value){
  49. return value==1?'先生':'女士';
  50. }
  51. },
  52. methods:{
  53. listDeliveryAddressByUserId(){
  54. //查询送货地址
  55. this.$axios.post('DeliveryAddressController/listDeliveryAddressByUserId',this.$qs.stringify({
  56. userId:this.user.userId
  57. })).then(response=>{
  58. this.deliveryAddressArr = response.data;
  59. }).catch(error=>{
  60. console.error(error);
  61. });
  62. },
  63. setDeliveryAddress(deliveryAddress){
  64. //把用户选择的默认送货地址存储到localStorage中
  65. this.$setLocalStorage(this.user.userId,deliveryAddress);
  66. this.$router.push({path:'/orders',query:{businessId:this.businessId}});
  67. },
  68. toAddUserAddress(){
  69. this.$router.push({path:'/addUserAddress',query:{businessId:this.businessId}});
  70. },
  71. editUserAddress(daId){
  72. this.$router.push({path:'/editUserAddress',query:{businessId:this.businessId,daId:daId}});
  73. },
  74. removeUserAddress(daId){
  75. if(!confirm('确认要删除此送货地址吗?')){
  76. return;
  77. }
  78. this.$axios.post('DeliveryAddressController/removeDeliveryAddress',this.$qs.stringify({
  79. daId:daId
  80. })).then(response=>{
  81. if(response.data>0){
  82. let deliveryAddress = this.$getLocalStorage(this.user.userId);
  83. if(deliveryAddress!=null&&deliveryAddress.daId==daId){
  84. this.$removeLocalStorage(this.user.userId);
  85. }
  86. this.listDeliveryAddressByUserId();
  87. }else{
  88. alert('删除地址失败!');
  89. }
  90. }).catch(error=>{
  91. console.error(error);
  92. });
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped>
  98. /*************** 总容器 ***************/
  99. .wrapper {
  100. width: 100%;
  101. height: 100%;
  102. background-color: #F5F5F5;
  103. }
  104. /*************** header ***************/
  105. .wrapper header {
  106. width: 100%;
  107. height: 12vw;
  108. background-color: #0097FF;
  109. display: flex;
  110. justify-content: space-around;
  111. align-items: center;
  112. color: #fff;
  113. font-size: 4.8vw;
  114. position: fixed;
  115. left: 0;
  116. top: 0;
  117. /*保证在最上层*/
  118. z-index: 1000;
  119. }
  120. /*************** addresslist ***************/
  121. .wrapper .addresslist {
  122. width: 100%;
  123. margin-top: 12vw;
  124. background-color: #fff;
  125. }
  126. .wrapper .addresslist li {
  127. width: 100%;
  128. box-sizing: border-box;
  129. border-bottom: solid 1px #DDD;
  130. padding: 3vw;
  131. display: flex;
  132. }
  133. .wrapper .addresslist li .addresslist-left {
  134. flex: 5;
  135. /*左边这块区域是可以点击的*/
  136. user-select: none;
  137. cursor: pointer;
  138. }
  139. .wrapper .addresslist li .addresslist-left h3 {
  140. font-size: 4.6vw;
  141. font-weight: 300;
  142. color: #666;
  143. }
  144. .wrapper .addresslist li .addresslist-left p {
  145. font-size: 4vw;
  146. color: #666;
  147. }
  148. .wrapper .addresslist li .addresslist-right {
  149. flex: 1;
  150. font-size: 5.6vw;
  151. color: #999;
  152. cursor: pointer;
  153. display: flex;
  154. justify-content: space-around;
  155. align-items: center;
  156. }
  157. /*************** 新增地址部分 ***************/
  158. .wrapper .addbtn {
  159. width: 100%;
  160. height: 14vw;
  161. border-top: solid 1px #DDD;
  162. border-bottom: solid 1px #DDD;
  163. background-color: #fff;
  164. margin-top: 4vw;
  165. display: flex;
  166. justify-content: center;
  167. align-items: center;
  168. font-size: 4.5vw;
  169. color: #0097FF;
  170. user-select: none;
  171. cursor: pointer;
  172. }
  173. .wrapper .addbtn p {
  174. margin-left: 2vw;
  175. }
  176. </style>

5.1.7.AddUserAddress组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>新增送货地址</p>
  6. </header>
  7. <!-- 表单部分 -->
  8. <ul class="form-box">
  9. <li>
  10. <div class="title">
  11. 联系人:
  12. </div>
  13. <div class="content">
  14. <input type="text" v-model="deliveryAddress.contactName" placeholder="联系人姓名">
  15. </div>
  16. </li>
  17. <li>
  18. <div class="title">
  19. 性别:
  20. </div>
  21. <div class="content" style="font-size: 3vw;">
  22. <input type="radio" v-model="deliveryAddress.contactSex" value="1" style="width:6vw;height:3.2vw;">
  23. <input type="radio" v-model="deliveryAddress.contactSex" value="0" style="width:6vw;height:3.2vw;">
  24. </div>
  25. </li>
  26. <li>
  27. <div class="title">
  28. 电话:
  29. </div>
  30. <div class="content">
  31. <input type="tel" v-model="deliveryAddress.contactTel" placeholder="电话">
  32. </div>
  33. </li>
  34. <li>
  35. <div class="title">
  36. 收货地址:
  37. </div>
  38. <div class="content">
  39. <input type="text" v-model="deliveryAddress.address" placeholder="收货地址">
  40. </div>
  41. </li>
  42. </ul>
  43. <div class="button-add">
  44. <button @click="addUserAddress">保存</button>
  45. </div>
  46. <!-- 底部菜单部分 -->
  47. <Footer></Footer>
  48. </div>
  49. </template>
  50. <script>
  51. import Footer from '../components/Footer.vue';
  52. export default {
  53. name: 'AddUserAddress',
  54. data() {
  55. return {
  56. businessId:this.$route.query.businessId,
  57. user:{},
  58. deliveryAddress:{
  59. contactName:'',
  60. contactSex:1,
  61. contactTel:'',
  62. address:''
  63. }
  64. }
  65. },
  66. created() {
  67. this.user = this.$getSessionStorage('user');
  68. },
  69. components: {
  70. Footer
  71. },
  72. methods: {
  73. addUserAddress(){
  74. if(this.deliveryAddress.contactName==''){
  75. alert('联系人姓名不能为空!');
  76. return;
  77. }
  78. if(this.deliveryAddress.contactTel==''){
  79. alert('联系人电话不能为空!');
  80. return;
  81. }
  82. if(this.deliveryAddress.address==''){
  83. alert('联系人地址不能为空!');
  84. return;
  85. }
  86. this.deliveryAddress.userId = this.user.userId;
  87. this.$axios.post('DeliveryAddressController/saveDeliveryAddress', this.$qs.stringify(
  88. this.deliveryAddress
  89. )).then(response => {
  90. if(response.data>0){
  91. this.$router.push({path:'/userAddress',query:{businessId:this.businessId}});
  92. }else{
  93. alert('新增地址失败!');
  94. }
  95. }).catch(error => {
  96. console.error(error);
  97. });
  98. }
  99. }
  100. }
  101. </script>
  102. <style scoped>
  103. /*************** 总容器 ***************/
  104. .wrapper {
  105. width: 100%;
  106. height: 100%;
  107. }
  108. /*************** header ***************/
  109. .wrapper header {
  110. width: 100%;
  111. height: 12vw;
  112. background-color: #0097FF;
  113. display: flex;
  114. justify-content: space-around;
  115. align-items: center;
  116. color: #fff;
  117. font-size: 4.8vw;
  118. position: fixed;
  119. left: 0;
  120. top: 0;
  121. /*保证在最上层*/
  122. z-index: 1000;
  123. }
  124. /*************** (表单信息) ***************/
  125. .wrapper .form-box {
  126. width: 100%;
  127. margin-top: 12vw;
  128. }
  129. .wrapper .form-box li {
  130. box-sizing: border-box;
  131. padding: 4vw 3vw 0vw 3vw;
  132. display: flex;
  133. }
  134. .wrapper .form-box li .title {
  135. flex: 0 0 18vw;
  136. font-size: 3vw;
  137. font-weight: 700;
  138. color: #666;
  139. }
  140. .wrapper .form-box li .content {
  141. flex: 1;
  142. display: flex;
  143. align-items: center;
  144. }
  145. .wrapper .form-box li .content input {
  146. border: none;
  147. outline: none;
  148. width: 100%;
  149. height: 4vw;
  150. font-size: 3vw;
  151. }
  152. .wrapper .button-add {
  153. box-sizing: border-box;
  154. padding: 4vw 3vw 0vw 3vw;
  155. }
  156. .wrapper .button-add button {
  157. width: 100%;
  158. height: 10vw;
  159. font-size: 3.8vw;
  160. font-weight: 700;
  161. border: none;
  162. outline: none;
  163. border-radius: 4px;
  164. color: #fff;
  165. background-color: #38CA73;
  166. }
  167. </style>

5.1.8.EditUserAddress组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>编辑送货地址</p>
  6. </header>
  7. <!-- 表单部分 -->
  8. <ul class="form-box">
  9. <li>
  10. <div class="title">
  11. 联系人:
  12. </div>
  13. <div class="content">
  14. <input type="text" v-model="deliveryAddress.contactName" placeholder="联系人姓名">
  15. </div>
  16. </li>
  17. <li>
  18. <div class="title">
  19. 性别:
  20. </div>
  21. <div class="content" style="font-size: 3vw;">
  22. <input type="radio" v-model="deliveryAddress.contactSex" value="1" style="width:6vw;height:3.2vw;" checked>
  23. <input type="radio" v-model="deliveryAddress.contactSex" value="0" style="width:6vw;height:3.2vw;">
  24. </div>
  25. </li>
  26. <li>
  27. <div class="title">
  28. 电话:
  29. </div>
  30. <div class="content">
  31. <input type="tel" v-model="deliveryAddress.contactTel" placeholder="电话">
  32. </div>
  33. </li>
  34. <li>
  35. <div class="title">
  36. 收货地址:
  37. </div>
  38. <div class="content">
  39. <input type="text" v-model="deliveryAddress.address" placeholder="收货地址">
  40. </div>
  41. </li>
  42. </ul>
  43. <div class="button-add">
  44. <button @click="editUserAddress">更新</button>
  45. </div>
  46. <!-- 底部菜单部分 -->
  47. <Footer></Footer>
  48. </div>
  49. </template>
  50. <script>
  51. import Footer from '../components/Footer.vue';
  52. export default {
  53. name: 'EditUserAddress',
  54. data() {
  55. return {
  56. businessId: this.$route.query.businessId,
  57. daId: this.$route.query.daId,
  58. user: {},
  59. deliveryAddress: {}
  60. }
  61. },
  62. created() {
  63. this.user = this.$getSessionStorage('user');
  64. this.$axios.post('DeliveryAddressController/getDeliveryAddressById', this.$qs.stringify({
  65. daId:this.daId
  66. })).then(response => {
  67. this.deliveryAddress = response.data;
  68. }).catch(error => {
  69. console.error(error);
  70. });
  71. },
  72. components: {
  73. Footer
  74. },
  75. methods: {
  76. editUserAddress() {
  77. if (this.deliveryAddress.contactName == '') {
  78. alert('联系人姓名不能为空!');
  79. return;
  80. }
  81. if (this.deliveryAddress.contactTel == '') {
  82. alert('联系人电话不能为空!');
  83. return;
  84. }
  85. if (this.deliveryAddress.address == '') {
  86. alert('联系人地址不能为空!');
  87. return;
  88. }
  89. this.$axios.post('DeliveryAddressController/updateDeliveryAddress', this.$qs.stringify(
  90. this.deliveryAddress
  91. )).then(response => {
  92. if (response.data > 0) {
  93. this.$router.push({
  94. path: '/userAddress',
  95. query: {
  96. businessId: this.businessId
  97. }
  98. });
  99. } else {
  100. alert('更新地址失败!');
  101. }
  102. }).catch(error => {
  103. console.error(error);
  104. });
  105. }
  106. }
  107. }
  108. </script>
  109. <style scoped>
  110. /*************** 总容器 ***************/
  111. .wrapper {
  112. width: 100%;
  113. height: 100%;
  114. }
  115. /*************** header ***************/
  116. .wrapper header {
  117. width: 100%;
  118. height: 12vw;
  119. background-color: #0097FF;
  120. display: flex;
  121. justify-content: space-around;
  122. align-items: center;
  123. color: #fff;
  124. font-size: 4.8vw;
  125. position: fixed;
  126. left: 0;
  127. top: 0;
  128. /*保证在最上层*/
  129. z-index: 1000;
  130. }
  131. /*************** (表单信息) ***************/
  132. .wrapper .form-box {
  133. width: 100%;
  134. margin-top: 12vw;
  135. }
  136. .wrapper .form-box li {
  137. box-sizing: border-box;
  138. padding: 4vw 3vw 0vw 3vw;
  139. display: flex;
  140. }
  141. .wrapper .form-box li .title {
  142. flex: 0 0 18vw;
  143. font-size: 3vw;
  144. font-weight: 700;
  145. color: #666;
  146. }
  147. .wrapper .form-box li .content {
  148. flex: 1;
  149. display: flex;
  150. align-items: center;
  151. }
  152. .wrapper .form-box li .content input {
  153. border: none;
  154. outline: none;
  155. width: 100%;
  156. height: 4vw;
  157. font-size: 3vw;
  158. }
  159. .wrapper .button-add {
  160. box-sizing: border-box;
  161. padding: 4vw 3vw 0vw 3vw;
  162. }
  163. .wrapper .button-add button {
  164. width: 100%;
  165. height: 10vw;
  166. font-size: 3.8vw;
  167. font-weight: 700;
  168. border: none;
  169. outline: none;
  170. border-radius: 4px;
  171. color: #fff;
  172. background-color: #38CA73;
  173. }
  174. </style>

5.1.9.OrderList组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>我的订单</p>
  6. </header>
  7. <!-- 订单列表部分 -->
  8. <h3>未支付订单信息:</h3>
  9. <ul class="order">
  10. <li v-for="item in orderArr" v-if="item.orderState==0">
  11. <div class="order-info">
  12. <p>
  13. {{item.business.businessName}}
  14. <i class="fa fa-caret-down" @click="detailetShow(item)"></i>
  15. </p>
  16. <div class="order-info-right">
  17. <p>&#165;{{item.orderTotal}}</p>
  18. <div class="order-info-right-icon">去支付</div>
  19. </div>
  20. </div>
  21. <ul class="order-detailet" v-show="item.isShowDetailet">
  22. <li v-for="odItem in item.list">
  23. <p>{{odItem.food.foodName}} x {{odItem.quantity}}</p>
  24. <p>&#165;{{odItem.food.foodPrice*odItem.quantity}}</p>
  25. </li>
  26. <li>
  27. <p>配送费</p>
  28. <p>&#165;{{item.business.deliveryPrice}}</p>
  29. </li>
  30. </ul>
  31. </li>
  32. </ul>
  33. <h3>已支付订单信息:</h3>
  34. <ul class="order">
  35. <li v-for="item in orderArr" v-if="item.orderState==1">
  36. <div class="order-info">
  37. <p>
  38. {{item.business.businessName}}
  39. <i class="fa fa-caret-down" @click="detailetShow(item)"></i>
  40. </p>
  41. <div class="order-info-right">
  42. <p>&#165;{{item.orderTotal}}</p>
  43. </div>
  44. </div>
  45. <ul class="order-detailet" v-show="item.isShowDetailet">
  46. <li v-for="odItem in item.list">
  47. <p>{{odItem.food.foodName}} x {{odItem.quantity}}</p>
  48. <p>&#165;{{odItem.food.foodPrice*odItem.quantity}}</p>
  49. </li>
  50. <li>
  51. <p>配送费</p>
  52. <p>&#165;{{item.business.deliveryPrice}}</p>
  53. </li>
  54. </ul>
  55. </li>
  56. </ul>
  57. <!-- 底部菜单部分 -->
  58. <Footer></Footer>
  59. </div>
  60. </template>
  61. <script>
  62. import Footer from '../components/Footer.vue';
  63. export default{
  64. name:'OrderList',
  65. data(){
  66. return {
  67. orderArr:[],
  68. user:{}
  69. }
  70. },
  71. created() {
  72. this.user = this.$getSessionStorage('user');
  73. this.$axios.post('OrdersController/listOrdersByUserId',this.$qs.stringify({
  74. userId:this.user.userId
  75. })).then(response=>{
  76. let result = response.data;
  77. for(let orders of result){
  78. orders.isShowDetailet = false;
  79. }
  80. this.orderArr = result;
  81. }).catch(error=>{
  82. console.error(error);
  83. });
  84. },
  85. methods:{
  86. detailetShow(orders){
  87. orders.isShowDetailet = !orders.isShowDetailet;
  88. }
  89. },
  90. components:{
  91. Footer
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. /****************** 总容器 ******************/
  97. .wrapper {
  98. width: 100%;
  99. height: 100%;
  100. }
  101. /****************** header部分 ******************/
  102. .wrapper header {
  103. width: 100%;
  104. height: 12vw;
  105. background-color: #0097FF;
  106. color: #fff;
  107. font-size: 4.8vw;
  108. position: fixed;
  109. left: 0;
  110. top: 0;
  111. z-index: 1000;
  112. display: flex;
  113. justify-content: center;
  114. align-items: center;
  115. }
  116. /****************** 历史订单列表部分 ******************/
  117. .wrapper h3 {
  118. margin-top: 12vw;
  119. box-sizing: border-box;
  120. padding: 4vw;
  121. font-size: 4vw;
  122. font-weight: 300;
  123. color: #999;
  124. }
  125. .wrapper .order {
  126. width: 100%;
  127. }
  128. .wrapper .order li {
  129. width: 100%;
  130. }
  131. .wrapper .order li .order-info {
  132. box-sizing: border-box;
  133. padding: 2vw 4vw;
  134. font-size: 4vw;
  135. color: #666;
  136. display: flex;
  137. justify-content: space-between;
  138. align-items: center;
  139. }
  140. .wrapper .order li .order-info .order-info-right {
  141. display: flex;
  142. }
  143. .wrapper .order li .order-info .order-info-right .order-info-right-icon {
  144. background-color: #f90;
  145. color: #fff;
  146. border-radius: 3px;
  147. margin-left: 2vw;
  148. user-select: none;
  149. cursor: pointer;
  150. }
  151. .wrapper .order li .order-detailet {
  152. width: 100%;
  153. }
  154. .wrapper .order li .order-detailet li {
  155. width: 100%;
  156. box-sizing: border-box;
  157. padding: 1vw 4vw;
  158. color: #666;
  159. font-size: 3vw;
  160. display: flex;
  161. justify-content: space-between;
  162. align-items: center;
  163. }
  164. </style>

5.1.10.Login组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>用户登陆</p>
  6. </header>
  7. <!-- 表单部分 -->
  8. <ul class="form-box">
  9. <li>
  10. <div class="title">
  11. 手机号码:
  12. </div>
  13. <div class="content">
  14. <input type="text" v-model="userId" placeholder="手机号码">
  15. </div>
  16. </li>
  17. <li>
  18. <div class="title">
  19. 密码:
  20. </div>
  21. <div class="content">
  22. <input type="password" v-model="password" placeholder="密码">
  23. </div>
  24. </li>
  25. </ul>
  26. <div class="button-login">
  27. <button @click="login">登陆</button>
  28. </div>
  29. <div class="button-register">
  30. <button @click="register">去注册</button>
  31. </div>
  32. <!-- 底部菜单部分 -->
  33. <Footer></Footer>
  34. </div>
  35. </template>
  36. <script>
  37. import Footer from '../components/Footer.vue';
  38. export default{
  39. name:'Login',
  40. data(){
  41. return {
  42. userId:'',
  43. password:''
  44. }
  45. },
  46. methods:{
  47. login(){
  48. if(this.userId==''){
  49. alert('手机号码不能为空!');
  50. return;
  51. }
  52. if(this.password==''){
  53. alert('密码不能为空!');
  54. return;
  55. }
  56. //登录请求
  57. this.$axios.post('UserController/getUserByIdByPass',this.$qs.stringify({
  58. userId:this.userId,
  59. password:this.password
  60. })).then(response=>{
  61. let user = response.data;
  62. if(user==null){
  63. alert('用户名或密码不正确!');
  64. }else{
  65. //sessionstorage有容量限制,为了防止数据溢出,所以不将userImg数据放入session中
  66. user.userImg = '';
  67. this.$setSessionStorage('user',user);
  68. this.$router.go(-1);
  69. }
  70. }).catch(error=>{
  71. console.error(error);
  72. });
  73. },
  74. register(){
  75. this.$router.push({path:'register'});
  76. }
  77. },
  78. components:{
  79. Footer
  80. }
  81. }
  82. </script>
  83. <style scoped>
  84. /****************** 总容器 ******************/
  85. .wrapper {
  86. width: 100%;
  87. height: 100%;
  88. }
  89. /****************** header部分 ******************/
  90. .wrapper header {
  91. width: 100%;
  92. height: 12vw;
  93. background-color: #0097FF;
  94. color: #fff;
  95. font-size: 4.8vw;
  96. position: fixed;
  97. left: 0;
  98. top: 0;
  99. z-index: 1000;
  100. display: flex;
  101. justify-content: center;
  102. align-items: center;
  103. }
  104. /****************** 表单部分 ******************/
  105. .wrapper .form-box {
  106. width: 100%;
  107. margin-top: 12vw;
  108. }
  109. .wrapper .form-box li {
  110. box-sizing: border-box;
  111. padding: 4vw 3vw 0 3vw;
  112. display: flex;
  113. align-items: center;
  114. }
  115. .wrapper .form-box li .title {
  116. flex: 0 0 18vw;
  117. font-size: 3vw;
  118. font-weight: 700;
  119. color: #666;
  120. }
  121. .wrapper .form-box li .content {
  122. flex: 1;
  123. }
  124. .wrapper .form-box li .content input {
  125. border: none;
  126. outline: none;
  127. width: 100%;
  128. height: 4vw;
  129. font-size: 3vw;
  130. }
  131. .wrapper .button-login {
  132. width: 100%;
  133. box-sizing: border-box;
  134. padding: 4vw 3vw 0 3vw;
  135. }
  136. .wrapper .button-login button {
  137. width: 100%;
  138. height: 10vw;
  139. font-size: 3.8vw;
  140. font-weight: 700;
  141. color: #fff;
  142. background-color: #38CA73;
  143. border-radius: 4px;
  144. border: none;
  145. outline: none;
  146. }
  147. .wrapper .button-register {
  148. width: 100%;
  149. box-sizing: border-box;
  150. padding: 4vw 3vw 0 3vw;
  151. }
  152. .wrapper .button-register button {
  153. width: 100%;
  154. height: 10vw;
  155. font-size: 3.8vw;
  156. font-weight: 700;
  157. /*与上面登陆按钮不同的只有颜色、背景色、边框不同*/
  158. color: #666;
  159. background-color: #EEE;
  160. border: solid 1px #DDD;
  161. border-radius: 4px;
  162. border: none;
  163. outline: none;
  164. }
  165. /****************** 底部菜单部分 ******************/
  166. .wrapper .footer {
  167. width: 100%;
  168. height: 14vw;
  169. border-top: solid 1px #DDD;
  170. background-color: #fff;
  171. position: fixed;
  172. left: 0;
  173. bottom: 0;
  174. display: flex;
  175. justify-content: space-around;
  176. align-items: center;
  177. }
  178. .wrapper .footer li {
  179. display: flex;
  180. flex-direction: column;
  181. justify-content: center;
  182. align-items: center;
  183. color: #999;
  184. user-select: none;
  185. cursor: pointer;
  186. }
  187. .wrapper .footer li p {
  188. font-size: 2.8vw;
  189. }
  190. .wrapper .footer li i {
  191. font-size: 5vw;
  192. }
  193. </style>

5.1.11.Register组件

  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <p>用户注册</p>
  6. </header>
  7. <!-- 表单部分 -->
  8. <ul class="form-box">
  9. <li>
  10. <div class="title">
  11. 手机号码:
  12. </div>
  13. <div class="content">
  14. <input type="text" @blur="checkUserId" v-model="user.userId" placeholder="手机号码">
  15. </div>
  16. </li>
  17. <li>
  18. <div class="title">
  19. 密码:
  20. </div>
  21. <div class="content">
  22. <input type="password" v-model="user.password" placeholder="密码">
  23. </div>
  24. </li>
  25. <li>
  26. <div class="title">
  27. 确认密码:
  28. </div>
  29. <div class="content">
  30. <input type="password" v-model="confirmPassword" placeholder="确认密码">
  31. </div>
  32. </li>
  33. <li>
  34. <div class="title">
  35. 用户名称:
  36. </div>
  37. <div class="content">
  38. <input type="text" v-model="user.userName" placeholder="用户名称">
  39. </div>
  40. </li>
  41. <li>
  42. <div class="title">
  43. 性别:
  44. </div>
  45. <div class="content" style="font-size: 3vw;">
  46. <input type="radio" v-model="user.userSex" value="1" style="width:6vw;height: 3.2vw;">
  47. <input type="radio" v-model="user.userSex" value="0" style="width:6vw;height: 3.2vw;">
  48. </div>
  49. </li>
  50. </ul>
  51. <div class="button-login">
  52. <button @click="register">注册</button>
  53. </div>
  54. <!-- 底部菜单部分 -->
  55. <Footer></Footer>
  56. </div>
  57. </template>
  58. <script>
  59. import Footer from '../components/Footer.vue';
  60. export default {
  61. name: 'Register',
  62. data() {
  63. return {
  64. user:{
  65. userId:'',
  66. password:'',
  67. userName:'',
  68. userSex:1
  69. },
  70. confirmPassword:''
  71. }
  72. },
  73. methods: {
  74. checkUserId(){
  75. this.$axios.post('UserController/getUserById', this.$qs.stringify({
  76. userId: this.user.userId,
  77. })).then(response => {
  78. if(response.data==1){
  79. this.user.userId = '';
  80. alert('此手机号码已存在!')
  81. }
  82. }).catch(error => {
  83. console.error(error);
  84. });
  85. },
  86. register() {
  87. if (this.user.userId == '') {
  88. alert('手机号码不能为空!');
  89. return;
  90. }
  91. if (this.user.password == '') {
  92. alert('密码不能为空!');
  93. return;
  94. }
  95. if (this.user.password != this.confirmPassword) {
  96. alert('两次输入的密码不一致!');
  97. return;
  98. }
  99. if (this.user.userName == '') {
  100. alert('用户名不能为空!');
  101. return;
  102. }
  103. //注册请求
  104. this.$axios.post('UserController/saveUser', this.$qs.stringify(
  105. this.user
  106. )).then(response => {
  107. if(response.data>0){
  108. alert('注册成功!');
  109. this.$router.go(-1);
  110. }else{
  111. alert('注册失败!');
  112. }
  113. }).catch(error => {
  114. console.error(error);
  115. });
  116. }
  117. },
  118. components: {
  119. Footer
  120. }
  121. }
  122. </script>
  123. <style scoped>
  124. /****************** 总容器 ******************/
  125. .wrapper {
  126. width: 100%;
  127. height: 100%;
  128. }
  129. /****************** header部分 ******************/
  130. .wrapper header {
  131. width: 100%;
  132. height: 12vw;
  133. background-color: #0097FF;
  134. color: #fff;
  135. font-size: 4.8vw;
  136. position: fixed;
  137. left: 0;
  138. top: 0;
  139. z-index: 1000;
  140. display: flex;
  141. justify-content: center;
  142. align-items: center;
  143. }
  144. /****************** 表单部分 ******************/
  145. .wrapper .form-box {
  146. width: 100%;
  147. margin-top: 12vw;
  148. }
  149. .wrapper .form-box li {
  150. box-sizing: border-box;
  151. padding: 4vw 3vw 0 3vw;
  152. display: flex;
  153. align-items: center;
  154. }
  155. .wrapper .form-box li .title {
  156. flex: 0 0 18vw;
  157. font-size: 3vw;
  158. font-weight: 700;
  159. color: #666;
  160. }
  161. .wrapper .form-box li .content {
  162. flex: 1;
  163. }
  164. .wrapper .form-box li .content input {
  165. border: none;
  166. outline: none;
  167. width: 100%;
  168. height: 4vw;
  169. font-size: 3vw;
  170. }
  171. .wrapper .button-login {
  172. width: 100%;
  173. box-sizing: border-box;
  174. padding: 4vw 3vw 0 3vw;
  175. }
  176. .wrapper .button-login button {
  177. width: 100%;
  178. height: 10vw;
  179. font-size: 3.8vw;
  180. font-weight: 700;
  181. color: #fff;
  182. background-color: #38CA73;
  183. border-radius: 4px;
  184. border: none;
  185. outline: none;
  186. }
  187. .wrapper .button-register {
  188. width: 100%;
  189. box-sizing: border-box;
  190. padding: 4vw 3vw 0 3vw;
  191. }
  192. .wrapper .button-register button {
  193. width: 100%;
  194. height: 10vw;
  195. font-size: 3.8vw;
  196. font-weight: 700;
  197. color: #666;
  198. background-color: #EEE;
  199. border-radius: 4px;
  200. border: none;
  201. outline: none;
  202. border: solid 1px #DDD;
  203. }
  204. </style>

5.1.12.Footer共通组件

  1. <template>
  2. <ul class="footer">
  3. <li @click="toIndex">
  4. <i class="fa fa-home"></i>
  5. <p>首页</p>
  6. </li>
  7. <li>
  8. <i class="fa fa-compass"></i>
  9. <p>发现</p>
  10. </li>
  11. <li @click="toOrderList">
  12. <i class="fa fa-file-text-o"></i>
  13. <p>订单</p>
  14. </li>
  15. <li>
  16. <i class="fa fa-user-o"></i>
  17. <p>我的</p>
  18. </li>
  19. </ul>
  20. </template>
  21. <script>
  22. export default{
  23. name:'Footer',
  24. methods:{
  25. toIndex(){
  26. this.$router.push({path:'/index'});
  27. },
  28. toOrderList(){
  29. this.$router.push({path:'/orderList'});
  30. }
  31. }
  32. }
  33. </script>
  34. <style>
  35. .wrapper .footer {
  36. width: 100%;
  37. height: 14vw;
  38. border-top: solid 1px #DDD;
  39. background-color: #fff;
  40. position: fixed;
  41. left: 0;
  42. bottom: 0;
  43. display: flex;
  44. justify-content: space-around;
  45. align-items: center;
  46. }
  47. .wrapper .footer li {
  48. /*li本身的尺寸完全由内容撑起*/
  49. display: flex;
  50. flex-direction: column;
  51. justify-content: center;
  52. align-items: center;
  53. color: #999;
  54. user-select: none;
  55. cursor: pointer;
  56. }
  57. .wrapper .footer li p {
  58. font-size: 2.8vw;
  59. }
  60. .wrapper .footer li i {
  61. font-size: 5vw;
  62. }
  63. </style>