pay.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <!--支付组件-->
  3. <view>
  4. <uni-popup ref="popup" type="bottom" :catchtouchmove="true">
  5. <view class=" payView">
  6. <view class="flex-row justify-between">
  7. <text class="payType">请选择支付方式</text>
  8. <image class="x" src="/static/common/ox.png" @click="closePayPopup"></image>
  9. </view>
  10. <view class="payTitle">
  11. <text>选择微信支付或余额支付</text>
  12. </view>
  13. <view class=" payItemView">
  14. <view v-if="blPay" class="payItem flex-row justify-between" @click="payItem(1)">
  15. <view class="flex-row">
  16. <u-icon name="/static/me/u701.png" color="#38db38" size="36"></u-icon>
  17. <view class="payName flex-col justify-center">
  18. <text>余额支付</text>
  19. <text class="balance">可以余额¥{{ userInfo.balance || 0 }}</text>
  20. </view>
  21. </view>
  22. <view class="flex-col justify-center">
  23. <u-icon v-if="curServiceTab === 1" name="checkmark-circle-fill" color="#38db38"
  24. size="25"></u-icon>
  25. <u-icon v-else name="/static/order/ud9.png" color="green" size="25"></u-icon>
  26. </view>
  27. </view>
  28. <view v-if="wxPay" class="payItem flex-row justify-between" @click="payItem(2)">
  29. <view class="flex-row">
  30. <u-icon name="weixin-circle-fill" color="#38db38" size="36"></u-icon>
  31. <view class="payName flex-col justify-center">
  32. <text class="payName">微信支付</text>
  33. </view>
  34. </view>
  35. <view class="flex-col justify-center">
  36. <u-icon v-if="curServiceTab === 2" name="checkmark-circle-fill" color="#38db38"
  37. size="25"></u-icon>
  38. <u-icon v-else name="/static/order/ud9.png" color="green" size="25"></u-icon>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="commitBtn" @click="payment">
  43. <text>确定</text>
  44. </view>
  45. </view>
  46. </uni-popup>
  47. <uni-popup ref="passwordPopup">
  48. <view class="passwordView flex-col">
  49. <view class="h-pay-title flex-row justify-center">
  50. <text>请输入交易密码</text>
  51. </view>
  52. <view class="h-tab-bar flex-row justify-center">
  53. <u-code-input v-model="password" mode="box" dot></u-code-input>
  54. </view>
  55. <view class="flex-row justify-center">
  56. <view class="h-operate-btn flex-row justify-center" @click="balancePay">
  57. <text>确定</text>
  58. </view>
  59. </view>
  60. </view>
  61. </uni-popup>
  62. </view>
  63. </template>
  64. <script>
  65. /**
  66. * props参数
  67. *1,needPassword:Boolean类型 是否需要输入密码。true,使用余额支付时开启密码输入框,false,使用余额支付时不弹出密码输入框直接支付。默认false。
  68. *2,wxPay:Boolean类型,是否显示微信支付选项。true--显示,false--不显示。默认true。
  69. *3,blPay:Boolean类型,是否显示余额支付选项。true--显示,false--不显示。默认true。
  70. *4,selectBlPay:Boolean类型,余额支付选项是否能够选中。使用时请根据用户的余额进行判断。true--能,false--不能。默认true。
  71. *5,orderNo:String类型,支付的订单号。
  72. *6,openType:Number类型,1--支付预约费用,2---支付子订单费用。
  73. *
  74. * function 回调函数
  75. * 1,payResult(e),支付结果回调。
  76. */
  77. export default {
  78. name: "myPay",
  79. props: {
  80. needPassword: {
  81. type: Boolean,
  82. default () {
  83. return false
  84. }
  85. },
  86. wxPay: {
  87. type: Boolean,
  88. default () {
  89. return true
  90. }
  91. },
  92. blPay: {
  93. type: Boolean,
  94. default () {
  95. return true
  96. }
  97. },
  98. selectBlPay: {
  99. type: Boolean,
  100. default () {
  101. return true
  102. }
  103. },
  104. orderNo: {
  105. type: String,
  106. default () {
  107. return ''
  108. }
  109. },
  110. openType: {
  111. type: Number,
  112. default () {
  113. return 1
  114. }
  115. }
  116. },
  117. data() {
  118. return {
  119. curServiceTab: 2,
  120. userInfo: {},
  121. password: ''
  122. };
  123. },
  124. methods: {
  125. closePayPopup() {
  126. this.$refs.popup.close()
  127. },
  128. openPopup() {
  129. this.password = ''
  130. this.$refs.popup.open()
  131. },
  132. payItem(num) {
  133. if (!this.selectBlPay) {
  134. return
  135. }
  136. this.curServiceTab = num
  137. },
  138. payment() {
  139. this.$refs.popup.close()
  140. if (this.curServiceTab === 1) {
  141. if (this.needPassword) {
  142. this.$refs.passwordPopup.open()
  143. } else {
  144. //余额支付
  145. this.balancePay()
  146. }
  147. } else {
  148. //微信支付
  149. if (this.openType == 1){
  150. this.wechatPay() //支付预约费用
  151. }else {
  152. this.wechatPayTradeNo() //支付子订单费用
  153. }
  154. }
  155. },
  156. //支付子订单的统一下单接口
  157. wechatPayTradeNo(){
  158. this.$api.wechatPayTradeNo({
  159. tradeNo: this.orderNo
  160. }).then((res) => {
  161. this.requestPayment(res.data.data)
  162. }).catch((err) => {
  163. this.$emit('payResult',{
  164. payResult:false,
  165. res:err
  166. })
  167. });
  168. },
  169. //支付预约费用的统一下单接口
  170. wechatPay() {
  171. this.$api.wechatPay({
  172. orderNo: this.orderNo
  173. }).then((res) => {
  174. this.requestPayment(res.data.data)
  175. }).catch((err) => {
  176. this.$emit('payResult',{
  177. payResult:false,
  178. res:err
  179. })
  180. });
  181. },
  182. //调起微信支付
  183. requestPayment(param){
  184. uni.requestPayment({
  185. appId: param.appid,
  186. timeStamp: param.timestamp + "",
  187. nonceStr: param.noncestr,
  188. package: "prepay_id=" + param.prepayid,
  189. signType: "RSA",
  190. paySign: param.sign,
  191. success: res => {
  192. this.$emit('payResult',{
  193. payResult:true,
  194. res:res
  195. })
  196. },
  197. fail: res => {
  198. this.$emit('payResult',{
  199. payResult:false,
  200. res:res
  201. })
  202. }
  203. });
  204. },
  205. //余额支付
  206. balancePay() {
  207. if (this.password.length < 6 && this.needPassword) {
  208. uni.showToast({
  209. title: "交易密码不能小于6位"
  210. })
  211. return;
  212. }
  213. this.$refs.passwordPopup.close()
  214. if (this.openType == 1){ // 支付预约费用
  215. this.$api.balancePay({
  216. orderNo: this.orderNo,
  217. password: this.password
  218. }).then((res) => {
  219. this.$emit('payResult',{
  220. payResult:true,
  221. res:res
  222. })
  223. }).catch((res) => {
  224. this.$emit('payResult',{
  225. payResult:false,
  226. res:res
  227. })
  228. });
  229. }else { //支付子订单费用
  230. this.$api.trade({
  231. tradeNo: this.orderNo,
  232. password: this.password
  233. }).then((res) => {
  234. this.$emit('payResult',{
  235. payResult:true,
  236. res:res
  237. })
  238. }).catch((res) => {
  239. this.$emit('payResult',{
  240. payResult:false,
  241. res:res
  242. })
  243. });
  244. }
  245. },
  246. }
  247. }
  248. </script>
  249. <style lang="scss" scoped>
  250. .payView {
  251. height: 638rpx;
  252. background: #FFFFFF;
  253. box-shadow: 0rpx -4rpx 8rpx 0rpx rgba(0, 0, 0, 0.03);
  254. border-radius: 24rpx 24rpx 0rpx 0rpx;
  255. padding: 24rpx 32rpx;
  256. }
  257. .payType {
  258. font-size: 32rpx;
  259. font-weight: bord;
  260. color: #111111;
  261. line-height: 48rpx;
  262. }
  263. .x {
  264. width: 35rpx;
  265. height: 35rpx;
  266. border-radius: 18rpx;
  267. }
  268. .payTitle {
  269. font-size: 24rpx;
  270. font-family: PingFangSC-Regular, PingFang SC;
  271. font-weight: 400;
  272. color: #666666;
  273. line-height: 40rpx;
  274. margin-top: 8rpx;
  275. }
  276. .payItemView{
  277. height: 345rpx;
  278. }
  279. .payItem {
  280. background: #FAFAFA;
  281. border-radius: 20rpx;
  282. padding: 34rpx 32rpx;
  283. margin-top: 32rpx;
  284. }
  285. .payName {
  286. margin-left: 24rpx;
  287. }
  288. .balance {
  289. font-size: 24rpx;
  290. font-family: PingFangSC-Regular, PingFang SC;
  291. font-weight: 400;
  292. color: #999999;
  293. line-height: 40rpx;
  294. }
  295. .commitBtn {
  296. width: 686rpx;
  297. height: 108rpx;
  298. background: #FFE05C;
  299. border-radius: 60rpx;
  300. margin-top: 32rpx;
  301. font-size: 32rpx;
  302. font-family: PingFangSC-Medium, PingFang SC;
  303. font-weight: bold;
  304. color: #111111;
  305. line-height: 108rpx;
  306. text-align: center;
  307. }
  308. .passwordView {
  309. background: #FFFFFF;
  310. width: 686rpx;
  311. height: 400rpx;
  312. border-radius: 20rpx;
  313. padding: 34rpx 0;
  314. }
  315. .h-tab-bar {
  316. margin-top: 80rpx;
  317. }
  318. .h-operate-btn {
  319. width: 550rpx;
  320. height: 80rpx;
  321. border-radius: 40rpx;
  322. background: #FFE05C;
  323. line-height: 80rpx;
  324. text-align: center;
  325. margin-top: 80rpx;
  326. }
  327. </style>