teaching-case.vue 5.4 KB

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