courseDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <view style="height: 100%; background: #F8F9FA;">
  3. <van-image
  4. class="huodongText2-img"
  5. height="360rpx"
  6. :src="courseInfo.cover"
  7. width="100%"
  8. style="display: flex;align-items: center;"
  9. />
  10. <view class="huodong-ccontent" >
  11. <view class="course-content">
  12. <view class="course-title">{{ courseInfo.goods_name }}</view>
  13. <view class="course-date">
  14. <view style="padding-top: 7rpx;width:28rpx;height: 28rpx ">
  15. <van-image
  16. class="huodongText2-img"
  17. height="28rpx"
  18. src="/static/miaoshu.png"
  19. width="28rpx"
  20. style="display: flex;"
  21. />
  22. </view>
  23. <span style="padding: 0 20rpx">{{courseInfo.remark}}</span>
  24. </view>
  25. <view class="course-price" style="position: relative;">
  26. <span style="font-size: 24rpx; color: #C29556;">¥&nbsp;</span><span style="font-size: 36rpx;color: #C29556;">{{courseInfo.price_selling}}</span>
  27. <view style="position: absolute;right:0rpx;font-size: 22rpx;color:#888888; display: flex;">
  28. <view style="padding-top: 8rpx;width:28rpx;height: 28rpx ">
  29. <van-image
  30. class="huodongText2-img"
  31. height="28rpx"
  32. src="/static/baoming.png"
  33. width="28rpx"
  34. style="display: flex;"
  35. />
  36. </view>
  37. <span style="padding-left: 20rpx;"> &nbsp;{{courseInfo.stock_sales}}&nbsp;人已学习</span>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="course-content-title">
  43. 课程介绍
  44. </view>
  45. <view id="course-content" ref="courseContent" style="width: 95%;margin: 0 auto;" v-html="courseInfo.content">
  46. </view>
  47. <view style="width: 100%;height: 165rpx" > </view>
  48. <van-toast id="van-toast"/>
  49. <view class="bottom-navigation">
  50. <view class="bottom-navigation-div">
  51. <view style="width: 40rpx;margin-right: 30rpx" @click="toJump( 1)" >
  52. <van-image
  53. height="36rpx"
  54. src="/static/hd-icon-a.png"
  55. width="36rpx"
  56. style="display: flex;align-items: center; justify-content: center;"
  57. />
  58. <span>
  59. 首页
  60. </span>
  61. </view>
  62. <view style="width: 40rpx;position:relative" open-type="contact">
  63. <van-image
  64. height="36rpx"
  65. src="/static/hd-icon-c.png"
  66. width="36rpx"
  67. style="display: flex;align-items: center; justify-content: center;"
  68. />
  69. <span>
  70. 咨询
  71. </span>
  72. <button style="position: absolute;width: 100%;height: 100%;z-index: 999;opacity: 0;top:0;"
  73. open-type="contact" ></button>
  74. </view>
  75. </view>
  76. <button class="course-button" @click="handleRegister">立即报名</button>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. import {getConfigData} from '@/common/api/common.js';
  82. import Toast from "../../wxcomponents/vant/dist/toast/toast";
  83. import {getGoodsDetail} from "../../common/api";
  84. export default {
  85. components: {},
  86. data() {
  87. return {
  88. page: 1,
  89. pageSize: 10,
  90. courseTypeList: [],
  91. goods_code: 0,
  92. courseInfo: {},
  93. entry_end: 0,
  94. remainingImages: [],
  95. entry_num:0,
  96. entry_max:0,
  97. entry_balance:0,
  98. is_entry:false,
  99. };
  100. },
  101. onLoad: function (option) {
  102. this.goods_code = option.goods_code
  103. this.getCourseDetail()
  104. this.setImgWidth()
  105. },
  106. onShow() {
  107. this.$nextTick(() => {
  108. });
  109. },
  110. onReachBottom() {
  111. },
  112. onShareAppMessage(res) {
  113. let params = {};
  114. params = {
  115. goods_code: this.goods_code
  116. };
  117. let configs = uni.getStorageSync('configs') || {};
  118. return {
  119. title: configs.shop_share_title,
  120. imageUrl: configs.shop_share_img,
  121. path: `/subPages/courseDetail/courseDetail${this.$stringPageOptions(params)}`
  122. };
  123. },
  124. onShareTimeline(res) {
  125. let params = {};
  126. params = {
  127. goods_code: this.goods_code
  128. };
  129. let configs = uni.getStorageSync('configs') || {};
  130. return {
  131. title: configs.shop_share_title,
  132. imageUrl: configs.shop_share_img,
  133. path: `/subPages/courseDetail/courseDetail${this.$stringPageOptions(params)}`
  134. };
  135. },
  136. computed: {},
  137. watch: {},
  138. methods: {
  139. getConfigDatalist() {
  140. getConfigData({dict_id: 36}).then(({data}) => {
  141. this.courseTypeList = data.reverse();
  142. });
  143. },
  144. handleRegister() {
  145. Toast('敬请期待');
  146. // if (this.is_entry){
  147. // Toast.fail('您已报名,请勿重复报名');
  148. // return
  149. // }
  150. // uni.navigateTo({url: `/subPages/courseDetail/courseSave?goods_code=${ this.goods_code}`,})
  151. },
  152. getCourseDetail() {
  153. getGoodsDetail({goods_code: this.goods_code}).then(({data}) => {
  154. console.log(data)
  155. this.courseInfo = data.goods
  156. if (this.courseInfo.content) {
  157. this.courseInfo.content = this.courseInfo.content.replace(/\/apihttps:/g, 'https:');
  158. }
  159. // 修正 courseInfo.content 中的 src 属性值
  160. if (this.courseInfo.content) {
  161. this.courseInfo.content = this.courseInfo.content.replace(/\/apihttps:/g, 'https:');
  162. // 使用正则表达式匹配和修改 img 标签的 style 属性
  163. this.courseInfo.content = this.courseInfo.content.replace(/<img([^>]*)>/gi, (match, attributes) => {
  164. // 检查是否已经存在 style 属性
  165. if (attributes.includes('style')) {
  166. // 如果存在 style 属性,添加 width: 100%;
  167. return match.replace(/style="([^"]*)"/i, (styleMatch, styleContent) => {
  168. if (!styleContent.includes('width: 100%')) {
  169. return `style="${styleContent}; width: 100%;"`;
  170. }
  171. return styleMatch;
  172. });
  173. } else {
  174. // 如果不存在 style 属性,添加 style="width: 100%;"
  175. return match.replace(/<img/i, '<img style="width: 100%;"');
  176. }
  177. });
  178. // 使用正则表达式匹配和修改 p 标签的 style 属性
  179. this.courseInfo.content = this.courseInfo.content.replace(/<p([^>]*)>/gi, (match, attributes) => {
  180. // 检查是否已经存在 style 属性
  181. if (attributes.includes('style')) {
  182. // 如果存在 style 属性,添加新的样式
  183. return match.replace(/style="([^"]*)"/i, (styleMatch, styleContent) => {
  184. const newStyles = 'font-weight: 400; font-size: 24rpx; color: #666666; line-height: 36rpx;';
  185. if (!styleContent.includes(newStyles)) {
  186. return `style="${styleContent}; ${newStyles}"`;
  187. }
  188. return styleMatch;
  189. });
  190. } else {
  191. // 如果不存在 style 属性,添加 style 属性
  192. const newStyles = 'font-weight: 400; font-size: 24rpx; color: #666666; line-height: 36rpx;';
  193. return match.replace(/<p/i, `<p style="${newStyles}"`);
  194. }
  195. });
  196. }
  197. // 确保在数据更新后调用 setImgWidth
  198. this.$nextTick(() => {
  199. this.setImgWidth();
  200. });
  201. });
  202. },
  203. setImgWidth() {
  204. this.$nextTick(() => {
  205. if (this.$refs.courseContent) {
  206. const imgElements = this.$refs.courseContent.querySelectorAll('img');
  207. imgElements.forEach(img => {
  208. img.style.width = '100%';
  209. });
  210. } else {
  211. console.log(this.$refs)
  212. }
  213. });
  214. },
  215. getStyles(index=0) {
  216. let le =28
  217. let py=30
  218. if (this.entry_num%2==1){
  219. py+= 224/2-(84/2)-(le*Math.floor(this.entry_num / 2 ))-le/2
  220. }else{
  221. py+=224/2-(84/2)-(le*this.entry_num/2)
  222. }
  223. let right= index*le+py
  224. var newVar = {
  225. position: 'absolute',
  226. width: '84rpx',
  227. height: '84rpx',
  228. borderRadius: '84rpx',
  229. top: '30rpx',
  230. right: right+'rpx',
  231. };
  232. return newVar
  233. },
  234. toJump( index) {
  235. if(index==1){
  236. uni.switchTab({
  237. url:'/pages/home/index'
  238. });
  239. }else if(index==2){
  240. }
  241. },
  242. },
  243. };
  244. </script>
  245. <style lang="scss" scoped>
  246. .common-page {
  247. height: 100%;
  248. padding: 30rpx;
  249. }
  250. .huodong-ccontent {
  251. position: relative; /* 相对定位 */
  252. width: 650rpx;
  253. padding: 0rpx;
  254. margin: 30rpx auto;
  255. margin-bottom: 0;
  256. padding: 30rpx;
  257. background: #FFFFFF;
  258. border-radius: 16rpx 16rpx 16rpx 16rpx;
  259. }
  260. .course-content {
  261. margin-top: 30 rp;
  262. .course-title {
  263. font-family: PingFang SC, PingFang SC;
  264. font-weight: 400;
  265. font-size: 32rpx;
  266. color: #333333;
  267. line-height: 40rpx;
  268. text-align: left;
  269. font-style: normal;
  270. text-transform: none;
  271. font-weight: bold;
  272. margin-bottom: 16rpx;
  273. }
  274. .course-date {
  275. font-family: 苹方, 苹方;
  276. font-size: 26rpx;
  277. color: #666666;
  278. line-height: 40rpx;
  279. text-align: left;
  280. font-style: normal;
  281. text-transform: none;
  282. font-weight: 400;
  283. margin-bottom: 10rpx;
  284. display: flex;
  285. }
  286. .course-price {
  287. font-family: 苹方, 苹方;
  288. font-weight: 400;
  289. font-size: 24rpx;
  290. color: #666666;
  291. line-height: 40rpx;
  292. text-align: justify;
  293. font-style: normal;
  294. text-transform: none;
  295. display: flex;
  296. }
  297. }
  298. .bottom-navigation{
  299. position: fixed;
  300. // 文字垂直居中
  301. display: flex;
  302. align-items: center;
  303. justify-content: center;
  304. bottom: 0;
  305. height: 100rpx;
  306. width: calc(100% - 40rpx);
  307. background: #FFFFFF;
  308. box-shadow: 0rpx -2rpx 0rpx 0rpx #F1F3F6;
  309. border-radius: 24rpx 24rpx 0rpx 0rpx;
  310. border: 0rpx solid #979797;
  311. padding: 20rpx 20rpx 68rpx 20rpx ;
  312. &-div{
  313. height: 76rpx;
  314. width: 404rpx;
  315. // 文字垂直居中
  316. display: flex;
  317. align-items: center;
  318. padding-left: 30rpx;
  319. span{
  320. font-family: PingFang SC, PingFang SC;
  321. font-weight: 400;
  322. font-size: 20rpx;
  323. color: #333333;
  324. line-height: 32rpx;
  325. text-align: left;
  326. font-style: normal;
  327. text-transform: none;
  328. }
  329. }
  330. .course-button {
  331. width: 264rpx;
  332. height: 80rpx;
  333. background: linear-gradient(315deg, #CA9359 0%, #E2B98E 100%);
  334. border-radius: 292rpx 292rpx 292rpx 292rpx;
  335. font-family: PingFang SC, PingFang SC;
  336. font-weight: 400;
  337. font-size: 28rpx;
  338. color: #FFFFFF;
  339. line-height: 36rpx;
  340. text-align: center;
  341. font-style: normal;
  342. text-transform: none;
  343. // 文字垂直居中
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. }
  348. }
  349. /* 设置 v-html 渲染的内容中的 img 标签宽度为 100% */
  350. [v-html] img {
  351. width: 100%!important;
  352. }
  353. /* 定义 CSS 变量 */
  354. :root {
  355. --nav-bar-icon-color: black;
  356. --nav-bar-arrow-size: 16px;
  357. --tab-font-size: 28rpx;
  358. }
  359. .course-content-title {
  360. margin: 30rpx auto;
  361. width: 680rpx;
  362. // 垂直居中
  363. font-family: PingFang SC, PingFang SC;
  364. font-weight: 400;
  365. font-size: 28rpx;
  366. color: #333333;
  367. line-height: 40rpx;
  368. font-style: normal;
  369. text-transform: none;
  370. margin-bottom: 20rpx;
  371. // 加粗
  372. font-weight: bold;
  373. }
  374. /* 确保 van-nav-bar 内部的内容能够正确适应新的高度 */
  375. /deep/ .van-nav-bar__title {
  376. font-family: PingFang SC, PingFang SC !important;
  377. font-weight: 400 !important;
  378. font-size: 36rpx !important;
  379. color: #333333 !important;
  380. text-align: center;
  381. // 加粗
  382. // font-weight: bold;
  383. }
  384. /deep/ .van-nav-bar__content {
  385. text-align: center;
  386. }
  387. #course-content img{
  388. width: 100%!important;
  389. }
  390. /* 添加 van-tab 标题的字体大小样式 */
  391. /deep/ .van-tab__text {
  392. font-family: PingFang SC, PingFang SC;
  393. font-weight: 400;
  394. font-size: 28rpx;
  395. }
  396. </style>