index.vue 9.2 KB

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