pay.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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">可以余额¥{{balance}}</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. *7,balance:用户余额
  74. *
  75. * function 回调函数
  76. * 1,payResult(e),支付结果回调。
  77. */
  78. export default {
  79. name: "myPay",
  80. props: {
  81. needPassword: {
  82. type: Boolean,
  83. default () {
  84. return false
  85. }
  86. },
  87. wxPay: {
  88. type: Boolean,
  89. default () {
  90. return true
  91. }
  92. },
  93. blPay: {
  94. type: Boolean,
  95. default () {
  96. return true
  97. }
  98. },
  99. selectBlPay: {
  100. type: Boolean,
  101. default () {
  102. return true
  103. }
  104. },
  105. orderNo: {
  106. type: String,
  107. default () {
  108. return ''
  109. }
  110. },
  111. openType: {
  112. type: Number,
  113. default () {
  114. return 1
  115. }
  116. },
  117. balance: {
  118. type: Number,
  119. default () {
  120. return 0
  121. }
  122. }
  123. },
  124. data() {
  125. return {
  126. curServiceTab: 2,
  127. userInfo: {},
  128. password: ''
  129. };
  130. },
  131. methods: {
  132. closePayPopup() {
  133. this.$refs.popup.close()
  134. },
  135. openPopup() {
  136. this.password = ''
  137. this.$refs.popup.open()
  138. },
  139. payItem(num) {
  140. if (!this.selectBlPay) {
  141. return
  142. }
  143. this.curServiceTab = num
  144. },
  145. payment() {
  146. this.$refs.popup.close()
  147. if (this.curServiceTab === 1) {
  148. if (this.needPassword) {
  149. this.$refs.passwordPopup.open()
  150. } else {
  151. //余额支付
  152. this.balancePay()
  153. }
  154. } else {
  155. //微信支付
  156. if (this.openType == 1){
  157. this.wechatPay() //支付预约费用
  158. }else {
  159. this.wechatPayTradeNo() //支付子订单费用
  160. }
  161. }
  162. },
  163. //支付子订单的统一下单接口
  164. wechatPayTradeNo(){
  165. this.$api.wechatPayTradeNo({
  166. tradeNo: this.orderNo
  167. }).then((res) => {
  168. this.requestPayment(res.data.data)
  169. }).catch((err) => {
  170. this.$emit('payResult',{
  171. payResult:false,
  172. res:err
  173. })
  174. });
  175. },
  176. //支付预约费用的统一下单接口
  177. wechatPay() {
  178. this.$api.wechatPay({
  179. orderNo: this.orderNo
  180. }).then((res) => {
  181. this.requestPayment(res.data.data)
  182. }).catch((err) => {
  183. this.$emit('payResult',{
  184. payResult:false,
  185. res:err
  186. })
  187. });
  188. },
  189. //调起微信支付
  190. requestPayment(param){
  191. uni.requestPayment({
  192. appId: param.appid,
  193. timeStamp: param.timestamp + "",
  194. nonceStr: param.noncestr,
  195. package: "prepay_id=" + param.prepayid,
  196. signType: "RSA",
  197. paySign: param.sign,
  198. success: res => {
  199. this.$emit('payResult',{
  200. payResult:true,
  201. res:res
  202. })
  203. },
  204. fail: res => {
  205. this.$emit('payResult',{
  206. payResult:false,
  207. res:res
  208. })
  209. }
  210. });
  211. },
  212. //余额支付
  213. balancePay() {
  214. if (this.password.length < 6 && this.needPassword) {
  215. uni.showToast({
  216. title: "交易密码不能小于6位"
  217. })
  218. return;
  219. }
  220. this.$refs.passwordPopup.close()
  221. if (this.openType == 1){ // 支付预约费用
  222. this.$api.balancePay({
  223. orderNo: this.orderNo,
  224. password: this.password
  225. }).then((res) => {
  226. this.$emit('payResult',{
  227. payResult:true,
  228. res:res
  229. })
  230. }).catch((res) => {
  231. this.$emit('payResult',{
  232. payResult:false,
  233. res:res
  234. })
  235. });
  236. }else { //支付子订单费用
  237. this.$api.trade({
  238. tradeNo: this.orderNo,
  239. password: this.password
  240. }).then((res) => {
  241. this.$emit('payResult',{
  242. payResult:true,
  243. res:res
  244. })
  245. }).catch((res) => {
  246. this.$emit('payResult',{
  247. payResult:false,
  248. res:res
  249. })
  250. });
  251. }
  252. },
  253. }
  254. }
  255. </script>
  256. <style lang="scss" scoped>
  257. .payView {
  258. height: 638rpx;
  259. background: #FFFFFF;
  260. box-shadow: 0rpx -4rpx 8rpx 0rpx rgba(0, 0, 0, 0.03);
  261. border-radius: 24rpx 24rpx 0rpx 0rpx;
  262. padding: 24rpx 32rpx;
  263. }
  264. .payType {
  265. font-size: 32rpx;
  266. font-weight: bord;
  267. color: #111111;
  268. line-height: 48rpx;
  269. }
  270. .x {
  271. width: 35rpx;
  272. height: 35rpx;
  273. border-radius: 18rpx;
  274. }
  275. .payTitle {
  276. font-size: 24rpx;
  277. font-family: PingFangSC-Regular, PingFang SC;
  278. font-weight: 400;
  279. color: #666666;
  280. line-height: 40rpx;
  281. margin-top: 8rpx;
  282. }
  283. .payItemView{
  284. height: 345rpx;
  285. }
  286. .payItem {
  287. background: #FAFAFA;
  288. border-radius: 20rpx;
  289. padding: 34rpx 32rpx;
  290. margin-top: 32rpx;
  291. }
  292. .payName {
  293. margin-left: 24rpx;
  294. }
  295. .balance {
  296. font-size: 24rpx;
  297. font-family: PingFangSC-Regular, PingFang SC;
  298. font-weight: 400;
  299. color: #999999;
  300. line-height: 40rpx;
  301. }
  302. .commitBtn {
  303. width: 686rpx;
  304. height: 108rpx;
  305. background: #FFE05C;
  306. border-radius: 60rpx;
  307. margin-top: 32rpx;
  308. font-size: 32rpx;
  309. font-family: PingFangSC-Medium, PingFang SC;
  310. font-weight: bold;
  311. color: #111111;
  312. line-height: 108rpx;
  313. text-align: center;
  314. }
  315. .passwordView {
  316. background: #FFFFFF;
  317. width: 686rpx;
  318. height: 400rpx;
  319. border-radius: 20rpx;
  320. padding: 34rpx 0;
  321. }
  322. .h-tab-bar {
  323. margin-top: 80rpx;
  324. }
  325. .h-operate-btn {
  326. width: 550rpx;
  327. height: 80rpx;
  328. border-radius: 40rpx;
  329. background: #FFE05C;
  330. line-height: 80rpx;
  331. text-align: center;
  332. margin-top: 80rpx;
  333. }
  334. </style>