pay.vue 11 KB

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