courseDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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 16rpx">{{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: 7rpx;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. suitNum:1,
  100. };
  101. },
  102. onLoad: function (option) {
  103. this.goods_code = option.goods_code
  104. this.getCourseDetail()
  105. this.setImgWidth()
  106. },
  107. onShow() {
  108. this.$nextTick(() => {
  109. });
  110. },
  111. onReachBottom() {
  112. },
  113. onShareAppMessage(res) {
  114. let params = {};
  115. params = {
  116. goods_code: this.goods_code
  117. };
  118. let configs = uni.getStorageSync('configs') || {};
  119. return {
  120. title: configs.shop_share_title,
  121. imageUrl: configs.shop_share_img,
  122. path: `/subPages/courseDetail/courseDetail${this.$stringPageOptions(params)}`
  123. };
  124. },
  125. onShareTimeline(res) {
  126. let params = {};
  127. params = {
  128. goods_code: this.goods_code
  129. };
  130. let configs = uni.getStorageSync('configs') || {};
  131. return {
  132. title: configs.shop_share_title,
  133. imageUrl: configs.shop_share_img,
  134. path: `/subPages/courseDetail/courseDetail${this.$stringPageOptions(params)}`
  135. };
  136. },
  137. computed: {},
  138. watch: {},
  139. methods: {
  140. getConfigDatalist() {
  141. getConfigData({dict_id: 36}).then(({data}) => {
  142. this.courseTypeList = data.reverse();
  143. });
  144. },
  145. handleRegister() {
  146. // Toast('敬请期待');
  147. let tempList = this.courseInfo.data_specs[0].list
  148. tempList = tempList.map(item => {
  149. return {
  150. group_name: item.group,
  151. spec_name: item.name
  152. }
  153. })
  154. let specText = tempList.map(item => {
  155. return `${item.group_name}::${item.spec_name}`
  156. })
  157. // 准备发送的数据结构,包含商品代码、套件数量和规格文本
  158. const sendData = {
  159. items: [{
  160. code: this.courseInfo.code, // 商品代码
  161. count: this.suitNum, // 套件数量
  162. // 将规格文本数组用“;;”连接成单个字符串
  163. spec: specText.join(';;')
  164. }]
  165. }
  166. // 调用API创建订单
  167. this.$api.createOrder(sendData).then(res => {
  168. // 成功创建订单后,显示成功提示
  169. uni.showToast({
  170. title: '订单创建成功'
  171. })
  172. // 导航到结算中心页面,并传递订单号作为查询参数
  173. uni.navigateTo({
  174. url: `/subPages/settleCenter/courseSettleCenter?orderNo=${res.data.order_no}`
  175. })
  176. })
  177. },
  178. getCourseDetail() {
  179. getGoodsDetail({goods_code: this.goods_code}).then(({data}) => {
  180. console.log(data)
  181. this.courseInfo = data.goods
  182. // 修正 courseInfo.content 中的 src 属性值
  183. if (this.courseInfo.content) {
  184. this.courseInfo.content = this.courseInfo.content.replace(/\/apihttps:/g, 'https:');
  185. // 使用正则表达式匹配和修改 img 标签的 style 属性
  186. this.courseInfo.content = this.courseInfo.content.replace(/<img([^>]*)>/gi, (match, attributes) => {
  187. // 检查是否已经存在 style 属性
  188. if (attributes.includes('style')) {
  189. // 如果存在 style 属性,添加 width: 100%;
  190. return match.replace(/style="([^"]*)"/i, (styleMatch, styleContent) => {
  191. if (!styleContent.includes('width: 100%')) {
  192. return `style="${styleContent}; width: 100%;"`;
  193. }
  194. return styleMatch;
  195. });
  196. } else {
  197. // 如果不存在 style 属性,添加 style="width: 100%;"
  198. return match.replace(/<img/i, '<img style="width: 100%;"');
  199. }
  200. });
  201. // 使用正则表达式匹配和修改 p 标签的 style 属性
  202. this.courseInfo.content = this.courseInfo.content.replace(/<p([^>]*)>/gi, (match, attributes) => {
  203. // 检查是否已经存在 style 属性
  204. if (attributes.includes('style')) {
  205. // 如果存在 style 属性,添加新的样式
  206. return match.replace(/style="([^"]*)"/i, (styleMatch, styleContent) => {
  207. const newStyles = 'font-weight: 400; font-size: 24rpx; color: #666666; line-height: 36rpx;';
  208. if (!styleContent.includes(newStyles)) {
  209. return `style="${styleContent}; ${newStyles}"`;
  210. }
  211. return styleMatch;
  212. });
  213. } else {
  214. // 如果不存在 style 属性,添加 style 属性
  215. const newStyles = 'font-weight: 400; font-size: 24rpx; color: #666666; line-height: 36rpx;';
  216. return match.replace(/<p/i, `<p style="${newStyles}"`);
  217. }
  218. });
  219. }
  220. // 确保在数据更新后调用 setImgWidth
  221. this.$nextTick(() => {
  222. this.setImgWidth();
  223. });
  224. });
  225. },
  226. setImgWidth() {
  227. this.$nextTick(() => {
  228. if (this.$refs.courseContent) {
  229. const imgElements = this.$refs.courseContent.querySelectorAll('img');
  230. imgElements.forEach(img => {
  231. img.style.width = '100%';
  232. });
  233. } else {
  234. console.log(this.$refs)
  235. }
  236. });
  237. },
  238. getStyles(index=0) {
  239. let le =28
  240. let py=30
  241. if (this.entry_num%2==1){
  242. py+= 224/2-(84/2)-(le*Math.floor(this.entry_num / 2 ))-le/2
  243. }else{
  244. py+=224/2-(84/2)-(le*this.entry_num/2)
  245. }
  246. let right= index*le+py
  247. var newVar = {
  248. position: 'absolute',
  249. width: '84rpx',
  250. height: '84rpx',
  251. borderRadius: '84rpx',
  252. top: '30rpx',
  253. right: right+'rpx',
  254. };
  255. return newVar
  256. },
  257. toJump( index) {
  258. if(index==1){
  259. uni.switchTab({
  260. url:'/pages/home/index'
  261. });
  262. }else if(index==2){
  263. }
  264. },
  265. },
  266. };
  267. </script>
  268. <style lang="scss" scoped>
  269. .common-page {
  270. height: 100%;
  271. padding: 30rpx;
  272. }
  273. .huodong-ccontent {
  274. position: relative; /* 相对定位 */
  275. width: 650rpx;
  276. padding: 0rpx;
  277. margin: 30rpx auto;
  278. margin-bottom: 0;
  279. padding: 30rpx;
  280. background: #FFFFFF;
  281. border-radius: 16rpx 16rpx 16rpx 16rpx;
  282. }
  283. .course-content {
  284. margin-top: 30 rp;
  285. .course-title {
  286. font-family: PingFang SC, PingFang SC;
  287. font-weight: 400;
  288. font-size: 32rpx;
  289. color: #333333;
  290. line-height: 40rpx;
  291. text-align: left;
  292. font-style: normal;
  293. text-transform: none;
  294. font-weight: bold;
  295. margin-bottom: 16rpx;
  296. }
  297. .course-date {
  298. font-family: 苹方, 苹方;
  299. font-size: 26rpx;
  300. color: #666666;
  301. line-height: 40rpx;
  302. text-align: left;
  303. font-style: normal;
  304. text-transform: none;
  305. font-weight: 400;
  306. margin-bottom: 10rpx;
  307. display: flex;
  308. }
  309. .course-price {
  310. font-family: 苹方, 苹方;
  311. font-weight: 400;
  312. font-size: 24rpx;
  313. color: #666666;
  314. line-height: 40rpx;
  315. text-align: justify;
  316. font-style: normal;
  317. text-transform: none;
  318. display: flex;
  319. }
  320. }
  321. .bottom-navigation{
  322. position: fixed;
  323. // 文字垂直居中
  324. display: flex;
  325. align-items: center;
  326. justify-content: center;
  327. bottom: 0;
  328. height: 100rpx;
  329. width: calc(100% - 40rpx);
  330. background: #FFFFFF;
  331. box-shadow: 0rpx -2rpx 0rpx 0rpx #F1F3F6;
  332. border-radius: 24rpx 24rpx 0rpx 0rpx;
  333. border: 0rpx solid #979797;
  334. padding: 20rpx 20rpx 68rpx 20rpx ;
  335. &-div{
  336. height: 76rpx;
  337. width: 404rpx;
  338. padding-top: 10rpx;
  339. // 文字垂直居中
  340. display: flex;
  341. align-items: center;
  342. padding-left: 30rpx;
  343. span{
  344. font-family: PingFang SC, PingFang SC;
  345. font-weight: 400;
  346. font-size: 20rpx;
  347. color: #333333;
  348. line-height: 32rpx;
  349. text-align: left;
  350. font-style: normal;
  351. text-transform: none;
  352. }
  353. }
  354. .course-button {
  355. width: 264rpx;
  356. height: 80rpx;
  357. background: linear-gradient(315deg, #CA9359 0%, #E2B98E 100%);
  358. border-radius: 292rpx 292rpx 292rpx 292rpx;
  359. font-family: PingFang SC, PingFang SC;
  360. font-weight: 400;
  361. font-size: 28rpx;
  362. color: #FFFFFF;
  363. line-height: 36rpx;
  364. text-align: center;
  365. font-style: normal;
  366. text-transform: none;
  367. // 文字垂直居中
  368. display: flex;
  369. align-items: center;
  370. justify-content: center;
  371. }
  372. }
  373. /* 设置 v-html 渲染的内容中的 img 标签宽度为 100% */
  374. [v-html] img {
  375. width: 100%!important;
  376. }
  377. /* 定义 CSS 变量 */
  378. :root {
  379. --nav-bar-icon-color: black;
  380. --nav-bar-arrow-size: 16px;
  381. --tab-font-size: 28rpx;
  382. }
  383. .course-content-title {
  384. margin: 30rpx auto;
  385. width: 680rpx;
  386. // 垂直居中
  387. font-family: PingFang SC, PingFang SC;
  388. font-weight: 400;
  389. font-size: 28rpx;
  390. color: #333333;
  391. line-height: 40rpx;
  392. font-style: normal;
  393. text-transform: none;
  394. margin-bottom: 20rpx;
  395. // 加粗
  396. font-weight: bold;
  397. }
  398. /* 确保 van-nav-bar 内部的内容能够正确适应新的高度 */
  399. /deep/ .van-nav-bar__title {
  400. font-family: PingFang SC, PingFang SC !important;
  401. font-weight: 400 !important;
  402. font-size: 36rpx !important;
  403. color: #333333 !important;
  404. text-align: center;
  405. // 加粗
  406. // font-weight: bold;
  407. }
  408. /deep/ .van-nav-bar__content {
  409. text-align: center;
  410. }
  411. #course-content img{
  412. width: 100%!important;
  413. }
  414. /* 添加 van-tab 标题的字体大小样式 */
  415. /deep/ .van-tab__text {
  416. font-family: PingFang SC, PingFang SC;
  417. font-weight: 400;
  418. font-size: 28rpx;
  419. }
  420. </style>