index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. } else if (paytype == 'balance') {
  76. type = 'balance';
  77. }else if(paytype == 'alipay'){
  78. // #ifdef H5
  79. type = 'alipay';
  80. // #endif
  81. // #ifdef MP
  82. type = 'alipayQr';
  83. // #endif
  84. }
  85. if (!that.order_id) return that.$util.Tips({
  86. title: '请选择要支付的订单'
  87. });
  88. if (paytype == 'balance' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  89. title: '余额不足!'
  90. });
  91. uni.showLoading({
  92. title: '支付中'
  93. });
  94. let orderApi = that.order_type === 1 ? presellOrderPay : orderPay
  95. orderApi(that.order_id, {
  96. type: type,
  97. // #ifdef H5
  98. return_url: 'http://'+window.location.host+'/pages/users/order_list/index',
  99. // #endif
  100. }).then(res => {
  101. let status = res.data.status,
  102. orderId = res.data.result.order_id,
  103. jsConfig = res.data.result.config,
  104. callback_key = res.data.result.pay_key,
  105. goPages = '/pages/users/order_list/index';
  106. switch (status) {
  107. case 'ORDER_EXIST':
  108. case 'EXTEND_ORDER':
  109. case 'PAY_ERROR':
  110. case 'error':
  111. uni.hideLoading();
  112. this.$emit('onChangeFun', {
  113. action: 'payClose'
  114. });
  115. return that.$util.Tips({
  116. title: res.message
  117. });
  118. break;
  119. case 'success':
  120. uni.hideLoading();
  121. this.$emit('onChangeFun', {
  122. action: 'payClose'
  123. });
  124. if (that.BargainId || that.combinationId || that.pinkId || that.seckillId)
  125. return that.$util.Tips({
  126. title: res.message,
  127. icon: 'success'
  128. }, {
  129. tab: 5,
  130. url: goPages + '?status=1'
  131. });
  132. return that.$util.Tips({
  133. title: res.message,
  134. icon: 'success'
  135. }, {
  136. tab: 5,
  137. url: goPages + '?status=1'
  138. });
  139. break;
  140. case 'alipay':
  141. case 'alipayQr':
  142. uni.hideLoading();
  143. this.$emit('onChangeFun', {
  144. action: 'payClose'
  145. });
  146. uni.navigateTo({
  147. url: '/pages/order_pay_back/index?keyCode='+callback_key+'&url='+jsConfig,
  148. })
  149. return
  150. break;
  151. // #ifndef MP
  152. case "wechat":
  153. case "weixin":
  154. jsConfig.timeStamp = jsConfig.timestamp;
  155. that.$wechat.pay(jsConfig).then(res => {
  156. console.log('测试支付数据无效的success:'+res.data)
  157. this.$emit('onChangeFun', {
  158. action: 'payClose'
  159. });
  160. return that.$util.Tips({
  161. title: res.message,
  162. icon: 'success'
  163. }, {
  164. tab: 5,
  165. url: goPages + 'status=1'
  166. });
  167. }).catch(res => {
  168. console.log('测试支付数据无效的catch:'+res.data)
  169. if (res.errMsg == 'chooseWXPay:cancel') return that.$util.Tips({
  170. title: '取消支付'
  171. }, {
  172. tab: 5,
  173. url: goPages + '?status=0'
  174. });
  175. })
  176. break;
  177. // #endif
  178. // #ifdef MP
  179. case "routine":
  180. jsConfig.timeStamp = jsConfig.timestamp;
  181. that.toPay = true;
  182. uni.requestPayment({
  183. ...jsConfig,
  184. success: function(res) {
  185. uni.hideLoading();
  186. this.$emit('onChangeFun', {
  187. action: 'payClose'
  188. });
  189. if (that.BargainId || that.combinationId || that.pinkId || that.seckillId)
  190. return that.$util.Tips({
  191. title: '支付成功',
  192. icon: 'success'
  193. }, {
  194. tab: 5,
  195. url: goPages + '?status=1'
  196. });
  197. return that.$util.Tips({
  198. title: '支付成功',
  199. icon: 'success'
  200. }, {
  201. tab: 5,
  202. url: goPages + '?status=1'
  203. });
  204. },
  205. fail: function(e) {
  206. uni.hideLoading();
  207. this.$emit('onChangeFun', {
  208. action: 'payClose'
  209. });
  210. return that.$util.Tips({
  211. title: '取消支付'
  212. });
  213. },
  214. complete: function(e) {
  215. uni.hideLoading();
  216. //关闭当前页面跳转至订单状态
  217. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  218. title: '取消支付'
  219. });
  220. this.$emit('onChangeFun', {
  221. action: 'payClose'
  222. });
  223. },
  224. })
  225. break;
  226. // #endif
  227. case "balance":
  228. uni.hideLoading();
  229. this.$emit('onChangeFun', {
  230. action: 'payClose'
  231. });
  232. //余额不足
  233. return that.$util.Tips({
  234. title: res.message
  235. });
  236. break;
  237. // #ifdef H5
  238. case 'h5':
  239. let host = window.location.protocol+"//"+window.location.host;
  240. let url = `${host}/pages/order_pay_status/index?order_id=${orderId}`
  241. let eUrl = encodeURIComponent(url)
  242. let locations = `${jsConfig.mweb_url}&redirect_url=${eUrl}`
  243. setTimeout(() => {
  244. location.href = locations;
  245. }, 100);
  246. break;
  247. // #endif
  248. }
  249. }).catch(err => {
  250. uni.hideLoading();
  251. return that.$util.Tips({
  252. title: err
  253. });
  254. })
  255. }
  256. }
  257. }
  258. </script>
  259. <style scoped lang="scss">
  260. .payment {
  261. position: fixed;
  262. bottom: 0;
  263. left: 0;
  264. width: 100%;
  265. border-radius: 16rpx 16rpx 0 0;
  266. background-color: #fff;
  267. padding-bottom: 60rpx;
  268. z-index: 99;
  269. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  270. transform: translate3d(0, 100%, 0);
  271. }
  272. .payment.on {
  273. transform: translate3d(0, 0, 0);
  274. }
  275. .payment .title {
  276. text-align: center;
  277. height: 123rpx;
  278. font-size: 32rpx;
  279. color: #282828;
  280. font-weight: bold;
  281. padding-right: 30rpx;
  282. margin-left: 30rpx;
  283. position: relative;
  284. border-bottom: 1rpx solid #eee;
  285. }
  286. .payment .title .iconfont {
  287. position: absolute;
  288. right: 30rpx;
  289. top: 50%;
  290. transform: translateY(-50%);
  291. font-size: 43rpx;
  292. color: #8a8a8a;
  293. font-weight: normal;
  294. }
  295. .payment .item {
  296. border-bottom: 1rpx solid #eee;
  297. height: 130rpx;
  298. margin-left: 30rpx;
  299. padding-right: 30rpx;
  300. }
  301. .payment .item .left {
  302. width: 610rpx;
  303. }
  304. .payment .item .left .text {
  305. width: 540rpx;
  306. }
  307. .payment .item .left .text .name {
  308. font-size: 32rpx;
  309. color: #282828;
  310. }
  311. .payment .item .left .text .info {
  312. font-size: 24rpx;
  313. color: #999;
  314. }
  315. .payment .item .left .text .info .money {
  316. color: #ff9900;
  317. }
  318. .payment .item .left .iconfont {
  319. font-size: 45rpx;
  320. color: #09bb07;
  321. }
  322. .payment .item .left .iconfont.icon-zhifubao {
  323. color: #00aaea;
  324. }
  325. .payment .item .left .iconfont.icon-yuezhifu {
  326. color: #ff9900;
  327. }
  328. .payment .item .left .iconfont.icon-yuezhifu1 {
  329. color: #eb6623;
  330. }
  331. .payment .item .iconfont {
  332. font-size: 0.3rpx;
  333. color: #999;
  334. }
  335. </style>