index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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">
  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" @click='close' v-if="pay_close"></view>
  23. </view>
  24. </template>
  25. <script>
  26. import {
  27. orderPay
  28. } from '@/api/order.js';
  29. export default {
  30. props: {
  31. payMode: {
  32. type: Array,
  33. default: function() {
  34. return [];
  35. }
  36. },
  37. pay_close: {
  38. type: Boolean,
  39. default: false,
  40. },
  41. order_id: {
  42. type: String,
  43. default: ''
  44. },
  45. totalPrice: {
  46. type: String,
  47. default: '0'
  48. }
  49. },
  50. data() {
  51. return {
  52. };
  53. },
  54. methods: {
  55. close: function() {
  56. this.$emit('onChangeFun', {
  57. action: 'payClose'
  58. });
  59. },
  60. goPay: function(number, paytype) {
  61. let that = this;
  62. if (!that.order_id) return that.$util.Tips({
  63. title: '请选择要支付的订单'
  64. });
  65. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  66. title: '余额不足!'
  67. });
  68. uni.showLoading({
  69. title: '支付中'
  70. });
  71. orderPay({
  72. uni: that.order_id,
  73. paytype: paytype,
  74. // #ifdef MP
  75. 'from': 'routine',
  76. // #endif
  77. // #ifdef H5 || APP-PLUS
  78. 'from': this.$wechat.isWeixin() ? 'weixin' : 'weixinh5',
  79. // #endif
  80. }).then(res => {
  81. switch (paytype) {
  82. case 'weixin':
  83. if (res.data.result === undefined) return that.$util.Tips({
  84. title: '缺少支付参数'
  85. });
  86. // #ifdef MP || APP-PLUS
  87. let jsConfig = res.data.result.jsConfig;
  88. uni.requestPayment({
  89. timeStamp: jsConfig.timestamp,
  90. nonceStr: jsConfig.nonceStr,
  91. package: jsConfig.package,
  92. signType: jsConfig.signType,
  93. paySign: jsConfig.paySign,
  94. success: function(res) {
  95. uni.hideLoading();
  96. return that.$util.Tips({
  97. title: res.msg,
  98. icon: 'success'
  99. }, () => {
  100. that.$emit('onChangeFun', {
  101. action: 'pay_complete'
  102. });
  103. });
  104. },
  105. fail: function(e) {
  106. uni.hideLoading();
  107. return that.$util.Tips({
  108. title: '取消支付'
  109. }, () => {
  110. that.$emit('onChangeFun', {
  111. action: 'pay_fail'
  112. });
  113. });
  114. },
  115. complete: function(e) {
  116. uni.hideLoading();
  117. if (e.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  118. title: '取消支付'
  119. }, () => {
  120. that.$emit('onChangeFun', {
  121. action: 'pay_fail'
  122. });
  123. });
  124. },
  125. });
  126. // #endif
  127. // #ifdef H5
  128. let data = res.data;
  129. if (data.status == "WECHAT_H5_PAY") {
  130. uni.hideLoading();
  131. location.replace(data.result.jsConfig.mweb_url);
  132. return that.$util.Tips({
  133. title: "支付成功",
  134. icon: 'success'
  135. }, () => {
  136. that.$emit('onChangeFun', {
  137. action: 'pay_complete'
  138. });
  139. });
  140. } else {
  141. that.$wechat.pay(data.result.jsConfig)
  142. .finally(() => {
  143. return that.$util.Tips({
  144. title: "支付成功",
  145. icon: 'success'
  146. }, () => {
  147. that.$emit('onChangeFun', {
  148. action: 'pay_complete'
  149. });
  150. });
  151. })
  152. .catch(function() {
  153. return that.$util.Tips({
  154. title: '支付失败'
  155. });
  156. });
  157. }
  158. // #endif
  159. break;
  160. case 'yue':
  161. uni.hideLoading();
  162. return that.$util.Tips({
  163. title: res.msg,
  164. icon: 'success'
  165. }, () => {
  166. that.$emit('onChangeFun', {
  167. action: 'pay_complete'
  168. });
  169. });
  170. break;
  171. case 'offline':
  172. uni.hideLoading();
  173. return that.$util.Tips({
  174. title: res.msg,
  175. icon: 'success'
  176. }, () => {
  177. that.$emit('onChangeFun', {
  178. action: 'pay_complete'
  179. });
  180. });
  181. break;
  182. }
  183. }).catch(err => {
  184. uni.hideLoading();
  185. return that.$util.Tips({
  186. title: err
  187. }, () => {
  188. that.$emit('onChangeFun', {
  189. action: 'pay_fail'
  190. });
  191. });
  192. })
  193. }
  194. }
  195. }
  196. </script>
  197. <style scoped lang="scss">
  198. .payment {
  199. position: fixed;
  200. bottom: 0;
  201. left: 0;
  202. width: 100%;
  203. border-radius: 16rpx 16rpx 0 0;
  204. background-color: #fff;
  205. padding-bottom: 60rpx;
  206. z-index: 99;
  207. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  208. transform: translate3d(0, 100%, 0);
  209. }
  210. .payment.on {
  211. transform: translate3d(0, 0, 0);
  212. }
  213. .payment .title {
  214. text-align: center;
  215. height: 123rpx;
  216. font-size: 32rpx;
  217. color: #282828;
  218. font-weight: bold;
  219. padding-right: 30rpx;
  220. margin-left: 30rpx;
  221. position: relative;
  222. border-bottom: 1rpx solid #eee;
  223. }
  224. .payment .title .iconfont {
  225. position: absolute;
  226. right: 30rpx;
  227. top: 50%;
  228. transform: translateY(-50%);
  229. font-size: 43rpx;
  230. color: #8a8a8a;
  231. font-weight: normal;
  232. }
  233. .payment .item {
  234. border-bottom: 1rpx solid #eee;
  235. height: 130rpx;
  236. margin-left: 30rpx;
  237. padding-right: 30rpx;
  238. }
  239. .payment .item .left {
  240. width: 610rpx;
  241. }
  242. .payment .item .left .text {
  243. width: 540rpx;
  244. }
  245. .payment .item .left .text .name {
  246. font-size: 32rpx;
  247. color: #282828;
  248. }
  249. .payment .item .left .text .info {
  250. font-size: 24rpx;
  251. color: #999;
  252. }
  253. .payment .item .left .text .info .money {
  254. color: #ff9900;
  255. }
  256. .payment .item .left .iconfont {
  257. font-size: 45rpx;
  258. color: #09bb07;
  259. }
  260. .payment .item .left .iconfont.icon-zhifubao {
  261. color: #00aaea;
  262. }
  263. .payment .item .left .iconfont.icon-yuezhifu {
  264. color: #ff9900;
  265. }
  266. .payment .item .left .iconfont.icon-yuezhifu1 {
  267. color: #eb6623;
  268. }
  269. .payment .item .iconfont {
  270. font-size: 0.3rpx;
  271. color: #999;
  272. }
  273. </style>