cashier-desk.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="cashier-desk">
  3. <view class="view-top">
  4. </view>
  5. <view class="payment-methods">
  6. <u-radio-group v-model="formData.payType" @change="radioGroupChange">
  7. <!-- #ifdef MP-WEIXIN -->
  8. <view class="payment-item">
  9. <view class="left">
  10. <image src="/static/payment/pay1.png" class="payment-icon"></image>
  11. <text>微信支付</text>
  12. </view>
  13. <u-radio active-color="#38C148" name="2" />
  14. </view>
  15. <!-- #endif -->
  16. <!-- #ifdef MP-ALIPAY -->
  17. <view class="payment-item">
  18. <view class="left">
  19. <image src="/static/payment/alipay.png" class="payment-icon"></image>
  20. <text>支付宝支付</text>
  21. </view>
  22. <u-radio active-color="#38C148" name="2" />
  23. </view>
  24. <!-- #endif -->
  25. <view class="payment-item">
  26. <view class="left">
  27. <image src="/static/payment/pay2.png" class="payment-icon"></image>
  28. <text>余额支付(余额{{ orderInfo.accountMoney || 0 }})</text>
  29. <view class="discount-tag">8折优惠</view>
  30. </view>
  31. <u-radio active-color="#38C148" name="1" />
  32. </view>
  33. <!-- <view class="payment-item">
  34. <view class="left">
  35. <image src="/pages-mine/static/pay2.png" class="payment-icon"></image>
  36. <text>组合支付</text>
  37. </view>
  38. <u-radio active-color="#38C148" name="3" />
  39. </view> -->
  40. </u-radio-group>
  41. </view>
  42. <view class="total">
  43. <text>总计</text>
  44. <text class="amount">¥ {{ formData.payType === '1' ? orderInfo.accountDiscountMoney : orderInfo.orderMoney }}</text>
  45. </view>
  46. <button class="confirm-btn" type="primary" @click="onConfirmPayment">确认支付</button>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. formData: {
  54. payType: '2',
  55. orderId: ''
  56. },
  57. orderInfo: {}
  58. }
  59. },
  60. onLoad(options) {
  61. // 从本地存储获取订单信息
  62. const info = uni.getStorageSync('orderBuyInfo');
  63. if (info) {
  64. this.orderInfo = info;
  65. this.formData.orderId = info.orderId;
  66. } else {
  67. uni.showToast({
  68. title: '订单信息不存在',
  69. icon: 'none'
  70. });
  71. setTimeout(() => {
  72. uni.navigateBack();
  73. }, 1500);
  74. }
  75. },
  76. methods: {
  77. radioGroupChange(e) {
  78. console.log(e);
  79. },
  80. // 统一支付方法
  81. handlePayment(payData) {
  82. // #ifdef MP-WEIXIN
  83. this.wxPayment(payData);
  84. // #endif
  85. // #ifdef MP-ALIPAY
  86. this.aliPayment(payData);
  87. // #endif
  88. },
  89. // 微信支付方法
  90. wxPayment(payData) {
  91. uni.requestPayment({
  92. provider: 'wxpay',
  93. timeStamp: payData.timeStamp,
  94. nonceStr: payData.nonceStr,
  95. package: `prepay_id=${payData.prepayId}`,
  96. signType: payData.signType,
  97. paySign: payData.paySign,
  98. success: (res) => {
  99. // 支付成功
  100. this.paySuccess();
  101. },
  102. fail: (err) => {
  103. console.error('微信支付失败:', err);
  104. uni.showToast({
  105. title: '支付失败',
  106. icon: 'none'
  107. });
  108. }
  109. });
  110. },
  111. // 支付宝支付方法
  112. aliPayment(payData) {
  113. my.tradePay({
  114. tradeNO: payData.tradeNo,
  115. success: (res) => {
  116. if (res.resultCode === '9000') {
  117. // 支付成功
  118. this.paySuccess();
  119. } else {
  120. uni.showToast({
  121. title: '支付失败',
  122. icon: 'none'
  123. });
  124. }
  125. },
  126. fail: (err) => {
  127. console.error('支付宝支付失败:', err);
  128. uni.showToast({
  129. title: '支付失败',
  130. icon: 'none'
  131. });
  132. }
  133. });
  134. },
  135. paySuccess() {
  136. uni.redirectTo({
  137. url: `/pages-car/pages/pay-success?orderId=${this.orderInfo.orderId}`
  138. });
  139. },
  140. // 发起支付
  141. onConfirmPayment() {
  142. // 构建参数
  143. const params = {
  144. payType: this.formData.payType,
  145. orderId: this.orderInfo.orderId
  146. };
  147. // 获取支付参数
  148. this.$u.api.payShopOrderAjax(params).then(res => {
  149. if (res.code === 200) {
  150. if (res.data.needPay == 1) {
  151. // 调用统一支付方法
  152. this.handlePayment(res.data);
  153. } else {
  154. // 不需要支付(如全额余额支付),直接跳转成功
  155. this.paySuccess();
  156. }
  157. } else {
  158. uni.showToast({
  159. title: res.msg || '获取支付参数失败',
  160. icon: 'none'
  161. });
  162. }
  163. }).catch(err => {
  164. uni.showToast({
  165. title: err.msg || '请求失败',
  166. icon: 'none'
  167. });
  168. })
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .cashier-desk {
  175. min-height: 100vh;
  176. background-color: #f5f5f5;
  177. .view-top {
  178. background: #38C148;
  179. height: 160rpx;
  180. width: 100%;
  181. }
  182. .payment-methods {
  183. background-color: #ffffff;
  184. border-radius: 16rpx;
  185. margin: 30rpx;
  186. margin-top: -40px;
  187. margin-bottom: 20rpx;
  188. .payment-item {
  189. display: flex;
  190. justify-content: space-between;
  191. align-items: center;
  192. padding: 30rpx;
  193. border-bottom: 1px solid #f5f5f5;
  194. &:last-child {
  195. border-bottom: none;
  196. }
  197. .left {
  198. display: flex;
  199. align-items: center;
  200. gap: 20rpx;
  201. .payment-icon {
  202. width: 40rpx;
  203. height: 40rpx;
  204. }
  205. text {
  206. font-size: 30rpx;
  207. color: #333;
  208. }
  209. .discount-tag {
  210. background: linear-gradient(90deg, #ff6034, #ee0a24);
  211. color: #fff;
  212. font-size: 22rpx;
  213. padding: 4rpx 12rpx;
  214. border-radius: 20rpx 20rpx 20rpx 0;
  215. margin-left: 10rpx;
  216. font-weight: bold;
  217. }
  218. }
  219. }
  220. }
  221. .total {
  222. background-color: #ffffff;
  223. border-radius: 16rpx;
  224. padding: 30rpx;
  225. display: flex;
  226. justify-content: space-between;
  227. align-items: center;
  228. margin: 30rpx;
  229. margin-bottom: 20rpx;
  230. text {
  231. font-size: 30rpx;
  232. color: #333;
  233. }
  234. .amount {
  235. color: #ff0000;
  236. font-size: 32rpx;
  237. font-weight: bold;
  238. }
  239. }
  240. .confirm-btn {
  241. width: 90%;
  242. margin-left: 5%;
  243. margin-top: 100rpx;
  244. background: #38C148;
  245. color: #fff;
  246. border-radius: 45rpx;
  247. &::after {
  248. border: none;
  249. }
  250. }
  251. }
  252. </style>