index.vue 10 KB

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