index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef H5 -->
  4. <view style="color: #fff;">
  5. <tn-nav-bar backgroundColor="#26B3A0" :bottomShadow="false" @rightClick="jumpScoreRed">课程详情
  6. </tn-nav-bar>
  7. <view :style="{ height: tobheight + 'px' }"></view>
  8. </view>
  9. <!-- #endif -->
  10. <view class="content">
  11. <view class="pic">
  12. <image class="bigImg" :src="detail.cover_image==''?'../../../static/posImg.png':detail.cover_image"
  13. mode=""></image>
  14. </view>
  15. <view class="center">
  16. <view class="scoreTitle">
  17. <!-- Chat GPT应用场景学习 -->
  18. {{detail.name}}
  19. </view>
  20. <view class="selOutBox">
  21. <view class="price">
  22. ¥{{detail.price}}
  23. </view>
  24. <view class="sellOut" style="font-size: 26rpx;color: #999;">
  25. 已售出:{{detail.orders_count+2376}}份
  26. </view>
  27. </view>
  28. </view>
  29. <view class="bottom">
  30. <view class="title">
  31. 课程介绍
  32. </view>
  33. <view class="desBox">
  34. <u-parse selectable :content="detail.description"></u-parse>
  35. <!-- <image src="../../../static/posImg.png" mode=""></image> -->
  36. </view>
  37. </view>
  38. </view>
  39. <view class="pos">
  40. </view>
  41. <view class="kefuAndBtn">
  42. <view class="iconBox" @click="jumpToKefu">
  43. <u-icon class="icon" name="server-fill" color="#26B3A0" size="22"></u-icon>
  44. </view>
  45. <view class="btn" @click="pay(detail.id)">
  46. 立即学习
  47. </view>
  48. </view>
  49. <!-- <u-modal :show="payVisiable" title="请确认支付是否已完成" content='' confirmText="查询支付结果" confirmColor="#26b3a0"
  50. @confirm="isPaySuc"></u-modal> -->
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. courseDetail,
  56. shopCourse
  57. } from '@/api/score/index.js'
  58. import {
  59. wxPayPamars,
  60. wxConfigPamars,
  61. } from '@/api/public/index.js'
  62. import {
  63. myScoreOrder,
  64. myScoreOrderDetail
  65. } from '@/api/my/index.js'
  66. import ShoproPay from '@/common/pay';
  67. import wxsdk from '@/common/wechat/sdk'
  68. // 判断是否为微信环境
  69. const isWechat = () => {
  70. return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
  71. }
  72. export default {
  73. components: {},
  74. data() {
  75. return {
  76. tobheight: 45,
  77. detail: {},
  78. course_id: '',
  79. scoreOrderList: [],
  80. currPayOrderList: [],
  81. from: '',
  82. currOrder: {},
  83. // payVisiable: false
  84. };
  85. },
  86. computed: {
  87. },
  88. watch: {
  89. },
  90. async onLoad(o) {
  91. // this.from = o.from
  92. this.course_id = o.id
  93. let res = await courseDetail({
  94. course_id: o.id
  95. })
  96. if (res.code == 0) {
  97. this.detail = res.data
  98. }
  99. console.log('课程详情返回值', res);
  100. window.addEventListener('beforeunload', this.handleRefresh)
  101. },
  102. onReady() {
  103. },
  104. async onShow() {
  105. },
  106. onUnload() {
  107. window.removeEventListener('beforeunload', this.handleRefresh)
  108. },
  109. destroyed() {
  110. },
  111. beforeDestroy() {
  112. },
  113. methods: {
  114. pay(course_id) {
  115. if (isWechat()) {
  116. this.goStudy(course_id)
  117. } else {
  118. this.goStudy2(course_id)
  119. }
  120. },
  121. handleRefresh() {
  122. uni.setStorageSync('from', 'index')
  123. },
  124. async hasWaitingPayOrder() {
  125. let resss = await myScoreOrder()
  126. if (resss.code == 0) {
  127. this.scoreOrderList = resss.data
  128. this.currPayOrderList = this.scoreOrderList.filter((item, index) => {
  129. return item.course_id == this.course_id
  130. })
  131. }
  132. },
  133. jumpToKefu() {
  134. window.open('https://work.weixin.qq.com/kfid/kfc807229b723286051')
  135. },
  136. // 微信H5支付
  137. async goStudy2(course_id) {
  138. // 判断是否存在待支付的订单
  139. let resss = await myScoreOrder()
  140. if (resss.code == 0) {
  141. this.scoreOrderList = resss.data
  142. console.log('课程详情页-订单列表', this.scoreOrderList);
  143. this.currOrder = resss.data.find((item, index) => {
  144. return item.course_id == this.course_id
  145. })
  146. console.log('判断支付状态的那一项订单', this.currOrder);
  147. // return
  148. }
  149. if (this.currOrder) {
  150. if (this.currOrder.status) {
  151. uni.showToast({
  152. title: '你已购买过该课程,请勿重复购买!',
  153. icon: 'none',
  154. duration: 1500
  155. })
  156. } else {
  157. let res2 = await wxPayPamars({
  158. order_id: this.currOrder.id,
  159. type: 'h5'
  160. })
  161. console.log('res2-1', res2);
  162. if (res2.code == 0) {
  163. uni.setStorageSync('course_id', this.course_id)
  164. let addRedirectUrl = res2.data + '&redirect_url=' +
  165. encodeURIComponent(
  166. 'https://www.ai5566.cn/h5/pages/index/scorePayMiddle/index?id=' + this.course_id
  167. )
  168. location.href = addRedirectUrl
  169. } else {
  170. uni.showToast({
  171. title: res2.msg,
  172. icon: 'none',
  173. duration: 1500
  174. })
  175. }
  176. }
  177. } else {
  178. let res1 = await shopCourse({
  179. course_id
  180. })
  181. if (res1.code == 0) {
  182. let res2 = await wxPayPamars({
  183. order_id: res1.data.id,
  184. type: 'h5'
  185. })
  186. console.log('res2-2', res2);
  187. if (res2.code == 0) {
  188. uni.setStorageSync('course_id', this.course_id)
  189. let addRedirectUrl = res2.data + '&redirect_url=' +
  190. encodeURIComponent(
  191. 'https://www.ai5566.cn/h5/pages/index/scorePayMiddle/index?id=' + this.course_id
  192. )
  193. location.href = addRedirectUrl
  194. } else {
  195. uni.showToast({
  196. title: res2.msg,
  197. icon: 'none',
  198. duration: 1500
  199. })
  200. }
  201. } else {
  202. uni.showToast({
  203. title: res1.msg,
  204. icon: 'none',
  205. duration: 1500
  206. })
  207. }
  208. }
  209. },
  210. // 微信公众号内部支付
  211. async goStudy(course_id) {
  212. // 判断是否存在待支付的订单
  213. let resss = await myScoreOrder()
  214. if (resss.code == 0) {
  215. this.scoreOrderList = resss.data
  216. console.log('课程详情页-订单列表2', this.scoreOrderList);
  217. this.currOrder = resss.data.find((item, index) => {
  218. return item.course_id == this.course_id
  219. })
  220. console.log('判断支付状态的那一项订单2', this.currOrder);
  221. }
  222. if (this.currOrder) {
  223. // console.log('当前购买课程的待支付订单列表', this.currPayOrderList, resss);
  224. if (this.currOrder.status) {
  225. uni.showToast({
  226. title: '你已购买过该课程,请勿重复购买!',
  227. icon: 'none',
  228. duration: 1500
  229. })
  230. } else {
  231. let res2 = await wxPayPamars({
  232. order_id: this.currOrder.id
  233. })
  234. let url = window.location.href.split('#')[0]
  235. let res3 = await wxConfigPamars({
  236. url: url
  237. })
  238. if (res2.code == 0 && res3.code == 0) {
  239. wxsdk.wxpay(res3.data, res2.data, (res) => {
  240. if (res.errMsg == "chooseWXPay:ok") {
  241. setTimeout(() => {
  242. uni.setStorageSync('course_id', this.course_id)
  243. uni.navigateTo({
  244. url: '/pages/index/scorePaySuc/index?id=' + this
  245. .course_id
  246. })
  247. }, 1500)
  248. } else {
  249. uni.showToast({
  250. title: '支付失败,请稍后重试!',
  251. icon: 'error',
  252. duration: 1500
  253. })
  254. }
  255. });
  256. } else {
  257. if (res2.code != 0) {
  258. uni.showToast({
  259. title: res2.msg,
  260. icon: 'none',
  261. duration: 1500
  262. })
  263. } else if (res3.code != 0) {
  264. uni.showToast({
  265. title: res3.msg,
  266. icon: 'none',
  267. duration: 1500
  268. })
  269. }
  270. }
  271. }
  272. } else {
  273. let res1 = await shopCourse({
  274. course_id
  275. })
  276. console.log('立即学习(下单)返回值', res1);
  277. if (res1.code == 0) {
  278. let res2 = await wxPayPamars({
  279. order_id: res1.data.id
  280. })
  281. let url = window.location.href.split('#')[0]
  282. let res3 = await wxConfigPamars({
  283. url: url
  284. })
  285. if (res2.code == 0 && res3.code == 0) {
  286. wxsdk.wxpay(res3.data, res2.data, (res) => {
  287. if (res.errMsg == "chooseWXPay:ok") {
  288. // uni.showToast({
  289. // title: '付款成功',
  290. // icon: 'success',
  291. // duration: 1500
  292. // })
  293. setTimeout(() => {
  294. uni.setStorageSync('course_id', this.course_id)
  295. uni.navigateTo({
  296. url: '/pages/index/scorePaySuc/index?id=' + this
  297. .course_id
  298. })
  299. }, 1500)
  300. } else {
  301. uni.showToast({
  302. title: '支付失败,请稍后重试!',
  303. icon: 'error',
  304. duration: 1500
  305. })
  306. }
  307. });
  308. } else {
  309. if (res2.code != 0) {
  310. uni.showToast({
  311. title: res2.msg,
  312. icon: 'none',
  313. duration: 1500
  314. })
  315. } else if (res3.code != 0) {
  316. uni.showToast({
  317. title: res3.msg,
  318. icon: 'none',
  319. duration: 1500
  320. })
  321. }
  322. }
  323. } else {
  324. uni.showToast({
  325. title: res.msg,
  326. icon: 'none'
  327. })
  328. }
  329. }
  330. }
  331. }
  332. };
  333. </script>
  334. <style lang="scss" scoped>
  335. @import './index.scss';
  336. </style>