index.vue 11 KB

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