cashier-desk.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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="1" />
  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="1" />
  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>余额支付(余额{{ baseInfo.restMoney || 0 }})</text>
  29. </view>
  30. <u-radio active-color="#38C148" name="2" />
  31. </view>
  32. <view class="payment-item">
  33. <view class="left">
  34. <image src="/static/payment/pay2.png" class="payment-icon"></image>
  35. <text>组合支付</text>
  36. </view>
  37. <u-radio active-color="#38C148" name="3" />
  38. </view>
  39. </u-radio-group>
  40. </view>
  41. <view class="total">
  42. <text>总计</text>
  43. <text class="amount">¥ {{ baseInfo.expressMoney || 0 }}</text>
  44. </view>
  45. <button class="confirm-btn" @click="onConfirmPayment">确认支付</button>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. totalAmount: 7.00,
  53. formData: {
  54. payType: '1',
  55. refundOrderId: ''
  56. },
  57. baseInfo: {}
  58. }
  59. },
  60. onLoad(options) {
  61. if (options.id) {
  62. this.formData.refundOrderId = options.id
  63. this.getBaseInfo(options.id)
  64. }
  65. },
  66. methods: {
  67. //获取基本信息
  68. getBaseInfo(refundOrderId) {
  69. uni.$u.http.post('/token/order/refundGoPay', {
  70. refundOrderId
  71. }).then(res => {
  72. if (res.code === 200) {
  73. this.baseInfo = res.data
  74. }
  75. })
  76. },
  77. // 统一支付方法
  78. handlePayment(payData) {
  79. // #ifdef MP-WEIXIN
  80. this.wxPayment(payData);
  81. // #endif
  82. // #ifdef MP-ALIPAY
  83. this.aliPayment(payData);
  84. // #endif
  85. },
  86. // 微信支付方法
  87. wxPayment(payData) {
  88. uni.requestPayment({
  89. provider: 'wxpay',
  90. timeStamp: payData.timeStamp,
  91. nonceStr: payData.nonceStr,
  92. package: `prepay_id=${payData.prepayId}`,
  93. signType: payData.signType,
  94. paySign: payData.paySign,
  95. success: (res) => {
  96. //支付成功之后,跳转支付成功页面
  97. uni.navigateTo({
  98. url: `/pages-mine/pages/pay-success?orderId=${this.formData.refundOrderId}`
  99. });
  100. },
  101. fail: (err) => {
  102. console.error('微信支付失败:', err);
  103. uni.showToast({
  104. title: '支付失败',
  105. icon: 'none'
  106. });
  107. }
  108. });
  109. },
  110. // 支付宝支付方法
  111. aliPayment(payData) {
  112. my.tradePay({
  113. tradeNO: payData.tradeNo,
  114. success: (res) => {
  115. if (res.resultCode === '9000') {
  116. // 支付成功
  117. uni.navigateTo({
  118. url: `/pages-mine/pages/pay-success?orderId=${this.formData.refundOrderId}`
  119. });
  120. } else {
  121. uni.showToast({
  122. title: '支付失败',
  123. icon: 'none'
  124. });
  125. }
  126. },
  127. fail: (err) => {
  128. console.error('支付宝支付失败:', err);
  129. uni.showToast({
  130. title: '支付失败',
  131. icon: 'none'
  132. });
  133. }
  134. });
  135. },
  136. // 发起支付
  137. onConfirmPayment() {
  138. // 获取支付参数
  139. uni.$u.post('/token/order/refundOrderPay', this.formData).then(res => {
  140. if (res.code === 200) {
  141. if (res.data.needPay == 1) {
  142. // 调用统一支付方法
  143. this.handlePayment(res.data);
  144. } else {
  145. uni.navigateTo({
  146. url: `/pages-mine/pages/pay-success?orderId=${this.formData.refundOrderId}`
  147. });
  148. }
  149. } else {
  150. uni.showToast({
  151. title: res.msg || '获取支付参数失败',
  152. icon: 'none'
  153. });
  154. }
  155. }).catch(err => {
  156. uni.showToast({
  157. title: err.msg || '获取支付参数失败',
  158. icon: 'none'
  159. });
  160. })
  161. },
  162. radioGroupChange(e) {
  163. console.log(e);
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. .cashier-desk {
  170. min-height: 100vh;
  171. background-color: #f5f5f5;
  172. .view-top {
  173. background: #38C148;
  174. height: 160rpx;
  175. width: 100%;
  176. }
  177. .payment-methods {
  178. background-color: #ffffff;
  179. border-radius: 16rpx;
  180. margin-bottom: 20rpx;
  181. margin: 30rpx;
  182. margin-top: -40px;
  183. .payment-item {
  184. display: flex;
  185. justify-content: space-between;
  186. align-items: center;
  187. padding: 30rpx;
  188. border-bottom: 1px solid #f5f5f5;
  189. &:last-child {
  190. border-bottom: none;
  191. }
  192. .left {
  193. display: flex;
  194. align-items: center;
  195. gap: 20rpx;
  196. .payment-icon {
  197. width: 40rpx;
  198. height: 40rpx;
  199. }
  200. }
  201. }
  202. }
  203. .total {
  204. background-color: #ffffff;
  205. border-radius: 16rpx;
  206. padding: 30rpx;
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. margin-bottom: 20rpx;
  211. .amount {
  212. color: #ff0000;
  213. font-size: 32rpx;
  214. }
  215. }
  216. .confirm-btn {
  217. width: 90%;
  218. margin-left: 5%;
  219. margin-top: 100rpx;
  220. }
  221. }
  222. </style>