index.vue 12 KB

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