index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <template>
  2. <view>
  3. <!-- index.wxml -->
  4. <view class="wrap">
  5. <view class="wrap_nr">
  6. <!-- 自提订单 展示门店信息 -->
  7. <view class="address_wrap" v-if="fare_type == 1 && store">
  8. <view class="address_l">
  9. <view class="address">
  10. <view class="address_name">{{ store.title }}</view>
  11. <view class="address_text">{{ store.address }}</view>
  12. </view>
  13. <view class="phone_wrap" v-if="userInfo.phone">
  14. <text class="label">预留电话</text>
  15. <text>{{ userInfo.phone }}</text>
  16. </view>
  17. </view>
  18. <view class="address_r">
  19. <view class="juli">距您{{ store.distance }}km</view>
  20. <image class="store_logo" :src="imgUrl + store.thumb"></image>
  21. </view>
  22. </view>
  23. <!-- 外卖订单 展示收货地址 -->
  24. <view class="address_wrap takeout" v-if="fare_type == 0 && checkedAddress" @tap="goSelectAddress">
  25. <view class="address_l">
  26. <view class="address">{{ checkedAddress.area_address + checkedAddress.address }}</view>
  27. <view class="phone_wrap">
  28. <text class="label">{{ checkedAddress.name }}</text>
  29. <text>{{ checkedAddress.phone }}</text>
  30. </view>
  31. </view>
  32. <van-icon name="arrow" />
  33. </view>
  34. <!-- 订单信息 -->
  35. <view class="order_wrap">
  36. <view class="order_t">
  37. <view class="order_shop">商品详情</view>
  38. <view class="order_way">{{ fare_type == 1 ? '自提订单' : '外卖' }}</view>
  39. </view>
  40. <image class="border_line" src="/static/statics/img/line_tu.png"></image>
  41. <view class="border_out">
  42. <view class="order_goods">
  43. <view class="goods_item" v-for="(item, index) in cartGoods" :key="index">
  44. <view class="goods_item_l">
  45. <image class="goods_tu" :src="imgUrl + item.good_thumb"></image>
  46. <view class="goods_info">
  47. <view class="goods_title">
  48. <text class="add_tag">加购商品</text>
  49. {{ item.good_title }}
  50. </view>
  51. <view class="goods_labels" v-if="item.good_specs_title">
  52. <view class="label">{{ item.good_specs_title }}</view>
  53. <!-- <view class="label">甜辣</view>
  54. <view class="label">鸭翅</view> -->
  55. </view>
  56. </view>
  57. </view>
  58. <view class="goods_item_r">
  59. <view class="goods_price" v-if="!item.add_good_rule_id">
  60. <text class="unit">¥</text>
  61. {{ is_member ? item.member_price : item.price }}
  62. </view>
  63. <view class="goods_price" v-if="item.add_good_rule_id">
  64. <text class="unit">¥</text>
  65. {{ item.add_price }}
  66. </view>
  67. <view class="goods_num">x{{ item.nums }}</view>
  68. </view>
  69. </view>
  70. </view>
  71. <!-- 外卖单才有配送费 -->
  72. <view class="delivery" v-if="fare_type == 0">
  73. <view class="delivery_l">配送费</view>
  74. <view class="delivery_r">
  75. <text class="unit">¥</text>
  76. {{ transprotFare }}
  77. </view>
  78. </view>
  79. <view class="heji_price">
  80. <!-- <text class="heji_item">已优惠<text class="price"><text class="unit">¥</text>10</text></text> -->
  81. <!-- {{ is_member ? totalMemberPrice : totalPrice }} -->
  82. <text class="heji_item total">
  83. 小计
  84. <text class="price">
  85. <text class="unit">¥</text>
  86. {{ totalPrice }}
  87. </text>
  88. </text>
  89. </view>
  90. </view>
  91. </view>
  92. <view class="remark">
  93. <view class="remark_t">备注</view>
  94. <view class="remark_nr">
  95. <van-field :value="user_mark" placeholder="口味、偏好等要求" :border="false" type="textarea" :maxlength="50" show-word-limit @input="getUserMark" />
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. <view class="bottom">
  101. <view class="total_price">
  102. <text class="price">
  103. <text class="unit">¥</text>
  104. {{ totalPrice }}
  105. </text>
  106. </view>
  107. <view class="btn_tijiao" @tap="goCreateOrder">提交订单</view>
  108. </view>
  109. </view>
  110. </template>
  111. <script>
  112. // index.js
  113. let myPro = require('../../utils/wxRequest.js');
  114. let util = require('../../utils/util.js');
  115. export default {
  116. data() {
  117. return {
  118. imgUrl: getApp().globalData.imgUrl,
  119. fare_type: 1,
  120. // 0外卖 1自提 默认自提
  121. transprotFare: 0,
  122. // 配送费
  123. userInfo: null,
  124. forbidden: null,
  125. // 1不允许下单
  126. store: null,
  127. // 是否为会员
  128. is_member: 0,
  129. checkedAddress: {
  130. area_address: '',
  131. address: '',
  132. name: '',
  133. phone: ''
  134. },
  135. cartGoods: '',
  136. totalPrice: '',
  137. totalNums: '',
  138. user_mark: ''
  139. };
  140. },
  141. onLoad: function (options) {
  142. // Do some initialize when page load.
  143. let that = this;
  144. that.setData({
  145. userInfo: getApp().globalData.userInfo
  146. });
  147. },
  148. onShow: function () {
  149. // Do something when page show.
  150. let that = this;
  151. that.setData({
  152. is_member: getApp().globalData.is_member
  153. }); // 清掉备注
  154. uni.removeStorageSync('user_mark'); // 店铺
  155. if (uni.getStorageSync('store')) {
  156. that.setData({
  157. store: JSON.parse(uni.getStorageSync('store'))
  158. });
  159. }
  160. that.getCreatelist();
  161. },
  162. onReady: function () {
  163. // Do something when page ready.
  164. },
  165. onHide: function () {
  166. // Do something when page hide.
  167. },
  168. onUnload: function () {
  169. // Do something when page close.
  170. },
  171. onPullDownRefresh: function () {
  172. // Do something when pull down.
  173. },
  174. onReachBottom: function () {
  175. // Do something when page reach bottom.
  176. },
  177. onPageScroll: function () {
  178. // Do something when page scroll
  179. },
  180. onResize: function () {
  181. // Do something when page resize
  182. },
  183. methods: {
  184. // 获取购物车商品及配送费
  185. getCreatelist() {
  186. let that = this;
  187. let params = {}; // 获取配送方式
  188. if (uni.getStorageSync('fare_type')) {
  189. let fare_type = uni.getStorageSync('fare_type');
  190. params.fare_type = fare_type;
  191. that.setData({
  192. fare_type: fare_type
  193. });
  194. } // 获取收货地址
  195. if (that.fare_type != 1) {
  196. if (uni.getStorageSync('checkedAddress')) {
  197. let checkedAddress = JSON.parse(uni.getStorageSync('checkedAddress'));
  198. that.setData({
  199. checkedAddress: checkedAddress
  200. });
  201. params.address_id = checkedAddress.id;
  202. }
  203. } // console.log('params',params);
  204. myPro
  205. .wxRequest('user/v3/order/createlist', 'GET', params)
  206. .then((res) => {
  207. that.setData({
  208. cartGoods: res.result.cartsList,
  209. transprotFare: res.result.orderInfo.delivery_fee,
  210. totalPrice: res.result.orderInfo.pay_price
  211. });
  212. })
  213. .catch((err) => {
  214. console.log('报错信息', err);
  215. uni.showToast({
  216. title: err,
  217. icon: 'none'
  218. });
  219. });
  220. },
  221. // 获取购物车商品
  222. getCartsList() {
  223. let that = this;
  224. let params = {};
  225. myPro
  226. .wxRequest('user/v3/carts/list', 'GET', params)
  227. .then((res) => {
  228. // 已加购商品
  229. let list = res.result.list;
  230. that.setData({
  231. cartGoods: list,
  232. totalPrice: res.result.money,
  233. totalNums: res.result.total_num
  234. }); // 计算价格和数量
  235. that.computedGoods();
  236. })
  237. .catch((err) => {
  238. console.log('报错信息', err);
  239. uni.showToast({
  240. title: err,
  241. icon: 'none'
  242. });
  243. });
  244. },
  245. // 计算运费(店铺与收获地址的距离)
  246. getTransportFare() {
  247. let that = this;
  248. let params = {
  249. lat: that.checkedAddress.lat,
  250. lng: that.checkedAddress.lnt,
  251. // lnt没写错
  252. store_id: that.store.id
  253. };
  254. uni.request({
  255. method: 'GET',
  256. url: getApp().globalData.api + 'api/common/store/distance',
  257. data: params,
  258. success: function (res) {
  259. let data = res.data;
  260. if (data.code == 200) {
  261. that.setData({
  262. forbidden: null,
  263. transprotFare: data.result.delivery_fee
  264. }); // 计算总费用
  265. that.computedGoods();
  266. } else if (data.code == 400) {
  267. // 约定400 为超出配送范围
  268. uni.showToast({
  269. title: data.msg,
  270. icon: 'none'
  271. });
  272. that.setData({
  273. transprotFare: data.result.delivery_fee
  274. }); // 计算总费用 但不允许下单
  275. that.computedGoods();
  276. that.setData({
  277. forbidden: 1
  278. });
  279. } else {
  280. uni.showToast({
  281. title: data.msg,
  282. icon: 'none'
  283. });
  284. }
  285. },
  286. fail: function (res) {
  287. console.log('报错', res);
  288. }
  289. });
  290. },
  291. // 计算费用
  292. computedGoods() {
  293. let that = this; // 商品的总计数量和总价后台直接返回,但配送费得算上
  294. let totalPrice = that.totalPrice; // 加上配送费
  295. if (that.transprotFare) {
  296. // console.log('配送费',that.data.transprotFare)
  297. totalPrice += parseFloat(that.transprotFare); // 返回的可能是字符串
  298. }
  299. that.setData({
  300. totalPrice: totalPrice
  301. });
  302. },
  303. // 输入的备注信息
  304. getUserMark(event) {
  305. // console.log(event.detail);
  306. let that = this;
  307. uni.setStorage({
  308. key: 'user_mark',
  309. data: event.detail
  310. });
  311. },
  312. // 进创建订单页
  313. goCreateOrder(event) {
  314. let that = this;
  315. if (that.forbidden) {
  316. uni.showToast({
  317. title: '超出配送范围,请更换地址',
  318. icon: 'none'
  319. });
  320. } else {
  321. let url = '';
  322. if (that.fare_type == 0) {
  323. url = '/pages/pay-order/index?fare_type=' + that.fare_type + '&address_id=' + that.checkedAddress.id;
  324. } else {
  325. url = '/pages/pay-order/index?fare_type=' + that.fare_type;
  326. }
  327. uni.redirectTo({
  328. url: url
  329. });
  330. }
  331. },
  332. // 更改配送地址
  333. goSelectAddress() {
  334. let that = this;
  335. uni.navigateTo({
  336. url: '/pages/user/address/list/index?is_back=1'
  337. });
  338. }
  339. }
  340. };
  341. </script>
  342. <style>
  343. /**index.wxss**/
  344. .wrap {
  345. min-height: 100vh;
  346. background: #f6f6f6;
  347. padding-bottom: 100rpx;
  348. }
  349. .wrap_nr {
  350. padding: 20rpx 30rpx 100rpx;
  351. }
  352. .address_wrap {
  353. width: 690rpx;
  354. padding: 30rpx 30rpx 50rpx;
  355. background: #ffffff;
  356. border-radius: 5rpx;
  357. display: flex;
  358. align-items: center;
  359. justify-content: space-between;
  360. font-size: 28rpx;
  361. color: #0c0c0c;
  362. position: relative;
  363. }
  364. .address_wrap .address_l {
  365. /* width: 476rpx; */
  366. flex: 1;
  367. }
  368. .address_l .address_text {
  369. font-size: 26rpx;
  370. color: #666666;
  371. padding-top: 10rpx;
  372. }
  373. .phone_wrap {
  374. display: flex;
  375. align-items: center;
  376. padding-top: 24rpx;
  377. }
  378. .takeout .phone_wrap {
  379. color: #666666;
  380. }
  381. .phone_wrap .label {
  382. padding-right: 10rpx;
  383. }
  384. .phone_wrap .icon_edit {
  385. /* width: 23rpx;
  386. height: 23rpx; */
  387. margin-left: 15rpx;
  388. }
  389. .address_wrap .address_r {
  390. /* flex: 1; */
  391. padding-left: 20rpx;
  392. display: flex;
  393. flex-direction: column;
  394. align-items: center;
  395. }
  396. .address_r .juli {
  397. font-size: 24rpx;
  398. color: #666666;
  399. padding: 4rpx 10rpx;
  400. background: #ffffff;
  401. box-shadow: 0rpx 1rpx 10rpx 0rpx rgba(0, 0, 0, 0.1);
  402. border-radius: 14rpx;
  403. position: relative;
  404. }
  405. .address_r .juli::after {
  406. content: '';
  407. display: block;
  408. position: absolute;
  409. bottom: -22rpx;
  410. left: 50%;
  411. width: 0rpx;
  412. height: 0rpx;
  413. border: 12rpx solid transparent;
  414. border-top: 12rpx solid #ffffff;
  415. }
  416. .address_r .store_logo {
  417. width: 60rpx;
  418. height: 60rpx;
  419. margin-top: 20rpx;
  420. }
  421. .address_wrap .line {
  422. position: absolute;
  423. bottom: 0;
  424. left: 0;
  425. width: 690rpx;
  426. height: 20rpx;
  427. border-radius: 0 0 5rpx 5rpx;
  428. background-repeat: repeat-x;
  429. background-size: 18rpx 30rpx;
  430. }
  431. /* 订单商品 */
  432. .order_wrap {
  433. width: 690rpx;
  434. /* padding: 0 30rpx; */
  435. margin: 20rpx auto 0;
  436. /* background: #FFFFFF; */
  437. border-radius: 5rpx;
  438. }
  439. .order_wrap .order_t {
  440. padding: 30rpx;
  441. font-size: 30rpx;
  442. color: #080808;
  443. background: #ffffff;
  444. display: flex;
  445. align-items: center;
  446. justify-content: space-between;
  447. }
  448. .order_wrap .border_line {
  449. width: 690rpx;
  450. height: 30rpx;
  451. display: block;
  452. }
  453. .order_wrap .order_t .order_shop {
  454. width: 500rpx;
  455. }
  456. .order_wrap .order_t .order_way {
  457. padding: 5rpx 10rpx;
  458. background: #295c56;
  459. border-radius: 5rpx;
  460. font-size: 22rpx;
  461. color: #ffffff;
  462. display: flex;
  463. align-items: center;
  464. justify-content: center;
  465. }
  466. .order_wrap .border_out {
  467. padding: 0 30rpx;
  468. background: #ffffff;
  469. }
  470. .order_wrap .delivery {
  471. padding: 0 0 30rpx;
  472. display: flex;
  473. align-items: center;
  474. justify-content: space-between;
  475. border-bottom: 1rpx dashed rgba(0, 0, 0, 0.12);
  476. font-size: 30rpx;
  477. color: #000000;
  478. }
  479. .order_wrap .delivery .delivery_r {
  480. font-size: 34rpx;
  481. color: #080808;
  482. }
  483. .order_wrap .delivery .delivery_r .unit {
  484. font-size: 22rpx;
  485. }
  486. .order_wrap .heji_price {
  487. padding: 40rpx 0 30rpx;
  488. text-align: right;
  489. font-size: 26rpx;
  490. color: #000000;
  491. }
  492. .order_wrap .heji_price .price {
  493. font-size: 28rpx;
  494. color: #333333;
  495. padding-left: 16rpx;
  496. font-weight: bold;
  497. }
  498. .order_wrap .heji_price .price .unit {
  499. font-size: 22rpx;
  500. }
  501. .order_wrap .heji_item.total {
  502. padding-left: 28rpx;
  503. }
  504. .order_wrap .heji_item.total .price {
  505. font-size: 40rpx;
  506. }
  507. /* 备注 */
  508. .remark {
  509. margin: 20rpx auto;
  510. width: 690rpx;
  511. padding-bottom: 20rpx;
  512. background: #ffffff;
  513. border-radius: 10rpx;
  514. }
  515. .remark .remark_t {
  516. font-size: 28rpx;
  517. color: #000000;
  518. padding: 20rpx 30rpx;
  519. }
  520. .remark .remark_nr {
  521. width: 634rpx;
  522. margin: 20rpx auto 0;
  523. /* background: #FAFAFA;
  524. border-radius: 10rpx; */
  525. }
  526. .remark .remark_nr .van-cell {
  527. width: 634rpx;
  528. /* height: 198rpx; */
  529. background: #fafafa;
  530. border-radius: 10rpx;
  531. }
  532. /* .remark .remark_nr .van-field__control{
  533. height: 110rpx !important;
  534. } */
  535. /* 创建订单 */
  536. .bottom {
  537. width: 690rpx;
  538. height: 98rpx;
  539. padding: 0 30rpx;
  540. border-radius: 49rpx;
  541. background: #295c56;
  542. position: fixed;
  543. bottom: 60rpx;
  544. left: 50%;
  545. transform: translateX(-50%);
  546. display: flex;
  547. align-items: center;
  548. justify-content: space-between;
  549. z-index: 100;
  550. color: #ffffff;
  551. }
  552. .bottom .total_price {
  553. font-size: 26rpx;
  554. /* color: #FFFFFF; */
  555. }
  556. .bottom .total_price .price {
  557. padding-left: 14rpx;
  558. /* color: #333333; */
  559. font-size: 40rpx;
  560. font-weight: bold;
  561. }
  562. .bottom .total_price .price .unit {
  563. font-size: 22rpx;
  564. }
  565. .bottom .btn_tijiao {
  566. width: 197rpx;
  567. height: 100rpx;
  568. /* background: #D54C43; */
  569. font-size: 32rpx;
  570. font-weight: bold;
  571. /* color: #333333; */
  572. display: flex;
  573. align-items: center;
  574. justify-content: center;
  575. /* margin-left: 30rpx; */
  576. }
  577. /* 加购标志 */
  578. .add_tag {
  579. font-size: 24rpx;
  580. color: #ffffff;
  581. background: linear-gradient(90deg, #ff6637, #ff954e);
  582. border-radius: 5rpx;
  583. padding: 6rpx 8rpx;
  584. margin-right: 12rpx;
  585. }
  586. </style>