pay.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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/set.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. obj.$api.msg(msg);
  119. }
  120. }
  121. if (obj.payType == 'weixin') {
  122. let da = e.data.result.jsConfig;
  123. let data = {
  124. // #ifdef H5
  125. timestamp: da.timestamp,
  126. // #endif
  127. // #ifdef MP
  128. timeStamp: da.timestamp,
  129. // #endif
  130. nonceStr: da.nonceStr,
  131. package: da.package,
  132. signType: da.signType,
  133. paySign: da.paySign,
  134. success: function(res) {
  135. obj.paySuccessTo();
  136. },
  137. fail: () => {
  138. uni.navigateTo({
  139. url: '/pages/order/order?state=0'
  140. });
  141. }
  142. };
  143. // #ifdef H5
  144. if (obj.payType == 'weixin') {
  145. weixinObj.chooseWXPay(data);
  146. }
  147. // #endif
  148. // #ifdef MP-WEIXIN
  149. if (obj.payType == 'weixin') {
  150. wx.requestPayment(data);
  151. }
  152. // #endif
  153. }
  154. uni.hideLoading();
  155. obj.payLoding = false;
  156. })
  157. .catch(e => {
  158. // 支付完成
  159. uni.hideLoading();
  160. obj.payLoding = false;
  161. console.log(e);
  162. });
  163. },
  164. // 支付成功跳转
  165. paySuccessTo() {
  166. uni.hideLoading();
  167. uni.redirectTo({
  168. url: './paySuccess?orderid=' + this.orderId
  169. });
  170. },
  171. //确认支付
  172. confirm: async function() {
  173. let obj = this;
  174. uni.showLoading({
  175. title: '支付中',
  176. mask: true
  177. })
  178. // 判断是否余额不足
  179. if (obj.payType == 'yue' && +obj.now_money < obj.money) {
  180. uni.showModal({
  181. title: '提示',
  182. content: '账户余额不足!',
  183. showCancel: false,
  184. success: res => {},
  185. fail: () => {},
  186. complete: () => {}
  187. });
  188. return;
  189. }
  190. // 支付中
  191. obj.payLoding = true;
  192. // #ifdef H5
  193. // 获取当前是否为微信浏览器
  194. obj.froms = uni.getStorageSync('weichatBrowser') || '';
  195. // #endif
  196. // 判断是否为未支付订单中跳转进入
  197. obj.orderMoneyPay();
  198. }
  199. }
  200. };
  201. </script>
  202. <style lang="scss">
  203. .app {
  204. width: 100%;
  205. padding-top: 30rpx;
  206. }
  207. .moneyBox {
  208. position: relative;
  209. margin: 0 $page-row-spacing;
  210. border-radius: 20rpx;
  211. overflow: hidden;
  212. background-color: #FFFFFF;
  213. }
  214. .bg {
  215. background-color: $color-green;
  216. width: 950rpx;
  217. position: absolute;
  218. left: -100rpx;
  219. border-bottom-left-radius: 1000rpx;
  220. border-bottom-right-radius: 1000rpx;
  221. top: 0rpx;
  222. height: 300rpx;
  223. }
  224. .price-box {
  225. background-color: #fff;
  226. height: 200rpx;
  227. display: flex;
  228. flex-direction: column;
  229. justify-content: center;
  230. align-items: center;
  231. font-size: 28upx;
  232. color: #909399;
  233. .price {
  234. font-size: 50upx;
  235. color: #303133;
  236. margin-top: 12upx;
  237. &:before {
  238. content: '¥';
  239. font-size: 40upx;
  240. }
  241. }
  242. }
  243. .pay-type-list {
  244. margin-top: 20upx;
  245. background-color: #fff;
  246. padding-left: 60upx;
  247. .type-item {
  248. height: 120upx;
  249. padding: 20upx 0;
  250. display: flex;
  251. justify-content: space-between;
  252. align-items: center;
  253. padding-right: 60upx;
  254. font-size: 30upx;
  255. position: relative;
  256. }
  257. .icon {
  258. width: 100upx;
  259. font-size: 52upx;
  260. }
  261. .iconyue {
  262. color: #fe8e2e;
  263. }
  264. .iconweixin {
  265. color: #36cb59;
  266. }
  267. .iconzhifubao {
  268. color: #01aaef;
  269. }
  270. .tit {
  271. font-size: $font-lg;
  272. color: $font-color-dark;
  273. margin-bottom: 4upx;
  274. }
  275. .con {
  276. flex: 1;
  277. display: flex;
  278. flex-direction: column;
  279. font-size: $font-sm;
  280. color: $font-color-light;
  281. }
  282. }
  283. .clickbg {
  284. background-color: $color-gray !important;
  285. }
  286. .yt-list {
  287. background: #fff;
  288. margin: 0 $page-row-spacing;
  289. border-radius: 20rpx;
  290. padding-bottom: 20rpx;
  291. }
  292. .yt-list-cell {
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. padding: 10rpx 30rpx 10rpx 40rpx;
  297. line-height: 70rpx;
  298. position: relative;
  299. .checked,
  300. .noChecked {
  301. width: 36rpx;
  302. height: 36rpx;
  303. }
  304. .noChecked {
  305. border: 1px solid $font-color-light;
  306. border-radius: 100rpx;
  307. }
  308. &.cell-hover {
  309. background: #fafafa;
  310. }
  311. &.b-b:after {
  312. left: 30rpx;
  313. }
  314. .cell-icon {
  315. height: 32rpx;
  316. width: 32rpx;
  317. font-size: 22rpx;
  318. color: #fff;
  319. text-align: center;
  320. line-height: 32rpx;
  321. background: #f85e52;
  322. border-radius: 4rpx;
  323. margin-right: 12rpx;
  324. &.hb {
  325. background: #ffaa0e;
  326. }
  327. &.lpk {
  328. background: #3ab54a;
  329. }
  330. }
  331. .cell-more {
  332. align-self: center;
  333. font-size: 24rpx;
  334. color: $font-color-light;
  335. margin-left: 8rpx;
  336. margin-right: -10rpx;
  337. }
  338. .cell-tit {
  339. font-size: 26rpx;
  340. color: $font-color-light;
  341. margin-right: 10rpx;
  342. .orderIcon {
  343. width: 48rpx;
  344. }
  345. }
  346. .cell-tip {
  347. font-size: 26rpx;
  348. color: $font-color-dark;
  349. &.disabled {
  350. color: $font-color-light;
  351. }
  352. &.active {
  353. color: $base-color;
  354. }
  355. &.red {
  356. color: $base-color;
  357. }
  358. }
  359. &.desc-cell {
  360. .cell-tit {
  361. max-width: 90rpx;
  362. }
  363. }
  364. .desc {
  365. text-align: right;
  366. font-size: $font-base;
  367. color: $font-color-light;
  368. }
  369. }
  370. </style>