index.vue 11 KB

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