index.vue 8.6 KB

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