敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

547 lines
16 KiB

  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="购物车支付 " leftClick @leftClick="navigateBack" bgColor="#019245" color="#fff" />
  5. <!-- 店铺信息 -->
  6. <view class="shop-info">
  7. <view class="shop-header">
  8. <image class="shop-logo" :src="teamLeader.spotImage" mode="aspectFill"></image>
  9. <view class="shop-name-container">
  10. <text class="shop-name"> {{ teamLeader.spotName }} </text>
  11. <view class="shop-address">
  12. <view style="padding-top: 7rpx;">
  13. <!-- 需要置顶 -->
  14. <uv-icon name="map-fill" color="#019245" size="28rpx"></uv-icon>
  15. </view>
  16. <text class="address-text">{{ teamLeader.area }} {{ teamLeader.address }}</text>
  17. </view>
  18. <view class="shop-phone">
  19. <view style="padding-top: 7rpx;">
  20. <!-- 需要置顶 -->
  21. <uv-icon name="phone-fill" color="#019245" size="28rpx"></uv-icon>
  22. </view>
  23. <text class="phone-text">{{ teamLeader.phone }}</text>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="order-status">
  29. <!-- 商品列表 -->
  30. <view class="food-list">
  31. <view class="food-item" v-for="(food, index) in showedFoods" :key="food.id">
  32. <image class="food-image" :src="food.goods.image" mode="aspectFill" />
  33. <view class="food-info">
  34. <text class="food-name">{{ food.goods.title }}</text>
  35. <view class="food-sold">
  36. <uv-icon name="bag" size="28rpx"></uv-icon>
  37. <text>已售出 {{ food.goods.sales }}</text>
  38. </view>
  39. <text class="food-price"> <text style="font-size: 20rpx;"></text> {{ food.goods.price }}</text>
  40. <text class="food-count">×{{ food.num }}</text>
  41. </view>
  42. </view>
  43. <view class="expand-more" @tap="showAllFoods = !showAllFoods" v-if="cartData.sendData.length > 3">
  44. <text>{{ showAllFoods ? '收起' : '展开' }} ({{ cartData.sendData.length }})</text>
  45. <uv-icon :name="showAllFoods ? 'arrow-up' : 'arrow-down'" size="28rpx"></uv-icon>
  46. </view>
  47. </view>
  48. <!-- 订单信息 -->
  49. <view class="order-info">
  50. <view class="info-item">
  51. <text class="info-label">合计:</text>
  52. <!-- <text class="info-value price">{{ thePriceAll.toFixed(2) || 0 }}</text> -->
  53. <text class="info-value price">{{ (cartData.priceAll || 0).toFixed(2) || 0 }}</text>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="discount-info-container">
  58. <!-- 优惠信息 -->
  59. <view class="discount-info">
  60. <view class="discount-header">
  61. <text>优惠</text>
  62. </view>
  63. <view class="discount-item" @click="gotoCoupon">
  64. <view class="discount-left">
  65. <image src="@/static/image/券.webp" mode="aspectFill" class="coupon-icon" v-if="couponData.couponId" />
  66. <view :style="{ color: couponData.couponId ? 'inherit' : '#ccc' }">{{ couponData.couponId_dictText || '点击选择优惠卷->' }}
  67. </view>
  68. <text class="discount-amount">{{ couponData.discount ? ('-' + couponData.discount) : '' }}</text>
  69. </view>
  70. </view>
  71. </view>
  72. <!-- 备注 -->
  73. <view class="remark-section">
  74. <view class="remark-header">
  75. <text>备注</text>
  76. </view>
  77. <view class="remark-content">
  78. <input type="text" v-model="orderDetail.remark"
  79. placeholder="请输入您要备注的内容" placeholder-style="font-size: 28rpx" />
  80. </view>
  81. </view>
  82. <!-- 支付方式 -->
  83. <uv-radio-group v-model="payMethod">
  84. <view class="payment-methods">
  85. <view class="payment-item">
  86. <uv-icon name="weixin-circle-fill" size="70rpx" color="#019245" />
  87. <text class="payment-name">微信支付</text>
  88. <uv-radio activeColor="#019245" size="40rpx" name="0" />
  89. </view>
  90. <view class="payment-item">
  91. <uv-icon name="red-packet" size="70rpx" color="#019245" />
  92. <text class="payment-name">账户余额<text class="balance-text">(余额: {{ userInfo.balance
  93. }})</text></text>
  94. <uv-radio activeColor="#019245" size="40rpx" name="1" />
  95. </view>
  96. </view>
  97. </uv-radio-group>
  98. <!-- 底部支付栏 -->
  99. <view class="bottom-bar">
  100. <view class="total-section">
  101. <text class="total-label">
  102. {{ cartData.sendData.length }}
  103. <text style="color: black;">合计</text>
  104. </text>
  105. <text class="total-price">{{ (pricePay || 0).toFixed(2) || 0 }}</text>
  106. </view>
  107. <view class="pay-button" @tap="handlePay">立即下单</view>
  108. </view>
  109. </view>
  110. </view>
  111. </template>
  112. <script>
  113. import navbar from '@/components/base/navbar.vue'
  114. import { mapState, mapMutations } from 'vuex'
  115. export default {
  116. components: {
  117. navbar
  118. },
  119. data() {
  120. return {
  121. payMethod: '0',
  122. showAllFoods: false,
  123. teamLeader: {},
  124. thePriceAll: 0,
  125. }
  126. },
  127. computed: {
  128. ...mapState(['cartData', 'userInfo', 'couponData']),
  129. showedFoods() {
  130. return this.showAllFoods ? this.cartData.sendData : this.cartData.sendData.slice(0, 3)
  131. },
  132. pricePay() {
  133. return this.cartData.priceAll - (this.couponData.discount || 0)
  134. },
  135. // 格式为 goodId,goodNum;goodId2,goodsNum
  136. goodss() {
  137. return this.cartData.sendData.map(item => {
  138. return `${item.goodsId},${item.num},${item.goods.price * item.num}`
  139. }).join(';')
  140. }
  141. },
  142. onShow() {
  143. this.getLeaderData()
  144. },
  145. onHide() {
  146. this.clearCouponData()
  147. },
  148. methods: {
  149. ...mapMutations(['clearCouponData']),
  150. // 返回上一页
  151. navigateBack() {
  152. uni.navigateBack()
  153. },
  154. // 获取团长信息
  155. getLeaderData() {
  156. this.$api('queryMyLeader', {}, res => {
  157. if (res.code === 200) {
  158. this.teamLeader = res.result
  159. }else {
  160. uni.showModal({
  161. title: '提示',
  162. content: res.message,
  163. confirmColor: '#019245',
  164. confirmText: '去绑定',
  165. cancelText: '晚点再绑',
  166. success: (result) => {
  167. console.log('弹窗操作结果', result);
  168. if (result.confirm) {
  169. this.$utils.navigateTo({
  170. url: '/pages_order/mine/unbindTeam'
  171. })
  172. } else {
  173. this.$utils.navigateBack()
  174. }
  175. },
  176. fail: (err) => {
  177. console.error('弹窗显示失败', err);
  178. }
  179. })
  180. }
  181. })
  182. },
  183. // 处理支付
  184. handlePay() {
  185. uni.showLoading({
  186. title: '支付处理中...'
  187. })
  188. this.$api('createOrder', {
  189. priceAll: this.cartData.priceAll,
  190. pricePay: this.pricePay,
  191. pricePreferential: this.couponData.discount || 0,
  192. payType: this.payMethod,
  193. leaderId: this.teamLeader.id,
  194. goodss: this.goodss
  195. }, res => {
  196. uni.hideLoading()
  197. if (res.code === 200) {
  198. if (this.payMethod == '0') {
  199. uni.requestPaymentWxPay(res)
  200. .then(n => {
  201. setTimeout(uni.redirectTo, 700, {
  202. url: '/pages/index/order?tabIndex=1'
  203. })
  204. })
  205. } else {
  206. uni.showToast({
  207. title: '下单成功',
  208. icon: 'success'
  209. })
  210. setTimeout(uni.redirectTo, 700, {
  211. url: '/pages/index/order?tabIndex=1'
  212. })
  213. }
  214. }
  215. })
  216. },
  217. // 去优惠页面
  218. gotoCoupon() {
  219. // 只有在待支付订单的情况下 才会进入优惠卷页面进行选择
  220. this.$utils.navigateTo({
  221. url: '/pages_order/mine/coupon?usein=1'
  222. })
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang="scss" scoped>
  228. .page {
  229. background-color: #f5f5f5;
  230. min-height: 100vh;
  231. padding-bottom: 120rpx;
  232. }
  233. .status-bar {
  234. background-color: #019245;
  235. padding: 30rpx;
  236. color: #fff;
  237. font-size: 32rpx;
  238. font-weight: 500;
  239. }
  240. .shop-info {
  241. background-color: #fff;
  242. margin: 20rpx;
  243. border-radius: 16rpx;
  244. padding: 20rpx;
  245. .shop-header {
  246. display: flex;
  247. align-items: center;
  248. // background-color: red;
  249. .shop-logo {
  250. width: 150rpx;
  251. height: 150rpx;
  252. // border-radius: 10rpx;
  253. margin-right: 20rpx;
  254. }
  255. .shop-name-container {
  256. flex: 1;
  257. .shop-name {
  258. font-size: 30rpx;
  259. font-weight: 500;
  260. margin-bottom: 10rpx;
  261. display: block;
  262. }
  263. .shop-address,
  264. .shop-phone {
  265. display: flex;
  266. align-items: start;
  267. font-size: 24rpx;
  268. color: $uni-color-third;
  269. margin-top: 8rpx;
  270. .address-text,
  271. .phone-text {
  272. margin-left: 8rpx;
  273. width: 80%;
  274. white-space: wrap;
  275. // overflow: hidden;
  276. // text-overflow: ellipsis;
  277. }
  278. }
  279. .shop-address-top {
  280. display: flex;
  281. align-items: start;
  282. background-color: red;
  283. // gap: 10rpx;
  284. }
  285. }
  286. }
  287. }
  288. .order-status {
  289. background-color: #fff;
  290. margin: 20rpx;
  291. border-radius: 16rpx;
  292. padding: 20rpx;
  293. .food-list {
  294. // gap: 20rpx;
  295. // background-color: #019245;
  296. .food-item {
  297. display: flex;
  298. margin-bottom: 20rpx;
  299. // background-color: red;
  300. .food-image {
  301. width: 120rpx;
  302. height: 120rpx;
  303. // border-radius: 10rpx;
  304. margin-right: 20rpx;
  305. }
  306. .food-info {
  307. flex: 1;
  308. display: flex;
  309. flex-direction: column;
  310. justify-content: space-between;
  311. position: relative;
  312. .food-name {
  313. font-size: 28rpx;
  314. font-weight: 500;
  315. }
  316. .food-sold {
  317. display: flex;
  318. align-items: center;
  319. font-size: 24rpx;
  320. color: $uni-color-third;
  321. }
  322. .food-price {
  323. font-size: 28rpx;
  324. color: #f00;
  325. }
  326. .food-count {
  327. color: black;
  328. position: absolute;
  329. bottom: 50%;
  330. right: 0;
  331. }
  332. }
  333. }
  334. .expand-more {
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. padding: 20rpx 0 0;
  339. font-size: 24rpx;
  340. color: $uni-color-third;
  341. }
  342. }
  343. .order-info {
  344. padding-top: 20rpx;
  345. .info-item {
  346. display: flex;
  347. justify-content: space-between;
  348. margin-bottom: 15rpx;
  349. font-size: 26rpx;
  350. .info-label {
  351. color: black;
  352. }
  353. .info-value {
  354. color: #333;
  355. &.price {
  356. color: #f00;
  357. font-weight: 500;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. .discount-info-container {
  364. background-color: #fff;
  365. margin: 20rpx;
  366. border-radius: 16rpx;
  367. padding: 20rpx;
  368. display: flex;
  369. flex-direction: column;
  370. gap: 40rpx;
  371. }
  372. .discount-info {
  373. display: flex;
  374. align-items: center;
  375. justify-content: space-between;
  376. .discount-header {
  377. font-size: 28rpx;
  378. }
  379. .discount-item {
  380. display: flex;
  381. justify-content: space-between;
  382. align-items: center;
  383. gap: 20rpx;
  384. .discount-left {
  385. display: flex;
  386. align-items: center;
  387. gap: 10rpx;
  388. .coupon-icon {
  389. width: 36rpx;
  390. height: 36rpx;
  391. margin-top: 6rpx;
  392. }
  393. }
  394. .discount-amount {
  395. color: #f00;
  396. font-weight: 500;
  397. }
  398. .none-discount-amount {
  399. color: gray;
  400. font-weight: 500;
  401. }
  402. }
  403. }
  404. .remark-section {
  405. display: flex;
  406. // flex-direction: column;
  407. gap: 40rpx;
  408. // background-color: red;
  409. align-items: center;
  410. .remark-header {
  411. font-size: 28rpx;
  412. // font-weight: 500;
  413. }
  414. .remark-content {
  415. font-size: 26rpx;
  416. color: black;
  417. min-height: 60rpx;
  418. display: flex;
  419. align-items: center;
  420. }
  421. }
  422. .payment-methods {
  423. background-color: #fff;
  424. width: 100%;
  425. margin: 20rpx;
  426. border-radius: 16rpx;
  427. padding: 20rpx;
  428. display: flex;
  429. flex-direction: column;
  430. gap: 20rpx;
  431. .payment-item {
  432. display: flex;
  433. align-items: center;
  434. padding: 20rpx 0;
  435. border-bottom: 1rpx solid #f5f5f5;
  436. &:last-child {
  437. border-bottom: none;
  438. }
  439. .payment-name {
  440. flex: 1;
  441. margin-left: 20rpx;
  442. font-size: 28rpx;
  443. .balance-text {
  444. font-size: 24rpx;
  445. color: $uni-color-third;
  446. margin-left: 10rpx;
  447. }
  448. }
  449. }
  450. }
  451. .bottom-bar {
  452. position: fixed;
  453. bottom: 0;
  454. left: 0;
  455. right: 0;
  456. height: 100rpx;
  457. background-color: #fff;
  458. display: flex;
  459. align-items: center;
  460. padding: 0 30rpx;
  461. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  462. .total-section {
  463. flex: 1;
  464. .total-label {
  465. font-size: 26rpx;
  466. color: $uni-color-third;
  467. }
  468. .total-price {
  469. font-size: 32rpx;
  470. color: #f00;
  471. margin-left: 10rpx;
  472. }
  473. }
  474. .pay-button {
  475. width: 240rpx;
  476. height: 80rpx;
  477. background-color: #019245;
  478. color: #fff;
  479. font-size: 30rpx;
  480. display: flex;
  481. align-items: center;
  482. justify-content: center;
  483. border-radius: 40rpx;
  484. }
  485. }
  486. </style>