index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. case 'alipayQr':
  154. uni.hideLoading();
  155. this.$emit('onChangeFun', {
  156. action: 'payClose'
  157. });
  158. uni.navigateTo({
  159. url: '/pages/order_pay_back/index?keyCode='+callback_key+'&url='+jsConfig,
  160. })
  161. return
  162. break;
  163. // #ifndef MP
  164. case "wechat":
  165. case "weixin":
  166. case "weixinApp":
  167. jsConfig.timeStamp = jsConfig.timestamp;
  168. // #ifndef APP-PLUS
  169. that.$wechat.pay(jsConfig).then(res => {
  170. console.log('测试支付数据无效的success:'+res.data)
  171. this.$emit('onChangeFun', {
  172. action: 'payClose'
  173. });
  174. return that.$util.Tips({
  175. title: '支付成功',
  176. icon: 'success'
  177. }, {
  178. tab: 5,
  179. url: goPages + 'status=1'
  180. });
  181. }).catch(res => {
  182. console.log('测试支付数据无效的catch:'+res.data)
  183. if (res.errMsg == 'chooseWXPay:cancel') return that.$util.Tips({
  184. title: '取消支付'
  185. }, {
  186. tab: 5,
  187. url: goPages + '?status=0'
  188. });
  189. })
  190. // #endif
  191. // #ifdef APP-PLUS
  192. uni.requestPayment({
  193. provider: 'wxpay',
  194. orderInfo: jsConfig,
  195. success: (e) => {
  196. this.$emit('onChangeFun', {
  197. action: 'payClose'
  198. });
  199. return that.$util.Tips({
  200. title: '支付成功',
  201. icon: 'success'
  202. }, {
  203. tab: 5,
  204. url: goPages + 'status=1'
  205. });
  206. },
  207. fail: (e) => {
  208. return that.$util.Tips({
  209. title: '取消支付'
  210. }, {
  211. tab: 5,
  212. url: goPages + '?status=0'
  213. });
  214. },
  215. complete: () => {
  216. uni.hideLoading();
  217. },
  218. });
  219. // #endif
  220. break;
  221. // #endif
  222. // #ifdef MP
  223. case "routine":
  224. jsConfig.timeStamp = jsConfig.timestamp;
  225. that.toPay = true;
  226. uni.requestPayment({
  227. ...jsConfig,
  228. success: function(res) {
  229. uni.hideLoading();
  230. this.$emit('onChangeFun', {
  231. action: 'payClose'
  232. });
  233. if (that.BargainId || that.combinationId || that.pinkId || that.seckillId)
  234. return that.$util.Tips({
  235. title: '支付成功',
  236. icon: 'success'
  237. }, {
  238. tab: 5,
  239. url: goPages + '?status=1'
  240. });
  241. return that.$util.Tips({
  242. title: '支付成功',
  243. icon: 'success'
  244. }, {
  245. tab: 5,
  246. url: goPages + '?status=1'
  247. });
  248. },
  249. fail: function(e) {
  250. uni.hideLoading();
  251. this.$emit('onChangeFun', {
  252. action: 'payClose'
  253. });
  254. return that.$util.Tips({
  255. title: '取消支付'
  256. });
  257. },
  258. complete: function(e) {
  259. uni.hideLoading();
  260. //关闭当前页面跳转至订单状态
  261. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  262. title: '取消支付'
  263. });
  264. this.$emit('onChangeFun', {
  265. action: 'payClose'
  266. });
  267. },
  268. })
  269. break;
  270. // #endif
  271. case "balance":
  272. uni.hideLoading();
  273. this.$emit('onChangeFun', {
  274. action: 'payClose'
  275. });
  276. //余额不足
  277. return that.$util.Tips({
  278. title: res.message
  279. });
  280. break;
  281. // #ifdef H5
  282. case 'h5':
  283. let host = window.location.protocol+"//"+window.location.host;
  284. let url = `${host}/pages/order_pay_status/index?order_id=${orderId}`
  285. let eUrl = encodeURIComponent(url)
  286. let locations = `${jsConfig.mweb_url}&redirect_url=${eUrl}`
  287. setTimeout(() => {
  288. location.href = locations;
  289. }, 100);
  290. break;
  291. // #endif
  292. // #ifdef APP-PLUS
  293. case 'alipayApp':
  294. uni.requestPayment({
  295. provider: 'alipay',
  296. orderInfo: jsConfig,
  297. success: (e) => {
  298. this.$emit('onChangeFun', {
  299. action: 'payClose'
  300. });
  301. return that.$util.Tips({
  302. title: '支付成功',
  303. icon: 'success'
  304. }, {
  305. tab: 5,
  306. url: goPages + 'status=1'
  307. });
  308. },
  309. fail: (e) => {
  310. return that.$util.Tips({
  311. title: '取消支付'
  312. });
  313. },
  314. complete: () => {
  315. uni.hideLoading();
  316. },
  317. });
  318. break;
  319. // #endif
  320. }
  321. }).catch(err => {
  322. uni.hideLoading();
  323. return that.$util.Tips({
  324. title: err
  325. });
  326. })
  327. }
  328. }
  329. }
  330. </script>
  331. <style scoped lang="scss">
  332. .payment {
  333. position: fixed;
  334. bottom: 0;
  335. left: 0;
  336. width: 100%;
  337. border-radius: 16rpx 16rpx 0 0;
  338. background-color: #fff;
  339. padding-bottom: 60rpx;
  340. z-index: 99;
  341. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  342. transform: translate3d(0, 100%, 0);
  343. }
  344. .payment.on {
  345. transform: translate3d(0, 0, 0);
  346. }
  347. .payment .title {
  348. text-align: center;
  349. height: 123rpx;
  350. font-size: 32rpx;
  351. color: #282828;
  352. font-weight: bold;
  353. padding-right: 30rpx;
  354. margin-left: 30rpx;
  355. position: relative;
  356. border-bottom: 1rpx solid #eee;
  357. }
  358. .payment .title .iconfont {
  359. position: absolute;
  360. right: 30rpx;
  361. top: 50%;
  362. transform: translateY(-50%);
  363. font-size: 43rpx;
  364. color: #8a8a8a;
  365. font-weight: normal;
  366. }
  367. .payment .item {
  368. border-bottom: 1rpx solid #eee;
  369. height: 130rpx;
  370. margin-left: 30rpx;
  371. padding-right: 30rpx;
  372. }
  373. .payment .item .left {
  374. width: 610rpx;
  375. }
  376. .payment .item .left .text {
  377. width: 540rpx;
  378. }
  379. .payment .item .left .text .name {
  380. font-size: 32rpx;
  381. color: #282828;
  382. }
  383. .payment .item .left .text .info {
  384. font-size: 24rpx;
  385. color: #999;
  386. }
  387. .payment .item .left .text .info .money {
  388. color: #ff9900;
  389. }
  390. .payment .item .left .iconfont {
  391. font-size: 45rpx;
  392. color: #09bb07;
  393. }
  394. .payment .item .left .iconfont.icon-zhifubao {
  395. color: #00aaea;
  396. }
  397. .payment .item .left .iconfont.icon-yuezhifu {
  398. color: #ff9900;
  399. }
  400. .payment .item .left .iconfont.icon-yuezhifu1 {
  401. color: #eb6623;
  402. }
  403. .payment .item .iconfont {
  404. font-size: 0.3rpx;
  405. color: #999;
  406. }
  407. </style>