pay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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}}({{item.presentUserNo}})</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. uni.$u.toast('余额不足')
  199. return
  200. }
  201. this.curServiceTab = num
  202. },
  203. maskClick(){
  204. this.$emit('improperClose')
  205. },
  206. payment() {
  207. this.$refs.popup.close()
  208. if (this.curServiceTab === 0) {
  209. this.familyCardPay()
  210. }
  211. if (this.curServiceTab === 1) {
  212. if (this.needPassword) {
  213. this.$refs.passwordPopup.open()
  214. } else {
  215. //余额支付
  216. this.balancePay()
  217. }
  218. }
  219. if (this.curServiceTab === 2) {
  220. //微信支付
  221. if (this.openType == 1){
  222. this.wechatPay() //支付预约费用
  223. }else {
  224. this.wechatPayTradeNo() //支付子订单费用
  225. }
  226. }
  227. },
  228. //支付子订单的统一下单接口
  229. wechatPayTradeNo(){
  230. this.$api.wechatPayTradeNo({
  231. tradeNo: this.orderNo
  232. }).then((res) => {
  233. this.requestPayment(res.data.data)
  234. }).catch((err) => {
  235. this.$emit('payResult',{
  236. payResult:false,
  237. res:err
  238. })
  239. });
  240. },
  241. //支付预约费用的统一下单接口
  242. wechatPay() {
  243. this.$api.wechatPay({
  244. orderNo: this.orderNo
  245. }).then((res) => {
  246. this.requestPayment(res.data.data)
  247. }).catch((err) => {
  248. this.$emit('payResult',{
  249. payResult:false,
  250. res:err
  251. })
  252. });
  253. },
  254. familyCardPay(){
  255. //亲情卡支付预约费用
  256. this.$api.familyCardPay({
  257. orderNo: this.orderNo,
  258. loveCardId: this.loveCardId
  259. }).then(res=>{
  260. this.$emit('payResult',{
  261. payResult:true,
  262. res:res
  263. })
  264. }).catch((res) => {
  265. this.$emit('payResult',{
  266. payResult:false,
  267. res:res
  268. })
  269. });
  270. },
  271. //调起微信支付
  272. requestPayment(param){
  273. uni.requestPayment({
  274. appId: param.appid,
  275. timeStamp: param.timestamp + "",
  276. nonceStr: param.noncestr,
  277. package: "prepay_id=" + param.prepayid,
  278. signType: "RSA",
  279. paySign: param.sign,
  280. success: res => {
  281. this.$emit('payResult',{
  282. payResult:true,
  283. res:res
  284. })
  285. },
  286. fail: res => {
  287. this.$emit('payResult',{
  288. payResult:false,
  289. res:res
  290. })
  291. }
  292. });
  293. },
  294. //余额支付
  295. balancePay() {
  296. if (this.password.length < 6 && this.needPassword) {
  297. uni.showToast({
  298. title: "交易密码不能小于6位"
  299. })
  300. return;
  301. }
  302. this.$refs.passwordPopup.close()
  303. if (this.openType == 1){ // 支付预约费用
  304. this.$api.balancePay({
  305. orderNo: this.orderNo,
  306. password: this.password
  307. }).then((res) => {
  308. this.$emit('payResult',{
  309. payResult:true,
  310. res:res
  311. })
  312. }).catch((res) => {
  313. this.$emit('payResult',{
  314. payResult:false,
  315. res:res
  316. })
  317. });
  318. }else { //支付子订单费用
  319. this.$api.trade({
  320. tradeNo: this.orderNo,
  321. password: this.password
  322. }).then((res) => {
  323. this.$emit('payResult',{
  324. payResult:true,
  325. res:res
  326. })
  327. }).catch((res) => {
  328. this.$emit('payResult',{
  329. payResult:false,
  330. res:res
  331. })
  332. });
  333. }
  334. },
  335. //查询我的亲情卡
  336. getMyReceiveList(){
  337. this.$api.getMyReceiveList().then(res=>{
  338. this.loveCardList = res.data.data
  339. })
  340. }
  341. }
  342. }
  343. </script>
  344. <style lang="scss" scoped>
  345. .payView {
  346. /*height: 638rpx;*/
  347. background: #FFFFFF;
  348. box-shadow: 0rpx -4rpx 8rpx 0rpx rgba(0, 0, 0, 0.03);
  349. border-radius: 24rpx 24rpx 0rpx 0rpx;
  350. padding: 24rpx 32rpx;
  351. }
  352. .payType {
  353. font-size: 32rpx;
  354. font-weight: bord;
  355. color: #111111;
  356. line-height: 48rpx;
  357. }
  358. .x {
  359. width: 35rpx;
  360. height: 35rpx;
  361. border-radius: 18rpx;
  362. }
  363. .payTitle {
  364. font-size: 24rpx;
  365. font-family: PingFangSC-Regular, PingFang SC;
  366. font-weight: 400;
  367. color: #666666;
  368. line-height: 40rpx;
  369. margin-top: 8rpx;
  370. }
  371. .payItemView{
  372. min-height: 345rpx;
  373. }
  374. .payItem {
  375. background: #FAFAFA;
  376. border-radius: 20rpx;
  377. padding: 34rpx 32rpx;
  378. margin-top: 32rpx;
  379. }
  380. .payName {
  381. margin-left: 24rpx;
  382. }
  383. .balance {
  384. font-size: 24rpx;
  385. font-family: PingFangSC-Regular, PingFang SC;
  386. font-weight: 400;
  387. color: #999999;
  388. line-height: 40rpx;
  389. }
  390. .commitBtn {
  391. width: 686rpx;
  392. height: 108rpx;
  393. background: #FFE05C;
  394. border-radius: 60rpx;
  395. margin-top: 32rpx;
  396. font-size: 32rpx;
  397. font-family: PingFangSC-Medium, PingFang SC;
  398. font-weight: bold;
  399. color: #111111;
  400. line-height: 108rpx;
  401. text-align: center;
  402. }
  403. .passwordView {
  404. background: #FFFFFF;
  405. width: 686rpx;
  406. height: 400rpx;
  407. border-radius: 20rpx;
  408. padding: 34rpx 0;
  409. }
  410. .h-tab-bar {
  411. margin-top: 80rpx;
  412. }
  413. .h-operate-btn {
  414. width: 550rpx;
  415. height: 80rpx;
  416. border-radius: 40rpx;
  417. background: #FFE05C;
  418. line-height: 80rpx;
  419. text-align: center;
  420. margin-top: 80rpx;
  421. }
  422. .select{
  423. width: 400rpx;
  424. }
  425. .loveCard{
  426. flex-grow: 1;
  427. max-height: 300rpx;
  428. }
  429. .loveCardItem{
  430. margin-top: 15rpx;
  431. background: #FFFFFF;
  432. }
  433. </style>