index.vue 7.0 KB

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