You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

388 lines
9.0 KiB

  1. <template>
  2. <view class="app">
  3. <view class="price-box">
  4. <text>支付金额</text>
  5. <text class="price">{{total}}</text>
  6. </view>
  7. <view class="pay-type-list">
  8. <!-- <view class="type-item b-b" @click="changePayType(1)" v-if="payTypeList.wxpay && total > 0">
  9. <text class="icon yticon icon-wxpay"></text>
  10. <view class="con">
  11. <text class="tit">微信支付</text>
  12. </view>
  13. <label class="radio">
  14. <radio value="" color="#fa436a" :checked='payType == 1' />
  15. </radio>
  16. </label>
  17. </view> -->
  18. <view class="type-item b-b" @click="changePayType(2)" v-if="payTypeList.alipay && total > 0">
  19. <text class="icon yticon icon-alipay"></text>
  20. <view class="con">
  21. <text class="tit">支付宝支付</text>
  22. </view>
  23. <label class="radio">
  24. <radio value="" color="#fa436a" :checked='payType == 2' />
  25. </radio>
  26. </label>
  27. </view>
  28. <!-- <view class="type-item b-b" @click="changePayType(3)" v-if="payTypeList.offline">
  29. <text class="icon yticon icon-pay"></text>
  30. <view class="con">
  31. <text class="tit">货到付款</text>
  32. </view>
  33. <label class="radio">
  34. <radio value="" color="#fa436a" :checked='payType == 3' />
  35. </radio>
  36. </label>
  37. </view> -->
  38. </view>
  39. <uni-popup ref="popup" type="center" :maskClick="false">
  40. <div style="text-align:center;width: 100%">
  41. <image mode="aspectFit" :src="'http://internalsales.iicn.co/addons/unishop/order/addQRCode?url=' + encodeURIComponent(site)">
  42. </image>
  43. </div>
  44. <p style="padding: 50upx">
  45. After finishing your payment, the page will not automatically jump. Please find your completed order in ‘My-My order’
  46. </p>
  47. </uni-popup>
  48. <text class="mix-btn" @click="confirm">Confirm Pay</text>
  49. </view>
  50. </template>
  51. <script>
  52. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  53. // #ifdef H5
  54. var jweixin = require('jweixin-module');
  55. // #endif
  56. export default {
  57. components: {
  58. uniPopup
  59. },
  60. data() {
  61. return {
  62. payType: 1,
  63. orderInfo: {},
  64. orderId: '',
  65. out_trade_no: '',
  66. payTypeList: {
  67. wxpay: false,
  68. alipay: false
  69. },
  70. total: 0.00,
  71. site: window.location.href
  72. };
  73. },
  74. onLoad(options) {
  75. this.total = options.total;
  76. this.orderId = options.order_id;
  77. this.out_trade_no = options.out_trade_no;
  78. this.getPayType();
  79. },
  80. onShow() {
  81. if (navigator.platform == 'Win32') {
  82. this.$nextTick(() => {
  83. this.$refs.popup.open()
  84. })
  85. }
  86. },
  87. methods: {
  88. // 获取支付方式
  89. async getPayType() {
  90. let type = await this.$api.request('/pay/getPayType');
  91. if (type) {
  92. this.payTypeList = type;
  93. }
  94. },
  95. //选择支付方式
  96. changePayType(type) {
  97. this.payType = type;
  98. switch (type) {
  99. case 1: // 微信支付
  100. break;
  101. case 2: // 支付宝支付
  102. break;
  103. // case 3: // 货到付款
  104. // break;
  105. }
  106. },
  107. //确认支付
  108. async confirm() {
  109. console.log(navigator.platform)
  110. if (this.payType == 1) {
  111. // #ifdef H5 || APP-PLUS || MP-WEIXIN
  112. this.weixinPay();
  113. // #endif
  114. } else if (this.payType == 2) {
  115. // 支付宝支付
  116. this.alipay();
  117. } else if (this.payType == 3) {
  118. // // 货到付款
  119. this.offlinePay();
  120. }
  121. },
  122. async alipay() {
  123. // #ifdef H5
  124. window.open(this.$unishow + '/pay/alipay?order_id=' + this.orderId);
  125. setTimeout(function() {
  126. uni.showModal({
  127. title: 'Tip',
  128. content: 'Whether paid?',
  129. cancelText: 'No',
  130. confirmText: 'Yes',
  131. success: function(res) {
  132. if (res.confirm) {
  133. uni.redirectTo({
  134. url: '/pages/order/order?state=0'
  135. });
  136. } else if (res.cancel) {
  137. //console.log('用户点击取消');
  138. }
  139. },
  140. fail: function(res) {
  141. //console.log(res)
  142. }
  143. });
  144. }, 3000);
  145. // #endif
  146. // #ifdef APP-PLUS
  147. let orderInfo = await this.$api.request('/pay/alipay', 'POST', {
  148. order_id: this.orderId
  149. });
  150. if (orderInfo) {
  151. //console.log(orderInfo);
  152. uni.requestPayment({
  153. provider: 'alipay',
  154. orderInfo: orderInfo,
  155. success: function(res) {
  156. console.log('success:' + JSON.stringify(res));
  157. uni.redirectTo({
  158. url: '/pages/money/paySuccess'
  159. })
  160. },
  161. fail: function(err) {
  162. console.log('fail:' + JSON.stringify(err));
  163. that.$api.msg('支付失败');
  164. }
  165. });
  166. }
  167. // #endif
  168. },
  169. async weixinPay() {
  170. let data = await this.$api.request('/pay/unify', 'GET', {
  171. order_id: this.orderId
  172. });
  173. let that = this;
  174. if (data) {
  175. if (data.trade_type == 'MWEB') {
  176. // #ifdef H5
  177. // 微信外的H5
  178. location.href = data.mweb_url;
  179. // #endif
  180. // #ifdef APP-PLUS
  181. // app 使用h5支付
  182. var wv; //计划创建的webview
  183. wv = plus.webview.create("", "custom-webview", {
  184. 'uni-app': 'none', //不加载uni-app渲染层框架,避免样式冲突
  185. })
  186. wv.loadURL(data.mweb_url, {
  187. Referer: data.referer
  188. });
  189. setTimeout(function() {
  190. uni.showModal({
  191. title: 'Tip',
  192. content: 'Whether paid?',
  193. cancelText: 'NO',
  194. confirmText: 'Yes',
  195. success: function(res) {
  196. if (res.confirm) {
  197. uni.redirectTo({
  198. url: '/pages/order/order?state=0'
  199. });
  200. } else if (res.cancel) {
  201. //console.log('用户点击取消');
  202. }
  203. },
  204. fail: function(res) {
  205. //console.log(res)
  206. }
  207. });
  208. }, 3000);
  209. // #endif
  210. } else if (data.trade_type == 'JSAPI') {
  211. // #ifdef H5
  212. // 微信内的H5
  213. let config = await this.$api.request('/pay/jssdkBuildConfig');
  214. if (config) {
  215. jweixin.config(config);
  216. jweixin.ready(function() {
  217. jweixin.chooseWXPay({
  218. timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  219. nonceStr: data.nonce_str, // 支付签名随机串,不长于 32 位
  220. package: 'prepay_id=' + data.prepay_id, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  221. signType: 'MD5', // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  222. paySign: data.paySign, // 支付签名
  223. success: function(res) {
  224. // 支付成功后的回调函数
  225. uni.redirectTo({
  226. url: '/pages/money/paySuccess'
  227. })
  228. },
  229. fail: function(err) {
  230. //console.log('fail:' + JSON.stringify(err));
  231. //that.$api.msg('fail:' + JSON.stringify(err))
  232. that.$api.msg('支付失败');
  233. }
  234. })
  235. });
  236. jweixin.error(function(res) {
  237. //that.$api.msg(JSON.stringify(res));
  238. that.$api.msg('支付失败');
  239. });
  240. } else {
  241. that.$api.msg('支付失败');
  242. }
  243. // #endif
  244. // #ifdef MP-WEIXIN
  245. uni.requestPayment({
  246. provider: 'wxpay',
  247. timeStamp: data.timeStamp,
  248. nonceStr: data.nonce_str,
  249. package: 'prepay_id=' + data.prepay_id,
  250. signType: 'MD5',
  251. paySign: data.paySign,
  252. success: function(res) {
  253. uni.redirectTo({
  254. url: '/pages/money/paySuccess'
  255. })
  256. },
  257. fail: function(err) {
  258. //console.log('fail:' + JSON.stringify(err));
  259. //that.$api.msg('fail:' + JSON.stringify(err))
  260. that.$api.msg('支付失败');
  261. }
  262. });
  263. // #endif
  264. }
  265. }
  266. },
  267. async offlinePay() {
  268. let data = await this.$api.request('/addons/unishop/order/addQRCode?url=', 'GET', {
  269. order_id: this.orderId
  270. });
  271. if (data) {
  272. uni.redirectTo({
  273. url: '/pages/money/paySuccess'
  274. });
  275. }
  276. }
  277. }
  278. }
  279. </script>
  280. <style lang='scss'>
  281. .app {
  282. width: 100%;
  283. }
  284. .price-box {
  285. background-color: #fff;
  286. height: 265upx;
  287. display: flex;
  288. flex-direction: column;
  289. justify-content: center;
  290. align-items: center;
  291. font-size: 28upx;
  292. color: #909399;
  293. .price {
  294. font-size: 50upx;
  295. color: #303133;
  296. margin-top: 12upx;
  297. &:before {
  298. content: '¥';
  299. font-size: 40upx;
  300. }
  301. }
  302. }
  303. .pay-type-list {
  304. margin-top: 20upx;
  305. background-color: #fff;
  306. padding-left: 60upx;
  307. .type-item {
  308. height: 120upx;
  309. padding: 20upx 0;
  310. display: flex;
  311. justify-content: space-between;
  312. align-items: center;
  313. padding-right: 60upx;
  314. font-size: 30upx;
  315. position: relative;
  316. }
  317. .icon {
  318. width: 100upx;
  319. font-size: 52upx;
  320. }
  321. .icon-pay {
  322. color: #fe8e2e;
  323. }
  324. .icon-wxpay {
  325. color: #36cb59;
  326. }
  327. .icon-alipay {
  328. color: #01aaef;
  329. }
  330. .tit {
  331. font-size: $font-lg;
  332. color: $font-color-dark;
  333. margin-bottom: 4upx;
  334. }
  335. .con {
  336. flex: 1;
  337. display: flex;
  338. flex-direction: column;
  339. font-size: $font-sm;
  340. color: $font-color-light;
  341. }
  342. }
  343. .mix-btn {
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. width: 630upx;
  348. height: 80upx;
  349. margin: 80upx auto 30upx;
  350. font-size: $font-lg;
  351. color: #fff;
  352. background-color: $base-color;
  353. border-radius: 10upx;
  354. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  355. }
  356. </style>