index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. }
  337. }).catch(err => {
  338. uni.hideLoading();
  339. return that.$util.Tips({
  340. title: err
  341. }, () => {
  342. that.$emit('onChangeFun', {
  343. action: 'pay_fail'
  344. });
  345. });
  346. })
  347. }
  348. }
  349. }
  350. </script>
  351. <style scoped lang="scss">
  352. .bgcolor{
  353. background-color: var(--view-theme)
  354. }
  355. .payment {
  356. position: fixed;
  357. bottom: 0;
  358. left: 0;
  359. width: 100%;
  360. border-radius: 16rpx 16rpx 0 0;
  361. background-color: #fff;
  362. padding-bottom: 60rpx;
  363. z-index: 999;
  364. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  365. transform: translate3d(0, 100%, 0);
  366. .payMoney {
  367. font-size: 28rpx;
  368. color: #333333;
  369. text-align: center;
  370. margin-top: 50rpx;
  371. .font-color {
  372. margin-left: 10rpx;
  373. .money {
  374. font-size: 40rpx;
  375. }
  376. }
  377. }
  378. .button {
  379. width: 690rpx;
  380. height: 90rpx;
  381. border-radius: 45rpx;
  382. color: #FFFFFF;
  383. margin: 20rpx auto 0 auto;
  384. }
  385. }
  386. .payment.on {
  387. transform: translate3d(0, 0, 0);
  388. }
  389. .payment .title {
  390. text-align: center;
  391. height: 123rpx;
  392. font-size: 32rpx;
  393. color: #282828;
  394. font-weight: bold;
  395. padding-right: 30rpx;
  396. margin-left: 30rpx;
  397. position: relative;
  398. border-bottom: 1rpx solid #eee;
  399. }
  400. .payment .title .iconfont {
  401. position: absolute;
  402. right: 30rpx;
  403. top: 50%;
  404. transform: translateY(-50%);
  405. font-size: 38rpx;
  406. color: #8a8a8a;
  407. font-weight: normal;
  408. }
  409. .payment .item {
  410. border-bottom: 1rpx solid #eee;
  411. height: 130rpx;
  412. margin-left: 30rpx;
  413. padding-right: 30rpx;
  414. }
  415. .payment .item .left {
  416. width: 610rpx;
  417. }
  418. .payment .item .left .text {
  419. width: 540rpx;
  420. }
  421. .payment .item .left .text .name {
  422. font-size: 32rpx;
  423. color: #282828;
  424. }
  425. .payment .item .left .text .info {
  426. font-size: 24rpx;
  427. color: #999;
  428. }
  429. .payment .item .left .text .info .money {
  430. color: #ff9900;
  431. }
  432. .payment .item .left .iconfont {
  433. font-size: 45rpx;
  434. color: #09bb07;
  435. }
  436. .payment .item .left .iconfont.icon-zhifubao {
  437. color: #00aaea;
  438. }
  439. .payment .item .left .iconfont.icon-yuezhifu {
  440. color: #ff9900;
  441. }
  442. .payment .item .left .iconfont.icon-yuezhifu1 {
  443. color: #eb6623;
  444. }
  445. .payment .item .iconfont {
  446. font-size: 40rpx;
  447. color: #ccc;
  448. }
  449. </style>