index.vue 12 KB

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