pay.vue 10 KB

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