index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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. // #endif
  200. // #ifdef H5
  201. this.formpost(res.data.result.pay_url, jsConfig)
  202. // #endif
  203. } else {
  204. switch (paytype) {
  205. case 'weixin':
  206. if (res.data.result === undefined) return that.$util.Tips({
  207. title: that.$t(`缺少支付参数`)
  208. });
  209. // #ifdef MP
  210. let mp_pay_name = ''
  211. if (uni.requestOrderPayment) {
  212. mp_pay_name = 'requestOrderPayment'
  213. } else {
  214. mp_pay_name = 'requestPayment'
  215. }
  216. uni[mp_pay_name]({
  217. timeStamp: jsConfig.timestamp,
  218. nonceStr: jsConfig.nonceStr,
  219. package: jsConfig.package,
  220. signType: jsConfig.signType,
  221. paySign: jsConfig.paySign,
  222. success: function(res) {
  223. uni.hideLoading();
  224. return that.$util.Tips({
  225. title: res.msg,
  226. icon: 'success'
  227. }, () => {
  228. that.$emit('onChangeFun', {
  229. action: 'pay_complete'
  230. });
  231. });
  232. },
  233. fail: function(e) {
  234. uni.hideLoading();
  235. return that.$util.Tips({
  236. title: that.$t(`取消支付`)
  237. }, () => {
  238. that.$emit('onChangeFun', {
  239. action: 'pay_fail'
  240. });
  241. });
  242. },
  243. complete: function(e) {
  244. uni.hideLoading();
  245. if (e.errMsg == 'requestPayment:cancel' || e.errMsg ==
  246. 'requestOrderPayment:cancel') return that.$util
  247. .Tips({
  248. title: that.$t(`取消支付`)
  249. }, () => {
  250. that.$emit('onChangeFun', {
  251. action: 'pay_fail'
  252. });
  253. });
  254. },
  255. });
  256. // #endif
  257. // #ifdef H5
  258. let data = res.data;
  259. if (data.status == "WECHAT_H5_PAY") {
  260. uni.hideLoading();
  261. location.replace(data.result.jsConfig.h5_url);
  262. return that.$util.Tips({
  263. title: that.$t(`支付成功`),
  264. icon: 'success'
  265. }, () => {
  266. that.$emit('onChangeFun', {
  267. action: 'pay_complete'
  268. });
  269. });
  270. } else {
  271. that.$wechat.pay(data.result.jsConfig)
  272. .then(() => {
  273. return that.$util.Tips({
  274. title: that.$t(`支付成功`),
  275. icon: 'success'
  276. }, () => {
  277. that.$emit('onChangeFun', {
  278. action: 'pay_complete'
  279. });
  280. });
  281. })
  282. .catch(() => {
  283. return that.$util.Tips({
  284. title: that.$t(`支付失败`),
  285. }, () => {
  286. that.$emit('onChangeFun', {
  287. action: 'pay_fail'
  288. });
  289. });
  290. });
  291. }
  292. // #endif
  293. // #ifdef APP-PLUS
  294. uni.requestPayment({
  295. provider: 'wxpay',
  296. orderInfo: jsConfig,
  297. success: (e) => {
  298. let url = '/pages/goods/order_pay_status/index?order_id=' +
  299. orderId +
  300. '&msg=支付成功';
  301. uni.showToast({
  302. title: that.$t(`支付成功`)
  303. })
  304. setTimeout(res => {
  305. that.$emit('onChangeFun', {
  306. action: 'pay_complete'
  307. });
  308. }, 2000)
  309. },
  310. fail: (e) => {
  311. uni.showModal({
  312. content: that.$t(`支付失败`),
  313. showCancel: false,
  314. success: function(res) {
  315. if (res.confirm) {
  316. that.$emit('onChangeFun', {
  317. action: 'pay_fail'
  318. });
  319. } else if (res.cancel) {}
  320. }
  321. })
  322. },
  323. complete: () => {
  324. uni.hideLoading();
  325. },
  326. });
  327. // #endif
  328. break;
  329. case 'yue':
  330. uni.hideLoading();
  331. return that.$util.Tips({
  332. title: res.msg,
  333. icon: 'success'
  334. }, () => {
  335. that.$emit('onChangeFun', {
  336. action: 'pay_complete'
  337. });
  338. });
  339. break;
  340. case 'offline':
  341. uni.hideLoading();
  342. return that.$util.Tips({
  343. title: res.msg,
  344. icon: 'success'
  345. }, () => {
  346. that.$emit('onChangeFun', {
  347. action: 'pay_complete'
  348. });
  349. });
  350. break;
  351. case 'friend':
  352. uni.hideLoading();
  353. return that.$util.Tips({
  354. title: res.msg,
  355. icon: 'success'
  356. }, () => {
  357. that.$emit('onChangeFun', {
  358. action: 'pay_complete'
  359. });
  360. });
  361. break;
  362. case 'alipay':
  363. uni.hideLoading();
  364. //#ifdef H5
  365. if (this.$wechat.isWeixin()) {
  366. uni.redirectTo({
  367. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&pay_key=${res.data.result.pay_key}`
  368. });
  369. } else {
  370. uni.hideLoading();
  371. that.formContent = res.data.result.jsConfig;
  372. that.$nextTick(() => {
  373. document.getElementById('alipaysubmit').submit();
  374. });
  375. }
  376. //#endif
  377. // #ifdef MP
  378. uni.navigateTo({
  379. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&link=${res.data.result.jsConfig.qrCode}`
  380. });
  381. // #endif
  382. // #ifdef APP-PLUS
  383. uni.requestPayment({
  384. provider: 'alipay',
  385. orderInfo: jsConfig,
  386. success: (e) => {
  387. uni.showToast({
  388. title: that.$t(`支付成功`)
  389. })
  390. setTimeout(res => {
  391. that.$emit('onChangeFun', {
  392. action: 'pay_complete'
  393. });
  394. }, 2000)
  395. },
  396. fail: (e) => {
  397. uni.showModal({
  398. content: that.$t(`支付失败`),
  399. showCancel: false,
  400. success: function(res) {
  401. if (res.confirm) {
  402. that.$emit('onChangeFun', {
  403. action: 'pay_fail'
  404. });
  405. } else if (res.cancel) {}
  406. }
  407. })
  408. },
  409. complete: () => {
  410. uni.hideLoading();
  411. },
  412. });
  413. // #endif
  414. break;
  415. }
  416. }
  417. }).catch(err => {
  418. uni.hideLoading();
  419. return that.$util.Tips({
  420. title: err
  421. }, () => {
  422. that.$emit('onChangeFun', {
  423. action: 'pay_fail'
  424. });
  425. });
  426. })
  427. }
  428. }
  429. }
  430. </script>
  431. <style scoped lang="scss">
  432. .bgcolor {
  433. background-color: var(--view-theme)
  434. }
  435. .payment {
  436. position: fixed;
  437. bottom: 0;
  438. left: 0;
  439. width: 100%;
  440. border-radius: 16rpx 16rpx 0 0;
  441. background-color: #fff;
  442. padding-bottom: 60rpx;
  443. z-index: 999;
  444. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  445. transform: translate3d(0, 100%, 0);
  446. .payMoney {
  447. font-size: 28rpx;
  448. color: #333333;
  449. text-align: center;
  450. margin-top: 50rpx;
  451. .font-color {
  452. margin-left: 10rpx;
  453. .money {
  454. font-size: 40rpx;
  455. }
  456. }
  457. }
  458. .button {
  459. width: 690rpx;
  460. height: 90rpx;
  461. border-radius: 45rpx;
  462. color: #FFFFFF;
  463. margin: 20rpx auto 0 auto;
  464. }
  465. }
  466. .payment.on {
  467. transform: translate3d(0, 0, 0);
  468. }
  469. .payment .title {
  470. text-align: center;
  471. height: 123rpx;
  472. font-size: 32rpx;
  473. color: #282828;
  474. font-weight: bold;
  475. padding-right: 30rpx;
  476. margin-left: 30rpx;
  477. position: relative;
  478. border-bottom: 1rpx solid #eee;
  479. }
  480. .payment .title .iconfont {
  481. position: absolute;
  482. right: 30rpx;
  483. top: 50%;
  484. transform: translateY(-50%);
  485. font-size: 38rpx;
  486. color: #8a8a8a;
  487. font-weight: normal;
  488. }
  489. .payment .item {
  490. border-bottom: 1rpx solid #eee;
  491. height: 130rpx;
  492. margin-left: 30rpx;
  493. padding-right: 30rpx;
  494. }
  495. .payment .item .left {
  496. width: 610rpx;
  497. }
  498. .payment .item .left .text {
  499. width: 540rpx;
  500. }
  501. .payment .item .left .text .name {
  502. font-size: 32rpx;
  503. color: #282828;
  504. }
  505. .payment .item .left .text .info {
  506. font-size: 24rpx;
  507. color: #999;
  508. }
  509. .payment .item .left .text .info .money {
  510. color: #ff9900;
  511. }
  512. .payment .item .left .iconfont {
  513. font-size: 45rpx;
  514. color: #09bb07;
  515. }
  516. .payment .item .left .iconfont.icon-zhifubao {
  517. color: #00aaea;
  518. }
  519. .payment .item .left .iconfont.icon-yuezhifu {
  520. color: #ff9900;
  521. }
  522. .payment .item .left .iconfont.icon-yuezhifu1 {
  523. color: #eb6623;
  524. }
  525. .payment .item .left .iconfont.icon-tonglianzhifu1 {
  526. color: #305fd8;
  527. }
  528. .payment .item .iconfont {
  529. font-size: 40rpx;
  530. color: #ccc;
  531. }
  532. .icon-haoyoudaizhifu {
  533. color: #F34C3E !important;
  534. }
  535. </style>