index.vue 11 KB

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