pay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. <!--&lt;!&ndash; <text class="balance">{{loveCard.presentUserName + loveCard.presentUserNo}}赠送的亲情卡</text>&ndash;&gt;-->
  20. <!--&lt;!&ndash; <text class="balance">余额{{loveCard.totalBalance}}</text>&ndash;&gt;-->
  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. console.log(this.selectBlPay)
  188. if (!this.selectBlPay && num == 1) {
  189. console.log(this.selectBlPay)
  190. uni.$u.toast('余额不足')
  191. return
  192. }
  193. this.curServiceTab = num
  194. },
  195. maskClick(){
  196. this.$emit('improperClose')
  197. },
  198. payment() {
  199. this.$refs.popup.close()
  200. if (this.curServiceTab === 0) {
  201. this.familyCardPay()
  202. }
  203. if (this.curServiceTab === 1) {
  204. if (this.needPassword) {
  205. this.$refs.passwordPopup.open()
  206. } else {
  207. //余额支付
  208. this.balancePay()
  209. }
  210. }
  211. if (this.curServiceTab === 2) {
  212. //微信支付
  213. if (this.openType == 1){
  214. this.wechatPay() //支付预约费用
  215. }else {
  216. this.wechatPayTradeNo() //支付子订单费用
  217. }
  218. }
  219. },
  220. //支付子订单的统一下单接口
  221. wechatPayTradeNo(){
  222. this.$api.wechatPayTradeNo({
  223. tradeNo: this.orderNo
  224. }).then((res) => {
  225. this.requestPayment(res.data.data)
  226. }).catch((err) => {
  227. this.$emit('payResult',{
  228. payResult:false,
  229. res:err
  230. })
  231. });
  232. },
  233. //支付预约费用的统一下单接口
  234. wechatPay() {
  235. this.$api.wechatPay({
  236. orderNo: this.orderNo
  237. }).then((res) => {
  238. this.requestPayment(res.data.data)
  239. }).catch((err) => {
  240. this.$emit('payResult',{
  241. payResult:false,
  242. res:err
  243. })
  244. });
  245. },
  246. familyCardPay(){
  247. this.$api.familyCardPay({
  248. orderNo: this.orderNo,
  249. loveCardId: this.loveCard.id
  250. }).then(res=>{
  251. this.$emit('payResult',{
  252. payResult:true,
  253. res:res
  254. })
  255. }).catch((res) => {
  256. this.$emit('payResult',{
  257. payResult:false,
  258. res:res
  259. })
  260. });
  261. },
  262. //调起微信支付
  263. requestPayment(param){
  264. uni.requestPayment({
  265. appId: param.appid,
  266. timeStamp: param.timestamp + "",
  267. nonceStr: param.noncestr,
  268. package: "prepay_id=" + param.prepayid,
  269. signType: "RSA",
  270. paySign: param.sign,
  271. success: res => {
  272. this.$emit('payResult',{
  273. payResult:true,
  274. res:res
  275. })
  276. },
  277. fail: res => {
  278. this.$emit('payResult',{
  279. payResult:false,
  280. res:res
  281. })
  282. }
  283. });
  284. },
  285. //余额支付
  286. balancePay() {
  287. if (this.password.length < 6 && this.needPassword) {
  288. uni.showToast({
  289. title: "交易密码不能小于6位"
  290. })
  291. return;
  292. }
  293. this.$refs.passwordPopup.close()
  294. if (this.openType == 1){ // 支付预约费用
  295. this.$api.balancePay({
  296. orderNo: this.orderNo,
  297. password: this.password
  298. }).then((res) => {
  299. this.$emit('payResult',{
  300. payResult:true,
  301. res:res
  302. })
  303. }).catch((res) => {
  304. this.$emit('payResult',{
  305. payResult:false,
  306. res:res
  307. })
  308. });
  309. }else { //支付子订单费用
  310. this.$api.trade({
  311. tradeNo: this.orderNo,
  312. password: this.password
  313. }).then((res) => {
  314. this.$emit('payResult',{
  315. payResult:true,
  316. res:res
  317. })
  318. }).catch((res) => {
  319. this.$emit('payResult',{
  320. payResult:false,
  321. res:res
  322. })
  323. });
  324. }
  325. },
  326. //查询我的亲情卡
  327. getMyReceiveList(){
  328. this.$api.getMyReceiveList().then(res=>{
  329. if (this.loveCardList){
  330. this.loveCardId = res.data.data[0].id
  331. res.data.data.forEach(item=>{
  332. let tempItem = {
  333. value:item.id,
  334. text:item.presentUserName + item.presentUserNo + '亲情卡,余额:'+item.totalBalance
  335. }
  336. this.loveCardList.push(tempItem)
  337. })
  338. }
  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. </style>