checkout.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view class="cu-modal bottom-modal" :class="{ show: visible }">
  3. <view class="mask" @click="close"></view>
  4. <view class="wrapper cu-dialog">
  5. <view class="paddingY25 flex-align-center relative">
  6. <image :src="resource.pay_title_dart" class="title" />
  7. <image :src="resource.icon_x" class="x" @click="close" />
  8. </view>
  9. <view>
  10. <view class="flex-align paddingB25">
  11. <image :src="data.cover" class="logo flex-shrink0 flex-shrink0" />
  12. <view class="marginL12 flex1 self-stretch flex-column-between">
  13. <view class="color-1 font4 bold">{{ data.name }}</view>
  14. <view class="color-theme">
  15. <text class="font2">¥</text>
  16. <text class="font8 bold">{{ data.price }}</text>
  17. </view>
  18. </view>
  19. </view>
  20. <view
  21. v-if="cash && hide"
  22. class="flex-align paddingY15"
  23. style="border-top: 2rpx solid #eeeeee"
  24. >
  25. <view class="flex1 font4 color-1">
  26. 使用钱包支付
  27. <text class="color-theme">(余额:¥{{ cash.balance }})</text>
  28. </view>
  29. <switch
  30. class="purple"
  31. :checked="cashChecked"
  32. @change="changeCashChecked"
  33. ></switch>
  34. </view>
  35. </view>
  36. <cm-button ::height="44" @click="pay">¥{{ lastPrice }} 立即支付</cm-button>
  37. <view class="fill"></view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import cmButton from '../../components/cm-button.vue'
  43. import { throttle } from '@/utils'
  44. import { H5 } from '@/utils/config'
  45. import resource from '@/utils/resource'
  46. import { baseEncode } from '../../utils/utils'
  47. export default {
  48. components: { cmButton },
  49. props: {
  50. data: Object
  51. },
  52. data() {
  53. return {
  54. resource,
  55. visible: false,
  56. checked: true,
  57. cash: null,
  58. cashChecked: false,
  59. lastPrice: null //最终金额
  60. }
  61. },
  62. computed: {
  63. hide() {
  64. return !this.$store.state.hide
  65. },
  66. payInfo() {
  67. return this.$store.state.payInfo
  68. }
  69. },
  70. watch: {
  71. payInfo(val) {
  72. if (val && val.payResult == 'SUCCESS') {
  73. this.paySuccess(val)
  74. } else if (val && val.payResult !== 'SUCCESS') {
  75. }
  76. }
  77. },
  78. methods: {
  79. show(data = {}) {
  80. this.lastPrice = data.paymentAmount
  81. if (data.cash && data.cash.balance > data.paymentAmount) {
  82. this.cash = data.cash
  83. this.cashChecked = true
  84. } else {
  85. this.cash = null
  86. this.cashChecked = false
  87. }
  88. this.visible = true
  89. },
  90. close() {
  91. this.visible = false
  92. },
  93. changeCashChecked(e) {
  94. this.cashChecked = e.detail.value
  95. },
  96. async pay() {
  97. this.realPay()
  98. },
  99. async realPay() {
  100. let paymentType = this.cashChecked ? 'WALLET' : 'WXPAY_JSAPI'
  101. const res = await this.$service.sell.apply(this.data.id, paymentType:'ALIPAY_APP', 1)
  102. //判断是否是微信支付
  103. if (res) {
  104. if (res.paySuccess) {
  105. this.close()
  106. this.$event.emit(this.$event.key.SELL_REFRESH)
  107. this.$router.replace('sell_record', { active: 3 })
  108. return
  109. }
  110. let self = this
  111. // 支付宝支付
  112. uni.requestPayment({
  113. provider: 'alipay',
  114. orderInfo: res.payInfo,
  115. success: function (res) {
  116. self.close()
  117. self.$event.emit(self.$event.key.SELL_REFRESH)
  118. self.$router.replace('sell_record', { active: 3 })
  119. },
  120. fail: function (err) {
  121. console.log('fail:' + JSON.stringify(err));
  122. }
  123. });
  124. return
  125. }
  126. },
  127. wechatPay(data) {
  128. let payInfo = data.payInfo
  129. wx.requestPayment({
  130. timeStamp: payInfo.timeStamp,
  131. nonceStr: payInfo.nonceStr,
  132. package: payInfo.packageValue,
  133. signType: payInfo.signType,
  134. paySign: payInfo.paySign,
  135. success: (res) => {
  136. this.close()
  137. this.$event.emit(this.$event.key.SELL_REFRESH)
  138. this.$router.replace('sell_record', { active: 3 })
  139. },
  140. fail: (res) => {}
  141. })
  142. },
  143. thirdPay(data) {
  144. let self = this
  145. let redirectUrl = data.redirectUrl
  146. let requestId = data.requestId
  147. const base64Url = encodeURIComponent(baseEncode(redirectUrl))
  148. wx.openEmbeddedMiniProgram({
  149. path: 'pages/pay/order', // 启动目标页面
  150. appId: 'wx0448557563ffc600', // 启动的小程序
  151. envVersion: 'release', // develop | trial | release
  152. verify: 'binding',
  153. extraData: {
  154. title: '订单付款', // 导航Title
  155. tip: `待支付订单付款`, // 支付提示内容
  156. requestId: requestId, // 本次请求ID
  157. action: 'epPay', // 支付模式
  158. payUrl: base64Url // 支付地址, 需要进行Base64转换
  159. },
  160. success: (res) => {
  161. console.info('启动成功', res)
  162. },
  163. fail: (err) => {
  164. console.info('启动失败', err)
  165. }
  166. })
  167. },
  168. paySuccess(payInfo) {
  169. this.close()
  170. this.$store.state.payInfo = null
  171. this.$event.emit(this.$event.key.SELL_REFRESH)
  172. this.$router.replace('sell_record', { active: 3 })
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. .mask {
  179. position: absolute;
  180. left: 0;
  181. right: 0;
  182. top: 0;
  183. bottom: 0;
  184. }
  185. .wrapper {
  186. padding: 0 28rpx;
  187. background: #fff;
  188. overflow: hidden;
  189. border-top-left-radius: 30rpx !important;
  190. border-top-right-radius: 30rpx !important;
  191. .title {
  192. width: 172rpx;
  193. height: 28rpx;
  194. }
  195. .x {
  196. position: absolute;
  197. right: 28rpx;
  198. top: 50%;
  199. margin-top: -16rpx;
  200. width: 32rpx;
  201. height: 32rpx;
  202. }
  203. .logo {
  204. width: 180rpx;
  205. height: 180rpx;
  206. border-radius: 8rpx;
  207. }
  208. .fill {
  209. height: 40rpx;
  210. }
  211. }
  212. </style>