pay.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <template>
  2. <view class="app">
  3. <view class="price-box">
  4. <text>支付金额</text>
  5. <text class="price">{{ money }}</text>
  6. </view>
  7. <view class="pay-type-list">
  8. <view class="type-item b-b" @click="changePayType(1)" v-if="show">
  9. <uni-icons type="weixin" color="#00B848" size="25" />
  10. <view class="con">
  11. <text class="tit">微信支付</text>
  12. <text>推荐使用微信支付</text>
  13. </view>
  14. <label class="radio"><radio value="" color="#5dbc7c" :checked="payType == 1"></radio></label>
  15. </view>
  16. <!-- #ifdef APP-PLUS -->
  17. <view class="type-item b-b" @click="changePayType(2)" v-if="show">
  18. <text class="icon iconfont iconzhifubao"></text>
  19. <view class="con"><text class="tit">支付宝支付</text></view>
  20. <label class="radio"><radio value="" color="#5dbc7c" :checked="payType == 2"></radio></label>
  21. </view>
  22. <!-- #endif -->
  23. <view class="type-item flex_item" @click="changePayType(3)" v-if="show">
  24. <view class="img"><image class="yue" src="../../static/img/yue.png"></image></view>
  25. <view class="con">
  26. <text class="tit">余额支付</text>
  27. <text>可用余额 ¥{{ now_money }}</text>
  28. </view>
  29. <label class="radio"><radio value="" color="#5dbc7c" :checked="payType == 3"></radio></label>
  30. </view>
  31. </view>
  32. <text class="mix-btn" :class="{ clickbg: payLoding }" @click="!payLoding ? confirm() : ''">确认支付</text>
  33. <!-- <uni-popup ref="popup" type="center">
  34. <view class="pop-box">
  35. <view class="pop-text">
  36. 为了方便您查看您的拼团详细状况,我们需要您的通知授权
  37. </view>
  38. <view class="pop-button" @click="tongzhi()">
  39. 开启通知
  40. </view>
  41. </view>
  42. </uni-popup> -->
  43. </view>
  44. </template>
  45. <script>
  46. import { computedOrderkey, balance, createOrderkey, orderPay } from '@/api/money.js';
  47. import { orderDetail } from '@/api/order.js';
  48. import { mapState } from 'vuex';
  49. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  50. export default {
  51. components: {
  52. uniPopup
  53. },
  54. data() {
  55. return {
  56. payType: 1, //支付类型
  57. // #ifdef H5
  58. payName: 'weixin',
  59. // #endif
  60. // #ifdef MP-WEIXIN
  61. payName: 'weixin',
  62. // #endif
  63. orderInfo: {},
  64. money: 0.0, //订单金额
  65. now_money: 0.0, //余额
  66. orderKey: '',
  67. orderId: '', //保存订单id
  68. payLoding: false, //判断是否支付中
  69. type: '', //判断是否从订单中进入
  70. // #ifdef H5
  71. froms: '', //保存h5中数据来源对象
  72. // #endif
  73. pinkid: '', //保存拼团商品id
  74. estimated_time:'',//配送时间
  75. isBuyVip:"",
  76. Deliveryid:'',
  77. free: '', // 是否需要食物 0是 1否 1 payName = 'free'
  78. pink: 0, // 是否為拼團
  79. show: true ,// 是否显示
  80. pinkUser: '' ,//是否为团长
  81. goodsDetail:'',
  82. isPink: 0, // 是否为拼团商品 0 普通 1 拼团
  83. klonId: '', // 接龙id
  84. };
  85. },
  86. computed: {
  87. // #ifdef H5
  88. ...mapState(['weichatObj'])
  89. // #endif
  90. },
  91. onLoad(options) {
  92. console.log(options)
  93. // 是否需要食物
  94. this.free = options.free;
  95. if(this.free == 1) {
  96. this.show == false
  97. }
  98. if(options.pinkUser) {
  99. this.pinkUser = options.pinkUser;
  100. }
  101. if(options.pink){
  102. this.pink = options.pink;
  103. }
  104. if(options.klonId){
  105. this.klonId = options.klonId;
  106. }
  107. console.log(this.pink,987)
  108. if(options.estimated_time){
  109. this.estimated_time = options.estimated_time;
  110. }
  111. if (options.type == 1) {
  112. this.type = 1;
  113. this.orderId = options.ordid;
  114. this.money = options.money;
  115. } else {
  116. this.orderKey = options.key;
  117. this.free = options.free;
  118. this.isPink = options.isPink;
  119. let prepage = this.$api.prePage();
  120. let isBuyVip = '';
  121. if(prepage.isBuyVip){
  122. isBuyVip = prepage.isBuyVip;
  123. }else{
  124. isBuyVip = '';
  125. }
  126. this.isBuyVip = isBuyVip;
  127. this.Deliveryid = prepage.Deliveryid;
  128. computedOrderkey({
  129. isBuyVip:prepage.isBuyVip,//是否开通美卡
  130. estimated_time:prepage.estimated_time,
  131. orderkey: this.orderKey,
  132. couponId: prepage.couponChecked.id, //优惠券编号
  133. goCouponId: prepage.Deliveryid, //配送券编号
  134. productCouponId: prepage.GoodsChecked.id, //商品券编号
  135. addressId: prepage.addressData.id, //地址编号
  136. useIntegral: prepage.checkedPoints ? 1 : 0,
  137. is_pink_free: this.free ,// 是否需要实物
  138. isPink: this.isPink, // 是否为拼团商品 0 普通 1 拼团
  139. pinkId: this.pinkid, // 拼团id
  140. jl_id: this.klonId, // 接龙id
  141. }).then(({ data }) => {
  142. // 获取支付金额
  143. this.money = data.result.pay_price;
  144. });
  145. }
  146. // 保存pinkid
  147. if (options.pinkid) {
  148. this.pinkid = options.pinkid;
  149. }
  150. // 载入余额
  151. balance({}).then(({ data }) => {
  152. // 获取余额
  153. this.now_money = data.now_money;
  154. });
  155. },
  156. // onReady() {
  157. // let obj = this;
  158. // console.log(obj.pink)
  159. // obj.popimg();
  160. // },
  161. methods: {
  162. // popimg() {
  163. // console.log(111)
  164. // if( this.pink == 1 ) {
  165. // console.log(this.pink,777)
  166. // this.$refs.popup.open()
  167. // }
  168. // },
  169. //选择支付方式
  170. changePayType(type) {
  171. this.payType = type;
  172. if(this.free == 1) {
  173. this.payName = 'free'
  174. } else {
  175. if (this.payType == 1) {
  176. this.payName = 'weixin';
  177. }
  178. if (this.payType == 2) {
  179. this.payName = 'ali';
  180. }
  181. if (this.payType == 3) {
  182. this.payName = 'yue';
  183. }
  184. }
  185. },
  186. // 消息通知
  187. // tongzhi() {
  188. // this.$refs.popup.close()
  189. // wx.requestSubscribeMessage({
  190. // tmplIds: ['upq4J5ZQqRx-se7KgRdWS5d-l7EXKdAKT8W_J6HF70g','XKBGRmGwCzpT6oZZ0m6CF8nOS-eyGoDAI2KMSO4R4JY', '93fUZzhSsYNpBcDgFSgTDk3raKodD-bedAvfl3V4Iho'],
  191. // success (res) {
  192. // uni.showToast({
  193. // title:'开启通知成功'
  194. // })
  195. // }
  196. // })
  197. // },
  198. // 支付金额
  199. orderMoneyPay() {
  200. let obj = this;
  201. if(obj.free == 1) {
  202. obj.payName = 'free'
  203. }
  204. orderPay({
  205. uni: obj.orderId,
  206. // #ifdef H5
  207. from: obj.froms ? 'weixin' : 'H5', //来源
  208. // #endif
  209. // #ifdef MP-WEIXIN
  210. from: 'routine', //来源
  211. // #endif
  212. // #ifdef APP-PLUS
  213. from: 'app', //来源
  214. // #endif
  215. paytype: obj.payName //支付类型 weixin-微信 yue-余额
  216. })
  217. .then(e => {
  218. // 判断是否为余额支付
  219. if (obj.payName == 'yue') {
  220. if(obj.free == 1) {
  221. obj.payName == 'free'
  222. }
  223. if (e.status == 200) {
  224. obj.paySuccessTo();
  225. } else {
  226. obj.$api.msg(msg);
  227. }
  228. }
  229. // #ifdef H5
  230. if (obj.payName == 'weixin') {
  231. let da = e.data.result.jsConfig;
  232. obj.weichatObj.chooseWXPay({
  233. timestamp: da.timestamp,
  234. nonceStr: da.nonceStr,
  235. package: da.package,
  236. signType: da.signType,
  237. paySign: da.paySign,
  238. success: function(res) {
  239. obj.paySuccessTo();
  240. },
  241. fail: function(res) {
  242. console.log(res, '失败');
  243. console.log(res.errMsg);
  244. }
  245. });
  246. }
  247. // #endif
  248. // #ifdef MP-WEIXIN
  249. if (obj.payName == 'weixin') {
  250. let da = e.data.result.jsConfig;
  251. wx.requestPayment({
  252. timeStamp: da.timestamp,
  253. nonceStr: da.nonceStr,
  254. package: da.package,
  255. signType: da.signType,
  256. paySign: da.paySign,
  257. success: function(res) {
  258. obj.paySuccessTo();
  259. }
  260. });
  261. }
  262. // #endif
  263. obj.payLoding = false;
  264. })
  265. .catch(e => {
  266. // 支付完成
  267. obj.payLoding = false;
  268. console.log(e);
  269. });
  270. },
  271. // 支付成功跳转
  272. paySuccessTo() {
  273. let obj = this;
  274. console.log(obj.pink,22)
  275. console.log(obj.pink == 'true',33)
  276. if(obj.pink == 1){
  277. console.log('111111')
  278. orderDetail({}, obj.orderId).then(e => {
  279. this.goodsDetail = e.data;
  280. console.log(e.data)
  281. this.$nextTick(() => {
  282. uni.navigateTo({
  283. url: '/pages/groupBooking/groupdetails?id='+ e.data.pink_id + '&pinkUser=' + obj.pinkUser + '&order_id=' + obj.orderId + '&pink=' + obj.pink + '&tongzhi=1'
  284. })
  285. });
  286. });
  287. }
  288. if(obj.pink == 0){
  289. console.log('222222')
  290. uni.redirectTo({
  291. url: '/pages/money/paySuccess?orderId='+ obj.orderId
  292. });
  293. }
  294. },
  295. //确认支付
  296. confirm: async function() {
  297. let obj = this;
  298. // 判断是否余额不足
  299. if (obj.payName == 'yue' && +obj.now_money < obj.money) {
  300. uni.showModal({
  301. title: '提示',
  302. content: '账户余额不足!',
  303. showCancel: false,
  304. success: res => {},
  305. fail: () => {},
  306. complete: () => {}
  307. });
  308. return;
  309. }
  310. if(obj.free == 1) {
  311. obj.payName = 'free'
  312. }
  313. // 支付中
  314. obj.payLoding = true;
  315. // #ifdef H5
  316. // 获取当前是否为微信浏览器
  317. obj.froms = uni.getStorageSync('weichatBrowser') || '';
  318. // #endif
  319. // 判断是否为未支付订单中跳转进入
  320. if (obj.type != 1) {
  321. // 初次生成订单
  322. obj.firstCreateOrder();
  323. } else {
  324. // 判断是否支付宝支付
  325. if (obj.payName == 'ali') {
  326. obj.payAli();
  327. }else{
  328. // 已经生成订单未支付
  329. obj.orderMoneyPay();
  330. }
  331. }
  332. },
  333. // 初次订单创建
  334. firstCreateOrder() {
  335. let obj = this;
  336. // 获取下单页面数据
  337. if(obj.free == 1) {
  338. obj.payName = 'free'
  339. }
  340. let prepage = obj.$api.prePage();
  341. let isBuyVip = '';
  342. if(prepage.isBuyVip){
  343. isBuyVip = prepage.isBuyVip;
  344. }else{
  345. isBuyVip = '';
  346. }
  347. let data = {
  348. isBuyVip:isBuyVip,//美卡
  349. productCouponId:prepage.GoodsChecked.id,//商品券
  350. goCouponId:prepage.Deliveryid,//配送券
  351. real_name: prepage.addressData.real_name, //联系人名称
  352. phone: prepage.addressData.phone, //联系人号码
  353. couponId: prepage.couponChecked.id, //优惠券编号
  354. addressId: prepage.addressData.id, //支付地址id
  355. useIntegral: prepage.checkedPoints ? 1 : 0, //是否积分抵扣1为是0为否
  356. payType: obj.payName, //支付类型 weixin-微信 yue-余额
  357. estimated_time:obj.estimated_time,
  358. mark: prepage.desc, //备注
  359. isPink: obj.isPink, // 是否为拼团商品 0 普通 1 拼团
  360. // #ifdef H5
  361. from: obj.froms ? 'weixin' : 'H5', //来源
  362. // #endif
  363. // #ifdef MP-WEIXIN
  364. from: 'routine', //来源
  365. // #endif
  366. // #ifdef APP-PLUS
  367. from: 'app', //来源
  368. // #endif
  369. shipping_type: 1 //提货方式 1 快递 2自提
  370. };
  371. // 判断是否拼团商品
  372. if (obj.pinkid) {
  373. data.pinkId = obj.pinkid;
  374. }
  375. // 判断是否接龙商品
  376. if (obj.klonId) {
  377. data.jl_id = obj.klonId;
  378. }
  379. // 生成订单
  380. createOrderkey(data, obj.orderKey)
  381. .then(({ data, status, msg }) => {
  382. // 判断是否支付失败
  383. if (data.status == 'ORDER_EXIST') {
  384. uni.showModal({
  385. title: '提示',
  386. content: msg,
  387. showCancel: false
  388. });
  389. obj.payLoding = false;
  390. return;
  391. }
  392. // 保存订单号
  393. obj.orderId = data.result.orderId;
  394. // 判断是否为余额支付
  395. if (obj.payName == 'yue') {
  396. if (status == 200 && data.status == 'SUCCESS') {
  397. obj.paySuccessTo();
  398. } else {
  399. obj.$api.msg(msg);
  400. }
  401. } else if(status == 200 && data.status == 'SUCCESS' && msg == '购买成功') {
  402. obj.paySuccessTo();
  403. } else {
  404. // 立即支付
  405. obj.orderMoneyPay();
  406. }
  407. })
  408. .catch(e => {
  409. obj.payLoding = false;
  410. console.log(e);
  411. this.$api.msg(e.msg)
  412. });
  413. }
  414. }
  415. };
  416. </script>
  417. <style lang="scss">
  418. .app {
  419. width: 100%;
  420. }
  421. .price-box {
  422. background-color: #fff;
  423. height: 265upx;
  424. display: flex;
  425. flex-direction: column;
  426. justify-content: center;
  427. align-items: center;
  428. font-size: 28upx;
  429. color: #909399;
  430. .price {
  431. font-size: 50upx;
  432. color: #303133;
  433. margin-top: 12upx;
  434. &:before {
  435. content: '¥';
  436. font-size: 40upx;
  437. }
  438. }
  439. }
  440. .pay-type-list {
  441. margin-top: 20upx;
  442. background-color: #fff;
  443. padding-left: 60upx;
  444. .type-item {
  445. height: 120upx;
  446. padding: 20upx 0;
  447. display: flex;
  448. justify-content: space-between;
  449. align-items: center;
  450. padding-right: 60upx;
  451. font-size: 30upx;
  452. position: relative;
  453. }
  454. .icon {
  455. width: 100upx;
  456. font-size: 52upx;
  457. }
  458. .img{
  459. color: #fe8e2e;
  460. width: 52rpx;
  461. height: 52rpx;
  462. image{
  463. width: 100%;
  464. height: 100%;
  465. }
  466. }
  467. .iconweixin {
  468. color: #36cb59;
  469. }
  470. .iconzhifubao {
  471. color: #01aaef;
  472. }
  473. .tit {
  474. font-size: $font-lg;
  475. color: $font-color-dark;
  476. margin-bottom: 4upx;
  477. }
  478. .con {
  479. flex: 1;
  480. display: flex;
  481. flex-direction: column;
  482. padding-left: 25rpx;
  483. font-size: $font-sm;
  484. color: $font-color-light;
  485. }
  486. }
  487. .mix-btn {
  488. display: flex;
  489. align-items: center;
  490. justify-content: center;
  491. width: 630upx;
  492. height: 80upx;
  493. margin: 80upx auto 30upx;
  494. font-size: $font-lg;
  495. color: #fff;
  496. background-color: $base-color;
  497. border-radius: 10upx;
  498. /* box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4); */
  499. }
  500. .clickbg {
  501. background-color: $color-gray !important;
  502. }
  503. .pop-box {
  504. background: #FFFFFF;
  505. width: 600rpx;
  506. border-radius: 20rpx;
  507. padding: 30rpx 20rpx;
  508. .pop-text {
  509. text-align: center;
  510. font-size: 32rpx;
  511. }
  512. .pop-button {
  513. margin: 0 auto;
  514. font-size: 30rpx;
  515. margin-top: 30rpx;
  516. padding: 10rpx 0;
  517. border-radius: 15rpx;
  518. text-align: center;
  519. width: 200rpx;
  520. color: #FFFFFF;
  521. background: $base-color;
  522. }
  523. }
  524. </style>