You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

517 lines
13 KiB

3 months ago
  1. <template>
  2. <view :data-theme="theme">
  3. <view class='wrapper'>
  4. <view class='item borRadius14'>
  5. <view class="title"><text>{{payPrice}}</text></view>
  6. <view class='list'>
  7. <block v-for="(item,index) in cartArr" :key='index'>
  8. <view v-if="item.payStatus === 1" class='payItem acea-row row-middle'
  9. :class='active==index ?"on":""' @tap='payItem(index,item)'>
  10. <view class='name acea-row row-center-wrapper'>
  11. <view class='iconfont animated'
  12. :class='(item.icon) + " " + (animated==true&&active==index ?"bounceIn":"")'>
  13. </view>
  14. {{item.name}}
  15. </view>
  16. <view class="acea-row">
  17. <view class='tip'>
  18. {{item.title}}
  19. <block v-if="item.value === 'yue'">
  20. {{item.userBalance}}
  21. </block>
  22. </view>
  23. <view class="radio">
  24. <block v-if="active==index">
  25. <view class="iconfont icon-xuanzhong1 font-color"></view>
  26. </block>
  27. <block v-else>
  28. <view class="iconfont icon-weixuanzhong"></view>
  29. </block>
  30. </view>
  31. </view>
  32. </view>
  33. </block>
  34. </view>
  35. </view>
  36. </view>
  37. <view v-if="isShow" class="titleNo">暂无支付方式</view>
  38. <view class="btn-box">
  39. <button class='Bnt bg-color' @tap='toOrderPay' :disabled="isBuy">立即支付</button>
  40. </view>
  41. <view class="alipaysubmit" v-html="formContent"></view>
  42. </view>
  43. </template>
  44. <script>
  45. // +----------------------------------------------------------------------
  46. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  47. // +----------------------------------------------------------------------
  48. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  49. // +----------------------------------------------------------------------
  50. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  51. // +----------------------------------------------------------------------
  52. // | Author: CRMEB Team <admin@crmeb.com>
  53. // +----------------------------------------------------------------------
  54. import {openOrderSubscribe} from '@/utils/SubscribeMessage.js';
  55. import {
  56. orderPay,
  57. wechatQueryPayResult
  58. } from '@/api/order.js';
  59. import {
  60. Debounce
  61. } from '@/utils/validate.js'
  62. import {
  63. mapGetters
  64. } from "vuex";
  65. import store from '@/store'
  66. let app = getApp();
  67. export default {
  68. data() {
  69. return {
  70. active: null, //支付方式切换
  71. theme: app.globalData.theme,
  72. //支付方式
  73. //支付方式
  74. cartArr: [],
  75. payPrice: '',
  76. orderNo: '',
  77. animated: false,
  78. payType: '', //支付方式
  79. payChannel: '',
  80. formContent: '',
  81. isShow: false,
  82. userBalance: '', //余额
  83. isBuy: false //是否可以点击购买
  84. }
  85. },
  86. computed: {
  87. ...mapGetters(['productType', 'systemPlatform'])
  88. },
  89. onLoad(options) {
  90. this.payPrice = options.payPrice;
  91. this.orderNo = options.orderNo;
  92. },
  93. mounted() {
  94. this.payConfig();
  95. },
  96. methods: {
  97. // 支付配置
  98. payConfig() {
  99. uni.hideLoading();
  100. // 支付方式
  101. store.dispatch('getPayConfig').then((res) => {
  102. console.log(res.payConfig);
  103. this.cartArr = res.payConfig;
  104. // #ifdef APP
  105. res.payConfig.forEach(val=>{
  106. if(val.value==='weixin'){
  107. val.payStatus=0
  108. }
  109. })
  110. // #endif
  111. this.userBalance = res.userBalance;
  112. if (this.cartArr.length) {
  113. this.active = 0;
  114. this.payType = this.cartArr[0].value;
  115. this.isShow = false;
  116. } else {
  117. this.isShow = true;
  118. return this.$util.Tips({
  119. title: '暂无支付方式!'
  120. })
  121. }
  122. });
  123. },
  124. payItem: Debounce(function(e, item) {
  125. let that = this;
  126. if (item.userBalance) that.userBalance = item.userBalance
  127. let active = e;
  128. that.active = active;
  129. that.animated = true;
  130. that.payType = that.cartArr[active].value;
  131. setTimeout(function() {
  132. that.car();
  133. }, 500);
  134. }),
  135. car: function() {
  136. let that = this;
  137. that.animated = false;
  138. },
  139. //选择支付方式的判断,传参
  140. getPayCheck() {
  141. if (!this.payType) return this.$util.Tips({
  142. title: '请选择支付方式'
  143. });
  144. if (this.payType === 'yue') {
  145. this.payChannel = 'yue'
  146. } else if (this.payType == 'alipay') {
  147. // #ifdef H5
  148. this.payChannel = 'alipay';
  149. // #endif
  150. // #ifdef APP-PLUS
  151. this.payChannel = 'appAliPay';
  152. // #endif
  153. } else {
  154. // #ifdef H5
  155. this.payChannel = this.$wechat.isWeixin() ? 'public' : 'weixinh5';
  156. // #endif
  157. // #ifdef APP-PLUS
  158. this.payChannel = this.systemPlatform === 'ios' ? 'weixinAppIos' : 'weixinAppAndroid';
  159. // #endif
  160. // #ifdef MP
  161. this.payChannel = "routine";
  162. if (this.productType == 'video') {
  163. this.payChannel = "video";
  164. } else {
  165. this.payChannel = "routine";
  166. }
  167. // #endif
  168. }
  169. },
  170. getOrderPay: function(orderNo, message) {
  171. let that = this;
  172. let goPages = '/pages/order/order_pay_status/index?order_id=' + orderNo;
  173. orderPay({
  174. orderNo: orderNo,
  175. payChannel: that.payChannel,
  176. payType: that.payType,
  177. scene: that.productType === 'normal' ? 0 : 1177 //下单时小程序的场景值
  178. }).then(res => {
  179. let jsConfig = res.data.jsConfig;
  180. switch (res.data.payType) {
  181. case 'weixin':
  182. that.weixinPay(jsConfig, orderNo, goPages);
  183. break;
  184. case 'yue':
  185. return that.$util.Tips({
  186. title: message
  187. }, {
  188. tab: 5,
  189. url: goPages + '&status=1'
  190. });
  191. uni.hideLoading();
  192. break;
  193. case 'weixinh5':
  194. setTimeout(() => {
  195. location.href = jsConfig.mwebUrl + '&redirect_url=' +
  196. window.location
  197. .protocol + '//' + window.location.host + goPages +
  198. '&status=1';
  199. }, 100)
  200. uni.hideLoading();
  201. break;
  202. }
  203. }).catch(err => {
  204. uni.hideLoading();
  205. return that.$util.Tips({
  206. title: err
  207. });
  208. });
  209. },
  210. weixinPay(jsConfig, orderNo, goPages) {
  211. let that = this;
  212. // #ifdef MP
  213. if (that.productType === 'video') {
  214. uni.requestOrderPayment({
  215. timeStamp: jsConfig.timeStamp,
  216. nonceStr: jsConfig.nonceStr,
  217. package: jsConfig.packages,
  218. signType: jsConfig.signType,
  219. paySign: jsConfig.paySign,
  220. ticket: jsConfig.ticket,
  221. success: function(ress) {
  222. uni.hideLoading();
  223. openOrderSubscribe().then(() => {
  224. return that.$util.Tips({
  225. title: '支付成功',
  226. icon: 'success'
  227. }, {
  228. tab: 5,
  229. url: goPages
  230. }, );
  231. })
  232. },
  233. fail: function(e) {
  234. console.log(e)
  235. uni.hideLoading();
  236. return that.$util.Tips({
  237. title: '取消支付'
  238. }, {
  239. tab: 5,
  240. url: goPages + '&status=2'
  241. });
  242. },
  243. complete: function(e) {
  244. uni.hideLoading();
  245. //关闭当前页面跳转至订单状态
  246. if (e.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  247. title: '取消支付'
  248. }, {
  249. tab: 5,
  250. url: goPages + '&status=2'
  251. });
  252. },
  253. })
  254. } else {
  255. uni.requestPayment({
  256. timeStamp: jsConfig.timeStamp,
  257. nonceStr: jsConfig.nonceStr,
  258. package: jsConfig.packages,
  259. signType: jsConfig.signType,
  260. paySign: jsConfig.paySign,
  261. //ticket: jsConfig.ticket,
  262. success: function(ress) {
  263. uni.hideLoading();
  264. openOrderSubscribe().then(() => {
  265. return that.$util.Tips({
  266. title: '支付成功',
  267. icon: 'success'
  268. }, {
  269. tab: 5,
  270. url: goPages
  271. }, );
  272. })
  273. },
  274. fail: function(e) {
  275. console.log(e)
  276. uni.hideLoading();
  277. return that.$util.Tips({
  278. title: '取消支付'
  279. }, {
  280. tab: 5,
  281. url: goPages + '&status=2'
  282. });
  283. },
  284. complete: function(e) {
  285. uni.hideLoading();
  286. //关闭当前页面跳转至订单状态
  287. if (e.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  288. title: '取消支付'
  289. }, {
  290. tab: 5,
  291. url: goPages + '&status=2'
  292. });
  293. },
  294. })
  295. }
  296. // #endif
  297. // #ifdef H5
  298. let data = {
  299. timestamp: jsConfig.timeStamp,
  300. nonceStr: jsConfig.nonceStr,
  301. package: jsConfig.packages,
  302. signType: jsConfig.signType,
  303. paySign: jsConfig.paySign
  304. };
  305. that.$wechat.pay(data).then(res => {
  306. if (res.errMsg == 'chooseWXPay:cancel') {
  307. uni.hideLoading();
  308. return that.$util.Tips({
  309. title: '取消支付'
  310. }, {
  311. tab: 5,
  312. url: goPages + '&status=2'
  313. });
  314. } else {
  315. wechatQueryPayResult(orderNo).then(res => {
  316. uni.hideLoading();
  317. return that.$util.Tips({
  318. title: '支付成功',
  319. icon: 'success'
  320. }, {
  321. tab: 5,
  322. url: goPages
  323. });
  324. }).catch(err => {
  325. uni.hideLoading();
  326. return that.$util.Tips({
  327. title: err
  328. });
  329. })
  330. }
  331. }).catch(res => {
  332. uni.hideLoading();
  333. return that.$util.Tips({
  334. title: '取消支付'
  335. }, {
  336. tab: 5,
  337. url: goPages + '&status=2'
  338. });
  339. });
  340. // #endif
  341. // #ifdef APP-PLUS
  342. uni.requestPayment({
  343. provider: 'wxpay',
  344. orderInfo: {
  345. "appid": jsConfig.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  346. "noncestr": jsConfig.nonceStr, // 随机字符串
  347. "package": "Sign=WXPay", // 固定值
  348. "partnerid": jsConfig.partnerid, // 微信支付商户号
  349. "prepayid": jsConfig.packages, // 统一下单订单号
  350. "timestamp": Number(jsConfig.timeStamp), // 时间戳(单位:秒)
  351. "sign": this.systemPlatform === 'ios' ? 'MD5' : jsConfig
  352. .paySign // 签名,这里用的 MD5 签名
  353. }, //订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  354. success: function(res) {
  355. wechatQueryPayResult(orderNo).then(res => {
  356. uni.hideLoading();
  357. let url = '/pages/order/order_pay_status/index?order_id=' + orderNo +
  358. '&msg=支付成功';
  359. uni.showToast({
  360. title: "支付成功"
  361. })
  362. setTimeout(res => {
  363. uni.redirectTo({
  364. url: url
  365. })
  366. }, 2000)
  367. }).catch(err => {
  368. uni.hideLoading();
  369. return that.$util.Tips({
  370. title: err
  371. });
  372. })
  373. },
  374. fail: function(err) {
  375. uni.hideLoading();
  376. let url = '/pages/order/order_pay_status/index?order_id=' + orderNo +
  377. '&msg=支付失败';
  378. uni.showModal({
  379. content: "支付失败",
  380. showCancel: false,
  381. success: function(res) {
  382. if (res.confirm) {
  383. uni.redirectTo({
  384. url: url
  385. })
  386. }
  387. }
  388. })
  389. },
  390. complete: (err) => {
  391. uni.hideLoading();
  392. }
  393. });
  394. // #endif
  395. },
  396. //立即支付
  397. toOrderPay: Debounce(function() {
  398. this.getPayCheck();
  399. if (Number(this.payPrice) > Number(this.userBalance) && this.payType === 'yue') return this.$util
  400. .Tips({
  401. title: '余额的金额不够,请切换支付方式'
  402. });
  403. uni.showLoading({
  404. title: '加载中...'
  405. });
  406. this.isBuy = true;
  407. this.getOrderPay(this.orderNo, '支付成功')
  408. })
  409. },
  410. }
  411. </script>
  412. <style lang="scss" scoped>
  413. .titleNo {
  414. width: 100%;
  415. font-size: 28rpx;
  416. text-align: center;
  417. }
  418. .btn-box {
  419. padding: 0 30rpx;
  420. position: fixed;
  421. bottom: 43rpx;
  422. }
  423. .Bnt {
  424. font-size: 30rpx;
  425. font-weight: bold;
  426. color: #fff;
  427. width: 690rpx;
  428. height: 86rpx;
  429. border-radius: 43rpx;
  430. text-align: center;
  431. line-height: 86rpx;
  432. }
  433. .wrapper {
  434. padding: 30rpx;
  435. .list {
  436. margin-top: 50rpx;
  437. }
  438. .item {
  439. padding: 50rpx 30rpx;
  440. font-size: 30rpx;
  441. color: #333333;
  442. background-color: #fff;
  443. .title {
  444. text-align: center;
  445. @include main_color(theme);
  446. font-size: 34rpx;
  447. text {
  448. font-weight: 800;
  449. font-size: 50rpx;
  450. }
  451. }
  452. }
  453. .payItem {
  454. border-bottom: 1px solid #eee;
  455. justify-content: space-between;
  456. height: 138rpx;
  457. line-height: 138rpx;
  458. width: 100%;
  459. box-sizing: border-box;
  460. font-size: 32pxrpx;
  461. color: #333333;
  462. .on {
  463. // border-color: #fc5445;
  464. @include coupons_border_color(theme);
  465. color: $theme-color;
  466. }
  467. .name {
  468. .iconfont {
  469. width: 48rpx;
  470. height: 48rpx;
  471. border-radius: 50%;
  472. text-align: center;
  473. line-height: 48rpx;
  474. background-color: #fe960f;
  475. color: #fff;
  476. font-size: 30rpx;
  477. margin-right: 28rpx;
  478. }
  479. }
  480. .iconfont.icon-weixinzhifu1 {
  481. background-color: #41b035;
  482. }
  483. .iconfont.icon-zhifubao {
  484. background-color: #00AAEA;
  485. }
  486. .tip {
  487. text-align: center;
  488. font-size: 26rpx;
  489. color: #aaa;
  490. margin-right: 20rpx;
  491. }
  492. .radio {
  493. .iconfont {
  494. font-size: 46rpx;
  495. }
  496. }
  497. }
  498. }
  499. </style>