index.vue 13 KB

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