123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- <template>
- <view class="teaching_case">
- <view class="cont" @click="gotoWeb" v-for="(item, index) in acList" :key="index" :data-kid="item">
- <view class="starView" @click.stop="coll" :data-e="item">
- <image class="star" :src="collArr.includes(item.cid) ? pic_coll2 : pic_coll " mode="aspectFill"></image>
- </view>
- <image class="img" :src="item.img" mode="aspectFill" />
- <view class="tit btn-font">{{ item.ctit }}</view>
- <!-- <view class="teacher fz-font">{{ item.school }}</view> -->
- <view class="mon" v-if="indexId">
- ¥<text class="cost"></text>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: "teaching-case",
- props: {
- acList: {
- type: Array,
- default () {
- return [];
- },
- },
- indexId: {
- type: Number,
- default () {
- return 0;
- },
- },
- },
- data() {
- return {
- // 收藏列表
- collArr: [],
- // 节流阀
- stopTimer: 0,
- timer: null,
- animationDataArr: [],
- // 收藏星星
- pic_coll: 'https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/Vstar21707269669382.png',
- pic_coll2: 'https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/VStar1707269577778.png',
- };
- },
- methods: {
- // 收藏事件
- coll(event) {
- const value = this.$store.state.user.openid;
- if (!value) {
- uni.showToast({
- title: '未登录,请登录',
- icon: 'none'
- })
- setTimeout(this.goLog, 1000)
- return
- }
- if (this.stopTimer) return uni.showToast({
- icon: 'none',
- title: '点击过快'
- })
- this.stopTimer = 1
- setTimeout(() => {
- this.stopTimer = 0
- }, 500)
- // return console.log(event);
- let cId = event.currentTarget.dataset.e.cid
- // let type= event.currentTarget.dataset.e.type
- //判断是否收藏
- let iscoll = null
- // 查询是否收藏过
- let data = {
- cid: cId,
- oid: this.$store.state.user.openid, //用户id
- ty: 1
- }
- this.$request('/selectOneOperator', 'POST', data).then(res => {
- // console.log('查询是否收藏过',res);
- res[0].length ? iscoll = true : iscoll = false;
- // iscoll为true表示已经收藏过,执行删除 为true则收藏
- if (iscoll) {
- // console.log('执行删除');
- // this.animationDataArr.push({
- // collAoff: 0
- // })
- this.$store.dispatch('asyncUpdatemsg', {
- collAoff: 0
- })
- this.$request('/deleteOperator', 'POST', data).then(res => {
- this.getdata()
- setTimeout(() => {
- // this.animationDataArr.shift()
- // console.log(this.animationDataArr);
- this.$store.dispatch('asyncDelMsg')
- }, 1500)
- })
- } else {
- // console.log('执行添加');
- // this.animationDataArr.push({
- // collAoff: 1
- // })
- this.$store.dispatch('asyncUpdatemsg', {
- collAoff: 1
- })
- this.$request('/insertOperator', 'POST', data).then(res => {
- this.getdata()
- setTimeout(() => {
- // this.animationDataArr.shift()
- this.$store.dispatch('asyncDelMsg')
- // console.log(this.animationDataArr);
- }, 1500)
- })
- }
- })
- },
- // 收藏
- // coll() {
- // uni.showToast({
- // title:'暂时无法收藏哦',
- // icon:"none"
- // })
- // },
- // 查看课程内容
- gotoWeb(e) {
- const value = this.$store.state.user.openid;
- if (!value) {
- uni.showToast({
- title: '未登录,请登录',
- icon: 'none'
- })
- setTimeout(this.goLog, 1000)
- return
- }
- // return console.log('aaaaaa', e.currentTarget.dataset);
- let data = e.currentTarget.dataset.kid
- // console.log(data);
- uni.navigateTo({
- // url: "/pages/skipone/skipone?item='+ encodeURIComponent(JSON.stringify(item))"
- url: "/pages/skipone/skipone?item="+encodeURIComponent(JSON.stringify(data))
- });
- },
- // 获取课程收藏事件
- getdata() {
- const value = this.$store.state.user.openid;
- if (!value) return this.collArr = []
- // 触发收藏事件
- // console.log('触发收藏事件');
- let data = {
- oid: this.$store.state.user.openid, //用户id
- type: 1
- }
- this.$request('/selectCollClassList', 'POST', data).then(res => {
- // console.log('获取收藏', res);
- // 每次调用前清零,防止push叠加错误
- this.collArr = []
- // 将acid遍历到collArr中
- res[0].forEach(i => {
- this.collArr.push(i.cid)
- })
- // console.log(this.collArr);
- })
- },
- goLog() {
- uni.navigateTo({
- url: "/pages/login_Wechat/login_Wechat",
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .teaching_case {
- width: 100%;
- padding: 10px 30rpx;
- display: flex;
- flex-wrap: wrap;
- justify-content: space-between;
- // margin-bottom: 50px;
- // background-color: #000;
- .cont {
- background-color: #ffffff;
- width: calc(50% - 8px);
- padding: 20rpx 15rpx;
- border-radius: 10px;
- margin-bottom: 16px;
- position: relative;
- .starView {
- width: 40rpx;
- height: 40rpx;
- box-sizing: content-box;
- padding-bottom: 10rpx;
- padding-left: 10rpx;
- position: absolute;
- right: 20rpx;
- top: 20rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .star {
- // position: absolute;
- // right: 30rpx;
- // top: 30rpx;
- width: 30rpx;
- height: 30rpx;
- }
- .img {
- width: 100%;
- height: 170rpx;
- border-radius: 10rpx;
- }
- .tit {
- width: 257rpx;
- margin: 10rpx 0;
- font-weight: bold;
- white-space: normal;
- display: -webkit-box;
- word-break: break-all;
- text-overflow: ellipsis;
- overflow: hidden;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- /*设置 需要显示的行数*/
- }
- .teacher {
- color: #999999;
- }
- .mon {
- font-size: 34rpx;
- color: rgba(246, 135, 23, 1);
- font-weight: 34rpx;
- margin-top: 10rpx;
- .cost {
- font-weight: 40rpx;
- }
- }
- }
- // }
- }
- </style>
|