index.vue 11 KB

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