pay.vue 8.1 KB

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