listBlock1.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="" >
  3. <view class="listBlock1" v-for="(i,index) in classList" :key="index+'a'">
  4. <view class="img cell-img">
  5. <image :src="i.pic" mode="aspectFill"></image>
  6. </view>
  7. <view class="right">
  8. <view class="">
  9. <view class="title">
  10. <view class="tag bqZ-font">类型</view>
  11. <text class="btn-font" style="">
  12. {{i.acName}}
  13. </text>
  14. </view>
  15. <view class="introduce fwb-font">
  16. {{ i.brief }}
  17. </view>
  18. </view>
  19. <view class="operate">
  20. <view class="left">
  21. <view class="opr" style="padding-right: 25rpx" @click="coll" :data-e="i">
  22. <view class="icon">
  23. <image :src="collArr.includes(i.acId) ? pic2 : pic "
  24. style="width: 28rpx; height: 26rpx" mode="aspectFill"></image>
  25. </view>
  26. <text class="fz-font">收藏</text>
  27. </view>
  28. <view class="opr">
  29. <view class="icon">
  30. <image src="http://43.139.158.220:5007/img/static/yym/Vector (Stroke).png"
  31. style="width: 22rpx; height: 26rpx" mode="aspectFill"></image>
  32. </view>
  33. <text class="fz-font">订阅</text>
  34. </view>
  35. </view>
  36. <view class="">
  37. <button class="btn sBtn-font" @click.stop="join">
  38. 立即参与
  39. </button>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. name:"listBlock1",
  49. props: {
  50. classList: {
  51. type: Array,
  52. default () {
  53. return [];
  54. },
  55. }
  56. },
  57. // props:['classList'],
  58. data() {
  59. return {
  60. collArr:[],
  61. // collArr.includes(i.acId) ? 'http://43.139.158.220:5007/img/static/yym/Star 1 (Stroke).png' : 'http://43.139.158.220:5007/img/static/yym/Vector (Stroke).png'
  62. pic:'http://43.139.158.220:5007/img/static/yym/Star 1 (Stroke).png',
  63. pic2:'https://teacherapi.cocorobo.cn/teaching-file/static//mine/Collect_yellow.png'
  64. };
  65. },
  66. methods:{
  67. // 收藏事件
  68. coll(event){
  69. // console.log(event.currentTarget.dataset.e);
  70. console.log(this.$store.state.user.openid);
  71. let aId=event.currentTarget.dataset.e.acId
  72. // 先获取用户收藏信息
  73. let data={
  74. oid:this.$store.state.user.openid, //用户id
  75. }
  76. this.$request('/selectColl','POST',data).then(res=>{
  77. // console.log('获取收藏信息',res);
  78. // return console.log('获取收藏信息',res[0][0].coll=='');
  79. let res2
  80. let colls
  81. if(res[0][0].coll!==null && res[0][0].coll !==""){
  82. colls=JSON.parse(res[0][0].coll)
  83. console.log('获取收藏信息',colls);
  84. // 判断收藏表是否包含这个活动
  85. res2 = colls.some((e)=>{
  86. return e == aId
  87. })
  88. // console.log(res2);
  89. }
  90. // return console.log('2',res2);
  91. // 第一次存储返回值为null,然后存储收藏
  92. if(res[0][0].coll==null || res[0][0].coll==""){
  93. // 然后进行存储活动到用户coll字段
  94. let arr={
  95. oid:this.$store.state.user.openid, //用户id
  96. acid:JSON.stringify([aId])
  97. }
  98. this.$request('/updateColl','POST',arr).then(res=>{
  99. this.$request('/selectColl','POST',data).then(res=>{
  100. this.collArr=JSON.parse(res[0][0].coll)
  101. })
  102. })
  103. // 当数组中没有这个收藏活动时添加收藏
  104. }else if(!res2){
  105. colls.push(aId)
  106. let arr2={
  107. oid:this.$store.state.user.openid, //用户id
  108. acid:JSON.stringify(colls)
  109. }
  110. this.$request('/updateColl','POST',arr2).then(res=>{
  111. this.$request('/selectColl','POST',data).then(res=>{
  112. this.collArr=JSON.parse(res[0][0].coll)
  113. })
  114. })
  115. // 取消收藏
  116. }else if(res2){
  117. const newArray = colls.filter(item => item !== aId);
  118. let arr3={
  119. oid:this.$store.state.user.openid, //用户id
  120. acid:JSON.stringify(newArray)
  121. }
  122. this.$request('/updateColl','POST',arr3).then(res=>{
  123. this.$request('/selectColl','POST',data).then(res=>{
  124. this.collArr=JSON.parse(res[0][0].coll)
  125. })
  126. })
  127. }
  128. })
  129. },
  130. join() {
  131. const value = this.$store.state.user.openid;
  132. if (value == '') {
  133. uni.navigateTo({
  134. url: "/pages/login_Wechat/login_Wechat",
  135. });
  136. return 1;
  137. } else {
  138. //推荐课程
  139. const urls = [
  140. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00351166273N",
  141. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00330324841N",
  142. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00231455802N",
  143. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00406339964N",
  144. ];
  145. let index = this.indexId;
  146. if (index >= 0 && index < urls.length) {
  147. const url = urls[index];
  148. uni.navigateTo({
  149. url: "/pages/skipone/skipone?url=" + encodeURIComponent(url),
  150. });
  151. }
  152. }
  153. },
  154. getdata(){
  155. let data={
  156. oid:this.$store.state.user.openid, //用户id
  157. }
  158. this.$request('/selectColl','POST',data).then(res=>{
  159. this.collArr=JSON.parse(res[0][0].coll)
  160. console.log('进来就显示',this.collArr);
  161. })
  162. }
  163. },
  164. // created () {
  165. // this.getdata()
  166. // }
  167. }
  168. </script>
  169. <style lang="scss">
  170. .listBlock1{
  171. display: flex;
  172. justify-content: space-between;
  173. // margin-bottom: 10px;
  174. background-color: #ffffff;
  175. padding: 20rpx 30rpx;
  176. .img {
  177. width: 160rpx;
  178. height: 160rpx;
  179. image {
  180. width: 100%;
  181. height: 100%;
  182. border-radius: 10rpx;
  183. }
  184. }
  185. .right {
  186. padding-left: 20rpx;
  187. flex: 1;
  188. // height: 300px;
  189. width: 100rpx;
  190. display: flex;
  191. flex-direction: column;
  192. // align-content: flex-end ;
  193. justify-content: space-between;
  194. // align-content: space-between;
  195. .title {
  196. display: flex;
  197. justify-content: flex-start;
  198. align-items: center;
  199. margin-bottom: 15rpx;
  200. // margin-bottom: 10rpx;
  201. text {
  202. font-weight: bold;
  203. overflow: hidden;
  204. text-overflow: ellipsis;
  205. white-space: nowrap;
  206. }
  207. }
  208. .introduce {
  209. // font-size: 28rpx;
  210. color: #a7a7a7;
  211. // padding: 20rpx 0;
  212. // width: 560rpx;
  213. height: 40rpx;
  214. overflow: hidden;
  215. text-overflow: ellipsis;
  216. white-space: nowrap;
  217. }
  218. .operate {
  219. display: flex;
  220. justify-content: space-between;
  221. // align-items: baseline;
  222. align-items: flex-end;
  223. .left {
  224. display: flex;
  225. // justify-content: space-between;
  226. // align-items: center;
  227. align-items: baseline;
  228. // width: 200rpx;
  229. .opr {
  230. display: flex;
  231. align-items: center;
  232. .icon {
  233. width: 32rpx;
  234. height: 32rpx;
  235. display: flex;
  236. justify-content: center;
  237. align-items: center;
  238. }
  239. text {
  240. padding-left: 3rpx;
  241. color: #666666;
  242. }
  243. }
  244. }
  245. .btn {
  246. z-index: 5;
  247. border: none;
  248. padding: 0;
  249. text-align: center;
  250. // padding: 8px, 24px, 8px, 24px;
  251. background-color: rgba(48, 129, 232, 1);
  252. color: #fff;
  253. border-radius: 100rpx;
  254. float: right;
  255. width: 144rpx;
  256. height: 48rpx;
  257. line-height: 48rpx;
  258. letter-spacing: 1px;
  259. }
  260. }
  261. }
  262. .tag {
  263. border: 1px #00b2b6 solid;
  264. flex-shrink: 0;
  265. letter-spacing: 2rpx;
  266. width: 64rpx;
  267. height: 32rpx;
  268. display: flex;
  269. white-space: nowrap;
  270. justify-content: center;
  271. align-items: center;
  272. border-radius: 4rpx;
  273. margin-right: 10rpx;
  274. color: #00b2b6;
  275. line-height: 32rpx;
  276. }
  277. }
  278. </style>