pay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. 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. storeId:this.storeId
  262. }).then(res=>{
  263. this.$emit('payResult',{
  264. payResult:true,
  265. res:res
  266. })
  267. }).catch((res) => {
  268. this.$emit('payResult',{
  269. payResult:false,
  270. res:res
  271. })
  272. });
  273. },
  274. //调起微信支付
  275. requestPayment(param){
  276. uni.requestPayment({
  277. appId: param.appid,
  278. timeStamp: param.timestamp + "",
  279. nonceStr: param.noncestr,
  280. package: "prepay_id=" + param.prepayid,
  281. signType: "RSA",
  282. paySign: param.sign,
  283. success: res => {
  284. this.$emit('payResult',{
  285. payResult:true,
  286. res:res
  287. })
  288. },
  289. fail: res => {
  290. this.$emit('payResult',{
  291. payResult:false,
  292. res:res
  293. })
  294. }
  295. });
  296. },
  297. //余额支付
  298. balancePay() {
  299. if (this.password.length < 6 && this.needPassword) {
  300. uni.showToast({
  301. title: "交易密码不能小于6位"
  302. })
  303. return;
  304. }
  305. this.$refs.passwordPopup.close()
  306. if (this.openType == 1){ // 支付预约费用
  307. this.$api.balancePay({
  308. orderNo: 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. }else { //支付子订单费用
  322. this.$api.trade({
  323. tradeNo: this.orderNo,
  324. password: this.password
  325. }).then((res) => {
  326. this.$emit('payResult',{
  327. payResult:true,
  328. res:res
  329. })
  330. }).catch((res) => {
  331. this.$emit('payResult',{
  332. payResult:false,
  333. res:res
  334. })
  335. });
  336. }
  337. },
  338. //查询我的亲情卡
  339. getMyReceiveList(){
  340. this.$api.getMyReceiveList().then(res=>{
  341. this.loveCardList = res.data.data
  342. })
  343. }
  344. }
  345. }
  346. </script>
  347. <style lang="scss" scoped>
  348. .payView {
  349. /*height: 638rpx;*/
  350. background: #FFFFFF;
  351. box-shadow: 0rpx -4rpx 8rpx 0rpx rgba(0, 0, 0, 0.03);
  352. border-radius: 24rpx 24rpx 0rpx 0rpx;
  353. padding: 24rpx 32rpx;
  354. }
  355. .payType {
  356. font-size: 32rpx;
  357. font-weight: bold;
  358. color: #111111;
  359. line-height: 48rpx;
  360. }
  361. .x {
  362. width: 35rpx;
  363. height: 35rpx;
  364. border-radius: 18rpx;
  365. }
  366. .payTitle {
  367. font-size: 24rpx;
  368. font-family: PingFangSC-Regular, PingFang SC;
  369. font-weight: 400;
  370. color: #666666;
  371. line-height: 40rpx;
  372. margin-top: 8rpx;
  373. }
  374. .payItemView{
  375. min-height: 345rpx;
  376. }
  377. .payItem {
  378. background: #FAFAFA;
  379. border-radius: 20rpx;
  380. padding: 34rpx 32rpx;
  381. margin-top: 32rpx;
  382. }
  383. .payName {
  384. margin-left: 24rpx;
  385. }
  386. .balance {
  387. font-size: 24rpx;
  388. font-family: PingFangSC-Regular, PingFang SC;
  389. font-weight: 400;
  390. color: #999999;
  391. line-height: 40rpx;
  392. }
  393. .commitBtn {
  394. width: 686rpx;
  395. height: 108rpx;
  396. background: #FFE05C;
  397. border-radius: 60rpx;
  398. margin-top: 32rpx;
  399. font-size: 32rpx;
  400. font-family: PingFangSC-Medium, PingFang SC;
  401. font-weight: bold;
  402. color: #111111;
  403. line-height: 108rpx;
  404. text-align: center;
  405. }
  406. .passwordView {
  407. background: #FFFFFF;
  408. width: 686rpx;
  409. height: 400rpx;
  410. border-radius: 20rpx;
  411. padding: 34rpx 0;
  412. }
  413. .h-tab-bar {
  414. margin-top: 80rpx;
  415. }
  416. .h-operate-btn {
  417. width: 550rpx;
  418. height: 80rpx;
  419. border-radius: 40rpx;
  420. background: #FFE05C;
  421. line-height: 80rpx;
  422. text-align: center;
  423. margin-top: 80rpx;
  424. }
  425. .select{
  426. width: 400rpx;
  427. }
  428. .loveCard{
  429. flex-grow: 1;
  430. max-height: 300rpx;
  431. }
  432. .loveCardItem{
  433. margin-top: 15rpx;
  434. background: #FFFFFF;
  435. }
  436. </style>