courseDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. if (this.courseInfo.content) {
  183. this.courseInfo.content = this.courseInfo.content.replace(/\/apihttps:/g, 'https:');
  184. }
  185. // 修正 courseInfo.content 中的 src 属性值
  186. if (this.courseInfo.content) {
  187. this.courseInfo.content = this.courseInfo.content.replace(/\/apihttps:/g, 'https:');
  188. // 使用正则表达式匹配和修改 img 标签的 style 属性
  189. this.courseInfo.content = this.courseInfo.content.replace(/<img([^>]*)>/gi, (match, attributes) => {
  190. // 检查是否已经存在 style 属性
  191. if (attributes.includes('style')) {
  192. // 如果存在 style 属性,添加 width: 100%;
  193. return match.replace(/style="([^"]*)"/i, (styleMatch, styleContent) => {
  194. if (!styleContent.includes('width: 100%')) {
  195. return `style="${styleContent}; width: 100%;"`;
  196. }
  197. return styleMatch;
  198. });
  199. } else {
  200. // 如果不存在 style 属性,添加 style="width: 100%;"
  201. return match.replace(/<img/i, '<img style="width: 100%;"');
  202. }
  203. });
  204. // 使用正则表达式匹配和修改 p 标签的 style 属性
  205. this.courseInfo.content = this.courseInfo.content.replace(/<p([^>]*)>/gi, (match, attributes) => {
  206. // 检查是否已经存在 style 属性
  207. if (attributes.includes('style')) {
  208. // 如果存在 style 属性,添加新的样式
  209. return match.replace(/style="([^"]*)"/i, (styleMatch, styleContent) => {
  210. const newStyles = 'font-weight: 400; font-size: 24rpx; color: #666666; line-height: 36rpx;';
  211. if (!styleContent.includes(newStyles)) {
  212. return `style="${styleContent}; ${newStyles}"`;
  213. }
  214. return styleMatch;
  215. });
  216. } else {
  217. // 如果不存在 style 属性,添加 style 属性
  218. const newStyles = 'font-weight: 400; font-size: 24rpx; color: #666666; line-height: 36rpx;';
  219. return match.replace(/<p/i, `<p style="${newStyles}"`);
  220. }
  221. });
  222. }
  223. // 确保在数据更新后调用 setImgWidth
  224. this.$nextTick(() => {
  225. this.setImgWidth();
  226. });
  227. });
  228. },
  229. setImgWidth() {
  230. this.$nextTick(() => {
  231. if (this.$refs.courseContent) {
  232. const imgElements = this.$refs.courseContent.querySelectorAll('img');
  233. imgElements.forEach(img => {
  234. img.style.width = '100%';
  235. });
  236. } else {
  237. console.log(this.$refs)
  238. }
  239. });
  240. },
  241. getStyles(index=0) {
  242. let le =28
  243. let py=30
  244. if (this.entry_num%2==1){
  245. py+= 224/2-(84/2)-(le*Math.floor(this.entry_num / 2 ))-le/2
  246. }else{
  247. py+=224/2-(84/2)-(le*this.entry_num/2)
  248. }
  249. let right= index*le+py
  250. var newVar = {
  251. position: 'absolute',
  252. width: '84rpx',
  253. height: '84rpx',
  254. borderRadius: '84rpx',
  255. top: '30rpx',
  256. right: right+'rpx',
  257. };
  258. return newVar
  259. },
  260. toJump( index) {
  261. if(index==1){
  262. uni.switchTab({
  263. url:'/pages/home/index'
  264. });
  265. }else if(index==2){
  266. }
  267. },
  268. },
  269. };
  270. </script>
  271. <style lang="scss" scoped>
  272. .common-page {
  273. height: 100%;
  274. padding: 30rpx;
  275. }
  276. .huodong-ccontent {
  277. position: relative; /* 相对定位 */
  278. width: 650rpx;
  279. padding: 0rpx;
  280. margin: 30rpx auto;
  281. margin-bottom: 0;
  282. padding: 30rpx;
  283. background: #FFFFFF;
  284. border-radius: 16rpx 16rpx 16rpx 16rpx;
  285. }
  286. .course-content {
  287. margin-top: 30 rp;
  288. .course-title {
  289. font-family: PingFang SC, PingFang SC;
  290. font-weight: 400;
  291. font-size: 32rpx;
  292. color: #333333;
  293. line-height: 40rpx;
  294. text-align: left;
  295. font-style: normal;
  296. text-transform: none;
  297. font-weight: bold;
  298. margin-bottom: 16rpx;
  299. }
  300. .course-date {
  301. font-family: 苹方, 苹方;
  302. font-size: 26rpx;
  303. color: #666666;
  304. line-height: 40rpx;
  305. text-align: left;
  306. font-style: normal;
  307. text-transform: none;
  308. font-weight: 400;
  309. margin-bottom: 10rpx;
  310. display: flex;
  311. }
  312. .course-price {
  313. font-family: 苹方, 苹方;
  314. font-weight: 400;
  315. font-size: 24rpx;
  316. color: #666666;
  317. line-height: 40rpx;
  318. text-align: justify;
  319. font-style: normal;
  320. text-transform: none;
  321. display: flex;
  322. }
  323. }
  324. .bottom-navigation{
  325. position: fixed;
  326. // 文字垂直居中
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. bottom: 0;
  331. height: 100rpx;
  332. width: calc(100% - 40rpx);
  333. background: #FFFFFF;
  334. box-shadow: 0rpx -2rpx 0rpx 0rpx #F1F3F6;
  335. border-radius: 24rpx 24rpx 0rpx 0rpx;
  336. border: 0rpx solid #979797;
  337. padding: 20rpx 20rpx 68rpx 20rpx ;
  338. &-div{
  339. height: 76rpx;
  340. width: 404rpx;
  341. padding-top: 10rpx;
  342. // 文字垂直居中
  343. display: flex;
  344. align-items: center;
  345. padding-left: 30rpx;
  346. span{
  347. font-family: PingFang SC, PingFang SC;
  348. font-weight: 400;
  349. font-size: 20rpx;
  350. color: #333333;
  351. line-height: 32rpx;
  352. text-align: left;
  353. font-style: normal;
  354. text-transform: none;
  355. }
  356. }
  357. .course-button {
  358. width: 264rpx;
  359. height: 80rpx;
  360. background: linear-gradient(315deg, #CA9359 0%, #E2B98E 100%);
  361. border-radius: 292rpx 292rpx 292rpx 292rpx;
  362. font-family: PingFang SC, PingFang SC;
  363. font-weight: 400;
  364. font-size: 28rpx;
  365. color: #FFFFFF;
  366. line-height: 36rpx;
  367. text-align: center;
  368. font-style: normal;
  369. text-transform: none;
  370. // 文字垂直居中
  371. display: flex;
  372. align-items: center;
  373. justify-content: center;
  374. }
  375. }
  376. /* 设置 v-html 渲染的内容中的 img 标签宽度为 100% */
  377. [v-html] img {
  378. width: 100%!important;
  379. }
  380. /* 定义 CSS 变量 */
  381. :root {
  382. --nav-bar-icon-color: black;
  383. --nav-bar-arrow-size: 16px;
  384. --tab-font-size: 28rpx;
  385. }
  386. .course-content-title {
  387. margin: 30rpx auto;
  388. width: 680rpx;
  389. // 垂直居中
  390. font-family: PingFang SC, PingFang SC;
  391. font-weight: 400;
  392. font-size: 28rpx;
  393. color: #333333;
  394. line-height: 40rpx;
  395. font-style: normal;
  396. text-transform: none;
  397. margin-bottom: 20rpx;
  398. // 加粗
  399. font-weight: bold;
  400. }
  401. /* 确保 van-nav-bar 内部的内容能够正确适应新的高度 */
  402. /deep/ .van-nav-bar__title {
  403. font-family: PingFang SC, PingFang SC !important;
  404. font-weight: 400 !important;
  405. font-size: 36rpx !important;
  406. color: #333333 !important;
  407. text-align: center;
  408. // 加粗
  409. // font-weight: bold;
  410. }
  411. /deep/ .van-nav-bar__content {
  412. text-align: center;
  413. }
  414. #course-content img{
  415. width: 100%!important;
  416. }
  417. /* 添加 van-tab 标题的字体大小样式 */
  418. /deep/ .van-tab__text {
  419. font-family: PingFang SC, PingFang SC;
  420. font-weight: 400;
  421. font-size: 28rpx;
  422. }
  423. </style>