index.vue 13 KB

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