index.vue 9.6 KB

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