pay.vue 11 KB

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