teaching-case.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="teaching_case">
  3. <view class="cont" @click="gotoWeb" v-for="(item, index) in acList" :key="index"
  4. :data-kid="item.href">
  5. <image class="star" :src="collArr.includes(item.cid) ? pic_coll2 : pic_coll " @click.stop="coll" :data-e="item"
  6. mode="aspectFill"></image>
  7. <image class="img" :src="item.img" mode="aspectFill" />
  8. <view class="tit btn-font">{{ item.ctit }}</view>
  9. <view class="teacher fz-font">{{ item.school }}</view>
  10. <view class="mon" v-if="indexId">
  11. ¥<text class="cost"></text>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. name: "teaching-case",
  19. props: {
  20. acList: {
  21. type: Array,
  22. default () {
  23. return [];
  24. },
  25. },
  26. indexId: {
  27. type: Number,
  28. default () {
  29. return 0;
  30. },
  31. },
  32. },
  33. data() {
  34. return {
  35. // 收藏列表
  36. collArr: [],
  37. // 收藏星星
  38. pic_coll: 'https://teacherapi.cocorobo.cn/teaching-file/static/Stara.png',
  39. pic_coll2: 'https://teacherapi.cocorobo.cn/teaching-file/static/mine/Collect_yellow.png',
  40. };
  41. },
  42. methods: {
  43. // 收藏事件
  44. coll(event) {
  45. const value = this.$store.state.user.openid;
  46. if(!value){
  47. uni.showToast({title: '未登录,请登录',icon: 'none'})
  48. setTimeout(this.goLog,1000)
  49. return
  50. }
  51. // return console.log(event);
  52. let cId = event.currentTarget.dataset.e.cid
  53. // let type= event.currentTarget.dataset.e.type
  54. //判断是否收藏
  55. let iscoll = null
  56. // 查询是否收藏过
  57. let data = {
  58. cid: cId,
  59. oid: this.$store.state.user.openid, //用户id
  60. ty: 1
  61. }
  62. this.$request('/selectOneOperator', 'POST', data).then(res => {
  63. // console.log('查询是否收藏过',res);
  64. res[0].length ? iscoll = true : iscoll = false;
  65. // iscoll为true表示已经收藏过,执行删除 为true则收藏
  66. if (iscoll) {
  67. console.log('执行删除');
  68. this.$request('/deleteOperator', 'POST', data).then(res => {
  69. this.getdata()
  70. })
  71. } else {
  72. console.log('执行添加');
  73. this.$request('/insertOperator', 'POST', data).then(res => {
  74. this.getdata()
  75. })
  76. }
  77. })
  78. },
  79. // 收藏
  80. // coll() {
  81. // uni.showToast({
  82. // title:'暂时无法收藏哦',
  83. // icon:"none"
  84. // })
  85. // },
  86. // 查看课程内容
  87. gotoWeb(e) {
  88. const value = this.$store.state.user.openid;
  89. if(!value){
  90. uni.showToast({title: '未登录,请登录',icon: 'none'})
  91. setTimeout(this.goLog,1000)
  92. return
  93. }
  94. // return console.log('aaaaaa', e.currentTarget.dataset);
  95. let acid = e.currentTarget.dataset.kid
  96. uni.navigateTo({
  97. url: "/pages/skipone/skipone?url=" + encodeURIComponent(acid),
  98. });
  99. },
  100. // 获取课程收藏事件
  101. getdata() {
  102. const value = this.$store.state.user.openid;
  103. if(!value) return this.collArr = []
  104. // 触发收藏事件
  105. // console.log('触发收藏事件');
  106. let data = {
  107. oid: this.$store.state.user.openid, //用户id
  108. type: 1
  109. }
  110. this.$request('/selectCollClassList', 'POST', data).then(res => {
  111. console.log('获取收藏', res);
  112. // 每次调用前清零,防止push叠加错误
  113. this.collArr = []
  114. // 将acid遍历到collArr中
  115. res[0].forEach(i => {
  116. this.collArr.push(i.cid)
  117. })
  118. // console.log(this.collArr);
  119. })
  120. },
  121. goLog() {
  122. uni.navigateTo({
  123. url: "/pages/login_Wechat/login_Wechat",
  124. });
  125. },
  126. },
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. .teaching_case {
  131. width: 100%;
  132. padding: 10px 30rpx;
  133. display: flex;
  134. flex-wrap: wrap;
  135. justify-content: space-between;
  136. // margin-bottom: 50px;
  137. // background-color: #000;
  138. .cont {
  139. background-color: #ffffff;
  140. width: 332rpx;
  141. padding: 20rpx 15rpx;
  142. border-radius: 10px;
  143. margin-bottom: 20rpx;
  144. position: relative;
  145. .star {
  146. position: absolute;
  147. right: 30rpx;
  148. top: 30rpx;
  149. width: 30rpx;
  150. height: 30rpx;
  151. }
  152. .img {
  153. width: 300rpx;
  154. height: 170rpx;
  155. border-radius: 10rpx;
  156. }
  157. .tit {
  158. width: 257rpx;
  159. margin: 10rpx 0;
  160. font-weight: bold;
  161. white-space: normal;
  162. display: -webkit-box;
  163. word-break: break-all;
  164. text-overflow: ellipsis;
  165. overflow: hidden;
  166. -webkit-box-orient: vertical;
  167. -webkit-line-clamp: 2;
  168. /*设置 需要显示的行数*/
  169. }
  170. .teacher {
  171. color: #999999;
  172. }
  173. .mon {
  174. font-size: 34rpx;
  175. color: rgba(246, 135, 23, 1);
  176. font-weight: 34rpx;
  177. margin-top: 10rpx;
  178. .cost {
  179. font-weight: 40rpx;
  180. }
  181. }
  182. }
  183. // }
  184. }
  185. </style>