index.vue 9.5 KB

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