index.vue 12 KB

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