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.

464 lines
12 KiB

3 months ago
  1. <template>
  2. <view>
  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" @click='goPay(item.number || 0 , item.value)'
  8. v-for="(item,index) in payMode" :key="index" v-if="item.payStatus==1">
  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.number">
  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 icon-xiangyou"></view>
  20. </view>
  21. </view>
  22. <view class="mask" @click='close' v-if="pay_close"></view>
  23. <view class="alipaysubmit" v-html="formContent"></view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. orderPay,
  29. wechatQueryPayResult,
  30. getPayConfig
  31. } from '@/api/order.js';
  32. import {
  33. mapGetters
  34. } from "vuex";
  35. export default {
  36. props: {
  37. pay_close: {
  38. type: Boolean,
  39. default: false,
  40. },
  41. order_id: {
  42. type: String,
  43. default: ''
  44. },
  45. totalPrice: {
  46. type: String,
  47. default: '0'
  48. }
  49. },
  50. data() {
  51. return {
  52. formContent:'',
  53. payChannel:'',
  54. //支付方式
  55. payMode: [
  56. {
  57. "name": "微信支付",
  58. "icon": "icon-weixin2",
  59. value: 'weixin',
  60. title: '微信快捷支付',
  61. // #ifdef APP
  62. payStatus: 0,
  63. // #endif
  64. // #ifndef APP
  65. payStatus: 1,
  66. // #endif
  67. },
  68. {
  69. "name": "余额支付",
  70. "icon": "icon-yuezhifu",
  71. value: 'yue',
  72. title: '可用余额:',
  73. payStatus: 1,
  74. number: 0
  75. },
  76. ],
  77. };
  78. },
  79. computed: mapGetters(['systemPlatform','userInfo','productType']),
  80. created(){
  81. this.payConfig();
  82. this.payMode[1].number = this.userInfo.nowMoney;
  83. },
  84. methods: {
  85. close: function() {
  86. this.$emit('onChangeFun', {
  87. action: 'payClose'
  88. });
  89. },
  90. payConfig(){
  91. getPayConfig().then(res=>{
  92. this.payMode[1].payStatus = res.data.yuePayStatus === "'1'" ? 1 : 0;
  93. // #ifndef APP
  94. this.payMode[0].payStatus = res.data.payWeixinOpen === "'1'" ? 1 : 0;
  95. // #endif
  96. })
  97. },
  98. goPay: function(number, paytype) {
  99. let that = this;
  100. let goPages = '/pages/order/order_pay_status/index?order_id=' + that.order_id;
  101. if (!that.order_id) return that.$util.Tips({
  102. title: '请选择要支付的订单'
  103. });
  104. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  105. title: '余额不足!'
  106. });
  107. uni.showLoading({
  108. title: '支付中'
  109. });
  110. // #ifdef H5
  111. if(paytype == 'alipay'){
  112. that.payChannel = 'alipay';
  113. }else if(paytype == 'weixin' && this.$wechat.isWeixin()){
  114. that.payChannel = 'public';
  115. }else{
  116. that.payChannel = 'weixinh5';
  117. }
  118. // #endif
  119. // #ifdef APP-PLUS
  120. if(paytype == 'alipay'){
  121. that.payChannel = 'appAliPay';
  122. }else if(paytype == 'weixin'){
  123. that.payChannel = that.systemPlatform === 'ios' ? 'weixinAppIos' : 'weixinAppAndroid';
  124. }
  125. // #endif
  126. orderPay({
  127. orderNo: that.order_id,
  128. // #ifdef MP
  129. payChannel: 'routine',
  130. // #endif
  131. // #ifndef MP
  132. payChannel:that.payChannel,
  133. // #endif
  134. payType: paytype,
  135. scene: that.productType === 'normal' ? 0 : 1177 //下单时小程序的场景值
  136. }).then(res => {
  137. let jsConfig = res.data.jsConfig;
  138. that.order_id = res.data.orderNo;
  139. switch (res.data.payType) {
  140. case 'weixin':
  141. that.weixinPay(jsConfig);
  142. break;
  143. case 'yue':
  144. uni.hideLoading();
  145. return that.$util.Tips({
  146. title: '余额支付成功',
  147. icon: 'success'
  148. }, () => {
  149. that.$emit('onChangeFun', {
  150. action: 'pay_complete'
  151. });
  152. });
  153. break;
  154. case 'weixinh5':
  155. uni.hideLoading();
  156. location.replace(jsConfig.mwebUrl + '&redirect_url=' + window.location.protocol +
  157. '//' + window.location.host + goPages + '&status=1');
  158. return that.$util.Tips({
  159. title: "支付中",
  160. icon: 'success'
  161. }, () => {
  162. that.$emit('onChangeFun', {
  163. action: 'pay_complete'
  164. });
  165. });
  166. break;
  167. case 'alipay':
  168. //#ifdef H5
  169. if (this.$wechat.isWeixin()) {
  170. //微信公众号内支付
  171. } else {
  172. //h5支付
  173. uni.hideLoading();
  174. that.formContent = res.data.alipayRequest;
  175. uni.setStorage({key: 'orderNo', data:that.order_id});
  176. that.$nextTick(() => {
  177. document.forms['punchout_form'].submit();
  178. })
  179. }
  180. //#endif
  181. // #ifdef APP-PLUS
  182. let alipayRequest = res.data.alipayRequest;
  183. uni.requestPayment({
  184. provider: 'alipay',
  185. orderInfo: alipayRequest,
  186. success: (e) => {
  187. uni.showToast({
  188. title: "支付成功"
  189. })
  190. setTimeout(res => {
  191. that.$emit('onChangeFun', {
  192. action: 'pay_complete'
  193. });
  194. }, 2000)
  195. },
  196. fail: (e) => {
  197. uni.showModal({
  198. content: "支付失败",
  199. showCancel: false,
  200. success: function(res) {
  201. if (res.confirm) {
  202. //点击确认的操作
  203. that.$emit('onChangeFun', {
  204. action: 'pay_fail'
  205. });
  206. } else if (res.cancel) {
  207. }
  208. }
  209. })
  210. },
  211. complete: () => {
  212. uni.hideLoading();
  213. },
  214. });
  215. // #endif
  216. break;
  217. }
  218. }).catch(err => {
  219. uni.hideLoading();
  220. return that.$util.Tips({
  221. title: err
  222. }, () => {
  223. that.$emit('onChangeFun', {
  224. action: 'pay_fail'
  225. });
  226. });
  227. })
  228. },
  229. weixinPay(jsConfig){
  230. let that = this;
  231. // #ifdef MP
  232. uni.requestOrderPayment({
  233. timeStamp: jsConfig.timeStamp,
  234. nonceStr: jsConfig.nonceStr,
  235. package: jsConfig.packages,
  236. signType: jsConfig.signType,
  237. paySign: jsConfig.paySign,
  238. ticket: jsConfig.ticket,
  239. success: function(ress) {
  240. uni.hideLoading();
  241. wechatQueryPayResult(that.order_id).then(res => {
  242. uni.hideLoading();
  243. return that.$util.Tips({
  244. title: "支付成功",
  245. icon: 'success'
  246. }, () => {
  247. that.$emit('onChangeFun', {
  248. action: 'pay_complete'
  249. });
  250. });
  251. }).catch(err => {
  252. uni.hideLoading();
  253. return that.$util.Tips({
  254. title: err
  255. });
  256. })
  257. },
  258. fail: function(e) {
  259. uni.hideLoading();
  260. return that.$util.Tips({
  261. title: '取消支付'
  262. }, () => {
  263. that.$emit('onChangeFun', {
  264. action: 'pay_fail'
  265. });
  266. });
  267. },
  268. complete: function(e) {
  269. uni.hideLoading();
  270. if (e.errMsg == 'requestPayment:cancel') return that.$util
  271. .Tips({
  272. title: '取消支付'
  273. }, () => {
  274. that.$emit('onChangeFun', {
  275. action: 'pay_fail'
  276. });
  277. });
  278. },
  279. })
  280. // #endif
  281. // #ifdef H5
  282. let datas = {
  283. timestamp: jsConfig.timeStamp,
  284. nonceStr: jsConfig.nonceStr,
  285. package: jsConfig.packages,
  286. signType: jsConfig.signType,
  287. paySign: jsConfig.paySign
  288. };
  289. that.$wechat.pay(datas).then(res => {
  290. if (res.errMsg == 'chooseWXPay:cancel') {
  291. uni.hideLoading();
  292. return that.$util.Tips({
  293. title: '支付失败'
  294. });
  295. } else {
  296. wechatQueryPayResult(that.order_id).then(res => {
  297. uni.hideLoading();
  298. return that.$util.Tips({
  299. title: "支付成功",
  300. icon: 'success'
  301. }, () => {
  302. that.$emit('onChangeFun', {
  303. action: 'pay_complete'
  304. });
  305. });
  306. }).catch(err => {
  307. uni.hideLoading();
  308. return that.$util.Tips({
  309. title: err
  310. });
  311. })
  312. }
  313. }).catch(errW => {
  314. uni.hideLoading();
  315. return that.$util.Tips({
  316. title: errW
  317. });
  318. })
  319. // #endif
  320. // #ifdef APP-PLUS
  321. uni.requestPayment({
  322. provider: 'wxpay',
  323. orderInfo: {
  324. "appid": jsConfig.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  325. "noncestr": jsConfig.nonceStr, // 随机字符串
  326. "package": "Sign=WXPay", // 固定值
  327. "partnerid": jsConfig.partnerid, // 微信支付商户号
  328. "prepayid": jsConfig.packages, // 统一下单订单号
  329. "timestamp": Number(jsConfig.timeStamp), // 时间戳(单位:秒)
  330. "sign": this.systemPlatform === 'ios' ? 'MD5' : jsConfig
  331. .paySign // 签名,这里用的 MD5 签名
  332. }, //订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  333. success: (e) => {
  334. uni.hideLoading();
  335. let url = '/pages/order/order_pay_status/index?order_id=' + that.order_id;
  336. uni.showToast({
  337. title: "支付成功"
  338. })
  339. setTimeout(res => {
  340. that.$emit('onChangeFun', {
  341. action: 'pay_complete'
  342. });
  343. }, 2000)
  344. },
  345. fail: (e) => {
  346. uni.hideLoading();
  347. uni.showModal({
  348. content: "支付失败",
  349. showCancel: false,
  350. success: function(res) {
  351. if (res.confirm) {
  352. that.$emit('onChangeFun', {
  353. action: 'pay_fail'
  354. });
  355. } else if (res.cancel) {
  356. console.log('用户点击取消');
  357. }
  358. }
  359. })
  360. },
  361. complete: () => {
  362. uni.hideLoading();
  363. },
  364. });
  365. // #endif
  366. }
  367. }
  368. }
  369. </script>
  370. <style scoped lang="scss">
  371. .payment {
  372. position: fixed;
  373. bottom: 0;
  374. left: 0;
  375. width: 100%;
  376. border-radius: 16rpx 16rpx 0 0;
  377. background-color: #fff;
  378. padding-bottom: 60rpx;
  379. z-index: 99;
  380. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  381. transform: translate3d(0, 100%, 0);
  382. }
  383. .payment.on {
  384. transform: translate3d(0, 0, 0);
  385. }
  386. .payment .title {
  387. text-align: center;
  388. height: 123rpx;
  389. font-size: 32rpx;
  390. color: #282828;
  391. font-weight: bold;
  392. padding-right: 30rpx;
  393. margin-left: 30rpx;
  394. position: relative;
  395. border-bottom: 1rpx solid #eee;
  396. }
  397. .payment .title .iconfont {
  398. position: absolute;
  399. right: 30rpx;
  400. top: 50%;
  401. transform: translateY(-50%);
  402. font-size: 43rpx;
  403. color: #8a8a8a;
  404. font-weight: normal;
  405. }
  406. .payment .item {
  407. border-bottom: 1rpx solid #eee;
  408. height: 130rpx;
  409. margin-left: 30rpx;
  410. padding-right: 30rpx;
  411. }
  412. .payment .item .left {
  413. width: 610rpx;
  414. }
  415. .payment .item .left .text {
  416. width: 540rpx;
  417. }
  418. .payment .item .left .text .name {
  419. font-size: 32rpx;
  420. color: #282828;
  421. }
  422. .payment .item .left .text .info {
  423. font-size: 24rpx;
  424. color: #999;
  425. }
  426. .payment .item .left .text .info .money {
  427. color: #ff9900;
  428. }
  429. .payment .item .left .iconfont {
  430. font-size: 45rpx;
  431. color: #09bb07;
  432. }
  433. .payment .item .left .iconfont.icon-zhifubao {
  434. color: #00aaea;
  435. }
  436. .payment .item .left .iconfont.icon-yuezhifu {
  437. color: #ff9900;
  438. }
  439. .payment .item .left .iconfont.icon-yuezhifu1 {
  440. color: #eb6623;
  441. }
  442. .payment .item .iconfont {
  443. font-size: 0.3rpx;
  444. color: #999;
  445. }
  446. </style>