index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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. orderPay({
  118. uni: that.order_id,
  119. paytype: paytype,
  120. // #ifdef MP
  121. 'from': 'routine',
  122. // #endif
  123. // #ifdef H5
  124. 'from': this.$wechat.isWeixin() ? 'weixin' : 'weixinh5',
  125. // #endif
  126. // #ifdef H5
  127. quitUrl: location.port ? location.protocol + '//' + location.hostname + ':' + location
  128. .port +
  129. '/pages/goods/order_details/index?order_id=' + this.order_id : location.protocol +
  130. '//' + location.hostname +
  131. '/pages/goods/order_details/index?order_id=' + this.order_id
  132. // #endif
  133. // #ifdef APP-PLUS
  134. quitUrl: '/pages/goods/order_details/index?order_id=' + this.order_id
  135. // #endif
  136. }).then(res => {
  137. let jsConfig = res.data.result.jsConfig;
  138. switch (paytype) {
  139. case 'weixin':
  140. if (res.data.result === undefined) return that.$util.Tips({
  141. title: '缺少支付参数'
  142. });
  143. // #ifdef MP
  144. let mp_pay_name = ''
  145. if (uni.requestOrderPayment) {
  146. mp_pay_name = 'requestOrderPayment'
  147. } else {
  148. mp_pay_name = 'requestPayment'
  149. }
  150. uni[mp_pay_name]({
  151. timeStamp: jsConfig.timestamp,
  152. nonceStr: jsConfig.nonceStr,
  153. package: jsConfig.package,
  154. signType: jsConfig.signType,
  155. paySign: jsConfig.paySign,
  156. success: function(res) {
  157. uni.hideLoading();
  158. return that.$util.Tips({
  159. title: res.msg,
  160. icon: 'success'
  161. }, () => {
  162. that.$emit('onChangeFun', {
  163. action: 'pay_complete'
  164. });
  165. });
  166. },
  167. fail: function(e) {
  168. uni.hideLoading();
  169. return that.$util.Tips({
  170. title: '取消支付'
  171. }, () => {
  172. that.$emit('onChangeFun', {
  173. action: 'pay_fail'
  174. });
  175. });
  176. },
  177. complete: function(e) {
  178. uni.hideLoading();
  179. if (e.errMsg == 'requestPayment:cancel') return that.$util
  180. .Tips({
  181. title: '取消支付'
  182. }, () => {
  183. that.$emit('onChangeFun', {
  184. action: 'pay_fail'
  185. });
  186. });
  187. },
  188. });
  189. // #endif
  190. // #ifdef H5
  191. let data = res.data;
  192. if (data.status == "WECHAT_H5_PAY") {
  193. uni.hideLoading();
  194. location.replace(data.result.jsConfig.mweb_url);
  195. return that.$util.Tips({
  196. title: "支付成功",
  197. icon: 'success'
  198. }, () => {
  199. that.$emit('onChangeFun', {
  200. action: 'pay_complete'
  201. });
  202. });
  203. } else {
  204. that.$wechat.pay(data.result.jsConfig)
  205. .then(() => {
  206. return that.$util.Tips({
  207. title: "支付成功",
  208. icon: 'success'
  209. }, () => {
  210. that.$emit('onChangeFun', {
  211. action: 'pay_complete'
  212. });
  213. });
  214. })
  215. .catch(function(res) {
  216. if (res.errMsg == 'chooseWXPay:cancel') return that.$util.Tips({
  217. title: '取消支付'
  218. }, () => {
  219. that.$emit('onChangeFun', {
  220. action: 'pay_fail'
  221. });
  222. });
  223. });
  224. }
  225. // #endif
  226. // #ifdef APP-PLUS
  227. uni.requestPayment({
  228. provider: 'wxpay',
  229. orderInfo: jsConfig,
  230. success: (e) => {
  231. let url = '/pages/goods/order_pay_status/index?order_id=' +
  232. 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. case "huifu":
  338. // #ifdef MP
  339. console.log(res, 'resdata')
  340. let data = JSON.parse(res.data.result.data.pay_info);
  341. uni.requestPayment({
  342. timeStamp: data.timeStamp,
  343. nonceStr: data.nonceStr,
  344. package: data.package,
  345. signType: data.signType,
  346. paySign: data.paySign,
  347. success: function(res) {
  348. uni.showToast({
  349. title: "支付成功"
  350. })
  351. setTimeout(res => {
  352. that.$emit('onChangeFun', {
  353. action: 'pay_complete'
  354. });
  355. }, 2000)
  356. },
  357. fail: function() {
  358. return that.$util.Tips({
  359. title: '支付失败'
  360. });
  361. },
  362. complete: function(res) {
  363. if (res.errMsg == 'requestPayment:cancel') return that.$util
  364. .Tips({
  365. title: '取消支付'
  366. });
  367. }
  368. })
  369. // #endif
  370. // #ifdef H5
  371. window.location.href = res.data.result.counter_url;
  372. that.$emit('onChangeFun', {
  373. action: 'pay_complete'
  374. });
  375. // #endif
  376. // #ifdef APP
  377. plus.share.getServices((res) => {
  378. console.log(JSON.stringify(res));
  379. let sweixin = res.find(i => i.id === 'weixin');
  380. if (sweixin) {
  381. sweixin.launchMiniProgram({
  382. id: res.data.result.id,
  383. userName: '',
  384. path: res.data.result.counter_url,
  385. type: 0, //0正式1测试2体验
  386. })
  387. that.$emit('onChangeFun', {
  388. action: 'pay_complete'
  389. });
  390. }
  391. })
  392. // #endif
  393. break;
  394. }
  395. }).catch(err => {
  396. uni.hideLoading();
  397. return that.$util.Tips({
  398. title: err
  399. }, () => {
  400. that.$emit('onChangeFun', {
  401. action: 'pay_fail'
  402. });
  403. });
  404. })
  405. }
  406. }
  407. }
  408. </script>
  409. <style scoped lang="scss">
  410. .bgcolor {
  411. background-color: var(--view-theme)
  412. }
  413. .payment {
  414. position: fixed;
  415. bottom: 0;
  416. left: 0;
  417. width: 100%;
  418. border-radius: 16rpx 16rpx 0 0;
  419. background-color: #fff;
  420. padding-bottom: 60rpx;
  421. z-index: 999;
  422. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  423. transform: translate3d(0, 100%, 0);
  424. .payMoney {
  425. font-size: 28rpx;
  426. color: #333333;
  427. text-align: center;
  428. margin-top: 50rpx;
  429. .font-color {
  430. margin-left: 10rpx;
  431. .money {
  432. font-size: 40rpx;
  433. }
  434. }
  435. }
  436. .button {
  437. width: 690rpx;
  438. height: 90rpx;
  439. border-radius: 45rpx;
  440. color: #FFFFFF;
  441. margin: 20rpx auto 0 auto;
  442. }
  443. }
  444. .payment.on {
  445. transform: translate3d(0, 0, 0);
  446. }
  447. .payment .title {
  448. text-align: center;
  449. height: 123rpx;
  450. font-size: 32rpx;
  451. color: #282828;
  452. font-weight: bold;
  453. padding-right: 30rpx;
  454. margin-left: 30rpx;
  455. position: relative;
  456. border-bottom: 1rpx solid #eee;
  457. }
  458. .payment .title .iconfont {
  459. position: absolute;
  460. right: 30rpx;
  461. top: 50%;
  462. transform: translateY(-50%);
  463. font-size: 38rpx;
  464. color: #8a8a8a;
  465. font-weight: normal;
  466. }
  467. .payment .item {
  468. border-bottom: 1rpx solid #eee;
  469. height: 130rpx;
  470. margin-left: 30rpx;
  471. padding-right: 30rpx;
  472. }
  473. .payment .item .left {
  474. width: 610rpx;
  475. }
  476. .payment .item .left .text {
  477. width: 540rpx;
  478. }
  479. .payment .item .left .text .name {
  480. font-size: 32rpx;
  481. color: #282828;
  482. }
  483. .payment .item .left .text .info {
  484. font-size: 24rpx;
  485. color: #999;
  486. }
  487. .payment .item .left .text .info .money {
  488. color: #ff9900;
  489. }
  490. .payment .item .left .iconfont {
  491. font-size: 45rpx;
  492. color: #09bb07;
  493. }
  494. .payment .item .left .iconfont.icon-zhifubao {
  495. color: #00aaea;
  496. }
  497. .payment .item .left .iconfont.icon-yuezhifu {
  498. color: #ff9900;
  499. }
  500. .payment .item .left .iconfont.icon-yuezhifu1 {
  501. color: #eb6623;
  502. }
  503. .payment .item .iconfont {
  504. font-size: 40rpx;
  505. color: #ccc;
  506. }
  507. </style>