teaching-case.vue 5.9 KB

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