pay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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="lovePay && loveCardList.length>0" class="payItem flex-row" >
  15. <u-icon name="/static/me/familyCard_icon.png" color="#38db38" size="36"></u-icon>
  16. <view class="payName flex-col justify-center flex-grow">
  17. <text>亲情卡支付</text>
  18. <scroll-view scroll-y class="loveCard">
  19. <view class="flex-row justify-between loveCardItem " v-for="(item,index) in loveCardList" :key="index" @click="payLoveItem(0,index,item)">
  20. <view class="select flex-col" >
  21. <text>{{item.presentUserName}}</text>
  22. <text class="balance">本月剩余额度:{{item.totalBalance}}</text>
  23. </view>
  24. <view class="flex-col justify-center">
  25. <u-icon v-if="curServiceTab === 0 && item.select" name="checkmark-circle-fill" color="#38db38" size="25"></u-icon>
  26. <u-icon v-else name="/static/order/ud9.png" color="green" size="25"></u-icon>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. <view v-if="blPay" class="payItem flex-row justify-between" @click="payItem(1)">
  33. <view class="flex-row">
  34. <u-icon name="/static/me/u701.png" color="#38db38" size="36"></u-icon>
  35. <view class="payName flex-col justify-center ">
  36. <text>余额支付</text>
  37. <text class="balance">可用余额{{balance}}</text>
  38. </view>
  39. </view>
  40. <view class="flex-col justify-center">
  41. <u-icon v-if="curServiceTab === 1" name="checkmark-circle-fill" color="#38db38"
  42. size="25"></u-icon>
  43. <u-icon v-else name="/static/order/ud9.png" color="green" size="25"></u-icon>
  44. </view>
  45. </view>
  46. <view v-if="wxPay" class="payItem flex-row justify-between" @click="payItem(2)">
  47. <view class="flex-row">
  48. <u-icon name="weixin-circle-fill" color="#38db38" size="36"></u-icon>
  49. <view class="payName flex-col justify-center">
  50. <text class="payName">微信支付</text>
  51. </view>
  52. </view>
  53. <view class="flex-col justify-center">
  54. <u-icon v-if="curServiceTab === 2" name="checkmark-circle-fill" color="#38db38"
  55. size="25"></u-icon>
  56. <u-icon v-else name="/static/order/ud9.png" color="green" size="25"></u-icon>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="commitBtn" @click="payment">
  61. <text>确定</text>
  62. </view>
  63. </view>
  64. </uni-popup>
  65. <uni-popup ref="passwordPopup">
  66. <view class="passwordView flex-col">
  67. <view class="h-pay-title flex-row justify-center">
  68. <text>请输入交易密码</text>
  69. </view>
  70. <view class="h-tab-bar flex-row justify-center">
  71. <u-code-input v-model="password" mode="box" dot></u-code-input>
  72. </view>
  73. <view class="flex-row justify-center">
  74. <view class="h-operate-btn flex-row justify-center" @click="balancePay">
  75. <text>确定</text>
  76. </view>
  77. </view>
  78. </view>
  79. </uni-popup>
  80. </view>
  81. </template>
  82. <script>
  83. /**
  84. * props参数
  85. *1,needPassword:Boolean类型 是否需要输入密码。true,使用余额支付时开启密码输入框,false,使用余额支付时不弹出密码输入框直接支付。默认false。
  86. *2,wxPay:Boolean类型,是否显示微信支付选项。true--显示,false--不显示。默认true。
  87. *3,blPay:Boolean类型,是否显示余额支付选项。true--显示,false--不显示。默认true。
  88. *4,selectBlPay:Boolean类型,余额支付选项是否能够选中。使用时请根据用户的余额进行判断。true--能,false--不能。默认true。
  89. *5,orderNo:String类型,支付的订单号。
  90. *6,openType:Number类型,1--支付预约费用,2---支付子订单费用。
  91. *7,balance:用户余额
  92. *8.totalAmount 需要支付的金额
  93. * function 回调函数
  94. * 1,payResult(e),支付结果回调。
  95. * 2,improperClose 点击遮罩层和关闭按钮x 关闭弹窗时的回调
  96. */
  97. export default {
  98. name: "myPay",
  99. props: {
  100. needPassword: {
  101. type: Boolean,
  102. default () {
  103. return false
  104. }
  105. },
  106. wxPay: {
  107. type: Boolean,
  108. default () {
  109. return true
  110. }
  111. },
  112. lovePay: {
  113. type: Boolean,
  114. default () {
  115. return true
  116. }
  117. },
  118. blPay: {
  119. type: Boolean,
  120. default () {
  121. return true
  122. }
  123. },
  124. selectBlPay: {
  125. type: Boolean,
  126. default () {
  127. return true
  128. }
  129. },
  130. orderNo: {
  131. type: String,
  132. default () {
  133. return ''
  134. }
  135. },
  136. openType: {
  137. type: Number,
  138. default () {
  139. return 1
  140. }
  141. },
  142. balance: {
  143. type: Number,
  144. default () {
  145. return 0
  146. }
  147. },
  148. totalAmount: {
  149. type: Number,
  150. default () {
  151. return 0
  152. }
  153. }
  154. },
  155. data() {
  156. return {
  157. curServiceTab: 2,
  158. userInfo: {},
  159. password: '',
  160. loveCardId:'',
  161. loveCardList:[],
  162. };
  163. },
  164. created(){
  165. this.getMyReceiveList()
  166. },
  167. methods: {
  168. change(e){
  169. console.log(this.loveCardId)
  170. console.log(e)
  171. this.loveCardId = e
  172. },
  173. closePayPopup() {
  174. this.$refs.popup.close()
  175. this.$emit('improperClose')
  176. },
  177. openPopup() {
  178. this.password = ''
  179. this.$refs.popup.open()
  180. },
  181. payLoveItem(num,index,loveCard){
  182. console.log(loveCard.totalBalance*1, this.totalAmount*1)
  183. if (loveCard.totalBalance*1 < this.totalAmount*1 && num == 0){
  184. console.log(this.totalAmount)
  185. uni.$u.toast('余额不足')
  186. return
  187. }
  188. this.curServiceTab = num
  189. this.loveCardList.forEach(item=>{
  190. item.select = false
  191. })
  192. loveCard.select=true
  193. this.loveCardId = loveCard.id
  194. this.$set(this.loveCardList,index,loveCard)
  195. },
  196. payItem(num) {
  197. if (!this.selectBlPay && num == 1) {
  198. console.log(this.selectBlPay)
  199. uni.$u.toast('余额不足')
  200. return
  201. }
  202. this.curServiceTab = num
  203. },
  204. maskClick(){
  205. this.$emit('improperClose')
  206. },
  207. payment() {
  208. this.$refs.popup.close()
  209. if (this.curServiceTab === 0) {
  210. this.familyCardPay()
  211. }
  212. if (this.curServiceTab === 1) {
  213. if (this.needPassword) {
  214. this.$refs.passwordPopup.open()
  215. } else {
  216. //余额支付
  217. this.balancePay()
  218. }
  219. }
  220. if (this.curServiceTab === 2) {
  221. //微信支付
  222. if (this.openType == 1){
  223. this.wechatPay() //支付预约费用
  224. }else {
  225. this.wechatPayTradeNo() //支付子订单费用
  226. }
  227. }
  228. },
  229. //支付子订单的统一下单接口
  230. wechatPayTradeNo(){
  231. this.$api.wechatPayTradeNo({
  232. tradeNo: this.orderNo
  233. }).then((res) => {
  234. this.requestPayment(res.data.data)
  235. }).catch((err) => {
  236. this.$emit('payResult',{
  237. payResult:false,
  238. res:err
  239. })
  240. });
  241. },
  242. //支付预约费用的统一下单接口
  243. wechatPay() {
  244. this.$api.wechatPay({
  245. orderNo: this.orderNo
  246. }).then((res) => {
  247. this.requestPayment(res.data.data)
  248. }).catch((err) => {
  249. this.$emit('payResult',{
  250. payResult:false,
  251. res:err
  252. })
  253. });
  254. },
  255. familyCardPay(){
  256. //亲情卡支付预约费用
  257. this.$api.familyCardPay({
  258. orderNo: this.orderNo,
  259. loveCardId: this.loveCardId
  260. }).then(res=>{
  261. this.$emit('payResult',{
  262. payResult:true,
  263. res:res
  264. })
  265. }).catch((res) => {
  266. this.$emit('payResult',{
  267. payResult:false,
  268. res:res
  269. })
  270. });
  271. },
  272. //调起微信支付
  273. requestPayment(param){
  274. uni.requestPayment({
  275. appId: param.appid,
  276. timeStamp: param.timestamp + "",
  277. nonceStr: param.noncestr,
  278. package: "prepay_id=" + param.prepayid,
  279. signType: "RSA",
  280. paySign: param.sign,
  281. success: res => {
  282. this.$emit('payResult',{
  283. payResult:true,
  284. res:res
  285. })
  286. },
  287. fail: res => {
  288. this.$emit('payResult',{
  289. payResult:false,
  290. res:res
  291. })
  292. }
  293. });
  294. },
  295. //余额支付
  296. balancePay() {
  297. if (this.password.length < 6 && this.needPassword) {
  298. uni.showToast({
  299. title: "交易密码不能小于6位"
  300. })
  301. return;
  302. }
  303. this.$refs.passwordPopup.close()
  304. if (this.openType == 1){ // 支付预约费用
  305. this.$api.balancePay({
  306. orderNo: this.orderNo,
  307. password: this.password
  308. }).then((res) => {
  309. this.$emit('payResult',{
  310. payResult:true,
  311. res:res
  312. })
  313. }).catch((res) => {
  314. this.$emit('payResult',{
  315. payResult:false,
  316. res:res
  317. })
  318. });
  319. }else { //支付子订单费用
  320. this.$api.trade({
  321. tradeNo: this.orderNo,
  322. password: this.password
  323. }).then((res) => {
  324. this.$emit('payResult',{
  325. payResult:true,
  326. res:res
  327. })
  328. }).catch((res) => {
  329. this.$emit('payResult',{
  330. payResult:false,
  331. res:res
  332. })
  333. });
  334. }
  335. },
  336. //查询我的亲情卡
  337. getMyReceiveList(){
  338. this.$api.getMyReceiveList().then(res=>{
  339. this.loveCardList = res.data.data
  340. })
  341. }
  342. }
  343. }
  344. </script>
  345. <style lang="scss" scoped>
  346. .payView {
  347. /*height: 638rpx;*/
  348. background: #FFFFFF;
  349. box-shadow: 0rpx -4rpx 8rpx 0rpx rgba(0, 0, 0, 0.03);
  350. border-radius: 24rpx 24rpx 0rpx 0rpx;
  351. padding: 24rpx 32rpx;
  352. }
  353. .payType {
  354. font-size: 32rpx;
  355. font-weight: bord;
  356. color: #111111;
  357. line-height: 48rpx;
  358. }
  359. .x {
  360. width: 35rpx;
  361. height: 35rpx;
  362. border-radius: 18rpx;
  363. }
  364. .payTitle {
  365. font-size: 24rpx;
  366. font-family: PingFangSC-Regular, PingFang SC;
  367. font-weight: 400;
  368. color: #666666;
  369. line-height: 40rpx;
  370. margin-top: 8rpx;
  371. }
  372. .payItemView{
  373. min-height: 345rpx;
  374. }
  375. .payItem {
  376. background: #FAFAFA;
  377. border-radius: 20rpx;
  378. padding: 34rpx 32rpx;
  379. margin-top: 32rpx;
  380. }
  381. .payName {
  382. margin-left: 24rpx;
  383. }
  384. .balance {
  385. font-size: 24rpx;
  386. font-family: PingFangSC-Regular, PingFang SC;
  387. font-weight: 400;
  388. color: #999999;
  389. line-height: 40rpx;
  390. }
  391. .commitBtn {
  392. width: 686rpx;
  393. height: 108rpx;
  394. background: #FFE05C;
  395. border-radius: 60rpx;
  396. margin-top: 32rpx;
  397. font-size: 32rpx;
  398. font-family: PingFangSC-Medium, PingFang SC;
  399. font-weight: bold;
  400. color: #111111;
  401. line-height: 108rpx;
  402. text-align: center;
  403. }
  404. .passwordView {
  405. background: #FFFFFF;
  406. width: 686rpx;
  407. height: 400rpx;
  408. border-radius: 20rpx;
  409. padding: 34rpx 0;
  410. }
  411. .h-tab-bar {
  412. margin-top: 80rpx;
  413. }
  414. .h-operate-btn {
  415. width: 550rpx;
  416. height: 80rpx;
  417. border-radius: 40rpx;
  418. background: #FFE05C;
  419. line-height: 80rpx;
  420. text-align: center;
  421. margin-top: 80rpx;
  422. }
  423. .select{
  424. width: 400rpx;
  425. }
  426. .loveCard{
  427. flex-grow: 1;
  428. max-height: 300rpx;
  429. }
  430. .loveCardItem{
  431. margin-top: 15rpx;
  432. background: #FFFFFF;
  433. }
  434. </style>