index.vue 12 KB

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