pay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. loveCard:{}
  161. };
  162. },
  163. created(){
  164. this.getMyReceiveList()
  165. },
  166. methods: {
  167. change(e){
  168. console.log(this.loveCardId)
  169. console.log(e)
  170. this.loveCardId = e
  171. },
  172. closePayPopup() {
  173. this.$refs.popup.close()
  174. this.$emit('improperClose')
  175. },
  176. openPopup() {
  177. this.password = ''
  178. this.$refs.popup.open()
  179. },
  180. payItem(num) {
  181. if (this.loveCard.totalBalance*1 < this.totalAmount*1 && num == 0){
  182. console.log(this.totalAmount)
  183. uni.$u.toast('余额不足')
  184. return
  185. }
  186. if (!this.selectBlPay) {
  187. uni.$u.toast('余额不足')
  188. return
  189. }
  190. this.curServiceTab = num
  191. },
  192. maskClick(){
  193. this.$emit('improperClose')
  194. },
  195. payment() {
  196. this.$refs.popup.close()
  197. if (this.curServiceTab === 0) {
  198. this.familyCardPay()
  199. }
  200. if (this.curServiceTab === 1) {
  201. if (this.needPassword) {
  202. this.$refs.passwordPopup.open()
  203. } else {
  204. //余额支付
  205. this.balancePay()
  206. }
  207. }
  208. if (this.curServiceTab === 2) {
  209. //微信支付
  210. if (this.openType == 1){
  211. this.wechatPay() //支付预约费用
  212. }else {
  213. this.wechatPayTradeNo() //支付子订单费用
  214. }
  215. }
  216. },
  217. //支付子订单的统一下单接口
  218. wechatPayTradeNo(){
  219. this.$api.wechatPayTradeNo({
  220. tradeNo: this.orderNo
  221. }).then((res) => {
  222. this.requestPayment(res.data.data)
  223. }).catch((err) => {
  224. this.$emit('payResult',{
  225. payResult:false,
  226. res:err
  227. })
  228. });
  229. },
  230. //支付预约费用的统一下单接口
  231. wechatPay() {
  232. this.$api.wechatPay({
  233. orderNo: 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. familyCardPay(){
  244. this.$api.familyCardPay({
  245. orderNo: this.orderNo,
  246. loveCardId: this.loveCard.id
  247. }).then(res=>{
  248. this.$emit('payResult',{
  249. payResult:true,
  250. res:res
  251. })
  252. }).catch((res) => {
  253. this.$emit('payResult',{
  254. payResult:false,
  255. res:res
  256. })
  257. });
  258. },
  259. //调起微信支付
  260. requestPayment(param){
  261. uni.requestPayment({
  262. appId: param.appid,
  263. timeStamp: param.timestamp + "",
  264. nonceStr: param.noncestr,
  265. package: "prepay_id=" + param.prepayid,
  266. signType: "RSA",
  267. paySign: param.sign,
  268. success: res => {
  269. this.$emit('payResult',{
  270. payResult:true,
  271. res:res
  272. })
  273. },
  274. fail: res => {
  275. this.$emit('payResult',{
  276. payResult:false,
  277. res:res
  278. })
  279. }
  280. });
  281. },
  282. //余额支付
  283. balancePay() {
  284. if (this.password.length < 6 && this.needPassword) {
  285. uni.showToast({
  286. title: "交易密码不能小于6位"
  287. })
  288. return;
  289. }
  290. this.$refs.passwordPopup.close()
  291. if (this.openType == 1){ // 支付预约费用
  292. this.$api.balancePay({
  293. orderNo: this.orderNo,
  294. password: this.password
  295. }).then((res) => {
  296. this.$emit('payResult',{
  297. payResult:true,
  298. res:res
  299. })
  300. }).catch((res) => {
  301. this.$emit('payResult',{
  302. payResult:false,
  303. res:res
  304. })
  305. });
  306. }else { //支付子订单费用
  307. this.$api.trade({
  308. tradeNo: this.orderNo,
  309. password: this.password
  310. }).then((res) => {
  311. this.$emit('payResult',{
  312. payResult:true,
  313. res:res
  314. })
  315. }).catch((res) => {
  316. this.$emit('payResult',{
  317. payResult:false,
  318. res:res
  319. })
  320. });
  321. }
  322. },
  323. //查询我的亲情卡
  324. getMyReceiveList(){
  325. this.$api.getMyReceiveList().then(res=>{
  326. this.loveCard = res.data.data[0]
  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 + '亲情卡'
  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>