pay.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <view class="app">
  3. <view class="bg">
  4. </view>
  5. <view class="moneyBox">
  6. <view class="price-box">
  7. <text>支付金额</text>
  8. <text class="price">{{ money }}</text>
  9. </view>
  10. <view class="yt-list">
  11. <view class="yt-list-cell b-b" v-if="fx" @click="payType='weixin'">
  12. <view class="cell-tit flex">
  13. <image class="orderIcon" src="../../../static/icon/orderWx.png" mode="widthFix"></image>
  14. <text class="margin-l-10">微信支付</text>
  15. </view>
  16. <image class="checked" v-if="payType=='weixin'" src="../../../static/icon/addressIconXz.png"
  17. mode="widthFix"></image>
  18. <view v-else class="noChecked"></view>
  19. </view>
  20. <!-- #ifdef APP-PLUS -->
  21. <view class="yt-list-cell b-b" @click="payType='ali'">
  22. <view class="cell-tit flex">
  23. <image class="orderIcon" src="../../../static/icon/orderAli.png" mode="widthFix"></image>
  24. <text class="margin-l-10">支付宝</text>
  25. </view>
  26. <image class="checked" v-if="payType=='ali'" src="../../../static/icon/addressIconXz.png"
  27. mode="widthFix">
  28. </image>
  29. <view v-else class="noChecked"></view>
  30. </view>
  31. <!-- #endif -->
  32. <view class="yt-list-cell" @click="payType='yue'">
  33. <view class="cell-tit flex">
  34. <image class="orderIcon" src="../../../static/icon/ye.png" mode="widthFix"></image>
  35. <text class="margin-l-10">余额({{now_money}})</text>
  36. </view>
  37. <image class="checked" v-if="payType=='yue'" src="../../../static/icon/addressIconXz.png"
  38. mode="widthFix">
  39. </image>
  40. <view v-else class="noChecked"></view>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="base-buttom" :class="{ clickbg: payLoding }" @click="!payLoding ? confirm() : ''">确认支付</view>
  45. </view>
  46. </template>
  47. <script>
  48. import {
  49. mapState
  50. } from 'vuex'
  51. import {
  52. balance
  53. } from '@/api/wallet.js';
  54. import {
  55. orderPay
  56. } from '@/api/order.js';
  57. // #ifdef H5
  58. import weixinObj from "@/plugin/jweixin-module/index.js";
  59. // #endif
  60. export default {
  61. data() {
  62. return {
  63. // #ifdef H5
  64. payType: 'ali',
  65. // #endif
  66. // #ifdef MP-WEIXIN
  67. payType: 'ali',
  68. // #endif
  69. money: 0.0, //订单金额
  70. now_money: 0.0, //余额
  71. orderId: '', //保存订单id
  72. payLoding: false, //判断是否支付中
  73. payType: 'ali',
  74. // #ifdef H5
  75. froms: '', //保存h5中数据来源对象
  76. // #endif
  77. };
  78. },
  79. onLoad(options) {
  80. // 判断是否为已创建单号订单
  81. this.type = 1;
  82. this.orderId = options.ordid;
  83. this.money = options.money;
  84. // 载入余额
  85. balance({}).then(({
  86. data
  87. }) => {
  88. // 获取余额
  89. this.now_money = data.now_money;
  90. });
  91. },
  92. computed:{
  93. ...mapState(['fx'])
  94. },
  95. methods: {
  96. // 支付金额
  97. orderMoneyPay() {
  98. let obj = this;
  99. orderPay({
  100. uni: obj.orderId,
  101. // #ifdef H5
  102. from: obj.froms ? 'weixin' : 'H5', //来源
  103. // #endif
  104. // #ifdef MP-WEIXIN
  105. from: 'routine', //来源
  106. // #endif
  107. // #ifdef APP-PLUS
  108. from: 'app', //来源
  109. // #endif
  110. paytype: obj.payType //支付类型 weixin-微信 yue-余额
  111. })
  112. .then(e => {
  113. // 判断是否为余额支付
  114. if (obj.payType == 'yue' && e.data.status == 'SUCCESS') {
  115. if (e.status == 200) {
  116. obj.paySuccessTo();
  117. } else {
  118. uni.showToast({
  119. title:msg,
  120. icon:"none"
  121. })
  122. }
  123. }
  124. if (obj.payType == 'weixin') {
  125. let da = e.data.result.jsConfig;
  126. let data = {
  127. // #ifdef H5
  128. timestamp: da.timestamp,
  129. // #endif
  130. // #ifdef MP
  131. timeStamp: da.timestamp,
  132. // #endif
  133. nonceStr: da.nonceStr,
  134. package: da.package,
  135. signType: da.signType,
  136. paySign: da.paySign,
  137. success: function(res) {
  138. obj.paySuccessTo();
  139. },
  140. fail: () => {
  141. uni.navigateTo({
  142. url: '/pages/order/order?state=0'
  143. });
  144. }
  145. };
  146. // #ifdef H5
  147. if (obj.payType == 'weixin') {
  148. weixinObj.chooseWXPay(data);
  149. }
  150. // #endif
  151. // #ifdef MP-WEIXIN
  152. if (obj.payType == 'weixin') {
  153. wx.requestPayment(data);
  154. }
  155. // #endif
  156. }
  157. uni.hideLoading();
  158. obj.payLoding = false;
  159. })
  160. .catch(e => {
  161. // 支付完成
  162. uni.hideLoading();
  163. obj.payLoding = false;
  164. console.log(e);
  165. });
  166. },
  167. // 支付成功跳转
  168. paySuccessTo() {
  169. uni.hideLoading();
  170. uni.redirectTo({
  171. url: './paySuccess?orderid=' + this.orderId
  172. });
  173. },
  174. //确认支付
  175. confirm: async function() {
  176. let obj = this;
  177. uni.showLoading({
  178. title: '支付中',
  179. mask: true
  180. })
  181. // 判断是否余额不足
  182. if (obj.payType == 'yue' && +obj.now_money < obj.money) {
  183. uni.showModal({
  184. title: '提示',
  185. content: '账户余额不足!',
  186. showCancel: false,
  187. success: res => {},
  188. fail: () => {},
  189. complete: () => {}
  190. });
  191. return;
  192. }
  193. // 支付中
  194. obj.payLoding = true;
  195. // #ifdef H5
  196. // 获取当前是否为微信浏览器
  197. obj.froms = uni.getStorageSync('weichatBrowser') || '';
  198. // #endif
  199. // 判断是否为未支付订单中跳转进入
  200. obj.orderMoneyPay();
  201. }
  202. }
  203. };
  204. </script>
  205. <style lang="scss">
  206. .app {
  207. width: 100%;
  208. padding-top: 30rpx;
  209. }
  210. .moneyBox {
  211. position: relative;
  212. margin: 0 $page-row-spacing;
  213. border-radius: 20rpx;
  214. overflow: hidden;
  215. background-color: #FFFFFF;
  216. }
  217. .bg {
  218. background-color: $color-green;
  219. width: 950rpx;
  220. position: absolute;
  221. left: -100rpx;
  222. border-bottom-left-radius: 1000rpx;
  223. border-bottom-right-radius: 1000rpx;
  224. top: 0rpx;
  225. height: 300rpx;
  226. }
  227. .price-box {
  228. background-color: #fff;
  229. height: 200rpx;
  230. display: flex;
  231. flex-direction: column;
  232. justify-content: center;
  233. align-items: center;
  234. font-size: 28upx;
  235. color: #909399;
  236. .price {
  237. font-size: 50upx;
  238. color: #303133;
  239. margin-top: 12upx;
  240. &:before {
  241. content: '¥';
  242. font-size: 40upx;
  243. }
  244. }
  245. }
  246. .pay-type-list {
  247. margin-top: 20upx;
  248. background-color: #fff;
  249. padding-left: 60upx;
  250. .type-item {
  251. height: 120upx;
  252. padding: 20upx 0;
  253. display: flex;
  254. justify-content: space-between;
  255. align-items: center;
  256. padding-right: 60upx;
  257. font-size: 30upx;
  258. position: relative;
  259. }
  260. .icon {
  261. width: 100upx;
  262. font-size: 52upx;
  263. }
  264. .iconyue {
  265. color: #fe8e2e;
  266. }
  267. .iconweixin {
  268. color: #36cb59;
  269. }
  270. .iconzhifubao {
  271. color: #01aaef;
  272. }
  273. .tit {
  274. font-size: $font-lg;
  275. color: $font-color-dark;
  276. margin-bottom: 4upx;
  277. }
  278. .con {
  279. flex: 1;
  280. display: flex;
  281. flex-direction: column;
  282. font-size: $font-sm;
  283. color: $font-color-light;
  284. }
  285. }
  286. .clickbg {
  287. background-color: $color-gray !important;
  288. }
  289. .yt-list {
  290. background: #fff;
  291. margin: 0 $page-row-spacing;
  292. border-radius: 20rpx;
  293. padding-bottom: 20rpx;
  294. }
  295. .yt-list-cell {
  296. display: flex;
  297. align-items: center;
  298. justify-content: space-between;
  299. padding: 10rpx 30rpx 10rpx 40rpx;
  300. line-height: 70rpx;
  301. position: relative;
  302. .checked,
  303. .noChecked {
  304. width: 36rpx;
  305. height: 36rpx;
  306. }
  307. .noChecked {
  308. border: 1px solid $font-color-light;
  309. border-radius: 100rpx;
  310. }
  311. &.cell-hover {
  312. background: #fafafa;
  313. }
  314. &.b-b:after {
  315. left: 30rpx;
  316. }
  317. .cell-icon {
  318. height: 32rpx;
  319. width: 32rpx;
  320. font-size: 22rpx;
  321. color: #fff;
  322. text-align: center;
  323. line-height: 32rpx;
  324. background: #f85e52;
  325. border-radius: 4rpx;
  326. margin-right: 12rpx;
  327. &.hb {
  328. background: #ffaa0e;
  329. }
  330. &.lpk {
  331. background: #3ab54a;
  332. }
  333. }
  334. .cell-more {
  335. align-self: center;
  336. font-size: 24rpx;
  337. color: $font-color-light;
  338. margin-left: 8rpx;
  339. margin-right: -10rpx;
  340. }
  341. .cell-tit {
  342. font-size: 26rpx;
  343. color: $font-color-light;
  344. margin-right: 10rpx;
  345. .orderIcon {
  346. width: 48rpx;
  347. }
  348. }
  349. .cell-tip {
  350. font-size: 26rpx;
  351. color: $font-color-dark;
  352. &.disabled {
  353. color: $font-color-light;
  354. }
  355. &.active {
  356. color: $base-color;
  357. }
  358. &.red {
  359. color: $base-color;
  360. }
  361. }
  362. &.desc-cell {
  363. .cell-tit {
  364. max-width: 90rpx;
  365. }
  366. }
  367. .desc {
  368. text-align: right;
  369. font-size: $font-base;
  370. color: $font-color-light;
  371. }
  372. }
  373. </style>