index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <form class="form" @submit="checkForm" :style="colorStyle">
  3. <view class="input-section">
  4. <view class="section-hd">{{$t(`支付金额`)}}</view>
  5. <view class="section-bd">
  6. <view class="input-group">
  7. {{$t(`¥`)}}
  8. <input v-model.number="money" class="input" name="money" type="digit" @input="inputChange" placeholder="0.00" />
  9. </view>
  10. <view v-if="payPrice && show" class="discount">{{$t(`会员优惠价`)}}:{{$t(`¥`)}}{{ payPrice || 0 }}</view>
  11. </view>
  12. </view>
  13. <view class="radio-section">
  14. <view class="section-hd">{{$t(`支付方式`)}}</view>
  15. <radio-group class="section-bd" name="method">
  16. <label class="item" v-if="yuePay">
  17. <text class="iconfont icon-yue"></text>
  18. <view class="name">
  19. <text>{{$t(`余额支付`)}}</text>
  20. <text class="money">{{$t(`可用余额`)}}:{{$t(`¥`)}}{{ now_money || 0 }}</text>
  21. </view>
  22. <radio value="yue" :checked="payType === 'yue'" />
  23. </label>
  24. <label v-if="wxpay" class="item">
  25. <text class="iconfont icon-weixinzhifu"></text>
  26. <text class="name">{{$t(`微信支付`)}}</text>
  27. <radio value="weixin" :checked="payType === 'weixin'" />
  28. </label>
  29. </radio-group>
  30. </view>
  31. <button class="button" form-type="submit">{{$t(`确认`)}}</button>
  32. <view class="alipay" v-html="alipayHtml"></view>
  33. </form>
  34. </template>
  35. <script>
  36. import {
  37. offlineCheckPrice,
  38. offlineCreate,
  39. orderOfflinePayType
  40. } from '@/api/order.js';
  41. import {
  42. toLogin
  43. } from '@/libs/login.js';
  44. import {
  45. mapGetters
  46. } from "vuex";
  47. import colors from "@/mixins/color";
  48. const app = getApp();
  49. export default {
  50. mixins: [colors],
  51. data() {
  52. return {
  53. money: '',
  54. payPrice: '',
  55. payType: 'weixin',
  56. alipayHtml: '',
  57. alipay: false,
  58. wxpay: false,
  59. yuePay: false,
  60. paying: false,
  61. now_money: 0,
  62. isWeixin: false,
  63. site_name: '',
  64. isCommitted: false,
  65. show: false
  66. };
  67. },
  68. computed: mapGetters(['isLogin']),
  69. onLoad(options) {
  70. if (!this.isLogin) {
  71. toLogin()
  72. }
  73. // #ifdef H5
  74. if (options.code) {
  75. let spread = app.globalData.spid ? app.globalData.spid : '';
  76. wechatAuthV2(options.code, spread).then(res => {
  77. location.href = decodeURIComponent(
  78. decodeURIComponent(options.back_url)
  79. )
  80. })
  81. }
  82. // #endif
  83. },
  84. onShow() {
  85. if (this.isLogin) {
  86. this.getPayType();
  87. }
  88. //#ifdef H5
  89. this.isWeixin = this.$wechat.isWeixin();
  90. //#endif
  91. },
  92. methods: {
  93. inputChange(e){
  94. var that = this
  95. e.target.value = (e.target.value.match(/^\d*(.?\d{0,2})/g)[0]) || ""
  96. this.$nextTick(() => {
  97. this.money = e.target.value
  98. this.checkPrice();
  99. })
  100. },
  101. getPayType() {
  102. orderOfflinePayType()
  103. .then(res => {
  104. const {
  105. ali_pay_status,
  106. pay_weixin_open,
  107. yue_pay_status,
  108. offline_pay_status,
  109. site_name,
  110. now_money
  111. } = res.data;
  112. this.alipay = ali_pay_status;
  113. this.wxpay = pay_weixin_open;
  114. this.yuePay = yue_pay_status;
  115. this.now_money = now_money;
  116. this.site_name = site_name;
  117. if (!offline_pay_status) {
  118. uni.showModal({
  119. title: this.$t(`支付提醒`),
  120. content: this.$t(`线下支付已关闭,请点击确认按钮返回主页`),
  121. showCancel: false,
  122. success() {
  123. uni.switchTab({
  124. url: '/pages/index/index'
  125. })
  126. }
  127. });
  128. }
  129. if (site_name) {
  130. uni.setNavigationBarTitle({
  131. title: site_name
  132. });
  133. }
  134. })
  135. .catch(err => {
  136. uni.showToast({
  137. title: err,
  138. icon: 'none'
  139. });
  140. });
  141. },
  142. checkForm(e) {
  143. const {
  144. money,
  145. method
  146. } = e.detail.value;
  147. if (money) {
  148. this.combData(method);
  149. } else {
  150. uni.showToast({
  151. title: this.$t(`请输入支付金额`),
  152. icon: 'none'
  153. });
  154. }
  155. },
  156. // 优惠价
  157. checkPrice() {
  158. offlineCheckPrice({
  159. pay_price: this.money
  160. })
  161. .then(res => {
  162. this.payPrice = res.data.pay_price;
  163. this.show = res.data.show
  164. })
  165. .catch(err => {
  166. uni.showToast({
  167. title: err,
  168. icon: 'none'
  169. });
  170. });
  171. },
  172. // 组合数据
  173. combData(payType) {
  174. let data = {
  175. type: 3,
  176. pay_type: payType,
  177. from: 'weixinh5',
  178. price: this.payPrice || this.money,
  179. money: this.money
  180. };
  181. // #ifdef H5
  182. if (this.isWeixin) {
  183. data.from = 'weixin';
  184. }
  185. // #endif
  186. // #ifdef MP
  187. data.from = 'routine';
  188. // #endif
  189. if (this.paying) {
  190. return;
  191. }
  192. this.paying = true;
  193. uni.showLoading({
  194. title: this.$t(`正在确认`)
  195. });
  196. offlineCreate(data)
  197. .then(res => {
  198. uni.hideLoading();
  199. this.callPay(res);
  200. })
  201. .catch(err => {
  202. this.paying = false;
  203. uni.showToast({
  204. title: err,
  205. icon: 'none'
  206. });
  207. });
  208. },
  209. // 调用支付
  210. callPay(res) {
  211. const {
  212. status,
  213. result
  214. } = res.data, {
  215. orderId,
  216. jsConfig
  217. } = result,
  218. goPages = '/pages/annex/offline_result/index?site_name=' + this.site_name;
  219. switch (status) {
  220. case 'ORDER_EXIST':
  221. case 'EXTEND_ORDER':
  222. case 'PAY_ERROR':
  223. this.paying = false;
  224. this.$util.Tips({
  225. title: res.msg
  226. }, {
  227. tab: 5,
  228. url: goPages
  229. });
  230. break;
  231. case 'SUCCESS':
  232. this.paying = false;
  233. this.money = '';
  234. this.$util.Tips({
  235. title: res.msg,
  236. icon: 'success'
  237. }, {
  238. tab: 5,
  239. url: goPages
  240. });
  241. break;
  242. case 'WECHAT_PAY':
  243. // #ifdef MP
  244. let that = this;
  245. let mp_pay_name=''
  246. if(uni.requestOrderPayment){
  247. mp_pay_name='requestOrderPayment'
  248. }else{
  249. mp_pay_name='requestPayment'
  250. }
  251. uni[mp_pay_name]({
  252. timeStamp: jsConfig.timestamp,
  253. nonceStr: jsConfig.nonceStr,
  254. package: jsConfig.package,
  255. signType: jsConfig.signType,
  256. paySign: jsConfig.paySign,
  257. success: function(res) {
  258. that.$util.Tips({
  259. title: that.$t(`支付成功`),
  260. icon: 'success'
  261. }, {
  262. tab: 5,
  263. url: '/pages/annex/offline_result/index'
  264. });
  265. },
  266. fail: function() {
  267. uni.showToast({
  268. title: that.$t(`取消支付`),
  269. icon: 'none',
  270. success: function() {
  271. that.paying = false;
  272. }
  273. });
  274. },
  275. complete: function() {
  276. that.paying = false;
  277. uni.hideLoading();
  278. }
  279. });
  280. // #endif
  281. // #ifndef MP
  282. this.$wechat
  283. .pay(result.jsConfig)
  284. .then(res => {
  285. this.paying = false;
  286. this.$util.Tips({
  287. title: this.$t(`支付成功`),
  288. icon: 'success'
  289. }, {
  290. tab: 5,
  291. url: '/pages/annex/offline_result/index'
  292. });
  293. })
  294. .catch(err => {
  295. this.paying = false;
  296. if (err.errMsg == 'chooseWXPay:cancel') {
  297. uni.showToast({
  298. title: this.$t(`取消支付`),
  299. icon: 'none'
  300. });
  301. }
  302. });
  303. // #endif
  304. break;
  305. case 'PAY_DEFICIENCY':
  306. this.paying = false;
  307. this.$util.Tips({
  308. title: res.msg
  309. });
  310. break;
  311. case 'WECHAT_H5_PAY':
  312. this.paying = false;
  313. uni.showToast({
  314. title: res.msg,
  315. success() {
  316. location.href = jsConfig.h5_url;
  317. }
  318. });
  319. break;
  320. case 'ALIPAY_PAY':
  321. this.paying = false;
  322. // #ifdef H5
  323. if (this.$wechat.isWeixin()) {
  324. uni.navigateTo({
  325. url: `/pages/users/alipay_invoke/index?id=${orderId}&link=${jsConfig.qrCode}`
  326. });
  327. } else {
  328. this.alipayHtml = jsConfig;
  329. this.$nextTick(() => {
  330. document.getElementById('alipaysubmit').submit();
  331. });
  332. }
  333. // #endif
  334. // #ifdef MP
  335. uni.navigateTo({
  336. url: `/pages/users/alipay_invoke/index?id=${orderId}&link=${jsConfig.qrCode}`
  337. });
  338. // #endif
  339. break;
  340. }
  341. }
  342. }
  343. };
  344. </script>
  345. <style>
  346. page {
  347. background-color: #ffffff;
  348. }
  349. </style>
  350. <style lang="scss" scoped>
  351. /deep/uni-radio .uni-radio-input.uni-radio-input-checked {
  352. border: 1px solid #FDC383 !important;
  353. background-color: #FDC383 !important;
  354. }
  355. .input-section {
  356. .section-hd {
  357. padding: 30rpx;
  358. font-size: 28rpx;
  359. color: #666666;
  360. }
  361. .section-bd {
  362. padding-right: 30rpx;
  363. padding-left: 30rpx;
  364. }
  365. .input-group {
  366. display: flex;
  367. align-items: flex-end;
  368. padding: 45rpx 20rpx 47rpx;
  369. font-size: 80rpx;
  370. color: #999999;
  371. }
  372. .input {
  373. flex: 1;
  374. height: 110rpx;
  375. margin-left: 15rpx;
  376. font-size: 100rpx;
  377. color: #282828;
  378. }
  379. .discount {
  380. padding: 27rpx 20rpx;
  381. border-top: 1rpx solid #eeeeee;
  382. font-size: 28rpx;
  383. color: #e93323;
  384. }
  385. }
  386. .radio-section {
  387. border-top: 20rpx solid #f5f5f5;
  388. .section-hd {
  389. padding: 30rpx;
  390. font-size: 28rpx;
  391. color: #666666;
  392. }
  393. .section-bd {
  394. padding-left: 50rpx;
  395. }
  396. .item {
  397. display: flex;
  398. align-items: center;
  399. padding-top: 30rpx;
  400. padding-right: 30rpx;
  401. padding-bottom: 30rpx;
  402. border-bottom: 1rpx solid #f5f5f5;
  403. .name{
  404. display: flex;
  405. align-items: center;
  406. justify-content: space-between;
  407. }
  408. }
  409. .iconfont {
  410. font-size: 44rpx;
  411. }
  412. .icon-yue {
  413. color: #fe960f;
  414. }
  415. .icon-weixinzhifu {
  416. color: #41b035;
  417. }
  418. .icon-zhifubao {
  419. color: #099bdf;
  420. }
  421. .name {
  422. flex: 1;
  423. margin-left: 30rpx;
  424. font-size: 30rpx;
  425. color: #333333;
  426. }
  427. .money {
  428. float: right;
  429. padding-right: 20rpx;
  430. font-size: 20rpx;
  431. }
  432. }
  433. .button {
  434. height: 86rpx;
  435. border-radius: 43rpx;
  436. margin: 114rpx 30rpx 30rpx;
  437. background: linear-gradient(90deg, #FEE2B7 0%, #FDC383 100%);
  438. font-size: 30rpx;
  439. line-height: 86rpx;
  440. color: #5D3324;
  441. }
  442. .alipay {
  443. display: none;
  444. }
  445. </style>