detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <view>
  3. <nav-bar title="题库详情"></nav-bar>
  4. <view style="background-color: #FFFFFF;">
  5. <view>
  6. <image :src="$method.splitImgHost(goodsData.coverUrl, true)" style="width: 100%;"></image>
  7. <view style="padding:20rpx">
  8. <view style="display: flex;margin-top: 13rpx;">
  9. <view class="yearTag" v-if="goodsData.year">{{ goodsData.year }}</view>
  10. <view class="titleTag">{{ goodsData.goodsName }}</view>
  11. </view>
  12. <!-- <view style="display: flex;justify-content: space-between;margin-top: 13rpx;" v-if="false">
  13. <view class="noteTag"><image src="/static/icon/wk_icon1.png" class="wk_icon"></image>
  14. 共 <text class="blackFont">{{goodsData.updateTime}}</text> 张卷 <text class="blackFont">1200</text> 道题 </view>
  15. </view> -->
  16. </view>
  17. </view>
  18. <u-line color="#D6D6DB" />
  19. <view>
  20. <view><u-tabs :list="list" item-width="50%" font-size="30" bar-width="24" :current="current" @change="change" active-color="#007AFF"></u-tabs></view>
  21. </view>
  22. <u-line color="#D6D6DB" />
  23. </view>
  24. <view class="intro" v-if="current == 0">
  25. <view v-if="goodsData.mobileDetailHtml" class="content" style="padding:10rpx;"><rich-text :nodes="goodsData.mobileDetailHtml"></rich-text></view>
  26. </view>
  27. <view class="title-list" v-if="current == 1">
  28. <view class="content">
  29. <view class="list" v-for="(item1, index1) in bankList" :key="index1">
  30. <template v-if="item1.type == 1">
  31. <view class="moduleItem" @click="clickModule(index1,item1.majorId)">
  32. <view class="courseName">{{ item1.name }}</view>
  33. <view>
  34. <image src="/static/icon/up.png" class="icon_up" v-if="!item1.showList"></image>
  35. <image src="/static/icon/down.png" class="icon_up" v-if="item1.showList"></image>
  36. </view>
  37. </view>
  38. <template v-if="item1.showList">
  39. <view v-for="(item2, index2) in item1.list" :key="index2">
  40. <view class="section" @click="changeItem(index1,index2,item2.chapterExamId,item1.type)">
  41. <image src="/static/icon/down1.png" class="icon_up" v-if="item2.showList"></image>
  42. <image src="/static/icon/up1.png" class="icon_up" v-if="!item2.showList"></image>
  43. <!-- <u-icon v-if="!item2.showList" name="arrow-up"></u-icon>
  44. <u-icon v-if="item2.showList" name="arrow-down"></u-icon> -->
  45. <text style="margin-left:34rpx;">{{ item2.name }}</text>
  46. </view>
  47. <view class="article-list" v-if="item2.showList">
  48. <view class="article" :class="{ active: showTest(article.examId) }" v-for="(article, index3) in item2.list" :key="index3">
  49. <view class="flex_auto">{{ article.examName }}</view>
  50. <view class="btn" @click="goTest(item1.type,article)" v-if="showTest(article.examId)">试做</view>
  51. </view>
  52. </view>
  53. <u-line></u-line>
  54. </view>
  55. </template>
  56. </template>
  57. <template v-if="item1.type == 2">
  58. <view class="section" @click="changeItem(index1,'',item1.majorId,item1.type)" >
  59. <image src="/static/icon/down1.png" class="icon_up" v-if="item1.showList"></image>
  60. <image src="/static/icon/up1.png" class="icon_up" v-if="!item1.showList"></image>
  61. <!-- <u-icon v-if="!item1.showList" name="arrow-up"></u-icon>
  62. <u-icon v-if="item1.showList" name="arrow-down"></u-icon> -->
  63. <text style="margin-left:34rpx;">{{ item1.name }}</text>
  64. </view>
  65. <view class="article-list" v-if="item1.showList" >
  66. <view class="article" :class="{active:showTest(article.examId)}" :key="index2" v-for="(article,index2) in item1.list">
  67. <view class="flex_auto">{{article.examName}}</view>
  68. <view class="btn" @click="goTest(item1.type,article)" v-if="showTest(article.examId)">试做</view>
  69. </view>
  70. </view>
  71. </template>
  72. <template v-if="item1.type == 3">
  73. <view class="article" :class="{ active: showTest(item1.majorId) }">
  74. <view class="flex_auto">{{ item1.name }}</view>
  75. <view class="btn" @click="goTest(item1.type,item1)" v-if="showTest(item1.majorId)">试做</view>
  76. </view>
  77. </template>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="bottomBox" v-if="!hideBuyState">
  82. <view class="priceTag">¥ {{ toFixed(goodsData.standPrice) }}</view>
  83. <view style="display: flex;color: #FFFFFF;align-items: center;">
  84. <view class="btn1" @click="addCart">加购物车</view>
  85. <view class="btn2" @click="buy">立即购买</view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. // import { websocket } from '@/common/socket.js';
  92. import { mapGetters } from 'vuex';
  93. export default {
  94. data() {
  95. return {
  96. list: [
  97. {
  98. name: '详情'
  99. },
  100. {
  101. name: '大纲'
  102. }
  103. ],
  104. current: 0,
  105. id: '',
  106. goodsData: {},
  107. bankList: [],
  108. goodsExamConfig: []
  109. };
  110. },
  111. filters: {
  112. formatDate: function(value) {
  113. var date = new Date(value); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  114. var Y = date.getFullYear();
  115. return Y;
  116. }
  117. },
  118. onUnload() {},
  119. computed: { ...mapGetters(['userInfo','hideBuyState']) },
  120. onLoad(option) {
  121. this.id = option.id;
  122. this.getDetail();
  123. this.goodsBankList();
  124. },
  125. onShow() {},
  126. methods: {
  127. toFixed(number) {
  128. if(number) {
  129. return number.toFixed(2)
  130. } else {
  131. return '0.00'
  132. }
  133. },
  134. getDetail() {
  135. this.$api.commonGoodsDetail(this.id).then(res => {
  136. if (res.data.data.mobileDetailHtml) {
  137. res.data.data.mobileDetailHtml = res.data.data.mobileDetailHtml.replace(/<img/gi, '<img style="max-width:100%;"');
  138. }
  139. this.goodsData = res.data.data;
  140. this.goodsExamConfig = JSON.parse(res.data.data.goodsExamConfig);
  141. });
  142. },
  143. goodsBankList() {
  144. this.$api
  145. .goodsBankList({
  146. goodsId: this.id
  147. })
  148. .then(res => {
  149. console.log(res);
  150. this.bankList = res.data.data;
  151. this.showAllCharpter();
  152. });
  153. },
  154. /**
  155. * 展示第一个章下的节内容
  156. */
  157. showAllCharpter() {
  158. for(let i = 0; i < this.bankList.length; i++) {
  159. if(this.bankList[i].type == 1) { //第一个是模块直接展开,再展开章下面的节
  160. this.$api
  161. .goodsChapterList({
  162. moduleExamId: this.bankList[i].majorId
  163. })
  164. .then(res => {
  165. this.$set(this.bankList[i], 'showList', true);
  166. this.$set(this.bankList[i], 'list', res.data.data);
  167. this.changeItem(i,0,this.bankList[i].list[0].chapterExamId,this.bankList[i].type)
  168. });
  169. break;
  170. } else if(this.bankList[i].type == 2) { //第一个章展开下面的节
  171. this.changeItem(i,'',this.bankList[i].majorId,this.bankList[i].type)
  172. break;
  173. }
  174. }
  175. },
  176. goodsChapterList(bank, id) {
  177. this.$api
  178. .goodsChapterList({
  179. moduleExamId: id
  180. })
  181. .then(res => {
  182. this.$set(bank, 'list', res.data.data);
  183. });
  184. },
  185. goTest(type,item) {
  186. if(type == 1) {
  187. uni.setStorageSync('testname',item.examName)
  188. uni.navigateTo({
  189. url:'/pages2/bank/questionBankTest?id=' + item.examId + '&num=' + this.showTest(item.examId).num
  190. })
  191. } else if(type == 2) {
  192. uni.setStorageSync('testname',item.examName)
  193. uni.navigateTo({
  194. url:'/pages2/bank/questionBankTest?id='+item.examId+'&num='+ this.showTest(item.examId).num
  195. })
  196. } else if(type == 3) {
  197. uni.setStorageSync('testname',item.name)
  198. uni.navigateTo({
  199. url:'/pages2/bank/questionBankTest?id=' + item.majorId + '&num=' + this.showTest(item.majorId).num
  200. })
  201. }
  202. },
  203. showTest(id) {
  204. return this.goodsExamConfig.find(item => item.examId == id);
  205. },
  206. clickModule(index,id) {
  207. if (this.bankList[index].list) {
  208. this.$set(this.bankList[index], 'showList', !this.bankList[index].showList);
  209. return;
  210. }
  211. this.$api
  212. .goodsChapterList({
  213. moduleExamId: id
  214. })
  215. .then(res => {
  216. this.$set(this.bankList[index], 'showList', true);
  217. this.$set(this.bankList[index], 'list', res.data.data);
  218. });
  219. },
  220. buy() {
  221. if (this.$method.isGoLogin()) {
  222. return;
  223. }
  224. this.$navTo.togo('/pages2/order/confirm_list?id=' + this.id);
  225. },
  226. addCart() {
  227. if (this.$method.isGoLogin()) {
  228. return;
  229. }
  230. let self = this;
  231. this.$api.addCart({ goodsId: this.id }).then(res => {
  232. if (res.data.code == 200) {
  233. uni.setStorageSync('updateCart', 1); //提醒刷新购物车
  234. uni.showToast({
  235. title: '添加成功'
  236. });
  237. } else {
  238. this.$u.toast(res.data.msg);
  239. }
  240. });
  241. },
  242. open(item) {
  243. item.showChildren = !item.showChildren;
  244. },
  245. change(index) {
  246. this.current = index;
  247. },
  248. changeItem(index1,index2,id,type) {
  249. if (type == 1) {
  250. console.log(1)
  251. if (this.bankList[index1].list[index2].list) {
  252. this.$set(this.bankList[index1].list[index2], 'showList', !this.bankList[index1].list[index2].showList);
  253. return;
  254. }
  255. this.$api
  256. .goodsExamList({
  257. chapterExamId: id
  258. })
  259. .then(res => {
  260. this.$set(this.bankList[index1].list[index2], 'showList', true);
  261. this.$set(this.bankList[index1].list[index2], 'list', res.data.data);
  262. });
  263. } else if (type == 2) {
  264. console.log(2)
  265. if (this.bankList[index1].list) {
  266. this.$set(this.bankList[index1], 'showList', !this.bankList[index1].showList);
  267. return;
  268. }
  269. this.$api
  270. .goodsExamList({
  271. chapterExamId: id
  272. })
  273. .then(res => {
  274. this.$set(this.bankList[index1], 'showList', true);
  275. this.$set(this.bankList[index1], 'list', res.data.data);
  276. });
  277. }
  278. }
  279. }
  280. };
  281. </script>
  282. <style>
  283. page {
  284. background-color: #eaeef1;
  285. }
  286. </style>
  287. <style lang="scss" scope>
  288. .courseName {
  289. white-space: nowrap;
  290. overflow: hidden;
  291. text-overflow: ellipsis;
  292. }
  293. .icon_up {
  294. width: 32rpx;
  295. height: 32rpx;
  296. }
  297. .intro {
  298. background: #eaeef1;
  299. padding: 16rpx 16rpx 124rpx;
  300. .content {
  301. background: #fff;
  302. border-radius: 16rpx;
  303. .top {
  304. border-radius: 16rpx;
  305. padding: 32rpx 28rpx 16rpx;
  306. font-size: 30rpx;
  307. color: #333333;
  308. }
  309. .img {
  310. width: 100%;
  311. }
  312. }
  313. }
  314. .moduleItem {
  315. height: 80rpx;
  316. color: #333333;
  317. font-size: 32rpx;
  318. line-height: 80rpx;
  319. font-weight: bold;
  320. display: flex;
  321. justify-content: space-between;
  322. }
  323. .title-list {
  324. background: #eaeef1;
  325. padding: 16rpx 16rpx 124rpx;
  326. .content {
  327. .list {
  328. background: #fff;
  329. margin-bottom: 30rpx;
  330. overflow: hidden;
  331. border-radius: 16rpx;
  332. padding: 10rpx 16rpx;
  333. .module {
  334. font-size: 32rpx;
  335. color: #333333;
  336. .icon {
  337. margin-right: 10rpx;
  338. }
  339. }
  340. .section {
  341. font-size: 30rpx;
  342. color: #333;
  343. white-space: nowrap;
  344. overflow: hidden;
  345. text-overflow: ellipsis;
  346. margin: 20rpx 0;
  347. display: flex;
  348. align-items: center;
  349. }
  350. .article-list {
  351. margin-top:20rpx;
  352. }
  353. .article {
  354. padding:10rpx 0;
  355. min-height: 80rpx;
  356. display: flex;
  357. align-items: center;
  358. margin-left: 64rpx;
  359. font-size: 30rpx;
  360. color: #666666;
  361. border-bottom: 1rpx solid #eeeeee;
  362. display: flex;
  363. .flex_auto {
  364. flex: 1;
  365. }
  366. &:nth-last-of-type(1) {
  367. border: 0;
  368. }
  369. &.active {
  370. color: #007aff;
  371. .btn {
  372. width: 96rpx;
  373. height: 48rpx;
  374. line-height: 48rpx;
  375. text-align: center;
  376. color: #fff;
  377. font-size: 30rpx;
  378. border-radius: 24rpx;
  379. background: #007aff;
  380. margin-left: 36rpx;
  381. border-radius: 24rpx;
  382. }
  383. }
  384. }
  385. }
  386. }
  387. }
  388. .btn2 {
  389. width: 200rpx;
  390. height: 64rpx;
  391. background: linear-gradient(0deg, #ffb102, #fd644f);
  392. box-shadow: 0rpx 10rpx 16rpx 4rpx rgba(1, 99, 235, 0.04);
  393. border-radius: 32rpx;
  394. line-height: 64rpx;
  395. text-align: center;
  396. }
  397. .btn1 {
  398. width: 200rpx;
  399. height: 64rpx;
  400. background: linear-gradient(0deg, #015eea, #00c0fa);
  401. border-radius: 32rpx;
  402. line-height: 64rpx;
  403. text-align: center;
  404. margin-right: 20rpx;
  405. }
  406. .bottomBox {
  407. position: fixed;
  408. bottom: 0;
  409. width: 100%;
  410. left: 0;
  411. height: 98rpx;
  412. background-color: #ffffff;
  413. display: flex;
  414. justify-content: space-between;
  415. align-items: center;
  416. padding: 0 30rpx;
  417. }
  418. .blackFont {
  419. color: #333333;
  420. margin: 0 4rpx;
  421. }
  422. .wk_icon {
  423. width: 24rpx;
  424. height: 24rpx;
  425. margin-right: 12rpx;
  426. }
  427. .noteTag {
  428. ont-size: 24rpx;
  429. font-family: PingFang SC;
  430. font-weight: 500;
  431. color: #999999;
  432. align-items: center;
  433. }
  434. .priceTag {
  435. font-size: 30rpx;
  436. font-family: PingFang SC;
  437. font-weight: bold;
  438. color: #ff2d55;
  439. }
  440. .titleTag {
  441. font-size: 32rpx;
  442. font-weight: bold;
  443. color: #333333;
  444. margin-left: 8rpx;
  445. }
  446. .yearTag {
  447. width: 80rpx;
  448. height: 32rpx;
  449. background: #ebf5ff;
  450. border: 2rpx solid #007aff;
  451. border-radius: 16rpx;
  452. font-size: 24rpx;
  453. color: #007aff;
  454. text-align: center;
  455. line-height: 32rpx;
  456. }
  457. .itemBox {
  458. background: #ffffff;
  459. box-shadow: 0rpx 10rpx 9rpx 1rpx rgba(165, 196, 239, 0.1);
  460. border-radius: 24rpx;
  461. width: 100%;
  462. padding: 20rpx;
  463. margin-bottom: 20rpx;
  464. }
  465. </style>