cashier-desk.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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/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/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/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/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. uni.showLoading({
  139. title: '支付处理中'
  140. })
  141. // 获取支付参数
  142. uni.$u.post('/token/order/refundOrderPay', this.formData).then(res => {
  143. if (res.code === 200) {
  144. if (res.data.needPay == 1) {
  145. // 调用统一支付方法
  146. this.handlePayment(res.data);
  147. } else {
  148. uni.navigateTo({
  149. url: `/pages-mine/pages/pay-success?orderId=${this.formData.refundOrderId}`
  150. });
  151. }
  152. } else {
  153. uni.showToast({
  154. title: res.msg || '获取支付参数失败',
  155. icon: 'none'
  156. });
  157. }
  158. }).catch(err => {
  159. console.error('获取支付参数失败:', err);
  160. uni.showToast({
  161. title: err.msg || '获取支付参数失败',
  162. icon: 'none'
  163. });
  164. }).finally(() => {
  165. uni.hideLoading();
  166. })
  167. },
  168. radioGroupChange(e) {
  169. console.log(e);
  170. }
  171. }
  172. }
  173. </script>
  174. <style lang="scss" scoped>
  175. .cashier-desk {
  176. min-height: 100vh;
  177. background-color: #f5f5f5;
  178. .view-top {
  179. background: #38C148;
  180. height: 160rpx;
  181. width: 100%;
  182. }
  183. .payment-methods {
  184. background-color: #ffffff;
  185. border-radius: 16rpx;
  186. margin-bottom: 20rpx;
  187. margin: 30rpx;
  188. margin-top: -40px;
  189. .payment-item {
  190. display: flex;
  191. justify-content: space-between;
  192. align-items: center;
  193. padding: 30rpx;
  194. border-bottom: 1px solid #f5f5f5;
  195. &:last-child {
  196. border-bottom: none;
  197. }
  198. .left {
  199. display: flex;
  200. align-items: center;
  201. gap: 20rpx;
  202. .payment-icon {
  203. width: 40rpx;
  204. height: 40rpx;
  205. }
  206. }
  207. }
  208. }
  209. .total {
  210. background-color: #ffffff;
  211. border-radius: 16rpx;
  212. padding: 30rpx;
  213. display: flex;
  214. justify-content: space-between;
  215. align-items: center;
  216. margin-bottom: 20rpx;
  217. .amount {
  218. color: #ff0000;
  219. font-size: 32rpx;
  220. }
  221. }
  222. .confirm-btn {
  223. width: 90%;
  224. margin-left: 5%;
  225. margin-top: 100rpx;
  226. }
  227. }
  228. </style>