pay.vue 6.6 KB

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