index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <!-- 支付弹窗 -->
  3. <view :style="colorStyle">
  4. <view class="payment" :class="pay_close ? 'on' : ''">
  5. <view class="title acea-row row-center-wrapper">
  6. 选择付款方式<text class="iconfont icon-guanbi" @click='close'></text>
  7. </view>
  8. <view class="item acea-row row-between-wrapper" v-for="(item,index) in payMode" :key="index"
  9. v-if='item.payStatus' @click="payType(item.number || 0 , item.value,index)">
  10. <view class="left acea-row row-between-wrapper">
  11. <view class="iconfont" :class="item.icon"></view>
  12. <view class="text">
  13. <view class="name">{{item.name}}</view>
  14. <view class="info" v-if="item.value == 'yue'">
  15. {{item.title}} <span class="money">¥{{ item.number }}</span>
  16. </view>
  17. <view class="info" v-else>{{item.title}}</view>
  18. </view>
  19. </view>
  20. <view class="iconfont" :class="active==index?'icon-xuanzhong11 font-num':'icon-weixuan'"></view>
  21. </view>
  22. <view class="payMoney" >支付<span class="font-color">¥<span class="money">{{totalPrice}}</span></span></view>
  23. <view class="button bg-color acea-row row-center-wrapper" @click='goPay(number, paytype)'>去付款</view>
  24. <slot name="buttom"></slot>
  25. </view>
  26. <view class="mask" @click='close' v-if="pay_close"></view>
  27. <view v-show="false" v-html="formContent"></view>
  28. </view>
  29. </template>
  30. <script>
  31. import {
  32. orderPay
  33. } from '@/api/order.js';
  34. import colors from '@/mixins/color.js';
  35. export default {
  36. props: {
  37. payMode: {
  38. type: Array,
  39. default: function() {
  40. return [];
  41. }
  42. },
  43. pay_close: {
  44. type: Boolean,
  45. default: false,
  46. },
  47. order_id: {
  48. type: String,
  49. default: ''
  50. },
  51. totalPrice: {
  52. type: String,
  53. default: '0'
  54. },
  55. isCall: {
  56. type: Boolean,
  57. default: false
  58. }
  59. },
  60. mixins:[colors],
  61. data() {
  62. return {
  63. formContent: '',
  64. active: 0,
  65. paytype: '',
  66. number: 0
  67. };
  68. },
  69. watch: {
  70. payMode: {
  71. handler(newV, oldValue) {
  72. let newPayList = [];
  73. newV.forEach((item, index) => {
  74. if (item.payStatus) {
  75. item.index = index;
  76. newPayList.push(item)
  77. }
  78. });
  79. this.active = newPayList[0].index;
  80. this.paytype = newPayList[0].value;
  81. this.number = newPayList[0].number || 0;
  82. },
  83. immediate: true,
  84. deep: true
  85. }
  86. },
  87. methods: {
  88. payType(number, paytype, index) {
  89. this.active = index;
  90. console.log(this.active,'this.active');
  91. this.paytype = paytype;
  92. this.number = number;
  93. this.$emit('changePayType', paytype)
  94. },
  95. close: function() {
  96. this.$emit('onChangeFun', {
  97. action: 'payClose'
  98. });
  99. },
  100. goPay: function(number, paytype) {
  101. if (this.isCall) {
  102. return this.$emit('onChangeFun', {
  103. action: 'payCheck',
  104. value: paytype
  105. });
  106. }
  107. let that = this;
  108. if (!that.order_id) return that.$util.Tips({
  109. title: '请选择要支付的订单'
  110. });
  111. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  112. title: '余额不足!'
  113. });
  114. uni.showLoading({
  115. title: '支付中'
  116. });
  117. return
  118. orderPay({
  119. uni: that.order_id,
  120. paytype: paytype,
  121. // #ifdef MP
  122. 'from': 'routine',
  123. // #endif
  124. // #ifdef H5
  125. 'from': this.$wechat.isWeixin() ? 'weixin' : 'weixinh5',
  126. // #endif
  127. // #ifdef H5
  128. quitUrl: location.port ? location.protocol + '//' + location.hostname + ':' + location
  129. .port +
  130. '/pages/goods/order_details/index?order_id=' + this.order_id : location.protocol +
  131. '//' + location.hostname +
  132. '/pages/goods/order_details/index?order_id=' + this.order_id
  133. // #endif
  134. // #ifdef APP-PLUS
  135. quitUrl: '/pages/goods/order_details/index?order_id=' + this.order_id
  136. // #endif
  137. }).then(res => {
  138. let jsConfig = res.data.result.jsConfig;
  139. switch (paytype) {
  140. case 'weixin':
  141. if (res.data.result === undefined) return that.$util.Tips({
  142. title: '缺少支付参数'
  143. });
  144. // #ifdef MP
  145. let mp_pay_name=''
  146. if(uni.requestOrderPayment){
  147. mp_pay_name='requestOrderPayment'
  148. }else{
  149. mp_pay_name='requestPayment'
  150. }
  151. uni[mp_pay_name]({
  152. timeStamp: jsConfig.timestamp,
  153. nonceStr: jsConfig.nonceStr,
  154. package: jsConfig.package,
  155. signType: jsConfig.signType,
  156. paySign: jsConfig.paySign,
  157. success: function(res) {
  158. uni.hideLoading();
  159. return that.$util.Tips({
  160. title: res.msg,
  161. icon: 'success'
  162. }, () => {
  163. that.$emit('onChangeFun', {
  164. action: 'pay_complete'
  165. });
  166. });
  167. },
  168. fail: function(e) {
  169. uni.hideLoading();
  170. return that.$util.Tips({
  171. title: '取消支付'
  172. }, () => {
  173. that.$emit('onChangeFun', {
  174. action: 'pay_fail'
  175. });
  176. });
  177. },
  178. complete: function(e) {
  179. uni.hideLoading();
  180. if (e.errMsg == 'requestPayment:cancel') return that.$util
  181. .Tips({
  182. title: '取消支付'
  183. }, () => {
  184. that.$emit('onChangeFun', {
  185. action: 'pay_fail'
  186. });
  187. });
  188. },
  189. });
  190. // #endif
  191. // #ifdef H5
  192. let data = res.data;
  193. if (data.status == "WECHAT_H5_PAY") {
  194. uni.hideLoading();
  195. location.replace(data.result.jsConfig.mweb_url);
  196. return that.$util.Tips({
  197. title: "支付成功",
  198. icon: 'success'
  199. }, () => {
  200. that.$emit('onChangeFun', {
  201. action: 'pay_complete'
  202. });
  203. });
  204. } else {
  205. that.$wechat.pay(data.result.jsConfig)
  206. .then(() => {
  207. return that.$util.Tips({
  208. title: "支付成功",
  209. icon: 'success'
  210. }, () => {
  211. that.$emit('onChangeFun', {
  212. action: 'pay_complete'
  213. });
  214. });
  215. })
  216. .catch(function(res) {
  217. if (res.errMsg == 'chooseWXPay:cancel') return that.$util.Tips({
  218. title: '取消支付'
  219. },() => {
  220. that.$emit('onChangeFun', {
  221. action: 'pay_fail'
  222. });
  223. });
  224. });
  225. }
  226. // #endif
  227. // #ifdef APP-PLUS
  228. uni.requestPayment({
  229. provider: 'wxpay',
  230. orderInfo: jsConfig,
  231. success: (e) => {
  232. let url = '/pages/goods/order_pay_status/index?order_id=' + orderId +
  233. '&msg=支付成功';
  234. uni.showToast({
  235. title: "支付成功"
  236. })
  237. setTimeout(res => {
  238. that.$emit('onChangeFun', {
  239. action: 'pay_complete'
  240. });
  241. }, 2000)
  242. },
  243. fail: (e) => {
  244. uni.showModal({
  245. content: "支付失败",
  246. showCancel: false,
  247. success: function(res) {
  248. if (res.confirm) {
  249. that.$emit('onChangeFun', {
  250. action: 'pay_fail'
  251. });
  252. } else if (res.cancel) {}
  253. }
  254. })
  255. },
  256. complete: () => {
  257. uni.hideLoading();
  258. },
  259. });
  260. // #endif
  261. break;
  262. case 'yue':
  263. uni.hideLoading();
  264. return that.$util.Tips({
  265. title: res.msg,
  266. icon: 'success'
  267. }, () => {
  268. that.$emit('onChangeFun', {
  269. action: 'pay_complete'
  270. });
  271. });
  272. break;
  273. case 'offline':
  274. uni.hideLoading();
  275. return that.$util.Tips({
  276. title: res.msg,
  277. icon: 'success'
  278. }, () => {
  279. that.$emit('onChangeFun', {
  280. action: 'pay_complete'
  281. });
  282. });
  283. break;
  284. case 'alipay':
  285. uni.hideLoading();
  286. //#ifdef H5
  287. if (this.$wechat.isWeixin()) {
  288. uni.redirectTo({
  289. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&pay_key=${res.data.result.pay_key}`
  290. });
  291. } else {
  292. uni.hideLoading();
  293. that.formContent = res.data.result.jsConfig;
  294. that.$nextTick(() => {
  295. document.getElementById('alipaysubmit').submit();
  296. });
  297. }
  298. //#endif
  299. // #ifdef MP
  300. uni.navigateTo({
  301. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&link=${res.data.result.jsConfig.qrCode}`
  302. });
  303. // #endif
  304. // #ifdef APP-PLUS
  305. uni.requestPayment({
  306. provider: 'alipay',
  307. orderInfo: jsConfig,
  308. success: (e) => {
  309. uni.showToast({
  310. title: "支付成功"
  311. })
  312. setTimeout(res => {
  313. that.$emit('onChangeFun', {
  314. action: 'pay_complete'
  315. });
  316. }, 2000)
  317. },
  318. fail: (e) => {
  319. uni.showModal({
  320. content: "支付失败",
  321. showCancel: false,
  322. success: function(res) {
  323. if (res.confirm) {
  324. that.$emit('onChangeFun', {
  325. action: 'pay_fail'
  326. });
  327. } else if (res.cancel) {}
  328. }
  329. })
  330. },
  331. complete: () => {
  332. uni.hideLoading();
  333. },
  334. });
  335. // #endif
  336. break;
  337. }
  338. }).catch(err => {
  339. uni.hideLoading();
  340. return that.$util.Tips({
  341. title: err
  342. }, () => {
  343. that.$emit('onChangeFun', {
  344. action: 'pay_fail'
  345. });
  346. });
  347. })
  348. }
  349. }
  350. }
  351. </script>
  352. <style scoped lang="scss">
  353. .bgcolor{
  354. background-color: var(--view-theme)
  355. }
  356. .payment {
  357. position: fixed;
  358. bottom: 0;
  359. left: 0;
  360. width: 100%;
  361. border-radius: 16rpx 16rpx 0 0;
  362. background-color: #fff;
  363. padding-bottom: 60rpx;
  364. z-index: 999;
  365. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  366. transform: translate3d(0, 100%, 0);
  367. .payMoney {
  368. font-size: 28rpx;
  369. color: #333333;
  370. text-align: center;
  371. margin-top: 50rpx;
  372. .font-color {
  373. margin-left: 10rpx;
  374. .money {
  375. font-size: 40rpx;
  376. }
  377. }
  378. }
  379. .button {
  380. width: 690rpx;
  381. height: 90rpx;
  382. border-radius: 45rpx;
  383. color: #FFFFFF;
  384. margin: 20rpx auto 0 auto;
  385. }
  386. }
  387. .payment.on {
  388. transform: translate3d(0, 0, 0);
  389. }
  390. .payment .title {
  391. text-align: center;
  392. height: 123rpx;
  393. font-size: 32rpx;
  394. color: #282828;
  395. font-weight: bold;
  396. padding-right: 30rpx;
  397. margin-left: 30rpx;
  398. position: relative;
  399. border-bottom: 1rpx solid #eee;
  400. }
  401. .payment .title .iconfont {
  402. position: absolute;
  403. right: 30rpx;
  404. top: 50%;
  405. transform: translateY(-50%);
  406. font-size: 38rpx;
  407. color: #8a8a8a;
  408. font-weight: normal;
  409. }
  410. .payment .item {
  411. border-bottom: 1rpx solid #eee;
  412. height: 130rpx;
  413. margin-left: 30rpx;
  414. padding-right: 30rpx;
  415. }
  416. .payment .item .left {
  417. width: 610rpx;
  418. }
  419. .payment .item .left .text {
  420. width: 540rpx;
  421. }
  422. .payment .item .left .text .name {
  423. font-size: 32rpx;
  424. color: #282828;
  425. }
  426. .payment .item .left .text .info {
  427. font-size: 24rpx;
  428. color: #999;
  429. }
  430. .payment .item .left .text .info .money {
  431. color: #ff9900;
  432. }
  433. .payment .item .left .iconfont {
  434. font-size: 45rpx;
  435. color: #09bb07;
  436. }
  437. .payment .item .left .iconfont.icon-zhifubao {
  438. color: #00aaea;
  439. }
  440. .payment .item .left .iconfont.icon-yuezhifu {
  441. color: #ff9900;
  442. }
  443. .payment .item .left .iconfont.icon-yuezhifu1 {
  444. color: #eb6623;
  445. }
  446. .payment .item .iconfont {
  447. font-size: 40rpx;
  448. color: #ccc;
  449. }
  450. </style>