index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <view>
  3. <view class="payment" :class="pay_close ? 'on' : ''">
  4. <view class="title acea-row row-center-wrapper">
  5. 选择付款方式<text class="iconfont icon-guanbi" @click='close'></text>
  6. </view>
  7. <view class="item acea-row row-between-wrapper" @click='goPay(item.number || 0 , item.value)' v-for="(item,index) in payMode" v-if="item.payStatus==1"
  8. :key="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.number">
  14. {{item.title}} <span class="money">¥{{ item.number }}</span>
  15. </view>
  16. <view class="info" v-else>{{item.title}}</view>
  17. </view>
  18. </view>
  19. <view class="iconfont icon-xiangyou"></view>
  20. </view>
  21. </view>
  22. <view class="mask" ref="close" @click='close' v-if="pay_close"></view>
  23. </view>
  24. </template>
  25. <script>
  26. // +----------------------------------------------------------------------
  27. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  28. // +----------------------------------------------------------------------
  29. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  30. // +----------------------------------------------------------------------
  31. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  32. // +----------------------------------------------------------------------
  33. // | Author: CRMEB Team <admin@crmeb.com>
  34. // +----------------------------------------------------------------------
  35. import {
  36. orderPay,
  37. integralOrderPay,
  38. presellOrderPay
  39. } from '@/api/order.js';
  40. export default {
  41. props: {
  42. payMode: {
  43. type: Array,
  44. default: function() {
  45. return [];
  46. }
  47. },
  48. pay_close: {
  49. type: Boolean,
  50. default: false,
  51. },
  52. order_id: {
  53. type: String,
  54. default: ''
  55. },
  56. totalPrice: {
  57. type: String,
  58. default: '0'
  59. },
  60. order_type: {
  61. type: Number,
  62. default: 0,
  63. },
  64. isCall: {
  65. type: Boolean,
  66. default: false
  67. },
  68. returnUrl: {
  69. type: String,
  70. default: ''
  71. }
  72. },
  73. data() {
  74. return {
  75. };
  76. },
  77. mounted:function(){
  78. },
  79. methods: {
  80. close: function() {
  81. this.$emit('onChangeFun', {
  82. action: 'payClose'
  83. });
  84. },
  85. goPay: function(number, paytype) {
  86. if (this.isCall) {
  87. return this.$emit('onChangeFun', {
  88. action: 'payCheck',
  89. value: paytype
  90. });
  91. }
  92. let that = this;
  93. let type = ''
  94. if (paytype == 'wechat') {
  95. // #ifdef H5
  96. type = this.$wechat.isWeixin() ? 'weixin' : 'h5';
  97. // #endif
  98. // #ifdef APP-PLUS
  99. type = 'weixin';
  100. // #endif
  101. // #ifdef MP
  102. type = 'routine';
  103. // #endif
  104. } else if (paytype == 'balance') {
  105. type = 'balance';
  106. }else if(paytype == 'alipay'){
  107. // #ifndef MP
  108. type = 'alipay';
  109. // #endif
  110. // #ifdef MP
  111. type = 'alipayQr';
  112. // #endif
  113. }
  114. if (!that.order_id) return that.$util.Tips({
  115. title: '请选择要支付的订单'
  116. });
  117. if (paytype == 'balance' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  118. title: '余额不足!'
  119. });
  120. uni.showLoading({
  121. title: '支付中'
  122. });
  123. let orderApi = that.order_type === 1 ? presellOrderPay : that.order_type === 2 ? integralOrderPay : orderPay
  124. orderApi(that.order_id, {
  125. type: type,
  126. // #ifdef H5
  127. return_url: that.returnUrl!=='' ? 'http://'+window.location.host+that.returnUrl : 'http://'+window.location.host+'/pages/users/order_list/index',
  128. // #endif
  129. }).then(res => {
  130. let status = res.data.status,
  131. orderId = res.data.result.order_id,
  132. jsConfig = res.data.result.config,
  133. callback_key = res.data.result.pay_key,
  134. goPages = that.returnUrl ? that.returnUrl : '/pages/users/order_list/index';
  135. switch (status) {
  136. case 'ORDER_EXIST':
  137. case 'EXTEND_ORDER':
  138. case 'PAY_ERROR':
  139. case 'error':
  140. uni.hideLoading();
  141. this.$emit('onChangeFun', {
  142. action: 'payClose'
  143. });
  144. return that.$util.Tips({
  145. title: res.message
  146. });
  147. break;
  148. case 'success':
  149. uni.hideLoading();
  150. this.$emit('onChangeFun', {
  151. action: 'payClose'
  152. });
  153. return that.$util.Tips({
  154. title: '支付成功',
  155. icon: 'success'
  156. }, {
  157. tab: 5,
  158. url: goPages + '?status=1'
  159. });
  160. break;
  161. case 'alipay':
  162. case 'alipayQr':
  163. uni.hideLoading();
  164. this.$emit('onChangeFun', {
  165. action: 'payClose'
  166. });
  167. uni.navigateTo({
  168. url: '/pages/order_pay_back/index?keyCode='+callback_key+'&url='+jsConfig,
  169. })
  170. return
  171. break;
  172. // #ifndef MP
  173. case "wechat":
  174. case "weixin":
  175. case "weixinApp":
  176. jsConfig.timeStamp = jsConfig.timestamp;
  177. // #ifndef APP-PLUS
  178. that.$wechat.pay(jsConfig).then(res => {
  179. console.log('测试支付数据无效的success:'+res.data)
  180. this.$emit('onChangeFun', {
  181. action: 'payClose'
  182. });
  183. uni.hideLoading();
  184. return that.$util.Tips({
  185. title: '支付成功',
  186. icon: 'success'
  187. }, {
  188. tab: 5,
  189. url: goPages + 'status=1'
  190. });
  191. }).catch(res => {
  192. console.log('测试支付数据无效的catch:'+res.data)
  193. if (res.errMsg == 'chooseWXPay:cancel'){
  194. if(that.isCall){
  195. return that.$util.Tips({
  196. title: '取消支付'
  197. });
  198. }else{
  199. return that.$util.Tips({
  200. title: '取消支付'
  201. }, {
  202. tab: 5,
  203. url: goPages + '?status=0'
  204. });
  205. }
  206. }
  207. })
  208. // #endif
  209. // #ifdef APP-PLUS
  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. provider: 'wxpay',
  218. orderInfo: jsConfig,
  219. success: (e) => {
  220. this.$emit('onChangeFun', {
  221. action: 'payClose'
  222. });
  223. return that.$util.Tips({
  224. title: '支付成功',
  225. icon: 'success'
  226. }, {
  227. tab: 5,
  228. url: goPages + 'status=1'
  229. });
  230. },
  231. fail: (e) => {
  232. if(that.isCall){
  233. return that.$util.Tips({
  234. title: '取消支付'
  235. });
  236. }else{
  237. return that.$util.Tips({
  238. title: '取消支付'
  239. }, {
  240. tab: 5,
  241. url: goPages + '?status=0'
  242. });
  243. }
  244. },
  245. complete: () => {
  246. uni.hideLoading();
  247. },
  248. });
  249. // #endif
  250. break;
  251. // #endif
  252. // #ifdef MP
  253. case "routine":
  254. jsConfig.timeStamp = jsConfig.timestamp;
  255. that.toPay = true;
  256. let mp_pay_name=''
  257. if(uni.requestOrderPayment){
  258. mp_pay_name='requestOrderPayment'
  259. }else{
  260. mp_pay_name='requestPayment'
  261. }
  262. uni[mp_pay_name]({
  263. ...jsConfig,
  264. success: function(res) {
  265. uni.hideLoading();
  266. that.$emit('onChangeFun', {
  267. action: 'payClose'
  268. });
  269. if (that.BargainId || that.combinationId || that.pinkId || that.seckillId)
  270. return that.$util.Tips({
  271. title: '支付成功',
  272. icon: 'success'
  273. }, {
  274. tab: 5,
  275. url: goPages + '?status=1'
  276. });
  277. return that.$util.Tips({
  278. title: '支付成功',
  279. icon: 'success'
  280. }, {
  281. tab: 5,
  282. url: goPages + '?status=1'
  283. });
  284. },
  285. fail: function(e) {
  286. uni.hideLoading();
  287. that.$emit('onChangeFun', {
  288. action: 'payClose'
  289. });
  290. return that.$util.Tips({
  291. title: '取消支付'
  292. });
  293. },
  294. complete: function(e) {
  295. uni.hideLoading();
  296. //关闭当前页面跳转至订单状态
  297. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  298. title: '取消支付'
  299. });
  300. that.$emit('onChangeFun', {
  301. action: 'payClose'
  302. });
  303. },
  304. })
  305. break;
  306. // #endif
  307. case "balance":
  308. uni.hideLoading();
  309. that.$emit('onChangeFun', {
  310. action: 'payClose'
  311. });
  312. //余额不足
  313. return that.$util.Tips({
  314. title: res.message
  315. });
  316. break;
  317. // #ifdef H5
  318. case 'h5':
  319. let host = window.location.protocol+"//"+window.location.host;
  320. let url = `${host}/pages/order_pay_status/index?order_id=${orderId}`
  321. let eUrl = encodeURIComponent(url)
  322. let jsurl = jsConfig.mweb_url || jsConfig.h5_url
  323. let locations = `${jsurl}&redirect_url=${eUrl}`
  324. setTimeout(() => {
  325. location.href = locations;
  326. }, 100);
  327. break;
  328. // #endif
  329. // #ifdef APP-PLUS
  330. case 'alipayApp':
  331. uni.requestPayment({
  332. provider: 'alipay',
  333. orderInfo: jsConfig,
  334. success: (e) => {
  335. that.$emit('onChangeFun', {
  336. action: 'payClose'
  337. });
  338. return that.$util.Tips({
  339. title: '支付成功',
  340. icon: 'success'
  341. }, {
  342. tab: 5,
  343. url: goPages + 'status=1'
  344. });
  345. },
  346. fail: (e) => {
  347. return that.$util.Tips({
  348. title: '取消支付'
  349. });
  350. },
  351. complete: () => {
  352. uni.hideLoading();
  353. },
  354. });
  355. break;
  356. // #endif
  357. }
  358. }).catch(err => {
  359. uni.hideLoading();
  360. return that.$util.Tips({
  361. title: err
  362. });
  363. })
  364. }
  365. }
  366. }
  367. </script>
  368. <style scoped lang="scss">
  369. .payment {
  370. position: fixed;
  371. bottom: 0;
  372. left: 0;
  373. width: 100%;
  374. max-height: 600rpx;
  375. border-radius: 16rpx 16rpx 0 0;
  376. background-color: #fff;
  377. padding-bottom: 60rpx;
  378. z-index: 99;
  379. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  380. transform: translate3d(0, 100%, 0);
  381. }
  382. .payment.on {
  383. transform: translate3d(0, 0, 0);
  384. }
  385. .payment .title {
  386. text-align: center;
  387. height: 123rpx;
  388. font-size: 32rpx;
  389. color: #282828;
  390. font-weight: bold;
  391. padding-right: 30rpx;
  392. margin-left: 30rpx;
  393. position: relative;
  394. border-bottom: 1px solid #eee;
  395. }
  396. .payment .title .iconfont {
  397. position: absolute;
  398. right: 30rpx;
  399. top: 50%;
  400. transform: translateY(-50%);
  401. font-size: 43rpx;
  402. color: #8a8a8a;
  403. font-weight: normal;
  404. }
  405. .payment .item {
  406. border-bottom: 1px solid #eee;
  407. height: 130rpx;
  408. margin-left: 30rpx;
  409. padding-right: 30rpx;
  410. }
  411. .payment .item .left {
  412. width: 610rpx;
  413. }
  414. .payment .item .left .text {
  415. width: 540rpx;
  416. }
  417. .payment .item .left .text .name {
  418. font-size: 32rpx;
  419. color: #282828;
  420. }
  421. .payment .item .left .text .info {
  422. font-size: 24rpx;
  423. color: #999;
  424. }
  425. .payment .item .left .text .info .money {
  426. color: #ff9900;
  427. }
  428. .payment .item .left .iconfont {
  429. font-size: 45rpx;
  430. color: #09bb07;
  431. }
  432. .payment .item .left .iconfont.icon-zhifubao {
  433. color: #00aaea;
  434. }
  435. .payment .item .left .iconfont.icon-yuezhifu {
  436. color: #ff9900;
  437. }
  438. .payment .item .left .iconfont.icon-yuezhifu1 {
  439. color: #eb6623;
  440. }
  441. .payment .item .iconfont {
  442. font-size: 0.3rpx;
  443. color: #999;
  444. }
  445. </style>