detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <template>
  2. <view class="container">
  3. <!-- 轮播图 -->
  4. <view class="swiper">
  5. <view class="swiper-box">
  6. <swiper circular="true" autoplay="true" @change="swiperChange">
  7. <swiper-item v-for="swiper in swiperlist" :key="swiper.id"><image :src="swiper"></image></swiper-item>
  8. </swiper>
  9. <view class="indicator"><view class="dots" v-for="(swiper, index) in swiperlist" :class="[swiperCurrent >= index ? 'on' : '']" :key="index"></view></view>
  10. </view>
  11. <view class="swiper-name">
  12. <view class="flex item-box">
  13. <view class="item-name ellipsis">{{ list.title }}</view>
  14. <view class="item-collection" @click="collect">
  15. <image src="../../static/img/img026.png" v-if="list.collect == false"></image>
  16. <image src="../../static/img/img027.png" v-if="list.collect == true"></image>
  17. <view class="collection">收藏</view>
  18. </view>
  19. </view>
  20. <view class="tip-box">
  21. <text v-for="ls in list.label">{{ ls }}</text>
  22. </view>
  23. <view class="price-box flex">
  24. <view class="price">
  25. <text>{{ list.money }}</text>
  26. </view>
  27. <view class="number">已有{{ list.browse_count }}人学习</view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="navbar">
  32. <view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  33. </view>
  34. <!-- 详情 -->
  35. <view class="course-details" v-if="tabCurrentIndex == 1">
  36. <view class="details-intro">
  37. <view class="intro-title"><text>- 课程介绍 -</text></view>
  38. <rich-text class="detail-centent" :nodes="list.content"></rich-text>
  39. </view>
  40. </view>
  41. <!-- 课程目录 -->
  42. <view class="course-catalogue" v-if="tabCurrentIndex == 0"><view class="no-data" v-if="courseList == ''">暂无数据</view></view>
  43. <view class="course-catalogue" v-if="tabCurrentIndex == 0">
  44. <view class="course-menu flex_item" v-for="(ls, index) in courseList" :key="index" @click="ToCourseDetail(ls)">
  45. <image :src="ls.image"></image>
  46. <view class="menu-info">
  47. <view class="title">{{ ls.title }}</view>
  48. <view class="tip"><text>直播回放</text></view>
  49. <view class="price red" v-if="ls.is_pay == 1 && isPay == true">您已购买</view>
  50. <view class="price" v-if="ls.is_pay == 1 && isPay == false">付费购买</view>
  51. <text class="free" v-if="ls.is_pay == 0">免费</text>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="foot-box flex" v-if="isPay == false">
  56. <view class="home" @click="ToHome">
  57. <image src="../../static/img/img028.png"></image>
  58. <view>首页</view>
  59. </view>
  60. <view class="Topay" @click="OpenPay">立即购买</view>
  61. </view>
  62. <!-- 支付弹窗 -->
  63. <uni-popup ref="popup" type="bottom">
  64. <view class="payment">
  65. <view class="first flex " @click="payclose()">
  66. <text class="word">选择支付方式</text>
  67. <image src="../../static/img/img25.png"></image>
  68. </view>
  69. <view class="pay-type-list">
  70. <view class="type-item b-b" @click="changePayType('weixin')">
  71. <view class="img"><image class="yue" src="../../static/img/img26.png"></image></view>
  72. <view class="con"><text class="tit">微信支付</text></view>
  73. <label class="radio"><radio value="" color="#FC4141" :checked="payType == 'weixin'"></radio></label>
  74. </view>
  75. <view class="type-item flex_item" @click="changePayType('yue')">
  76. <view class="img"><image class="yue" src="../../static/img/img017.png"></image></view>
  77. <view class="con"><text class="tit">余额支付</text></view>
  78. <label class="radio"><radio value="" color="#FC4141" :checked="payType == 'yue'"></radio></label>
  79. </view>
  80. </view>
  81. <view class="one"></view>
  82. <view class="Third flex">
  83. <view class="two1">
  84. <text class="two1-1 ">合计:</text>
  85. <text class="two1-2">¥</text>
  86. <text class="two1-2 size">{{ list.money }}</text>
  87. </view>
  88. <view class="two2" :class="{ clickbg: payLoding }" @click.stop="!payLoding ? confirm() : ''"><text>立即支付</text></view>
  89. </view>
  90. </view>
  91. </uni-popup>
  92. </view>
  93. </template>
  94. <script>
  95. import { details, collect, course, create_order } from '@/api/course.js';
  96. // #ifdef H5
  97. import weixinObj from '@/libs/jweixin-module/index.js';
  98. // #endif
  99. export default {
  100. data() {
  101. return {
  102. tabCurrentIndex: 0,
  103. id: '', //专题详情id
  104. isPay: '', //是否购买该专题
  105. swiperlist: '', //轮播图
  106. swiperCurrent: 0, //轮播图
  107. swiperHeight: 300,
  108. list: '', //详情数据
  109. navList: [
  110. {
  111. state: 1,
  112. text: '课程目录'
  113. },
  114. {
  115. state: 0,
  116. text: '详情'
  117. }
  118. ],
  119. courseList: [],
  120. payType: 'weixin', //支付类型
  121. payLoding: false, //判断是否支付中
  122. // #ifdef H5
  123. froms: '', //当前是否为微信浏览器
  124. // #endif
  125. type: '' //判断是否从订单中进入
  126. };
  127. },
  128. onLoad(option) {
  129. this.id = option.id;
  130. this.loadData();
  131. this.course();
  132. },
  133. methods: {
  134. //加载专题详情
  135. loadData() {
  136. let obj = this;
  137. details({
  138. id: obj.id
  139. })
  140. .then(data => {
  141. obj.isPay = data.data.isPay;
  142. obj.swiperlist = data.data.special.swiperlist;
  143. obj.list = data.data.special.special;
  144. })
  145. .catch(e => {
  146. console.log(e.message);
  147. });
  148. },
  149. //专题收藏或者取消收藏
  150. collect() {
  151. let obj = this;
  152. collect({
  153. id: obj.id
  154. })
  155. .then(data => {
  156. obj.loadData();
  157. })
  158. .catch(e => {
  159. console.log(e.message);
  160. });
  161. },
  162. //课程目录列表
  163. course() {
  164. let obj = this;
  165. course({
  166. special_id: obj.id,
  167. limit: 10,
  168. page: 1
  169. })
  170. .then(data => {
  171. this.courseList = data.data.list;
  172. })
  173. .catch(e => {
  174. console.log(e.message);
  175. });
  176. },
  177. //课程详情
  178. ToCourseDetail(ls) {
  179. let obj = this;
  180. if (ls.is_pay == 1) {
  181. if (obj.isPay == false) {
  182. this.$api.msg('清先购买该课程!');
  183. } else {
  184. uni.navigateTo({
  185. url: '/pages/course/curriculum?id=' + ls.id + '&specialId=' + obj.id
  186. });
  187. }
  188. this.$api.msg('清先购买该课程!');
  189. } else {
  190. uni.navigateTo({
  191. url: '/pages/course/curriculum?id=' + ls.id + '&specialId=' + obj.id
  192. });
  193. }
  194. },
  195. //轮播图
  196. swiperChange(e) {
  197. const index = e.detail.current;
  198. this.swiperCurrent = index;
  199. },
  200. //顶部tab点击
  201. tabClick(index) {
  202. this.tabCurrentIndex = index;
  203. },
  204. //返回首页
  205. ToHome() {
  206. uni.switchTab({
  207. url: '/pages/index/index'
  208. });
  209. },
  210. //打开支付弹窗
  211. OpenPay() {
  212. this.$refs.popup.open();
  213. },
  214. //关闭支付弹窗
  215. payclose() {
  216. this.$refs.popup.close();
  217. },
  218. //选择支付方式
  219. changePayType(type) {
  220. this.payType = type;
  221. console.log(this.payType);
  222. },
  223. //确认支付
  224. confirm: async function() {
  225. let obj = this;
  226. // 支付中
  227. obj.payLoding = true;
  228. // #ifdef H5
  229. // 获取当前是否为微信浏览器
  230. obj.froms = uni.getStorageSync('weichatBrowser') || '';
  231. // #endif
  232. obj.CreateOrder();
  233. },
  234. //订单创建
  235. CreateOrder() {
  236. let obj = this;
  237. // 生成订单
  238. create_order({
  239. special_id: obj.id,
  240. pay_type_num: 2,
  241. payType: obj.payType ,//支付类型
  242. total_num:1,
  243. })
  244. .then(data => {
  245. // 判断是否为余额支付
  246. if (obj.payType == 'yue') {
  247. if (data.code == 200) {
  248. if (data.msg == '余额支付成功') {
  249. obj.$api.msg('购买成功!');
  250. }
  251. obj.payclose();
  252. obj.loadData();
  253. } else {
  254. obj.$api.msg(msg);
  255. }
  256. }
  257. // #ifdef H5
  258. if (obj.payType == 'weixin') {
  259. console.log(data,'data')
  260. let config = data.data.jsConfig;
  261. console.log(config, 'config');
  262. weixinObj.chooseWXPay({
  263. timestamp: config.timestamp,
  264. nonceStr: config.nonceStr,
  265. package: config.package,
  266. signType: config.signType,
  267. paySign: config.paySign,
  268. success: function(res) {
  269. obj.loadData();
  270. obj.payclose();
  271. },
  272. fail: function(res) {
  273. obj.payLoding = false;
  274. console.log(res, '失败');
  275. console.log(res.errMsg);
  276. }
  277. });
  278. }
  279. // #endif
  280. })
  281. .catch(e => {
  282. // 支付完成
  283. console.log(e.message);
  284. if (e.message == '该订单已支付!') {
  285. // obj.paySuccessTo();
  286. }
  287. });
  288. },
  289. navTo(url) {
  290. uni.navigateTo({
  291. url
  292. });
  293. }
  294. }
  295. };
  296. </script>
  297. <style lang="scss">
  298. .container {
  299. }
  300. //轮播图
  301. .swiper {
  302. width: 100%;
  303. background-color: #ffffff;
  304. .swiper-box {
  305. width: 100%;
  306. height: 500rpx;
  307. overflow: hidden;
  308. // box-shadow: 0upx 8upx 25upx rgba(0, 0, 0, 0.2);
  309. //兼容ios,微信小程序
  310. position: relative;
  311. z-index: 1;
  312. swiper {
  313. width: 100%;
  314. height: 500rpx;
  315. swiper-item {
  316. image {
  317. width: 100%;
  318. height: 500rpx;
  319. }
  320. }
  321. }
  322. .indicator {
  323. position: absolute;
  324. bottom: 20upx;
  325. left: 20upx;
  326. background-color: rgba(255, 255, 255, 0.4);
  327. width: 150upx;
  328. height: 5upx;
  329. border-radius: 3upx;
  330. overflow: hidden;
  331. display: flex;
  332. .dots {
  333. width: 0upx;
  334. background-color: rgba(255, 255, 255, 1);
  335. transition: all 0.3s ease-out;
  336. &.on {
  337. width: (100%/3);
  338. }
  339. }
  340. }
  341. }
  342. }
  343. .swiper-name {
  344. width: 100%;
  345. padding: 35rpx 30rpx;
  346. .item-box {
  347. position: relative;
  348. .item-name {
  349. position: relative;
  350. top: 0rpx;
  351. font-size: 36rpx;
  352. width: 90%;
  353. }
  354. .item-collection {
  355. text-align: center;
  356. position: absolute;
  357. top: 0rpx;
  358. right: 0;
  359. image {
  360. width: 55rpx;
  361. height: 50rpx;
  362. }
  363. .collection {
  364. font-size: 26rpx;
  365. color: #999999;
  366. }
  367. }
  368. }
  369. .tip-box {
  370. padding: 15rpx 0rpx;
  371. text {
  372. background-color: #e3e9fe;
  373. color: #6786fb;
  374. font-size: 22rpx;
  375. padding: 8rpx 15rpx;
  376. border-radius: 10rpx;
  377. margin-right: 15rpx;
  378. }
  379. }
  380. .price-box {
  381. font-size: 26rpx;
  382. color: #999999;
  383. .price {
  384. color: #e73932;
  385. text {
  386. font-size: 35rpx;
  387. font-weight: bold;
  388. }
  389. }
  390. }
  391. }
  392. //视频
  393. .top {
  394. width: 100%;
  395. height: 500rpx;
  396. .course-video {
  397. width: 100%;
  398. height: 100%;
  399. }
  400. }
  401. .navbar {
  402. display: flex;
  403. height: 40px;
  404. padding: 0 5px;
  405. background: #fff;
  406. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  407. position: relative;
  408. z-index: 10;
  409. .nav-item {
  410. flex: 1;
  411. display: flex;
  412. justify-content: center;
  413. align-items: center;
  414. height: 100%;
  415. font-size: 30rpx;
  416. color: $font-color-dark;
  417. position: relative;
  418. &.current {
  419. color: $base-color;
  420. }
  421. }
  422. }
  423. // 详情
  424. .course-details {
  425. padding: 20rpx;
  426. .details-content {
  427. background: #ffffff;
  428. border-radius: 10rpx;
  429. text-align: center;
  430. .details-title {
  431. padding: 30rpx 0;
  432. border-bottom: 1px solid #f0f0f0;
  433. font-size: $font-base;
  434. font-weight: bold;
  435. color: rgba(51, 51, 51, 1);
  436. }
  437. .details-num {
  438. display: flex;
  439. padding: 30rpx 0;
  440. font-size: $font-sm + 2rpx;
  441. font-weight: bold;
  442. color: rgba(102, 102, 102, 1);
  443. text {
  444. flex: 1;
  445. }
  446. .interval {
  447. width: 2px;
  448. background-color: #eeeeee;
  449. }
  450. }
  451. }
  452. .details-intro {
  453. padding: 40rpx 20rpx;
  454. background: #ffffff;
  455. border-radius: 10rpx;
  456. margin-top: 20rpx;
  457. margin-bottom: 120rpx;
  458. .intro-title {
  459. width: 100%;
  460. font-size: 36rpx;
  461. font-weight: bold;
  462. color: $font-color;
  463. text-align: center;
  464. margin-bottom: 40rpx;
  465. }
  466. .intro-text {
  467. color: #5dcafa;
  468. font-size: $font-base;
  469. line-height: 40rpx;
  470. }
  471. .intro-img {
  472. width: 100%;
  473. height: 400rpx;
  474. margin-top: 40rpx;
  475. .img {
  476. width: 100%;
  477. height: 100%;
  478. }
  479. }
  480. }
  481. }
  482. // 课程目录
  483. .course-catalogue {
  484. padding: 20rpx;
  485. .no-data {
  486. width: 100%;
  487. text-align: center;
  488. font-size: 26rpx;
  489. }
  490. .course-menu {
  491. background: #ffffff;
  492. border-bottom: 1px solid #f0f0f0;
  493. padding: 20rpx;
  494. display: flex;
  495. align-items: center;
  496. font-size: 24rpx;
  497. image {
  498. width: 250rpx;
  499. height: 135rpx;
  500. border-radius: 15rpx;
  501. }
  502. .menu-info {
  503. padding-left: 25rpx;
  504. color: #333333;
  505. .title {
  506. font-size: 28rpx;
  507. }
  508. .tip {
  509. margin: 15rpx 0rpx;
  510. text {
  511. padding: 5rpx 10rpx;
  512. background-color: rgba(43, 121, 245, 0.18);
  513. color: #6786fb;
  514. }
  515. }
  516. .price {
  517. color: #e73932;
  518. }
  519. .red {
  520. color: #6786fb !important;
  521. }
  522. .free {
  523. background: rgba(253, 248, 234, 1);
  524. border-radius: 19px;
  525. color: rgba(241, 174, 39, 1);
  526. padding: 2rpx 10rpx;
  527. }
  528. }
  529. }
  530. }
  531. .foot-box {
  532. position: fixed;
  533. bottom: 0;
  534. width: 100%;
  535. background-color: #ffffff;
  536. padding: 0rpx 35rpx;
  537. font-size: 22rpx;
  538. color: #333333;
  539. .home {
  540. width: 15%;
  541. text-align: center;
  542. image {
  543. width: 35rpx;
  544. height: 38rpx;
  545. }
  546. }
  547. .Topay {
  548. width: 80%;
  549. background-color: #6786fb;
  550. text-align: center;
  551. color: #ffffff;
  552. padding: 25rpx 0rpx;
  553. margin: 15rpx 0rpx;
  554. border-radius: 45rpx;
  555. }
  556. }
  557. //支付弹窗
  558. .pay-type-list {
  559. margin-top: 20upx;
  560. background-color: #fff;
  561. padding-left: 40upx;
  562. .type-item {
  563. height: 120upx;
  564. padding: 20upx 0;
  565. display: flex;
  566. justify-content: space-between;
  567. align-items: center;
  568. padding-right: 60upx;
  569. font-size: 30upx;
  570. position: relative;
  571. }
  572. .icon {
  573. width: 100upx;
  574. font-size: 52upx;
  575. }
  576. .img {
  577. color: #fe8e2e;
  578. width: 50rpx;
  579. height: 50rpx;
  580. image {
  581. width: 100%;
  582. height: 100%;
  583. }
  584. }
  585. .tit {
  586. font-size: $font-lg;
  587. color: $font-color-dark;
  588. margin-bottom: 4upx;
  589. }
  590. .con {
  591. flex: 1;
  592. display: flex;
  593. flex-direction: column;
  594. padding-left: 25rpx;
  595. font-size: $font-sm;
  596. color: $font-color-light;
  597. }
  598. }
  599. .payment {
  600. background-color: #ffffff;
  601. border-radius: 15rpx 15rpx 0rpx 0rpx;
  602. z-index: 999;
  603. .first {
  604. border-bottom: 2rpx solid $border-color-light;
  605. padding: 38rpx 25rpx;
  606. .word {
  607. font-size: $uni-font-size-base;
  608. font-weight: bold;
  609. color: $font-color-dark;
  610. }
  611. image {
  612. width: 25rpx;
  613. height: 25rpx;
  614. }
  615. }
  616. .one {
  617. height: 20rpx;
  618. background-color: #f6f6f6;
  619. }
  620. .Third {
  621. .two1 {
  622. width: 55%;
  623. background-color: #ffffff;
  624. padding-left: 25rpx;
  625. .two1-1 {
  626. font-size: $uni-font-size-base;
  627. font-weight: 400;
  628. color: $font-color-dark;
  629. }
  630. .two1-2 {
  631. font-size: $uni-font-size-sm;
  632. font-weight: bold;
  633. color: $color-red1;
  634. }
  635. .size {
  636. font-size: $uni-font-size-lg + 4rpx;
  637. }
  638. }
  639. .two2 {
  640. width: 45%;
  641. background: $color-red1;
  642. color: #ffffff;
  643. font-size: $uni-font-size-lg;
  644. font-weight: 550;
  645. text-align: center;
  646. padding: 30rpx 0rpx;
  647. }
  648. .clickbg {
  649. background-color: $color-gray !important;
  650. }
  651. }
  652. }
  653. </style>