pay.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <member-base :show="false" >
  3. <view class="div container">
  4. <view class="div common-header-wrap">
  5. <view :style="'height:'+navHeight+'px'"></view>
  6. <view class="common-header-holder"></view>
  7. <view class="common-header-fixed">
  8. <title-header />
  9. <uni-nav-bar v-if="isback" title="付款" class="common-header" left-icon="back" @clickLeft="goBack">
  10. </uni-nav-bar>
  11. <uni-nav-bar v-else title="付款" class="common-header">
  12. </uni-nav-bar>
  13. </view>
  14. </view>
  15. <view class="div" v-if="pay_info">
  16. <view class="div top-wrapper">
  17. <view class="div row-wrapper title-wrapper">
  18. <text class="i iconfont">&#xe6d2;</text>
  19. <label class="title">订单提交成功,请选择付款方式</label>
  20. </view>
  21. <view class="div subtitle-wrapper">
  22. <label class="subtitle">合计:</label>
  23. <label class="price">¥{{pay_info.pay_amount}}</label>
  24. </view>
  25. </view>
  26. <view class="div main-content">
  27. <flex-line v-if="pay_info.member_available_pd>0" :show-border="true">
  28. <view class="div"><text class="span">预存款</text><text
  29. class="span left-price">¥{{pay_info.member_available_pd}}</text></view>
  30. <view class="div" slot="right">
  31. <switch @change="switchChange(1,$event)" :checked="!!payment_info.pd_pay"></switch>
  32. </view>
  33. </flex-line>
  34. <flex-line v-if="pay_info.member_available_rcb>0" :show-border="true">
  35. <view class="div"><text class="span">充值卡</text><text
  36. class="span left-price">¥{{pay_info.member_available_rcb}}</text></view>
  37. <view class="div" slot="right">
  38. <switch @change="switchChange(2,$event)" :checked="!!payment_info.rcb_pay"></switch>
  39. </view>
  40. </flex-line>
  41. <flex-line :show-border="true" @click.native="payType(item.payment_code)" v-for="(item,index) in payment_list"
  42. :key="index">
  43. <view class="div item-left-wrapper">
  44. <text class="i" :class="'icon ' + item.payment_code"></text>
  45. <label class="item-title">{{item.payment_name}}</label>
  46. </view>
  47. <view slot="right" class="div item-right-wrapper">
  48. <text class="i item-select iconfont" v-if="payment_info.payment_code == item.payment_code">&#xe69d;</text>
  49. </view>
  50. </flex-line>
  51. </view>
  52. </view>
  53. <view class="div bottom-wrapper">
  54. <view class="div common-btn ds-button-large" @click="submit">立即付款</view>
  55. </view>
  56. </view>
  57. <uni-popup background-color="#fff" ref="confirm" type="dialog">
  58. <uni-popup-dialog :mode="dialog.mode" :title="dialog.title" :content="dialog.content"
  59. :placeholder="dialog.content" @confirm="confirmDialog" @close="closeDialog"></uni-popup-dialog>
  60. </uni-popup>
  61. </member-base>
  62. </template>
  63. <script>
  64. import { getStoreJoinin } from '../../../api/seller'
  65. import {getFontSize} from '@/util/common'
  66. import TitleHeader from '../../TitleHeader'
  67. import MemberBase from '../MemberBase'
  68. import { isWechat } from '../../../util/wechat'
  69. import {
  70. wechatUser
  71. } from '../../../api/memberLogin'
  72. import {
  73. getOrderpayInfo
  74. } from '../../../api/memberBuy'
  75. import {
  76. getVrOrderpayInfo
  77. } from '../../../api/memberVrBuy'
  78. import {
  79. mapState
  80. } from 'vuex'
  81. import {
  82. pay,
  83. getPaymentList
  84. } from '../../../api/memberPayment'
  85. import {
  86. getRechargeInfo
  87. } from '../../../api/memberRecharge'
  88. import {
  89. loadScript
  90. } from '../../../util/common'
  91. import flexLine from '../../flexLine'
  92. export default {
  93. name: 'pay',
  94. mounted(){
  95. // #ifdef MP-WEIXIN
  96. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  97. // #endif
  98. var pages = getCurrentPages()
  99. var page = pages[pages.length - 2]
  100. var route = page.route
  101. if(route != 'pages/member/order/OrderList'){
  102. this.isback = false
  103. }else{
  104. this.isback = true
  105. }
  106. },
  107. data(){
  108. return {
  109. navHeight: 0,
  110. dialog: {},
  111. pay_sn: '',
  112. pay_type: '',
  113. // 订单支付显示的数据
  114. pay_info: null,
  115. isback:false,//是否显示返回按钮
  116. // 提交支付需要用到的数据
  117. payment_info: {
  118. openid:'',
  119. password: '', // 支付密码
  120. rcb_pay: 0, // 是否使用充值卡进行支付
  121. pd_pay: 0, // 是否使用预存款进行支付
  122. payment_code: 'alipay_h5' // 支付方式
  123. },
  124. payment_list: [],
  125. showNotice: 0,
  126. notice: 0,
  127. }
  128. },
  129. components:{
  130. TitleHeader,
  131. MemberBase,
  132. flexLine
  133. },
  134. computed:{
  135. fontSize(){
  136. return getFontSize()
  137. },
  138. ...mapState({
  139. token: state => state.member.token
  140. })
  141. },
  142. onLoad: function(option) {
  143. this.pay_sn = option.pay_sn ? option.pay_sn : ''
  144. this.pay_type = option.pay_type ? option.pay_type : ''
  145. this.notice = option.notice
  146. this.getMemberPayInfo()
  147. this.getPaymentList()
  148. },
  149. watch: {
  150. showNotice: function(val) {
  151. if (val && this.notice) {
  152. this.dialog = {
  153. condition: 1,
  154. title: '确认支付是否完成',
  155. content: '如果您已完成支付,请点击“确定”按钮,如果您未完成支付,请点击“取消”重新发起支付',
  156. cancelButtonText: '重新支付',
  157. confirmButtonText: '完成付款'
  158. }
  159. this.$refs.confirm.open()
  160. }
  161. }
  162. },
  163. methods: {
  164. switchChange(i, e) {
  165. switch (i) {
  166. case 1:
  167. this.payment_info.pd_pay = e.detail.value
  168. break
  169. case 2:
  170. this.payment_info.rcb_pay = e.detail.value
  171. break
  172. }
  173. },
  174. closeDialog() {
  175. },
  176. confirmDialog(value) {
  177. switch (this.dialog.condition) {
  178. case 1:
  179. this.goNext()
  180. break
  181. case 2:
  182. uni.navigateTo({
  183. url: '/pages/member/setting/AccountSet'
  184. })
  185. break
  186. case 3:
  187. this.payment_info.password = value
  188. this.submit()
  189. break
  190. }
  191. },
  192. goBack() {
  193. if (this.notice) {
  194. uni.navigateBack({
  195. delta: 2
  196. })
  197. } else {
  198. uni.navigateBack({
  199. delta: 1
  200. })
  201. }
  202. },
  203. goNext() {
  204. if (this.pay_type === 'pay_new') {
  205. uni.redirectTo({
  206. url: '/pages/member/order/OrderList?if_pay=1'
  207. })
  208. } else if (this.pay_type === 'vr_pay_new') {
  209. uni.redirectTo({
  210. url: '/pages/member/vrorder/OrderList?if_pay=1'
  211. })
  212. } else if (this.pay_type === 'pd_pay') {
  213. uni.redirectTo({
  214. url: '/pages/member/recharge/RechargeList?if_pay=1'
  215. })
  216. } else if (this.pay_type === 'sj_pay') {
  217. uni.redirectTo({
  218. url: '/pages/member/sellerjoinin/Step1?if_pay=1'
  219. })
  220. }
  221. },
  222. payType(code) {
  223. this.payment_info.payment_code = code
  224. },
  225. getPaymentList() {
  226. var from = ''
  227. var code = ''
  228. // #ifdef H5
  229. if(isWechat()){
  230. code = 'wxpay_jsapi'
  231. }
  232. // #endif
  233. // #ifdef APP-PLUS
  234. from = 'app'
  235. // #endif
  236. // #ifdef MP-WEIXIN
  237. code = 'wxpay_minipro'
  238. // #endif
  239. getPaymentList(from,code).then(res => {
  240. this.payment_list = res.result.payment_list
  241. if (this.payment_list.length) {
  242. this.payment_info.payment_code = this.payment_list[0].payment_code
  243. }
  244. }).catch(function(error) {
  245. uni.showToast({
  246. icon: 'none',
  247. title: error.message
  248. })
  249. })
  250. },
  251. getMemberPayInfo() {
  252. if (this.pay_type === 'pay_new') {
  253. let _this = this
  254. getOrderpayInfo(
  255. this.pay_sn
  256. ).then((res) => {
  257. if (res.code === 10000) {
  258. this.pay_info = res.result.pay_info
  259. }
  260. this.showNotice = 1
  261. }).catch(function(error) {
  262. if (error.code === 12001) { // 订单已经支付
  263. _this.goNext()
  264. } else {
  265. uni.showToast({
  266. icon: 'none',
  267. title: error.message
  268. })
  269. }
  270. })
  271. } else if (this.pay_type === 'vr_pay_new') {
  272. let _this = this
  273. getVrOrderpayInfo(
  274. this.pay_sn
  275. ).then((res) => {
  276. if (res.code === 10000) {
  277. this.pay_info = res.result.pay_info
  278. }
  279. this.showNotice = 1
  280. }).catch(function(error) {
  281. if (error.code === 12001) { // 订单已经支付
  282. _this.goNext()
  283. } else {
  284. uni.showToast({
  285. icon: 'none',
  286. title: error.message
  287. })
  288. }
  289. })
  290. } else if (this.pay_type === 'sj_pay') {
  291. let _this = this
  292. getStoreJoinin().then((res) => {
  293. if (res.code === 10000) {
  294. this.pay_info = res.result.store_joinin
  295. }
  296. this.showNotice = 1
  297. }).catch(function (error) {
  298. if (error.code === 12001) { // 订单已经支付
  299. _this.goNext()
  300. } else {
  301. Toast(error.message)
  302. }
  303. })
  304. } else if (this.pay_type === 'pd_pay') {
  305. getRechargeInfo(
  306. this.pay_sn
  307. ).then((res) => {
  308. if (res.code === 10000) {
  309. this.pay_info = {
  310. pay_amount: res.result.pdinfo.pdr_amount
  311. }
  312. }
  313. this.showNotice = 1
  314. }).catch(function(error) {
  315. if (error.code === 12001) { // 订单已经支付
  316. _this.goNext()
  317. } else {
  318. uni.showToast({
  319. icon: 'none',
  320. title: error.message
  321. })
  322. }
  323. })
  324. }
  325. },
  326. submit() {
  327. if (this.payment_info.pd_pay || this.payment_info.rcb_pay) {
  328. if (!this.pay_info.member_paypwd) {
  329. this.dialog = {
  330. condition: 2,
  331. content: '您需要先去设置支付密码'
  332. }
  333. this.$refs.confirm.open()
  334. } else {
  335. if (!this.payment_info.password) {
  336. this.dialog = {
  337. condition: 3,
  338. mode: 'input',
  339. title: '请输入支付密码',
  340. content: '注:默认支付密码为:123456'
  341. }
  342. this.$refs.confirm.open()
  343. return
  344. }
  345. }
  346. }
  347. // #ifdef MP-WEIXIN
  348. uni.login({
  349. provider: 'weixin',
  350. success: (res)=>{
  351. wechatUser({
  352. code: res.code,
  353. from: 'miniprogram',
  354. }).then(res=>{
  355. this.payment_info.openid=res.result.openid
  356. this.goPay()
  357. }).catch(error=>{
  358. uni.showToast({
  359. icon: 'loading',
  360. title: error.message
  361. })
  362. })
  363. },
  364. fail: (err)=>{
  365. uni.showToast({
  366. icon: 'loading',
  367. title: '登录失败'
  368. })
  369. }
  370. })
  371. // #endif
  372. // #ifndef MP-WEIXIN
  373. this.goPay()
  374. // #endif
  375. },
  376. goPay(){
  377. pay(
  378. this.pay_sn, this.pay_type, this.payment_info, this.token
  379. ).then((res) => {
  380. this.payment_info.password=''
  381. if (res.code) {
  382. if (res.code === 12001) {
  383. this.goNext()
  384. } else if (res.code === 10000) {
  385. var _this = this
  386. // #ifdef APP-PLUS
  387. var orderInfo = res.result.content
  388. var provider = 'wxpay'
  389. if (this.payment_info.payment_code == 'alipay_app') {
  390. var provider = 'alipay'
  391. }
  392. uni.requestPayment({
  393. provider: provider,
  394. orderInfo: orderInfo, //微信、支付宝订单数据
  395. complete: function() {
  396. _this.goNext()
  397. }
  398. })
  399. // #endif
  400. // #ifdef MP-WEIXIN
  401. var result = JSON.parse(res.result)
  402. uni.requestPayment({
  403. provider: 'wxpay',
  404. timeStamp: result.timeStamp,
  405. nonceStr: result.nonceStr,
  406. package: result.package,
  407. signType: 'MD5',
  408. paySign: result.paySign,
  409. complete: function() {
  410. _this.goNext()
  411. }
  412. })
  413. // #endif
  414. } else {
  415. uni.showToast({
  416. icon: 'none',
  417. title: res.message
  418. })
  419. }
  420. } else {
  421. // #ifdef H5
  422. document.write(res)
  423. // #endif
  424. }
  425. }).catch((error)=> {
  426. this.payment_info.password=''
  427. if (error.message) {
  428. uni.showToast({
  429. icon: 'none',
  430. title: error.message
  431. })
  432. } else {
  433. // #ifdef H5
  434. document.write(error)
  435. // #endif
  436. }
  437. })
  438. }
  439. }
  440. }
  441. </script>
  442. <style scoped lang='scss'>
  443. .container {
  444. display: flex;
  445. flex-direction: column;
  446. justify-content: flex-start;
  447. align-items: stretch;
  448. background-color: #F0F2F5;
  449. }
  450. .bottom-wrapper {
  451. background: #fff;
  452. position: absolute;
  453. width: 100%;
  454. padding: .5rem $pageSpace;
  455. box-sizing: border-box;
  456. bottom: 0;
  457. left: 0;
  458. }
  459. .main-content {
  460. padding: 0 $pageSpace;
  461. background: #fff
  462. }
  463. .top-wrapper {
  464. padding: 0 $pageSpace;
  465. height: 5rem;
  466. display: flex;
  467. flex-direction: column;
  468. justify-content: flex-start;
  469. align-items: stretch;
  470. background-color: #fff;
  471. margin-bottom: 0.75rem;
  472. }
  473. .row-wrapper {
  474. display: flex;
  475. flex-direction: row;
  476. justify-content: flex-start;
  477. align-items: center;
  478. }
  479. .title-wrapper {
  480. height: 3.2rem;
  481. .i {
  482. font-size: $mainFontSize;
  483. margin-right: .2rem;
  484. }
  485. }
  486. .subtitle-wrapper {
  487. height: 1.5rem;
  488. text-align: right;
  489. }
  490. .icon {
  491. width: 1.2rem;
  492. height: 1.2rem;
  493. font-size: 1.2rem;
  494. margin-right: 0.5rem;
  495. }
  496. .title {
  497. font-size: $subFontSize;
  498. color: $formInputColor;
  499. font-weight: 700;
  500. }
  501. .subtitle {
  502. font-size: $subFontSize;
  503. color: $descTextColor;
  504. }
  505. .price {
  506. font-size: $h2;
  507. color: $primaryColor;
  508. font-weight: 700;
  509. }
  510. .left-price {
  511. font-size: $h2;
  512. color: #48A1FB;
  513. }
  514. .item-wrapper {
  515. height: 3.1rem;
  516. display: flex;
  517. flex-direction: row;
  518. justify-content: flex-start;
  519. align-items: center;
  520. background-color: #fff;
  521. border-bottom: 1px solid #E8EAED;
  522. }
  523. .item-wrapper {
  524. display: flex;
  525. flex-direction: row;
  526. justify-content: flex-start;
  527. align-items: stretch;
  528. background-color: #fff;
  529. }
  530. .item-left-wrapper {
  531. flex: 1;
  532. display: flex;
  533. flex-direction: row;
  534. justify-content: flex-start;
  535. align-items: center;
  536. .i {
  537. background-image: url(../../../static/image/wxpayicon.png);
  538. background-repeat: no-repeat;
  539. background-size: 100%;
  540. }
  541. .alipay_h5,
  542. .alipay_app {
  543. background-image: url(../../../static/image/alipayicon.png);
  544. }
  545. .unionpay_h5 {
  546. background-image: url(../../../static/image/unionpayicon.png);
  547. }
  548. }
  549. .item-right-wrapper {
  550. flex: 1;
  551. display: flex;
  552. flex-direction: row;
  553. justify-content: flex-end;
  554. align-items: center;
  555. }
  556. .item-title {}
  557. .item-subtitle {
  558. font-size: $h2;
  559. color: #8C8C8C;
  560. margin-right: 0.25rem;
  561. text-align: right;
  562. }
  563. .item-select {
  564. font-size: 1.2rem;
  565. color: #7ED321;
  566. }
  567. .indicator {
  568. width: 0.7rem;
  569. height: 0.7rem;
  570. margin-left: 0.25rem;
  571. margin-right: 0.8rem;
  572. }
  573. .action-wrapper {
  574. display: flex;
  575. flex-direction: row;
  576. justify-content: center;
  577. align-items: center;
  578. height: 2.5rem;
  579. margin-top: 2.25rem;
  580. }
  581. </style>