index.vue 7.0 KB

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