payment -_xx_pay.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <view style="padding-top: 50rpx;">
  3. <view class="top" v-if="!showSignup">
  4. <image src="https://qnys.chuliu.cc/daweiboshi_szy/1_1615541900_nrG1vctYn8.jpg"
  5. mode="widthFix" style="width: 750rpx;margin-bottom: 60rpx;"></image>
  6. <view class="title">
  7. 第{{ data.season }}届大卫博士创业实战营
  8. </view>
  9. <view class="time">
  10. 举办时间:{{ data.start + '-' + data.end }}
  11. </view>
  12. <view v-if="data.status == 1" class="btnSig gray">已报名</view>
  13. <view v-else class="btnSig" :class="status ? 'red' : 'gray'" v-throttle="2000" @click="singup">支付{{ data.cost }}元报名</view>
  14. </view>
  15. <view class="voucher" v-else>
  16. <image src="../../static/new_my/bg.png" class="bgImg" mode="widthFix" style="width: 750rpx;"></image>
  17. <view class="bgImg">
  18. <text style="margin-top: 30rpx;">第{{ data.season }}届大卫博士创业实战营</text>
  19. </view>
  20. <view class="voucher_con">
  21. <view class="voucher_icon">
  22. <image src="../../static/icon/success.png" mode="widthFix" style="width: 300rpx;margin-top: 78rpx;">
  23. <!-- <image :src="`../../static/icon/${data.pay_status ? 'success' : 'show'}.png`" mode="widthFix" style="width: 300rpx;margin-top: 78rpx;"> -->
  24. </image>
  25. <view class="success">{{ data.pay_status ? '报名成功' : '获取名额成功,请完成支付' }}</view>
  26. <view class="timed">
  27. 举办时间:{{ data.start+ '-' +data.end }}
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="bottom" v-if="showSignup">
  33. <view v-if="data.pay_status " class="bottom-btn" @click="goBack">返回首页</view>
  34. <view v-else class="bottom-btn" v-throttle="2000" @click="singup">立即支付</view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import {
  40. _API_payment,
  41. _API_SearchStatus,
  42. GetEnrollInfo,
  43. GetEnrollUserAddress,
  44. GetSzyGiftInfo
  45. } from '@/apis/szy.js';
  46. export default {
  47. data() {
  48. return {
  49. status: false,
  50. data: {
  51. season: '',
  52. start: '',
  53. end: '',
  54. name: '',
  55. mobile: '',
  56. cost: '',
  57. local: ''
  58. },
  59. noClick: true,
  60. showSignup: false,
  61. }
  62. },
  63. onLoad() {
  64. this.getInfo()
  65. },
  66. computed: {
  67. userinfo() {
  68. return this.$store.state.userinfo
  69. }
  70. },
  71. onPullDownRefresh() {
  72. this.getInfo()
  73. },
  74. methods: {
  75. // 查看物流信息
  76. toLogistics() {
  77. uni.navigateTo({
  78. url: "/pages/szy-logistics/szy-logistics?info=" + JSON.stringify(this.logInfo)
  79. })
  80. },
  81. // 返回首页
  82. goBack() {
  83. uni.switchTab({
  84. url: '/pages/index/index'
  85. })
  86. },
  87. // 获取赛季信息
  88. getInfo() {
  89. GetEnrollInfo().then(res => {
  90. if (res.code == 200) {
  91. res.data = {
  92. cost: 199,
  93. end: "2023.11.25",
  94. end_time: "2023-11-25 18:00:00",
  95. enroll_end_time: "2023-11-21 16:00:00",
  96. enroll_start_time: "2023-11-14 10:30:00",
  97. limit_num: 100000,
  98. num: 0,
  99. pay_status: 0,
  100. season: 63,
  101. start: "2023.10.24",
  102. start_time: "2023-11-24 08:00:00",
  103. status: 0
  104. }
  105. this.data = res.data
  106. this.data.start = this.getTimes(res.data.start_time)
  107. this.data.end = this.getTimes(res.data.end_time)
  108. const a = new Date(res.data.enroll_start_time.replace(/-/g,'/')).getTime()
  109. const b = new Date(res.data.enroll_end_time.replace(/-/g,'/')).getTime()
  110. const now = Date.parse(new Date())
  111. if (now > a && now < b && res.data.limit_num > res.data.num) {
  112. this.status = true
  113. }
  114. if (res.data.status == 1) {
  115. this.showSignup = true
  116. } else {
  117. this.showSignup = false
  118. }
  119. } else {
  120. uni.showModal({
  121. content: res.message || '获取失败',
  122. showCancel: false
  123. })
  124. }
  125. })
  126. },
  127. getTimes(data) {
  128. var time = new Date(data)
  129. var year = time.getFullYear()
  130. var month = time.getMonth() + 1 < 10 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1;
  131. var day = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
  132. var today = year + '.' + month + '.' + day;
  133. return today;
  134. },
  135. // 支付状态
  136. SearchStatus() {
  137. uni.showLoading({
  138. mask: true
  139. })
  140. _API_SearchStatus().then(res => {
  141. uni.hideLoading()
  142. if (res.code == 200) {
  143. this.getInfo()
  144. } else {
  145. uni.showModal({
  146. content: res.message || '获取失败',
  147. showCancel: false
  148. })
  149. }
  150. })
  151. },
  152. //WeixinJSBridge判断
  153. wxJsPay(data, callback_succ_func, callback_error_func) {
  154. if (typeof WeixinJSBridge == 'undefined') {
  155. if (document.addEventListener) {
  156. document.addEventListener('WeixinJSBridgeReady', this.jsApiCall, false);
  157. } else if (document.attachEvent) {
  158. document.attachEvent('WeixinJSBridgeReady', this.jsApiCall);
  159. document.attachEvent('onWeixinJSBridgeReady', this.jsApiCall);
  160. }
  161. } else {
  162. this.jsApiCall(data, callback_succ_func, callback_error_func);
  163. }
  164. },
  165. //调起支付
  166. jsApiCall(data, callback_succ_func, callback_error_func) {
  167. let that = this
  168. //使用原生的,避免初始化appid问题
  169. WeixinJSBridge.invoke(
  170. 'getBrandWCPayRequest', {
  171. appId: data.appId,
  172. timeStamp: data.timestamp,
  173. nonceStr: data.nonceStr,
  174. package: data.package,
  175. signType: data.signType,
  176. paySign: data.paySign
  177. },
  178. function(res) {
  179. var msg = res.err_msg ? res.err_msg : res.errMsg;
  180. switch (msg) {
  181. //支付成功时
  182. case 'get_brand_wcpay_request:ok':
  183. if (callback_succ_func) {
  184. uni.showModal({
  185. title: '支付成功',
  186. showCancel: false
  187. })
  188. callback_succ_func(res);
  189. }
  190. break;
  191. default:
  192. //支付失败时
  193. WeixinJSBridge.log('支付失败!' + msg + ',请返回重试.');
  194. if (callback_error_func) {
  195. callback_error_func({
  196. msg: msg
  197. });
  198. }
  199. break;
  200. }
  201. }
  202. );
  203. },
  204. singup() {
  205. if (!this.status && !this.data.status) {
  206. return
  207. }
  208. let that = this
  209. _API_payment().then(res => {
  210. if (res.code == 200) {
  211. let callback_succ_func = res => {
  212. uni.showModal({
  213. content: '支付成功!',
  214. showCancel: false,
  215. success: function(res) {
  216. that.SearchStatus()
  217. }
  218. })
  219. }
  220. let callback_error_func = res => {
  221. uni.showModal({
  222. content: '支付失败!',
  223. showCancel: false
  224. })
  225. }
  226. this.wxJsPay(res.data, callback_succ_func, callback_error_func)
  227. } else {
  228. uni.showToast({
  229. title: res.message || '失败',
  230. icon: 'none'
  231. })
  232. return false;
  233. }
  234. })
  235. .catch(err => {})
  236. .finally(() => {
  237. setTimeout(() => {}, 3000)
  238. })
  239. }
  240. },
  241. }
  242. </script>
  243. <style lang="scss" scoped>
  244. .top {
  245. margin: 0 30rpx 0 30rpx;
  246. border-radius: 16rpx;
  247. background-color: #fff;
  248. padding: 40rpx 20rpx 40rpx 20rpx;
  249. }
  250. .title {
  251. font-size: 34rpx;
  252. font-weight: bold;
  253. }
  254. .time {
  255. margin-top: 20rpx;
  256. font-size: 32rpx;
  257. }
  258. .btnSig {
  259. margin: 50rpx auto 0;
  260. width: 600rpx;
  261. line-height: 88rpx;
  262. border-radius: 44rpx;
  263. text-align: center;
  264. color: #fff;
  265. font-size: 32rpx;
  266. }
  267. .red {
  268. background: linear-gradient(93deg, #FF232C 0%, #FF571B 100%);
  269. }
  270. .gray {
  271. background-color: #E1E1E1;
  272. }
  273. .voucher {
  274. hieght: 100vh;
  275. min-height: 100vh;
  276. width: 100vw;
  277. position: relative;
  278. .bgImg {
  279. height: 100vh;
  280. width: 100vw;
  281. position: fixed;
  282. top: 0;
  283. left: 0;
  284. display: flex;
  285. flex-direction: column;
  286. align-items: center;
  287. font-size: 46rpx;
  288. font-weight: bold;
  289. text {
  290. color: #FFFFFF;
  291. margin-top: 10rpx;
  292. }
  293. }
  294. .voucher_con {
  295. position: fixed;
  296. height: 85%;
  297. width: 100%;
  298. bottom: 0;
  299. left: 0;
  300. background: #fff;
  301. border-top-left-radius: 60rpx;
  302. border-top-right-radius: 60rpx;
  303. .line {
  304. width: 128rpx;
  305. height: 8rpx;
  306. background: #f1f3f5;
  307. margin: 36rpx auto 0;
  308. }
  309. .title {
  310. color: #333;
  311. font-size: 38rpx;
  312. // margin: 48rpx auto 60rpx;
  313. text-align: center;
  314. font-weight: bold;
  315. }
  316. .voucher_icon {
  317. text-align: center;
  318. // image {
  319. // height: 192rpx;
  320. // width: 192rpx;
  321. // margin-bottom: 30rpx;
  322. // }
  323. .success {
  324. margin-top: 18rpx;
  325. font-size: 48rpx;
  326. color: #333;
  327. font-weight: bold;
  328. }
  329. .timed {
  330. margin-top: 36rpx;
  331. font-size: 40rpx;
  332. font-weight: bold;
  333. color: #FF0000;
  334. }
  335. }
  336. .logistics {
  337. width: 250rpx;
  338. height: 68rpx;
  339. margin: 0 auto;
  340. background: rgba(255, 244, 243, 0.39);
  341. border: 2rpx solid #FB231F;
  342. opacity: 1;
  343. border-radius: 44rpx;
  344. color: #FB231F;
  345. }
  346. .info {
  347. margin: 68rpx 50rpx 40rpx 50rpx;
  348. color: #333333;
  349. text {
  350. font-size: 32rpx;
  351. }
  352. >view {
  353. margin-top: 20rpx;
  354. }
  355. }
  356. }
  357. }
  358. .bottom {
  359. position: fixed;
  360. bottom: 0;
  361. width: 100%;
  362. height: 100rpx;
  363. padding: 6rpx 30rpx;
  364. background-color: #fff;
  365. border-top: 1px solid #eeeeee;
  366. &-btn {
  367. color: #fff;
  368. text-align: center;
  369. font-size: 32rpx;
  370. font-weight: bold;
  371. line-height: 88rpx;
  372. height: 88rpx;
  373. background: linear-gradient(90deg, #F30000 0%, #FE4815 100%);
  374. opacity: 1;
  375. border-radius: 44px;
  376. }
  377. }
  378. </style>