index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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=' + orderId +
  232. '&msg=支付成功';
  233. uni.showToast({
  234. title: "支付成功"
  235. })
  236. setTimeout(res => {
  237. that.$emit('onChangeFun', {
  238. action: 'pay_complete'
  239. });
  240. }, 2000)
  241. },
  242. fail: (e) => {
  243. uni.showModal({
  244. content: "支付失败",
  245. showCancel: false,
  246. success: function(res) {
  247. if (res.confirm) {
  248. that.$emit('onChangeFun', {
  249. action: 'pay_fail'
  250. });
  251. } else if (res.cancel) {}
  252. }
  253. })
  254. },
  255. complete: () => {
  256. uni.hideLoading();
  257. },
  258. });
  259. // #endif
  260. break;
  261. case 'yue':
  262. uni.hideLoading();
  263. return that.$util.Tips({
  264. title: res.msg,
  265. icon: 'success'
  266. }, () => {
  267. that.$emit('onChangeFun', {
  268. action: 'pay_complete'
  269. });
  270. });
  271. break;
  272. case 'offline':
  273. uni.hideLoading();
  274. return that.$util.Tips({
  275. title: res.msg,
  276. icon: 'success'
  277. }, () => {
  278. that.$emit('onChangeFun', {
  279. action: 'pay_complete'
  280. });
  281. });
  282. break;
  283. case 'alipay':
  284. uni.hideLoading();
  285. //#ifdef H5
  286. if (this.$wechat.isWeixin()) {
  287. uni.redirectTo({
  288. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&pay_key=${res.data.result.pay_key}`
  289. });
  290. } else {
  291. uni.hideLoading();
  292. that.formContent = res.data.result.jsConfig;
  293. that.$nextTick(() => {
  294. document.getElementById('alipaysubmit').submit();
  295. });
  296. }
  297. //#endif
  298. // #ifdef MP
  299. uni.navigateTo({
  300. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&link=${res.data.result.jsConfig.qrCode}`
  301. });
  302. // #endif
  303. // #ifdef APP-PLUS
  304. uni.requestPayment({
  305. provider: 'alipay',
  306. orderInfo: jsConfig,
  307. success: (e) => {
  308. uni.showToast({
  309. title: "支付成功"
  310. })
  311. setTimeout(res => {
  312. that.$emit('onChangeFun', {
  313. action: 'pay_complete'
  314. });
  315. }, 2000)
  316. },
  317. fail: (e) => {
  318. uni.showModal({
  319. content: "支付失败",
  320. showCancel: false,
  321. success: function(res) {
  322. if (res.confirm) {
  323. that.$emit('onChangeFun', {
  324. action: 'pay_fail'
  325. });
  326. } else if (res.cancel) {}
  327. }
  328. })
  329. },
  330. complete: () => {
  331. uni.hideLoading();
  332. },
  333. });
  334. // #endif
  335. break;
  336. case "lakala":
  337. // #ifdef MP
  338. wx.navigateToMiniProgram({
  339. appId: 'wx889424d565967811',
  340. path: `payment-cashier/pages/checkout/index?source=WECHATMINI&counterUrl=${
  341.        encodeURIComponent(res.data.result.counter_url)
  342.    }`,
  343. envVersion: 'release',
  344. // release: 正式版  trial: 体验版
  345. success(res) {
  346. uni.showToast({
  347. title: "支付成功"
  348. })
  349. setTimeout(res => {
  350. that.$emit('onChangeFun', {
  351. action: 'pay_complete'
  352. });
  353. }, 2000)
  354. },
  355. complete() {
  356. uni.hideLoading();
  357. }
  358. })
  359. // #endif
  360. // #ifdef H5
  361. window.location.href = res.data.result.counter_url;
  362. that.$emit('onChangeFun', {
  363. action: 'pay_complete'
  364. });
  365. // #endif
  366. // #ifdef APP
  367. plus.share.getServices((res) => {
  368. console.log(JSON.stringify(res));
  369. let sweixin = res.find(i => i.id === 'weixin');
  370. if (sweixin) {
  371. sweixin.launchMiniProgram({
  372. id: res.data.result.id,
  373. userName: '',
  374. path: res.data.result.counter_url,
  375. type: 0, //0正式1测试2体验
  376. })
  377. that.$emit('onChangeFun', {
  378. action: 'pay_complete'
  379. });
  380. }
  381. })
  382. // #endif
  383. break;
  384. }
  385. }).catch(err => {
  386. uni.hideLoading();
  387. return that.$util.Tips({
  388. title: err
  389. }, () => {
  390. that.$emit('onChangeFun', {
  391. action: 'pay_fail'
  392. });
  393. });
  394. })
  395. }
  396. }
  397. }
  398. </script>
  399. <style scoped lang="scss">
  400. .bgcolor{
  401. background-color: var(--view-theme)
  402. }
  403. .payment {
  404. position: fixed;
  405. bottom: 0;
  406. left: 0;
  407. width: 100%;
  408. border-radius: 16rpx 16rpx 0 0;
  409. background-color: #fff;
  410. padding-bottom: 60rpx;
  411. z-index: 999;
  412. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  413. transform: translate3d(0, 100%, 0);
  414. .payMoney {
  415. font-size: 28rpx;
  416. color: #333333;
  417. text-align: center;
  418. margin-top: 50rpx;
  419. .font-color {
  420. margin-left: 10rpx;
  421. .money {
  422. font-size: 40rpx;
  423. }
  424. }
  425. }
  426. .button {
  427. width: 690rpx;
  428. height: 90rpx;
  429. border-radius: 45rpx;
  430. color: #FFFFFF;
  431. margin: 20rpx auto 0 auto;
  432. }
  433. }
  434. .payment.on {
  435. transform: translate3d(0, 0, 0);
  436. }
  437. .payment .title {
  438. text-align: center;
  439. height: 123rpx;
  440. font-size: 32rpx;
  441. color: #282828;
  442. font-weight: bold;
  443. padding-right: 30rpx;
  444. margin-left: 30rpx;
  445. position: relative;
  446. border-bottom: 1rpx solid #eee;
  447. }
  448. .payment .title .iconfont {
  449. position: absolute;
  450. right: 30rpx;
  451. top: 50%;
  452. transform: translateY(-50%);
  453. font-size: 38rpx;
  454. color: #8a8a8a;
  455. font-weight: normal;
  456. }
  457. .payment .item {
  458. border-bottom: 1rpx solid #eee;
  459. height: 130rpx;
  460. margin-left: 30rpx;
  461. padding-right: 30rpx;
  462. }
  463. .payment .item .left {
  464. width: 610rpx;
  465. }
  466. .payment .item .left .text {
  467. width: 540rpx;
  468. }
  469. .payment .item .left .text .name {
  470. font-size: 32rpx;
  471. color: #282828;
  472. }
  473. .payment .item .left .text .info {
  474. font-size: 24rpx;
  475. color: #999;
  476. }
  477. .payment .item .left .text .info .money {
  478. color: #ff9900;
  479. }
  480. .payment .item .left .iconfont {
  481. font-size: 45rpx;
  482. color: #09bb07;
  483. }
  484. .payment .item .left .iconfont.icon-zhifubao {
  485. color: #00aaea;
  486. }
  487. .payment .item .left .iconfont.icon-yuezhifu {
  488. color: #ff9900;
  489. }
  490. .payment .item .left .iconfont.icon-yuezhifu1 {
  491. color: #eb6623;
  492. }
  493. .payment .item .iconfont {
  494. font-size: 40rpx;
  495. color: #ccc;
  496. }
  497. </style>