index.vue 12 KB

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