pay.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. export default {
  66. name: "myPay",
  67. props: {
  68. needPassword: {
  69. type: Boolean,
  70. default () {
  71. return false
  72. }
  73. },
  74. wxPay: {
  75. type: Boolean,
  76. default () {
  77. return true
  78. }
  79. },
  80. blPay: {
  81. type: Boolean,
  82. default () {
  83. return true
  84. }
  85. }
  86. },
  87. data() {
  88. return {
  89. curServiceTab: 2,
  90. userInfo: {},
  91. password: ''
  92. };
  93. },
  94. methods: {
  95. closePayPopup() {
  96. this.$refs.popup.close()
  97. },
  98. openPopup() {
  99. this.userInfo = uni.getStorageSync('userInfo')
  100. this.$refs.popup.open()
  101. },
  102. payItem(num) {
  103. if (this.userInfo.balance * 1 < this.price * 1) {
  104. return
  105. }
  106. this.curServiceTab = num
  107. },
  108. payment() {
  109. this.$refs.popup.close()
  110. if (this.curServiceTab === 1) {
  111. if (this.needPassword) {
  112. this.$refs.passwordPopup.open()
  113. } else {
  114. this.balancePay()
  115. }
  116. } else {
  117. this.wechatPay()
  118. }
  119. },
  120. //微信支付
  121. wechatPay() {
  122. // 发起微信支付
  123. this.$api.wechatPay({
  124. orderNo: this.subOrderNo
  125. }).then((res) => {
  126. var param = res.data.data;
  127. uni.requestPayment({
  128. appId: param.appid,
  129. timeStamp: param.timestamp + "",
  130. nonceStr: param.noncestr,
  131. package: "prepay_id=" + param.prepayid,
  132. signType: "RSA",
  133. paySign: param.sign,
  134. success: res => {
  135. uni.showToast({
  136. title: '支付成功!'
  137. });
  138. setTimeout(res => {
  139. uni.switchTab({
  140. url: '/pages/order/index'
  141. })
  142. }, 1000)
  143. },
  144. fail: res => {
  145. console.log(res)
  146. uni.showModal({
  147. content: '支付失败',
  148. showCancel: false
  149. });
  150. setTimeout(res => {
  151. uni.switchTab({
  152. url: '/pages/order/index'
  153. })
  154. }, 1000)
  155. }
  156. });
  157. }).catch(() => {
  158. uni.showToast({
  159. title: "操作失败"
  160. })
  161. });
  162. },
  163. //余额支付
  164. balancePay() {
  165. if (this.password.length < 6 && this.needPassword) {
  166. uni.showToast({
  167. title: "交易密码不能小于6位"
  168. })
  169. return;
  170. }
  171. this.$refs.passwordPopup.close()
  172. this.$api.balancePay({
  173. orderNo: this.subOrderNo,
  174. password: this.password
  175. }).then((res) => {
  176. uni.showToast({
  177. title: '支付成功!'
  178. });
  179. setTimeout(res => {
  180. uni.switchTab({
  181. url: '/pages/order/index'
  182. })
  183. }, 1000)
  184. this.getUserInfo()
  185. }).catch((res) => {
  186. console.log(res)
  187. let msg = res.data.msg || '操作失败';
  188. uni.showToast({
  189. title: msg,
  190. icon: 'error'
  191. })
  192. });
  193. },
  194. getUserInfo() {
  195. this.$api.getUserInfo().then(res => {
  196. console.log('++++++++++++获取用户信息++++++++++++++++++', res)
  197. uni.setStorageSync('userInfo', res.data.data)
  198. this.userInfo = res.data.data
  199. })
  200. },
  201. }
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .payView {
  206. height: 638rpx;
  207. background: #FFFFFF;
  208. box-shadow: 0rpx -4rpx 8rpx 0rpx rgba(0, 0, 0, 0.03);
  209. border-radius: 24rpx 24rpx 0rpx 0rpx;
  210. padding: 24rpx 32rpx;
  211. }
  212. .payType {
  213. font-size: 32rpx;
  214. font-weight: bord;
  215. color: #111111;
  216. line-height: 48rpx;
  217. }
  218. .x {
  219. width: 35rpx;
  220. height: 35rpx;
  221. border-radius: 18rpx;
  222. }
  223. .payTitle {
  224. font-size: 24rpx;
  225. font-family: PingFangSC-Regular, PingFang SC;
  226. font-weight: 400;
  227. color: #666666;
  228. line-height: 40rpx;
  229. margin-top: 8rpx;
  230. }
  231. .payItemView{
  232. height: 345rpx;
  233. }
  234. .payItem {
  235. background: #FAFAFA;
  236. border-radius: 20rpx;
  237. padding: 34rpx 32rpx;
  238. margin-top: 32rpx;
  239. }
  240. .payName {
  241. margin-left: 24rpx;
  242. }
  243. .balance {
  244. font-size: 24rpx;
  245. font-family: PingFangSC-Regular, PingFang SC;
  246. font-weight: 400;
  247. color: #999999;
  248. line-height: 40rpx;
  249. }
  250. .commitBtn {
  251. width: 686rpx;
  252. height: 108rpx;
  253. background: #FFE05C;
  254. border-radius: 60rpx;
  255. margin-top: 32rpx;
  256. font-size: 32rpx;
  257. font-family: PingFangSC-Medium, PingFang SC;
  258. font-weight: bold;
  259. color: #111111;
  260. line-height: 108rpx;
  261. text-align: center;
  262. }
  263. .passwordView {
  264. background: #FFFFFF;
  265. width: 686rpx;
  266. height: 400rpx;
  267. border-radius: 20rpx;
  268. padding: 34rpx 0;
  269. }
  270. .h-tab-bar {
  271. margin-top: 80rpx;
  272. }
  273. .h-operate-btn {
  274. width: 550rpx;
  275. height: 80rpx;
  276. border-radius: 40rpx;
  277. background: #FFE05C;
  278. line-height: 80rpx;
  279. text-align: center;
  280. margin-top: 80rpx;
  281. }
  282. </style>