score.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <view class="main-page">
  3. <view class="img">
  4. <image src="../../static/img/zhishang.png"></image>
  5. </view>
  6. <view>{{ book_name }}</view>
  7. <view>你的测评已完成,支付完成后查看测评结果。</view>
  8. <view @click="pay(1)"><span>
  9. <image src="../../static/img/zhipay.png"></image>支付宝支付
  10. </span>
  11. </view>
  12. <view @click="pay(2)">
  13. <span>
  14. <image src="../../static/img/weipay.png"></image>微信支付
  15. </span>
  16. </view>
  17. <view class="weixin_pc" v-if="pc_pay">
  18. <view class="pc_popup">
  19. <view>
  20. <p>微信支付</p>
  21. <p>订单编号:{{ oid }}</p>
  22. </view>
  23. <view>
  24. <view id="qrcode" ref="qrcode" class="qrCodeUrl"></view>
  25. <p>¥{{ price }}</p>
  26. <view class="butns"><a @click="getpcpay">取消</a></view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import QRCode from "qrcodejs2";
  34. import {
  35. mapGetters
  36. } from 'vuex';
  37. import {
  38. wxpayJspay,
  39. alipayH5pay,
  40. wxpayH5pay,
  41. wxpayWeb,
  42. alipayWeb
  43. } from '../../api/pay.js';
  44. import { getorderResult } from '../../api/test.js';
  45. export default {
  46. data() {
  47. return {
  48. pc_pay: false,
  49. is_apill: false,
  50. score: 0,
  51. name_id: '',
  52. nums: '',
  53. payForm: '',
  54. time: '',
  55. sign: '',
  56. oid: '',
  57. book_name: '',
  58. price: 0
  59. };
  60. },
  61. onLoad(option) {
  62. this.book_name = option.book_name;
  63. this.name_id = option.name_id;
  64. this.price = option.price;
  65. this.score = option.score;
  66. this.oid = option.orderId;
  67. this.$store.commit("user/SET_ALLSCORCE", option.score);
  68. this.$store.commit("user/SET_NAMEID", option.name_id);
  69. this.$store.commit("user/SET_OID", option.orderId);
  70. },
  71. computed: {
  72. ...mapGetters(['WXCode', 'openId']),
  73. },
  74. methods: {
  75. //取消微信支付
  76. getpcpay(){
  77. this.pc_pay = !this.pc_pay;
  78. clearInterval(timer)
  79. },
  80. //判断是否微信环境登录
  81. isWeiXinLogin() {
  82. var ua = window.navigator.userAgent.toLowerCase();
  83. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  84. return true;
  85. } else {
  86. return false;
  87. }
  88. },
  89. //支付
  90. pay(paytype) {
  91. let browser = this.$browser;
  92. let that = this;
  93. if (this.isWeiXinLogin()) {
  94. if (paytype == 1) {
  95. // 微信公众中支付宝支付
  96. uni.showToast({
  97. icon: 'none',
  98. position: 'center',
  99. title: '微信中暂时不支持支付宝,请使用微信支付!'
  100. });
  101. } else {
  102. // 微信公众号支付
  103. wxpayJspay({
  104. out_trade_no: this.oid,
  105. openid: this.openId
  106. }).then(res => {
  107. if (res.code == 1) {
  108. var jweixin = require('jweixin-module');
  109. jweixin.config({
  110. debug: false,
  111. appId: res.data.appId,
  112. timestamp: res.data.timeStamp,
  113. nonceStr: res.data.nonceStr,
  114. signature: res.data.paySign,
  115. jsApiList: ['chooseWXPay']
  116. });
  117. jweixin.ready(function() {
  118. jweixin.chooseWXPay({
  119. timestamp: Number(res.data.timeStamp),
  120. nonceStr: res.data.nonceStr,
  121. package: res.data.package,
  122. signType: res.data.signType,
  123. paySign: res.data.paySign,
  124. success: function(res) {
  125. //支付成功后处理事件
  126. that.payResult();
  127. },
  128. fail: function(err) {
  129. // 取消支付后处理事件
  130. console.log('fail:' + err);
  131. }
  132. });
  133. });
  134. jweixin.error(function(res) {
  135. console.log('报错信息', res)
  136. });
  137. }
  138. })
  139. }
  140. } else {
  141. if (paytype == 1) {
  142. if (browser.versions.mobile || browser.versions.ios || browser.versions.android || browser.versions
  143. .iPhone || browser.versions.iPad) {
  144. //移动端支付宝支付
  145. alipayH5pay({
  146. out_trade_no: this.oid
  147. }).then(res => {
  148. uni.setStorageSync('form', res)
  149. uni.navigateTo({
  150. url: '/pages/apilypay/apilypay'
  151. })
  152. })
  153. } else {
  154. //pc端支付宝支付
  155. alipayWeb({
  156. out_trade_no: this.oid
  157. }).then(res => {
  158. if(res.code == 1){
  159. uni.setStorageSync('form', res.data)
  160. uni.navigateTo({
  161. url: '/pages/apilypay/apilypay'
  162. })
  163. }
  164. })
  165. }
  166. } else {
  167. if (browser.versions.mobile || browser.versions.ios || browser.versions.android || browser.versions
  168. .iPhone || browser.versions.iPad) {
  169. //移动端微信支付
  170. wxpayH5pay({
  171. out_trade_no: this.oid
  172. }).then(res => {
  173. if (res.code == 1) {
  174. location.href = res.data;
  175. }
  176. })
  177. } else {
  178. //pc端微信支付
  179. wxpayWeb({
  180. out_trade_no: this.oid
  181. }).then(res => {
  182. if (res.code == 1) {
  183. // 先显示微信支付弹窗
  184. this.pc_pay = true;
  185. // 在生成支付二维码
  186. this.$nextTick(() => {
  187. this.qrcode = new QRCode("qrcode", {
  188. width: 180,//二维码宽度
  189. height: 180,//二维码高度
  190. text: res.data.code_url,//调用微信支付接口返回的微信特殊链接:例如"weixin://wxpay/bizpayurl?pr=uDKsQ4E00"
  191. colorDark: "#000",//颜色配置
  192. colorLight: "#fff",
  193. });
  194. });
  195. window.timer = setInterval(() => {
  196. setTimeout(this.pcpay(), 0)
  197. }, 2000)
  198. }
  199. })
  200. }
  201. }
  202. }
  203. },
  204. // pc端微信支付每2秒查询一次接口
  205. pcpay() {
  206. getorderResult({oid:this.oid}).then(res => {
  207. if (res.code == 1) {
  208. this.pc_pay = false;
  209. clearInterval(timer)
  210. uni.navigateTo({
  211. url: '../result/result'
  212. })
  213. }
  214. })
  215. },
  216. //微信支付
  217. payResult() {
  218. uni.navigateTo({
  219. url: '/pages/result/result?name_id=' + this.name_id + '&score=' + this.score
  220. })
  221. }
  222. }
  223. };
  224. </script>
  225. <style lang="scss" scoped>
  226. page {
  227. background-color: #FFFFFF;
  228. }
  229. .main-page {
  230. width: 100%;
  231. text-align: center;
  232. .img {
  233. width: 350upx;
  234. height: 320upx;
  235. margin: 130upx auto 60upx auto;
  236. image {
  237. width: 100%;
  238. height: 100%;
  239. }
  240. }
  241. view {
  242. &:nth-child(2) {
  243. font-size: 44upx;
  244. font-weight: 600;
  245. letter-spacing: 2upx;
  246. color: #333333;
  247. }
  248. &:nth-child(3) {
  249. font-size: 28upx;
  250. font-weight: 400;
  251. color: #5D5D5D;
  252. margin-top: 32upx;
  253. }
  254. &:nth-child(4),
  255. &:nth-child(5) {
  256. width: 606upx;
  257. margin: auto;
  258. height: 80upx;
  259. line-height: 80upx;
  260. border-radius: 50upx;
  261. text-align: center;
  262. color: #fff;
  263. image {
  264. width: 60upx;
  265. height: 60upx;
  266. margin-top: 10upx;
  267. display: inline-block;
  268. position: absolute;
  269. left: -70upx;
  270. }
  271. span {
  272. position: relative;
  273. height: 80upx;
  274. margin-left: 60upx;
  275. line-height: 80upx;
  276. display: inline-block;
  277. }
  278. }
  279. &:nth-child(4) {
  280. background: #06B4FD;
  281. margin-top: 48upx;
  282. }
  283. &:nth-child(5) {
  284. margin-top: 36upx;
  285. background-color: #07C160;
  286. }
  287. }
  288. .weixin_pc {
  289. width: 100vw;
  290. height: 100vh;
  291. position: fixed;
  292. left: 0;
  293. top: 0;
  294. bottom: 0;
  295. right: 0;
  296. background-color: rgba(0, 0, 0, 0.3);
  297. .pc_popup {
  298. position: absolute;
  299. width: 900upx;
  300. overflow: hidden;
  301. padding: 40upx 60upx;
  302. height: 1000upx;
  303. background-color: #FFFFFF;
  304. left: calc((100vw - 900upx)/2);
  305. top: calc((100vh - 1000upx)/2);
  306. color: #484848;
  307. z-index: 100;
  308. view {
  309. &:nth-child(1) {
  310. p {
  311. text-align: left;
  312. &:nth-child(1) {
  313. font-size: 50upx;
  314. color: #06C05F;
  315. font-weight: bold;
  316. }
  317. &:nth-child(2) {
  318. font-size: 32upx;
  319. padding-bottom: 100upx;
  320. margin-top: 30upx;
  321. border-bottom: 2upx solid #E7EBED;
  322. }
  323. }
  324. }
  325. &:nth-child(2) {
  326. text-align: center;
  327. margin-top: 40upx;
  328. p {
  329. color: #ff6600;
  330. margin-top: 40upx;
  331. }
  332. .qrCodeUrl {
  333. display: block;
  334. margin: auto;
  335. width: 360upx;
  336. height: 360upx;
  337. }
  338. .butns{
  339. margin-top: 60upx;
  340. text-align: center;
  341. a{
  342. display: inline-block;
  343. width: 360upx;
  344. height: 70upx;
  345. line-height: 70upx;
  346. font-size: 32upx;
  347. background-color: #efd140;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. </style>