teaching-case.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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.navigateTo({
  48. url: "/pages/login_Wechat/login_Wechat",
  49. });
  50. return
  51. }
  52. // return console.log(event);
  53. let cId = event.currentTarget.dataset.e.cid
  54. // let type= event.currentTarget.dataset.e.type
  55. //判断是否收藏
  56. let iscoll = null
  57. // 查询是否收藏过
  58. let data = {
  59. cid: cId,
  60. oid: this.$store.state.user.openid, //用户id
  61. ty: 1
  62. }
  63. this.$request('/selectOneOperator', 'POST', data).then(res => {
  64. // console.log('查询是否收藏过',res);
  65. res[0].length ? iscoll = true : iscoll = false;
  66. // iscoll为true表示已经收藏过,执行删除 为true则收藏
  67. if (iscoll) {
  68. console.log('执行删除');
  69. this.$request('/deleteOperator', 'POST', data).then(res => {
  70. this.getdata()
  71. })
  72. } else {
  73. console.log('执行添加');
  74. this.$request('/insertOperator', 'POST', data).then(res => {
  75. this.getdata()
  76. })
  77. }
  78. })
  79. },
  80. // 收藏
  81. // coll() {
  82. // uni.showToast({
  83. // title:'暂时无法收藏哦',
  84. // icon:"none"
  85. // })
  86. // },
  87. // 查看课程内容
  88. gotoWeb(e) {
  89. const value = this.$store.state.user.openid;
  90. if (value == '') {
  91. uni.navigateTo({
  92. url: "/pages/login_Wechat/login_Wechat",
  93. });
  94. return
  95. }
  96. // return console.log('aaaaaa', e.currentTarget.dataset);
  97. let acid = e.currentTarget.dataset.kid
  98. uni.navigateTo({
  99. url: "/pages/skipone/skipone?url=" + encodeURIComponent(acid),
  100. });
  101. },
  102. // 获取课程收藏事件
  103. getdata() {
  104. // 触发收藏事件
  105. // console.log('触发收藏事件');
  106. let data = {
  107. oid: this.$store.state.user.openid, //用户id
  108. type: 1
  109. }
  110. this.$request('/selectOperatorTech', '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. },
  122. };
  123. </script>
  124. <style lang="scss" scoped>
  125. .teaching_case {
  126. width: 100%;
  127. padding: 10px 30rpx;
  128. display: flex;
  129. flex-wrap: wrap;
  130. justify-content: space-between;
  131. margin-bottom: 50px;
  132. // background-color: #000;
  133. .cont {
  134. background-color: #ffffff;
  135. width: 332rpx;
  136. padding: 20rpx 15rpx;
  137. border-radius: 10px;
  138. margin-bottom: 20rpx;
  139. position: relative;
  140. .star {
  141. position: absolute;
  142. right: 30rpx;
  143. top: 30rpx;
  144. width: 30rpx;
  145. height: 30rpx;
  146. }
  147. .img {
  148. width: 300rpx;
  149. height: 170rpx;
  150. border-radius: 10rpx;
  151. }
  152. .tit {
  153. width: 257rpx;
  154. margin: 10rpx 0;
  155. font-weight: bold;
  156. white-space: normal;
  157. display: -webkit-box;
  158. word-break: break-all;
  159. text-overflow: ellipsis;
  160. overflow: hidden;
  161. -webkit-box-orient: vertical;
  162. -webkit-line-clamp: 2;
  163. /*设置 需要显示的行数*/
  164. }
  165. .teacher {
  166. color: #999999;
  167. }
  168. .mon {
  169. font-size: 34rpx;
  170. color: rgba(246, 135, 23, 1);
  171. font-weight: 34rpx;
  172. margin-top: 10rpx;
  173. .cost {
  174. font-weight: 40rpx;
  175. }
  176. }
  177. }
  178. // }
  179. }
  180. </style>