returnPay.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <view class="content">
  3. <image src="https://soap.cliu.cc/chumeng/indexBanner.png" class="content_banner"></image>
  4. <view class="content_box">
  5. <view class="top">
  6. <text>¥</text>
  7. <text>{{ amount }}</text>
  8. </view>
  9. <view class="tip">
  10. 【大卫博士健康内裤】差价退还
  11. </view>
  12. </view>
  13. <view class="content_num flexB">
  14. <text>购买数量</text>
  15. <text>1</text>
  16. </view>
  17. <view class="bottom">
  18. <view class="bottom_top">
  19. <text>共计;</text>
  20. <text class="text2">¥</text>
  21. <text class="text3">{{ amount }}</text>
  22. </view>
  23. <view class="bottom_btn"@click="$noMultipleClicks(toPay)">
  24. 立即支付
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { CustomerReturnPay } from '@/api/refundDifference.js';
  31. import { location } from '@/api/index.js'
  32. const jweixin = require('jweixin-module');
  33. export default {
  34. data() {
  35. return {
  36. noClick: true,
  37. amount: '',
  38. id: '',
  39. location: ''
  40. }
  41. },
  42. onLoad(e) {
  43. this.id = e.id
  44. this.amount = e.amount
  45. },
  46. mounted() {
  47. this.getAddress()
  48. },
  49. methods: {
  50. //通过后端获取wx.config的配置,再通过微信的js-sdk获取经纬度
  51. getAddress() {
  52. uni.showLoading({ title: '加载中', mask: true })
  53. const _this = this;
  54. let link = window.location.href;
  55. location({
  56. url: link
  57. }).then(res => {
  58. if (res.code == 200) {
  59. let data = JSON.parse(res.data);
  60. console.log('后端返回的wx.config的配置:', JSON.parse(res.data));
  61. _this.getLocation(data);
  62. } else {
  63. uni.hideLoading()
  64. console.log('获取位置失败');
  65. }
  66. }).catch(err => {
  67. uni.hideLoading()
  68. })
  69. },
  70. getLocation(params) {
  71. const _this = this;
  72. // 判断是否支持获取定位
  73. jweixin.config({
  74. debug: false, //开启debug模式.正式环境设置为false,测试环境设置为true
  75. appId: params.appId,
  76. timestamp: params.timestamp,
  77. nonceStr: params.nonceStr,
  78. signature: params.signature,
  79. jsApiList: ['getLocation'] //根据需要看需要哪些SDK的功能
  80. });
  81. // sdk加载完成后执行
  82. jweixin.ready(() => {
  83. jweixin.checkJsApi({
  84. jsApiList: ['getLocation'],
  85. success: res => {
  86. uni.hideLoading()
  87. if (res.checkResult.getLocation == false) {
  88. alert('你的微信版本太低,不支持微信JS接口,请升级到最新的微信版本!');
  89. return;
  90. }
  91. }
  92. });
  93. jweixin.error(res => {
  94. uni.hideLoading()
  95. console.log(res.errMsg, 'err');
  96. });
  97. // 获取位置
  98. jweixin.getLocation({
  99. type: 'gcj02',
  100. success: res => {
  101. this.location = `${res.longitude},${res.latitude}`;
  102. console.log('location', this.location, res)
  103. uni.hideLoading()
  104. },
  105. cancel: res => {
  106. uni.hideLoading()
  107. uni.showToast({
  108. title: '您已禁止获取位置信息',
  109. icon: 'none'
  110. });
  111. },
  112. fail: err => {
  113. uni.hideLoading()
  114. uni.showModal({
  115. title: '提示',
  116. content: '获取位置信息失败,请关闭网页重新打开,否则会导致无法支付',
  117. showCancel: false,
  118. })
  119. }
  120. });
  121. });
  122. },
  123. toPay() {
  124. if (!this.location) {
  125. uni.toast('未获取到位置信息')
  126. return
  127. }
  128. CustomerReturnPay({ refund_id: this.id, amount: this.amount, location: this.location }).then(res => {
  129. if (res.code === 200) {
  130. let callback_succ_func = res => {
  131. uni.showToast({
  132. title: '支付成功'
  133. })
  134. }
  135. let callback_error_func = res => {
  136. uni.showModal({
  137. content: '支付失败!',
  138. showCancel: false
  139. })
  140. }
  141. let info = res.data.data.pay_info
  142. this.wxJsPay(info, callback_succ_func, callback_error_func)
  143. } else {
  144. uni.showToast({
  145. title: res.message || '失败',
  146. icon: 'none'
  147. })
  148. return false;
  149. }
  150. })
  151. .catch(err => {})
  152. .finally(() => {
  153. setTimeout(() => {}, 3000)
  154. })
  155. },
  156. //WeixinJSBridge判断
  157. wxJsPay(data, callback_succ_func, callback_error_func) {
  158. if (typeof WeixinJSBridge == 'undefined') {
  159. if (document.addEventListener) {
  160. document.addEventListener('WeixinJSBridgeReady', this.jsApiCall, false);
  161. } else if (document.attachEvent) {
  162. document.attachEvent('WeixinJSBridgeReady', this.jsApiCall);
  163. document.attachEvent('onWeixinJSBridgeReady', this.jsApiCall);
  164. }
  165. } else {
  166. this.jsApiCall(data, callback_succ_func, callback_error_func);
  167. }
  168. },
  169. //调起支付
  170. jsApiCall(data, callback_succ_func, callback_error_func) {
  171. //使用原生的,避免初始化appid问题
  172. WeixinJSBridge.invoke(
  173. 'getBrandWCPayRequest', {
  174. appId: data.appId,
  175. timeStamp: data.timeStamp,
  176. nonceStr: data.nonceStr,
  177. package: data.package,
  178. signType: data.signType,
  179. paySign: data.paySign
  180. },
  181. function(res) {
  182. var msg = res.err_msg ? res.err_msg : res.errMsg;
  183. switch (msg) {
  184. // //支付成功时
  185. case 'get_brand_wcpay_request:ok':
  186. // if (callback_succ_func) {
  187. uni.showModal({
  188. title: '支付成功',
  189. showCancel: false,
  190. success: function(res) {
  191. uni.switchTab({
  192. url: "/pages/index/index"
  193. })
  194. },
  195. // complete: function() {
  196. // that.SearchStatus()
  197. // }
  198. });
  199. // }
  200. break;
  201. default:
  202. //支付失败时
  203. WeixinJSBridge.log('支付失败!' + msg + ',请返回重试.');
  204. if (callback_error_func) {
  205. callback_error_func({
  206. msg: msg
  207. });
  208. }
  209. break;
  210. }
  211. }
  212. );
  213. },
  214. }
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. .content {
  219. &_banner {
  220. width: 100%;
  221. height: 476rpx;
  222. margin-bottom: 32rpx;
  223. }
  224. &_box {
  225. padding: 16rpx 0 24rpx 24rpx;
  226. font-size: 28rpx;
  227. background: #FFFFFF;
  228. margin-bottom: 24rpx;
  229. text:nth-child(1) {
  230. color: #FB231F;
  231. }
  232. text:nth-child(2) {
  233. font-size: 60rpx;
  234. color: #FB231F;
  235. font-weight: 500;
  236. }
  237. .tip {
  238. margin-top: 16rpx;
  239. font-size: 36rpx;
  240. font-family: PingFang SC-Bold, PingFang SC;
  241. font-weight: bold;
  242. color: #333333;
  243. }
  244. }
  245. &_num {
  246. padding: 36rpx 24rpx;
  247. background: #FFFFFF;
  248. text:nth-child(1) {
  249. font-size: 32rpx;
  250. font-family: PingFang SC-Regular, PingFang SC;
  251. font-weight: 400;
  252. color: #333333;
  253. }
  254. text:nth-child(2) {
  255. font-size: 40rpx;
  256. font-family: PingFang SC-Bold, PingFang SC;
  257. font-weight: bold;
  258. color: #FB231F;
  259. }
  260. }
  261. .bottom {
  262. position: fixed;
  263. left: 0;
  264. bottom: 0;
  265. width: 100%;
  266. padding: 8rpx 24rpx 8rpx 24rpx;
  267. box-shadow: 0px -4rpx 24rpx 2rpx rgba(0, 0, 0, 0.1);
  268. background-color: #fff;
  269. &_top {
  270. font-size: 28rpx;
  271. color: #333;
  272. .text2 {
  273. color: #FB231F;
  274. }
  275. .text3 {
  276. font-size: 60rpx;
  277. color: #FB231F;
  278. font-weight: bold;
  279. }
  280. }
  281. &_btn {
  282. width: 702rpx;
  283. height: 88rpx;
  284. background: linear-gradient(91deg, #F30000 0%, #FE4815 100%);
  285. border-radius: 44rpx 44rpx 44rpx 44rpx;
  286. text-align: center;
  287. line-height: 88rpx;
  288. font-size: 32rpx;
  289. font-weight: bold;
  290. color: #FFFFFF;
  291. margin-top: 12rpx;
  292. }
  293. }
  294. }
  295. </style>