detail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. <template>
  2. <view class="wrap">
  3. <u-navbar :autoBack="true" title="培训详情" bgColor="rgba(255,255,255,255)" :placeholder="true" titleStyle="font-weight:bold;color:#121212"></u-navbar>
  4. <view class="main" v-if="hasLoad">
  5. <view class="b-photos">
  6. <swiper indicator-dots circular="true" duration="400">
  7. <swiper-item class="swiper-item" v-for="(item, index) in state.photo_list" :key="index">
  8. <view class="image-wrapper" @click="onPreviewPhoto(index)">
  9. <image :src="item.url" mode="aspectFill"></image>
  10. </view>
  11. </swiper-item>
  12. </swiper>
  13. </view>
  14. <view class="b-slide">
  15. <view class="b-item" :class="{ 'f-active': showContent === 'detail' }" @click="onContentSwitch('detail')">介绍</view>
  16. <view class="b-item" :class="{ 'f-active': showContent === 'course' }" @click="onContentSwitch('course')">课程</view>
  17. <view class="b-item" :class="{ 'f-active': showContent === 'examine' }" @click="onContentSwitch('examine')" v-if="state.has_examine">考核</view>
  18. </view>
  19. <view class="content-list" v-show="showContent === 'course'">
  20. <view class="course-item" v-for="(item, index) in state.course_list" :key="index" :class="{ 'f-active': courseIndex == index }">
  21. <view class="b-main">
  22. <view class="b-name too-long">第{{ index + 1 }}课 {{ item.name }}</view>
  23. <view class="b-percent">
  24. <view class="b-line" v-if="state.auth_state == 3">
  25. <view class="s-num" :style="'width:' + item.learn_percent + '%'"></view>
  26. </view>
  27. <view class="b-info">
  28. <view class="s-time">{{ item.need_length }}课时</view>
  29. <view class="s-percent" v-if="state.auth_state == 3">已学{{ item.learn_percent }}%</view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="b-play" @click="onJumpCourse(item.id)">
  34. <view class="iconfont icon-video"></view>
  35. <view class="b-state" v-if="state.auth_state != 3">查看详情</view>
  36. <view class="b-state" v-else>{{ item.learn_percent > 0 ? '继续学习' : '开始学习' }}</view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="course-detail" v-show="showContent === 'detail'">
  41. <view class="info">
  42. <view class="b-title">{{ state.name }}</view>
  43. <view class="b-main">
  44. <view class="b-price">
  45. <view class="s-payment" :class="{ 'f-small': textCost }">{{ goodsPrice(state.price) }}</view>
  46. <!-- <view class="s-vip-price" v-if="state.card_price > 0 && !iphonePlatform">会员价 ¥{{ state.card_price }}</view>
  47. <view class="s-vip-free" v-if="state.vip_free">会员免费</view> -->
  48. </view>
  49. <view class="b-opt">
  50. <view class="s-btn f-like" @click="onHandleLike()">
  51. <view class="f-yes iconfont icon-like-yes" v-if="state.is_like"></view>
  52. <view class="f-no iconfont icon-like-no" v-else></view>
  53. </view>
  54. <button class="s-btn f-shar open-data-btn" open-type="share">
  55. <view class="iconfont icon-share"></view>
  56. </button>
  57. <!-- <view class="s-btn f-share">
  58. <view class="iconfont icon-share"></view>
  59. </view> -->
  60. </view>
  61. </view>
  62. <view class="b-info">
  63. <view class="s-worth">{{ state.category_name }}</view>
  64. <view class="s-count">
  65. <view class="s-left">{{ state.count_user }}人参加</view>
  66. <view class="s-gain">{{ state.count_like }}人收藏</view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="content">
  71. <view class="b-title">
  72. <view class="xiant"></view>
  73. <view class="s-tit">培训详情</view>
  74. <view class="xiant"></view>
  75. </view>
  76. <view class="b-rich">
  77. <rich-text :nodes="state.content"></rich-text>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="course-examine" v-show="showContent === 'examine'">
  82. <view class="examine-list" v-if="examineList.length > 0">
  83. <examine-item v-for="(item, index) in examineList" :key="index" :item="item"></examine-item>
  84. </view>
  85. </view>
  86. <view class="navbar" v-if="state.auth_state != 3">
  87. <view class="b-main">
  88. <view class="b-amount">
  89. <!-- <view class="s-tit"></view> -->
  90. <view class="s-num" :class="{ 'f-small': textCost }">{{ goodsPrice(state.price) }}</view>
  91. </view>
  92. </view>
  93. <view class="b-action" v-if="state.auth_state == 0">
  94. <view class="b-btn f-mute" v-if="iphonePlatform">根据相关规定,iOS不支持购买</view>
  95. <template v-else>
  96. <view class="b-btn f-cart" @click="onAddCart()">加入购物车</view>
  97. <view class="b-btn f-order" @click="onPreviewOrder()">立即购买</view>
  98. </template>
  99. </view>
  100. <view class="b-action" v-else-if="state.auth_state == 1">
  101. <view class="b-btn f-learn" @click="onStartLearn()">开始学习</view>
  102. </view>
  103. <view class="b-action" v-else-if="state.auth_state == 2">
  104. <view class="b-btn f-learn" @click="onStartLearn()">VIP免费</view>
  105. </view>
  106. </view>
  107. </view>
  108. <!-- 加载中 -->
  109. <load-more :loadingType="loadingType" :loadingText="loadingText" :top="300"></load-more>
  110. <!-- 快捷购物车 -->
  111. <quick-cart :show="showCart" @close="onCloseCart()"></quick-cart>
  112. <!-- 首页 -->
  113. <app-home></app-home>
  114. </view>
  115. </template>
  116. <script>
  117. // import { startLearn, handleLike, getScheduleDetail, getScheduleExamine } from '@/service/api/schedule.js';
  118. // import { addCart } from '@/service/api/order.js';
  119. import mixinsGoods from '@/mixins/goods.js';
  120. import mixinsCommon from '@/mixins/common.js';
  121. let that;
  122. export default {
  123. mixins: [mixinsCommon, mixinsGoods],
  124. data() {
  125. return {
  126. state: null,
  127. examineList: [],
  128. courseIndex: -1,
  129. showContent: 'detail',
  130. showCart: false,
  131. hasLoad: false,
  132. loadingType: 1,
  133. loadingText: ''
  134. };
  135. },
  136. onLoad(options) {
  137. that = this;
  138. this.scheduleId = options.sid;
  139. this.loadDetail();
  140. },
  141. computed: {
  142. orderPayment() {
  143. return this.state.card_auth && this.state.card_price ? this.state.card_price : this.state.price;
  144. }
  145. },
  146. onShareAppMessage(res) {
  147. console.log('onShareAppMessage', res);
  148. if (res.from === 'button') {
  149. // 来自页面内分享按钮
  150. console.log(res.target);
  151. }
  152. return {
  153. title: this.state.name,
  154. path: '/pages/schedule/detail?cid=' + this.scheduleId,
  155. imageUrl: this.state.photo_list[0]['url']
  156. };
  157. },
  158. methods: {
  159. // 培训课程详情
  160. loadDetail() {
  161. this.$api.getScheduleDetail({ id: this.scheduleId }, function (res) {
  162. console.log('5656', res);
  163. if (res.code == 1) {
  164. if (!that.hasLoad) {
  165. if (res.data.auth_state == 3) {
  166. that.showContent = 'course';
  167. }
  168. }
  169. that.hasLoad = true;
  170. that.loadingType = -1;
  171. that.state = res.data;
  172. if (res.data.has_examine) {
  173. that.loadExamine();
  174. }
  175. uni.setNavigationBarTitle({
  176. title: res.data.name
  177. });
  178. } else {
  179. that.loadingType = 3;
  180. that.loadingText = '加载失败';
  181. }
  182. });
  183. // getScheduleDetail(this.scheduleId).then(([err, res]) => {
  184. // console.log('getScheduleDetail', err, res);
  185. // if (!err) {
  186. // if (!this.hasLoad) {
  187. // if (res.auth_state == 3) {
  188. // this.showContent = 'course';
  189. // }
  190. // }
  191. // this.hasLoad = true;
  192. // this.loadingType = -1;
  193. // this.state = res;
  194. // if (res.has_examine) {
  195. // this.loadExamine();
  196. // }
  197. // uni.setNavigationBarTitle({
  198. // title: res.name
  199. // });
  200. // } else {
  201. // this.loadingType = 3;
  202. // this.loadingText = err.data.msg || '加载失败';
  203. // }
  204. // });
  205. },
  206. loadExamine() {
  207. getScheduleExamine(this.scheduleId).then(([err, res]) => {
  208. console.log('getScheduleExamine', err, res);
  209. if (!err) {
  210. this.examineList = res;
  211. }
  212. });
  213. },
  214. onContentSwitch(type) {
  215. this.showContent = type;
  216. },
  217. onPreviewPhoto(index) {
  218. let photos = [];
  219. for (let i = 0; i < this.state.photo_list.length; i++) {
  220. photos.push(this.state.photo_list[i].url);
  221. }
  222. uni.previewImage({
  223. current: index,
  224. urls: photos
  225. });
  226. },
  227. onJumpHome() {
  228. uni.switchTab({
  229. url: '/pages/home/index'
  230. });
  231. },
  232. onJumpCourse(id) {
  233. uni.navigateTo({
  234. url: '/pages/course/detail?cid=' + id
  235. });
  236. },
  237. onHandleLike() {
  238. if (!this.checkLogin()) {
  239. return;
  240. }
  241. var action = this.state.is_like ? 'no' : 'yes';
  242. handleLike(this.scheduleId, action).then(([err, res]) => {
  243. console.log('handleLike', err, res);
  244. if (!err) {
  245. if (action === 'yes') {
  246. this.state.is_like = 1;
  247. } else {
  248. this.state.is_like = 0;
  249. }
  250. this.$logic.showToast('操作成功');
  251. }
  252. });
  253. },
  254. onCloseCart() {
  255. this.showCart = false;
  256. },
  257. onAddCart() {
  258. // if (!this.checkLogin()) {
  259. // return;
  260. // }
  261. addCart('schedule', this.scheduleId).then(([err, res]) => {
  262. console.log('addCart', err, res);
  263. if (!err) {
  264. this.$store.commit('addCartItem', {
  265. goods_id: this.scheduleId,
  266. goods_type: 'schedule',
  267. goods_name: this.state.name,
  268. goods_cover: this.state.cover_url,
  269. goods_price: this.state.price
  270. });
  271. this.showCart = true;
  272. setTimeout(() => {
  273. this.showCart = false;
  274. }, 5000);
  275. }
  276. });
  277. },
  278. onPreviewOrder() {
  279. if (!this.checkLogin()) {
  280. return;
  281. }
  282. let goodsData = [
  283. {
  284. goods_type: 'schedule',
  285. goods_id: this.scheduleId
  286. }
  287. ];
  288. uni.navigateTo({
  289. url: '/pages/order/preview?goods_data=' + JSON.stringify(goodsData)
  290. });
  291. },
  292. onStartLearn() {
  293. // if (!this.checkLogin()) {
  294. // return;
  295. // }
  296. this.$api.scheduleStartLearn({ id: this.scheduleId }, function (res) {
  297. console.log('startLearn', res);
  298. if (res.code == 1) {
  299. that.$logic.showToast('开通成功,可以开始学习了');
  300. that.loadDetail();
  301. }
  302. });
  303. // startLearn(this.scheduleId).then(([err, res]) => {
  304. // console.log('startLearn', err, res);
  305. // if (!err) {
  306. // this.$logic.showToast('开通成功,可以开始学习了');
  307. // this.loadDetail();
  308. // }
  309. // });
  310. },
  311. onContinueLearn() {
  312. this.showContent = 'course';
  313. if (this.state.recent_data) {
  314. for (let i = 0; i < this.state.course_list.length; i++) {
  315. if (this.state.course_list[i].id == this.state.recent_data.course_id) {
  316. this.courseIndex = i;
  317. break;
  318. }
  319. }
  320. if (this.courseIndex == -1) {
  321. this.courseIndex = 0;
  322. }
  323. } else {
  324. this.courseIndex = 0;
  325. }
  326. }
  327. }
  328. };
  329. </script>
  330. <style>
  331. .xiant {
  332. width: 60rpx;
  333. height: 3rpx;
  334. background-color: #dddedd;
  335. }
  336. .wrap {
  337. padding-bottom: 150upx;
  338. }
  339. .b-photos {
  340. position: relative;
  341. width: 750upx;
  342. height: 500upx;
  343. }
  344. .b-photos swiper {
  345. height: 100%;
  346. }
  347. .b-photos .swiper-item {
  348. display: flex;
  349. justify-content: center;
  350. align-content: center;
  351. height: 320upx;
  352. overflow: hidden;
  353. }
  354. .b-photos .swiper-item image {
  355. width: 100%;
  356. height: 100%;
  357. }
  358. .b-photos .image-wrapper {
  359. width: 100%;
  360. height: 100%;
  361. }
  362. .b-slide {
  363. display: flex;
  364. align-items: center;
  365. justify-content: center;
  366. background: #fff;
  367. border-bottom: 2upx solid #eee;
  368. }
  369. .b-slide .b-item {
  370. flex: 1;
  371. height: 80upx;
  372. line-height: 80upx;
  373. font-size: 28upx;
  374. text-align: center;
  375. }
  376. .b-slide .b-item.f-active {
  377. height: 76upx;
  378. line-height: 80upx;
  379. font-weight: bold;
  380. border-bottom: 4upx solid #da5650;
  381. }
  382. .info {
  383. padding: 30upx;
  384. background: #fff;
  385. }
  386. .info .b-title {
  387. font-size: 30upx;
  388. color: #333;
  389. }
  390. .info .b-main {
  391. margin-top: 20upx;
  392. display: flex;
  393. align-items: center;
  394. justify-content: space-between;
  395. }
  396. .info .b-main .b-price {
  397. display: flex;
  398. align-items: center;
  399. }
  400. .info .b-main .b-price .s-payment {
  401. margin-right: 20upx;
  402. font-size: 36upx;
  403. font-weight: bold;
  404. color: #dd524d;
  405. }
  406. .info .b-main .b-price .s-payment.f-small {
  407. font-size: 28upx;
  408. }
  409. .info .b-main .b-price .s-vip-price {
  410. margin-right: 20upx;
  411. font-size: 26upx;
  412. color: #f0ad4e;
  413. }
  414. .info .b-main .b-price .s-vip-free {
  415. margin-right: 20upx;
  416. padding: 6upx 10upx;
  417. font-size: 24upx;
  418. color: #555;
  419. background: #f0ad4e;
  420. border-radius: 5upx;
  421. }
  422. .info .b-main .b-opt {
  423. display: flex;
  424. align-items: center;
  425. }
  426. .info .b-main .b-opt .s-btn {
  427. margin-left: 20upx;
  428. font-size: 50upx;
  429. }
  430. .info .b-main .b-opt .s-btn.f-like .f-yes.iconfont {
  431. color: #da5650;
  432. }
  433. .info .b-main .b-opt .iconfont {
  434. font-size: 40upx;
  435. color: #999;
  436. }
  437. .info .b-info {
  438. margin-top: 20upx;
  439. display: flex;
  440. align-items: center;
  441. justify-content: space-between;
  442. }
  443. .info .b-info .s-worth {
  444. color: #999;
  445. font-size: 24upx;
  446. }
  447. .info .b-info .s-count {
  448. color: #999;
  449. font-size: 24upx;
  450. display: flex;
  451. align-items: center;
  452. }
  453. .info .b-info .s-count .s-gain {
  454. margin-left: 40upx;
  455. }
  456. .content {
  457. margin-top: 30upx;
  458. }
  459. .content .b-title {
  460. display: flex;
  461. align-items: center;
  462. justify-content: center;
  463. }
  464. .content .b-title .iconfont {
  465. color: #ccc;
  466. }
  467. .content .b-title .s-tit {
  468. margin: 0 20upx;
  469. font-size: 24upx;
  470. color: #666;
  471. }
  472. .content .b-rich {
  473. margin-top: 30upx;
  474. padding: 30upx 0;
  475. background: #fff;
  476. font-size: 28upx;
  477. }
  478. .content-list {
  479. padding: 20upx 30upx;
  480. background: #fff;
  481. }
  482. .content-list .course-item {
  483. padding: 30upx 0;
  484. display: flex;
  485. align-items: center;
  486. justify-content: space-between;
  487. border-bottom: 2upx solid #eee;
  488. }
  489. .content-list .course-item:last-child {
  490. border-bottom: none;
  491. }
  492. .content-list .course-item.f-active {
  493. font-weight: bold;
  494. }
  495. .content-list .course-item .b-main {
  496. flex: 1;
  497. display: flex;
  498. flex-direction: column;
  499. }
  500. .content-list .course-item .b-main .b-name {
  501. font-size: 28upx;
  502. color: #333;
  503. font-weight: bold;
  504. width: 498upx;
  505. display: inline-block;
  506. }
  507. .content-list .course-item .b-main .b-percent {
  508. margin-top: 20upx;
  509. display: flex;
  510. flex-direction: column;
  511. }
  512. .content-list .course-item .b-main .b-percent .b-line {
  513. position: relative;
  514. width: 100%;
  515. height: 20upx;
  516. background: #eee;
  517. }
  518. .content-list .course-item .b-main .b-percent .b-line .s-num {
  519. position: absolute;
  520. top: 0;
  521. left: 0;
  522. height: 20upx;
  523. background: rgba(218, 86, 80, 0.8);
  524. }
  525. .content-list .course-item .b-main .b-percent .b-info {
  526. margin-top: 10upx;
  527. display: flex;
  528. align-items: center;
  529. justify-content: space-between;
  530. }
  531. .content-list .course-item .b-main .b-percent .b-info .s-time {
  532. font-size: 28upx;
  533. color: #666;
  534. }
  535. .content-list .course-item .b-main .b-percent .b-info .s-percent {
  536. font-size: 26upx;
  537. color: #999;
  538. }
  539. .content-list .course-item .b-play {
  540. margin-left: 30upx;
  541. border-left: 2upx solid #eee;
  542. width: 160upx;
  543. display: flex;
  544. flex-direction: column;
  545. align-items: center;
  546. }
  547. .content-list .course-item .b-play .iconfont {
  548. font-size: 40upx;
  549. color: #999;
  550. }
  551. .content-list .course-item .b-play .b-state {
  552. margin-top: 20upx;
  553. font-size: 24upx;
  554. color: #666;
  555. }
  556. .navbar {
  557. padding: 10upx 0;
  558. position: fixed;
  559. left: 0;
  560. bottom: 0;
  561. width: 100%;
  562. height: 100upx;
  563. background: #fff;
  564. border-top: 1upx solid #f6f6f6;
  565. display: flex;
  566. align-items: center;
  567. justify-content: space-between;
  568. }
  569. .navbar .b-main {
  570. margin-left: 30upx;
  571. flex: 1;
  572. display: flex;
  573. align-items: center;
  574. }
  575. .navbar .b-main .b-amount {
  576. flex: 1;
  577. display: flex;
  578. align-items: center;
  579. justify-content: center;
  580. }
  581. .navbar .b-main .b-amount .s-tit {
  582. margin-right: 10upx;
  583. font-size: 28upx;
  584. color: #333;
  585. }
  586. .navbar .b-main .b-amount .s-num {
  587. font-size: 40upx;
  588. color: #da5650;
  589. }
  590. .navbar .b-main .b-amount .s-num.f-small {
  591. font-size: 32upx;
  592. }
  593. .navbar .b-action {
  594. margin-right: 30upx;
  595. width: 450upx;
  596. display: flex;
  597. align-items: center;
  598. }
  599. .navbar .b-action .b-btn {
  600. height: 80upx;
  601. line-height: 80upx;
  602. font-size: 28upx;
  603. color: #fff;
  604. text-align: center;
  605. letter-spacing: 2upx;
  606. }
  607. .navbar .b-action .f-cart {
  608. flex: 1;
  609. background: #ec9c4e;
  610. font-size: 26upx;
  611. border-radius: 40upx 0 0 40upx;
  612. }
  613. .navbar .b-action .f-cart.f-disable {
  614. background: rgba(218, 86, 80, 0.8);
  615. }
  616. .navbar .b-action .f-order {
  617. flex: 1;
  618. background: #da5650;
  619. font-size: 26upx;
  620. border-radius: 0 40upx 40upx 0;
  621. }
  622. .navbar .b-action .f-order.f-disable {
  623. background: rgba(218, 86, 80, 0.8);
  624. }
  625. .navbar .b-action .f-learn {
  626. flex: 1;
  627. letter-spacing: 4upx;
  628. background: #da5650;
  629. border-radius: 40upx;
  630. }
  631. .navbar .b-action .f-mute {
  632. flex: 1;
  633. color: #666;
  634. font-size: 26upx;
  635. background: #eee;
  636. border-radius: 40upx;
  637. }
  638. </style>