index.vue 9.6 KB

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