index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="payment" :class="pay_close ? 'on' : ''">
  4. <view class="title acea-row row-center-wrapper">
  5. 选择付款方式<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">¥{{ 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">支付<span class="font-color">¥<span class="money">{{totalPrice}}</span></span></view>
  22. <view class="button bg-color acea-row row-center-wrapper" @click='goPay(number, paytype)'>去付款</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: '请选择要支付的订单'
  111. });
  112. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  113. title: '余额不足!'
  114. });
  115. uni.showLoading({
  116. title: '支付中'
  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/users/order_details/index?order_id=' + this.order_id : location.protocol +
  141. '//' + location.hostname +
  142. '/pages/users/order_details/index?order_id=' + this.order_id
  143. // #endif
  144. // #ifdef APP-PLUS
  145. quitUrl: '/pages/users/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: '缺少支付参数'
  153. });
  154. // #ifdef MP
  155. uni.requestPayment({
  156. timeStamp: jsConfig.timestamp,
  157. nonceStr: jsConfig.nonceStr,
  158. package: jsConfig.package,
  159. signType: jsConfig.signType,
  160. paySign: jsConfig.paySign,
  161. success: function(res) {
  162. uni.hideLoading();
  163. return that.$util.Tips({
  164. title: res.msg,
  165. icon: 'success'
  166. }, () => {
  167. that.$emit('onChangeFun', {
  168. action: 'pay_complete'
  169. });
  170. });
  171. },
  172. fail: function(e) {
  173. uni.hideLoading();
  174. return that.$util.Tips({
  175. title: '取消支付'
  176. }, () => {
  177. that.$emit('onChangeFun', {
  178. action: 'pay_fail'
  179. });
  180. });
  181. },
  182. complete: function(e) {
  183. uni.hideLoading();
  184. if (e.errMsg == 'requestPayment:cancel') return that.$util
  185. .Tips({
  186. title: '取消支付'
  187. }, () => {
  188. that.$emit('onChangeFun', {
  189. action: 'pay_fail'
  190. });
  191. });
  192. },
  193. });
  194. // #endif
  195. // #ifdef H5
  196. let data = res.data;
  197. if (data.status == "WECHAT_H5_PAY") {
  198. uni.hideLoading();
  199. location.replace(data.result.jsConfig.mweb_url);
  200. return that.$util.Tips({
  201. title: "支付成功",
  202. icon: 'success'
  203. }, () => {
  204. that.$emit('onChangeFun', {
  205. action: 'pay_complete'
  206. });
  207. });
  208. } else {
  209. that.$wechat.pay(data.result.jsConfig)
  210. .then(() => {
  211. return that.$util.Tips({
  212. title: "支付成功",
  213. icon: 'success'
  214. }, () => {
  215. that.$emit('onChangeFun', {
  216. action: 'pay_complete'
  217. });
  218. });
  219. })
  220. .catch(()=> {
  221. return that.$util.Tips({
  222. title: '支付失败'
  223. }, () => {
  224. that.$emit('onChangeFun', {
  225. action: 'pay_fail'
  226. });
  227. });
  228. });
  229. }
  230. // #endif
  231. // #ifdef APP-PLUS
  232. uni.requestPayment({
  233. provider: 'wxpay',
  234. orderInfo: jsConfig,
  235. success: (e) => {
  236. let url = '/pages/order_pay_status/index?order_id=' + orderId +
  237. '&msg=支付成功';
  238. uni.showToast({
  239. title: "支付成功"
  240. })
  241. setTimeout(res => {
  242. that.$emit('onChangeFun', {
  243. action: 'pay_complete'
  244. });
  245. }, 2000)
  246. },
  247. fail: (e) => {
  248. uni.showModal({
  249. content: "支付失败",
  250. showCancel: false,
  251. success: function(res) {
  252. if (res.confirm) {
  253. that.$emit('onChangeFun', {
  254. action: 'pay_fail'
  255. });
  256. } else if (res.cancel) {}
  257. }
  258. })
  259. },
  260. complete: () => {
  261. uni.hideLoading();
  262. },
  263. });
  264. // #endif
  265. break;
  266. case 'yue':
  267. uni.hideLoading();
  268. return that.$util.Tips({
  269. title: res.msg,
  270. icon: 'success'
  271. }, () => {
  272. that.$emit('onChangeFun', {
  273. action: 'pay_complete'
  274. });
  275. });
  276. break;
  277. case 'offline':
  278. uni.hideLoading();
  279. return that.$util.Tips({
  280. title: res.msg,
  281. icon: 'success'
  282. }, () => {
  283. that.$emit('onChangeFun', {
  284. action: 'pay_complete'
  285. });
  286. });
  287. break;
  288. case 'friend':
  289. uni.hideLoading();
  290. return that.$util.Tips({
  291. title: res.msg,
  292. icon: 'success'
  293. }, () => {
  294. that.$emit('onChangeFun', {
  295. action: 'pay_complete'
  296. });
  297. });
  298. break;
  299. case 'alipay':
  300. uni.hideLoading();
  301. //#ifdef H5
  302. if (this.$wechat.isWeixin()) {
  303. uni.redirectTo({
  304. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&pay_key=${res.data.result.pay_key}`
  305. });
  306. } else {
  307. uni.hideLoading();
  308. that.formContent = res.data.result.jsConfig;
  309. that.$nextTick(() => {
  310. document.getElementById('alipaysubmit').submit();
  311. });
  312. }
  313. //#endif
  314. // #ifdef MP
  315. uni.navigateTo({
  316. url: `/pages/users/alipay_invoke/index?id=${res.data.result.order_id}&link=${res.data.result.jsConfig.qrCode}`
  317. });
  318. // #endif
  319. // #ifdef APP-PLUS
  320. uni.requestPayment({
  321. provider: 'alipay',
  322. orderInfo: jsConfig,
  323. success: (e) => {
  324. uni.showToast({
  325. title: "支付成功"
  326. })
  327. setTimeout(res => {
  328. that.$emit('onChangeFun', {
  329. action: 'pay_complete'
  330. });
  331. }, 2000)
  332. },
  333. fail: (e) => {
  334. uni.showModal({
  335. content: "支付失败",
  336. showCancel: false,
  337. success: function(res) {
  338. if (res.confirm) {
  339. that.$emit('onChangeFun', {
  340. action: 'pay_fail'
  341. });
  342. } else if (res.cancel) {}
  343. }
  344. })
  345. },
  346. complete: () => {
  347. uni.hideLoading();
  348. },
  349. });
  350. // #endif
  351. break;
  352. }
  353. }).catch(err => {
  354. uni.hideLoading();
  355. return that.$util.Tips({
  356. title: err
  357. }, () => {
  358. that.$emit('onChangeFun', {
  359. action: 'pay_fail'
  360. });
  361. });
  362. })
  363. }
  364. }
  365. }
  366. </script>
  367. <style scoped lang="scss">
  368. .bgcolor {
  369. background-color: var(--view-theme)
  370. }
  371. .payment {
  372. position: fixed;
  373. bottom: 0;
  374. left: 0;
  375. width: 100%;
  376. border-radius: 16rpx 16rpx 0 0;
  377. background-color: #fff;
  378. padding-bottom: 60rpx;
  379. z-index: 999;
  380. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  381. transform: translate3d(0, 100%, 0);
  382. .payMoney {
  383. font-size: 28rpx;
  384. color: #333333;
  385. text-align: center;
  386. margin-top: 50rpx;
  387. .font-color {
  388. margin-left: 10rpx;
  389. .money {
  390. font-size: 40rpx;
  391. }
  392. }
  393. }
  394. .button {
  395. width: 690rpx;
  396. height: 90rpx;
  397. border-radius: 45rpx;
  398. color: #FFFFFF;
  399. margin: 20rpx auto 0 auto;
  400. }
  401. }
  402. .payment.on {
  403. transform: translate3d(0, 0, 0);
  404. }
  405. .payment .title {
  406. text-align: center;
  407. height: 123rpx;
  408. font-size: 32rpx;
  409. color: #282828;
  410. font-weight: bold;
  411. padding-right: 30rpx;
  412. margin-left: 30rpx;
  413. position: relative;
  414. border-bottom: 1rpx solid #eee;
  415. }
  416. .payment .title .iconfont {
  417. position: absolute;
  418. right: 30rpx;
  419. top: 50%;
  420. transform: translateY(-50%);
  421. font-size: 38rpx;
  422. color: #8a8a8a;
  423. font-weight: normal;
  424. }
  425. .payment .item {
  426. border-bottom: 1rpx solid #eee;
  427. height: 130rpx;
  428. margin-left: 30rpx;
  429. padding-right: 30rpx;
  430. }
  431. .payment .item .left {
  432. width: 610rpx;
  433. }
  434. .payment .item .left .text {
  435. width: 540rpx;
  436. }
  437. .payment .item .left .text .name {
  438. font-size: 32rpx;
  439. color: #282828;
  440. }
  441. .payment .item .left .text .info {
  442. font-size: 24rpx;
  443. color: #999;
  444. }
  445. .payment .item .left .text .info .money {
  446. color: #ff9900;
  447. }
  448. .payment .item .left .iconfont {
  449. font-size: 45rpx;
  450. color: #09bb07;
  451. }
  452. .payment .item .left .iconfont.icon-zhifubao {
  453. color: #00aaea;
  454. }
  455. .payment .item .left .iconfont.icon-yuezhifu {
  456. color: #ff9900;
  457. }
  458. .payment .item .left .iconfont.icon-yuezhifu1 {
  459. color: #eb6623;
  460. }
  461. .payment .item .iconfont {
  462. font-size: 40rpx;
  463. color: #ccc;
  464. }
  465. .icon-haoyoudaizhifu {
  466. color: #F34C3E !important;
  467. }
  468. </style>