index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="payment" :class="pay_close ? 'on' : ''">
  4. <view class="title acea-row row-center-wrapper">
  5. {{$t(`选择付款方式`)}}<text class="iconfont icon-guanbi" @click='close'></text>
  6. </view>
  7. <view class="item acea-row row-between-wrapper" v-for="(item,index) in payMode" :key="index"
  8. v-show='item.payStatus' @click="payType(item.number || 0 , item.value,index)">
  9. <view class="left acea-row row-between-wrapper">
  10. <view class="iconfont" :class="item.icon"></view>
  11. <view class="text">
  12. <view class="name">{{item.name}}</view>
  13. <view class="info" v-if="item.value == 'yue'">
  14. {{item.title}} <span class="money">{{$t(`¥`)}}{{ item.number }}</span>
  15. </view>
  16. <view class="info" v-else>{{item.title}}</view>
  17. </view>
  18. </view>
  19. <view class="iconfont" :class="active==index?'icon-xuanzhong11 font-num':'icon-weixuan'"></view>
  20. </view>
  21. <view class="payMoney">{{$t(`支付`)}}<span class="font-color">{{$t(`¥`)}}<span
  22. class="money">{{totalPrice}}</span></span></view>
  23. <view class="button bg-color acea-row row-center-wrapper" @click='goPay(number, paytype)'>{{$t(`去付款`)}}
  24. </view>
  25. </view>
  26. <view class="mask" @click='close' v-if="pay_close"></view>
  27. <view v-show="false" v-html="formContent"></view>
  28. </view>
  29. </template>
  30. <script>
  31. import {
  32. orderPay
  33. } from '@/api/order.js';
  34. import colors from '@/mixins/color.js';
  35. export default {
  36. props: {
  37. payMode: {
  38. type: Array,
  39. default: function() {
  40. return [];
  41. }
  42. },
  43. pay_close: {
  44. type: Boolean,
  45. default: false,
  46. },
  47. order_id: {
  48. type: String,
  49. default: ''
  50. },
  51. totalPrice: {
  52. type: String,
  53. default: '0'
  54. },
  55. isCall: {
  56. type: Boolean,
  57. default: false
  58. },
  59. friendPay: {
  60. type: Boolean,
  61. default: false
  62. }
  63. },
  64. mixins: [colors],
  65. data() {
  66. return {
  67. formContent: '',
  68. active: 0,
  69. paytype: '',
  70. number: 0
  71. };
  72. },
  73. watch: {
  74. payMode: {
  75. handler(newV, oldValue) {
  76. let newPayList = [];
  77. newV.forEach((item, index) => {
  78. if (item.payStatus) {
  79. item.index = index;
  80. newPayList.push(item)
  81. }
  82. });
  83. this.active = newPayList[0].index;
  84. this.paytype = newPayList[0].value;
  85. this.number = newPayList[0].number || 0;
  86. },
  87. immediate: true,
  88. deep: true
  89. }
  90. },
  91. methods: {
  92. payType(number, paytype, index) {
  93. this.active = index;
  94. this.paytype = paytype;
  95. this.number = number;
  96. this.$emit('changePayType', paytype)
  97. },
  98. formpost(url, postData) {
  99. let tempform = document.createElement("form");
  100. tempform.action = url;
  101. tempform.method = "post";
  102. tempform.target = "_self";
  103. tempform.style.display = "none";
  104. for (let x in postData) {
  105. let opt = document.createElement("input");
  106. opt.name = x;
  107. opt.value = postData[x];
  108. tempform.appendChild(opt);
  109. }
  110. document.body.appendChild(tempform);
  111. this.$nextTick(e => {
  112. tempform.submit();
  113. })
  114. },
  115. close: function() {
  116. this.$emit('onChangeFun', {
  117. action: 'payClose'
  118. });
  119. },
  120. goPay: function(number, paytype) {
  121. console.log(paytype)
  122. if (this.isCall) {
  123. return this.$emit('onChangeFun', {
  124. action: 'payCheck',
  125. value: paytype
  126. });
  127. }
  128. let that = this;
  129. if (!that.order_id) return that.$util.Tips({
  130. title: that.$t(`请选择要支付的订单`)
  131. });
  132. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  133. title: that.$t(`余额不足`)
  134. });
  135. uni.showLoading({
  136. title: that.$t(`支付中`)
  137. });
  138. if (paytype == 'friend' && that.order_id) {
  139. return uni.navigateTo({
  140. url: '/pages/users/payment_on_behalf/index?order_id=' + that.order_id + '&spread=' +
  141. this.$store.state.app.uid,
  142. success: res => {},
  143. fail: () => {},
  144. complete: () => {}
  145. });
  146. }
  147. console.log('11111')
  148. orderPay({
  149. uni: that.order_id,
  150. paytype: paytype,
  151. type: that.friendPay ? 1 : 0,
  152. // #ifdef MP
  153. 'from': 'routine',
  154. // #endif
  155. // #ifdef H5
  156. 'from': this.$wechat.isWeixin() ? 'weixin' : 'weixinh5',
  157. // #endif
  158. // #ifdef H5
  159. quitUrl: location.port ? location.protocol + '//' + location.hostname + ':' + location
  160. .port +
  161. '/pages/goods/order_details/index?order_id=' + this.order_id : location.protocol +
  162. '//' + location.hostname +
  163. '/pages/goods/order_details/index?order_id=' + this.order_id
  164. // #endif
  165. // #ifdef APP-PLUS
  166. quitUrl: '/pages/goods/order_details/index?order_id=' + this.order_id
  167. // #endif
  168. }).then(res => {
  169. let jsConfig = res.data.result.jsConfig;
  170. console.log(paytype)
  171. if (res.data.status === 'ALLINPAY_PAY') {
  172. uni.hideLoading();
  173. // #ifdef MP
  174. wx.openEmbeddedMiniProgram({
  175. appId: 'wxef277996acc166c3',
  176. extraData: {
  177. cusid: jsConfig.cusid,
  178. appid: jsConfig.appid,
  179. version: jsConfig.version,
  180. trxamt: jsConfig.trxamt,
  181. reqsn: jsConfig.reqsn,
  182. notify_url: jsConfig.notify_url,
  183. body: jsConfig.body,
  184. remark: jsConfig.remark,
  185. validtime: jsConfig.validtime,
  186. randomstr: jsConfig.randomstr,
  187. paytype: jsConfig.paytype,
  188. sign: jsConfig.sign,
  189. signtype: jsConfig.signtype
  190. }
  191. })
  192. this.jumpData = {
  193. orderId: res.data.result.orderId,
  194. msg: res.msg,
  195. }
  196. // #endif
  197. // #ifdef APP-PLUS
  198. plus.runtime.openURL(jsConfig.payinfo);
  199. setTimeout(e => {
  200. uni.reLaunch({
  201. url: goPages
  202. })
  203. }, 1000)
  204. // #endif
  205. // #ifdef H5
  206. this.formpost(res.data.result.pay_url, jsConfig)
  207. // #endif
  208. } else {
  209. switch (paytype) {
  210. case 'weixin':
  211. if (res.data.result === undefined) return that.$util.Tips({
  212. title: that.$t(`缺少支付参数`)
  213. });
  214. // #ifdef MP
  215. let mp_pay_name = ''
  216. if (uni.requestOrderPayment) {
  217. mp_pay_name = 'requestOrderPayment'
  218. } else {
  219. mp_pay_name = 'requestPayment'
  220. }
  221. uni[mp_pay_name]({
  222. timeStamp: jsConfig.timestamp,
  223. nonceStr: jsConfig.nonceStr,
  224. package: jsConfig.package,
  225. signType: jsConfig.signType,
  226. paySign: jsConfig.paySign,
  227. success: function(res) {
  228. uni.hideLoading();
  229. return that.$util.Tips({
  230. title: res.msg,
  231. icon: 'success'
  232. }, () => {
  233. that.$emit('onChangeFun', {
  234. action: 'pay_complete'
  235. });
  236. });
  237. },
  238. fail: function(e) {
  239. uni.hideLoading();
  240. return that.$util.Tips({
  241. title: that.$t(`取消支付`)
  242. }, () => {
  243. that.$emit('onChangeFun', {
  244. action: 'pay_fail'
  245. });
  246. });
  247. },
  248. complete: function(e) {
  249. uni.hideLoading();
  250. if (e.errMsg == 'requestPayment:cancel' || e.errMsg ==
  251. 'requestOrderPayment:cancel') return that.$util
  252. .Tips({
  253. title: that.$t(`取消支付`)
  254. }, () => {
  255. that.$emit('onChangeFun', {
  256. action: 'pay_fail'
  257. });
  258. });
  259. },
  260. });
  261. // #endif
  262. // #ifdef H5
  263. let data = res.data;
  264. if (data.status == "WECHAT_H5_PAY") {
  265. uni.hideLoading();
  266. location.replace(data.result.jsConfig.mweb_url);
  267. return that.$util.Tips({
  268. title: that.$t(`支付成功`),
  269. icon: 'success'
  270. }, () => {
  271. that.$emit('onChangeFun', {
  272. action: 'pay_complete'
  273. });
  274. });
  275. } else {
  276. that.$wechat.pay(data.result.jsConfig)
  277. .then(() => {
  278. return that.$util.Tips({
  279. title: that.$t(`支付成功`),
  280. icon: 'success'
  281. }, () => {
  282. that.$emit('onChangeFun', {
  283. action: 'pay_complete'
  284. });
  285. });
  286. })
  287. .catch(() => {
  288. return that.$util.Tips({
  289. title: that.$t(`支付失败`),
  290. }, () => {
  291. that.$emit('onChangeFun', {
  292. action: 'pay_fail'
  293. });
  294. });
  295. });
  296. }
  297. // #endif
  298. // #ifdef APP-PLUS
  299. uni.requestPayment({
  300. provider: 'wxpay',
  301. orderInfo: jsConfig,
  302. success: (e) => {
  303. let url = '/pages/goods/order_pay_status/index?order_id=' +
  304. orderId +
  305. '&msg=支付成功';
  306. uni.showToast({
  307. title: that.$t(`支付成功`)
  308. })
  309. setTimeout(res => {
  310. that.$emit('onChangeFun', {
  311. action: 'pay_complete'
  312. });
  313. }, 2000)
  314. },
  315. fail: (e) => {
  316. uni.showModal({
  317. content: that.$t(`支付失败`),
  318. showCancel: false,
  319. success: function(res) {
  320. if (res.confirm) {
  321. that.$emit('onChangeFun', {
  322. action: 'pay_fail'
  323. });
  324. } else if (res.cancel) {}
  325. }
  326. })
  327. },
  328. complete: () => {
  329. uni.hideLoading();
  330. },
  331. });
  332. // #endif
  333. break;
  334. case 'yue':
  335. uni.hideLoading();
  336. return that.$util.Tips({
  337. title: res.msg,
  338. icon: 'success'
  339. }, () => {
  340. that.$emit('onChangeFun', {
  341. action: 'pay_complete'
  342. });
  343. });
  344. break;
  345. case 'offline':
  346. uni.hideLoading();
  347. return that.$util.Tips({
  348. title: res.msg,
  349. icon: 'success'
  350. }, () => {
  351. that.$emit('onChangeFun', {
  352. action: 'pay_complete'
  353. });
  354. });
  355. break;
  356. case 'friend':
  357. uni.hideLoading();
  358. return that.$util.Tips({
  359. title: res.msg,
  360. icon: 'success'
  361. }, () => {
  362. that.$emit('onChangeFun', {
  363. action: 'pay_complete'
  364. });
  365. });
  366. break;
  367. case 'alipay':
  368. uni.hideLoading();
  369. //#ifdef H5
  370. if (this.$wechat.isWeixin()) {
  371. uni.redirectTo({
  372. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&pay_key=${res.data.result.pay_key}`
  373. });
  374. } else {
  375. uni.hideLoading();
  376. that.formContent = res.data.result.jsConfig;
  377. that.$nextTick(() => {
  378. document.getElementById('alipaysubmit').submit();
  379. });
  380. }
  381. //#endif
  382. // #ifdef MP
  383. uni.navigateTo({
  384. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&link=${res.data.result.jsConfig.qrCode}`
  385. });
  386. // #endif
  387. // #ifdef APP-PLUS
  388. uni.requestPayment({
  389. provider: 'alipay',
  390. orderInfo: jsConfig,
  391. success: (e) => {
  392. uni.showToast({
  393. title: that.$t(`支付成功`)
  394. })
  395. setTimeout(res => {
  396. that.$emit('onChangeFun', {
  397. action: 'pay_complete'
  398. });
  399. }, 2000)
  400. },
  401. fail: (e) => {
  402. uni.showModal({
  403. content: that.$t(`支付失败`),
  404. showCancel: false,
  405. success: function(res) {
  406. if (res.confirm) {
  407. that.$emit('onChangeFun', {
  408. action: 'pay_fail'
  409. });
  410. } else if (res.cancel) {}
  411. }
  412. })
  413. },
  414. complete: () => {
  415. uni.hideLoading();
  416. },
  417. });
  418. // #endif
  419. break;
  420. }
  421. }
  422. }).catch(err => {
  423. uni.hideLoading();
  424. return that.$util.Tips({
  425. title: err
  426. }, () => {
  427. that.$emit('onChangeFun', {
  428. action: 'pay_fail'
  429. });
  430. });
  431. })
  432. }
  433. }
  434. }
  435. </script>
  436. <style scoped lang="scss">
  437. .bgcolor {
  438. background-color: var(--view-theme)
  439. }
  440. .payment {
  441. position: fixed;
  442. bottom: 0;
  443. left: 0;
  444. width: 100%;
  445. border-radius: 16rpx 16rpx 0 0;
  446. background-color: #fff;
  447. padding-bottom: 60rpx;
  448. z-index: 999;
  449. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  450. transform: translate3d(0, 100%, 0);
  451. .payMoney {
  452. font-size: 28rpx;
  453. color: #333333;
  454. text-align: center;
  455. margin-top: 50rpx;
  456. .font-color {
  457. margin-left: 10rpx;
  458. .money {
  459. font-size: 40rpx;
  460. }
  461. }
  462. }
  463. .button {
  464. width: 690rpx;
  465. height: 90rpx;
  466. border-radius: 45rpx;
  467. color: #FFFFFF;
  468. margin: 20rpx auto 0 auto;
  469. }
  470. }
  471. .payment.on {
  472. transform: translate3d(0, 0, 0);
  473. }
  474. .payment .title {
  475. text-align: center;
  476. height: 123rpx;
  477. font-size: 32rpx;
  478. color: #282828;
  479. font-weight: bold;
  480. padding-right: 30rpx;
  481. margin-left: 30rpx;
  482. position: relative;
  483. border-bottom: 1rpx solid #eee;
  484. }
  485. .payment .title .iconfont {
  486. position: absolute;
  487. right: 30rpx;
  488. top: 50%;
  489. transform: translateY(-50%);
  490. font-size: 38rpx;
  491. color: #8a8a8a;
  492. font-weight: normal;
  493. }
  494. .payment .item {
  495. border-bottom: 1rpx solid #eee;
  496. height: 130rpx;
  497. margin-left: 30rpx;
  498. padding-right: 30rpx;
  499. }
  500. .payment .item .left {
  501. width: 610rpx;
  502. }
  503. .payment .item .left .text {
  504. width: 540rpx;
  505. }
  506. .payment .item .left .text .name {
  507. font-size: 32rpx;
  508. color: #282828;
  509. }
  510. .payment .item .left .text .info {
  511. font-size: 24rpx;
  512. color: #999;
  513. }
  514. .payment .item .left .text .info .money {
  515. color: #ff9900;
  516. }
  517. .payment .item .left .iconfont {
  518. font-size: 45rpx;
  519. color: #09bb07;
  520. }
  521. .payment .item .left .iconfont.icon-zhifubao {
  522. color: #00aaea;
  523. }
  524. .payment .item .left .iconfont.icon-yuezhifu {
  525. color: #ff9900;
  526. }
  527. .payment .item .left .iconfont.icon-yuezhifu1 {
  528. color: #eb6623;
  529. }
  530. .payment .item .left .iconfont.icon-tonglianzhifu1 {
  531. color: #305fd8;
  532. }
  533. .payment .item .iconfont {
  534. font-size: 40rpx;
  535. color: #ccc;
  536. }
  537. .icon-haoyoudaizhifu {
  538. color: #F34C3E !important;
  539. }
  540. </style>