敢为人鲜小程序前端代码仓库
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.

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