listBlock1.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <view class="">
  3. <view class="listBlock1" v-for="(i,index) in classList" :key="index+'a'" @click="gotoDetail" :data-aid="i.acId">
  4. <view class="img cell-img">
  5. <image :src="i.pic" mode="aspectFill"></image>
  6. <image class="star" @click.stop="coll" :data-e="i"
  7. :src="collArr.includes(i.acId) ? pic_coll2 : pic_coll " mode="aspectFill"></image>
  8. </view>
  9. <view class="right">
  10. <view class="title">
  11. <view class="bqZ-font" :class="i.acshape=='线下活动'?'tag':'tag1'"> {{i.acshape}}</view>
  12. <view class="titTxt btn-font" style="">
  13. {{i.acName}}
  14. </view>
  15. </view>
  16. <view class="introduce">
  17. <view class="bri">
  18. {{ i.brief }}
  19. <!-- {{ i.address }} -->
  20. </view>
  21. <view class="tim">
  22. {{ i.create_at }}
  23. </view>
  24. </view>
  25. <view class="operate">
  26. <view class="left">
  27. <view class="add fz-font">已报名{{i.bnum}}/{{i.pers}}人</view>
  28. </view>
  29. <view class="Oright" v-if="!indexId" @click.stop="gotoLink" :data-link="i.link">
  30. <view class="text">查看详情</view>
  31. <view class="arrow">
  32. <image src="https://teacherapi.cocorobo.cn/teaching-file/static/mine/arrow-right-blue.png"
  33. mode="aspectFill"></image>
  34. </view>
  35. </view>
  36. <view class="Oright" v-if="indexId">
  37. <view class="mon">¥<text style="font-size: 40rpx;">{{i.cost}}</text> </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. name: "listBlock1",
  47. props: {
  48. classList: {
  49. type: Array,
  50. default () {
  51. return [];
  52. },
  53. },
  54. indexId: {
  55. type: Number,
  56. default () {
  57. return 0;
  58. },
  59. },
  60. },
  61. // props:['classList'],
  62. data() {
  63. return {
  64. // 收藏list
  65. collArr: [],
  66. // subArr: [],
  67. pic_coll: 'https://teacherapi.cocorobo.cn/teaching-file/static/Stara.png',
  68. pic_coll2: 'https://teacherapi.cocorobo.cn/teaching-file/static/mine/Collect_yellow.png',
  69. // pic_sub: 'https://teacherapi.cocorobo.cn/teaching-file/static/yym/Vector (Stroke).png',
  70. // pic_sub2: '../../static/mine/dingyue_blue.png'
  71. };
  72. },
  73. methods: {
  74. // 收藏事件
  75. coll(event) {
  76. const value = this.$store.state.user.openid;
  77. if (value == '') {
  78. uni.navigateTo({
  79. url: "/pages/login_Wechat/login_Wechat",
  80. });
  81. return
  82. }
  83. // return console.log(event);
  84. let aId = event.currentTarget.dataset.e.acId
  85. // let type= event.currentTarget.dataset.e.type
  86. //判断是否收藏
  87. let iscoll = null
  88. // 查询是否收藏过
  89. let data = {
  90. acid: aId,
  91. oid: this.$store.state.user.openid, //用户id
  92. ty: 0
  93. }
  94. this.$request('/selectOneOperator', 'POST', data).then(res => {
  95. // console.log('查询是否收藏过',res);
  96. res[0].length ? iscoll = true : iscoll = false;
  97. // iscoll为true表示已经收藏过,执行删除 为true则收藏
  98. if (iscoll) {
  99. console.log('执行删除');
  100. this.$request('/deleteOperator', 'POST', data).then(res => {
  101. this.getdata()
  102. })
  103. } else {
  104. console.log('执行添加');
  105. this.$request('/insertOperator', 'POST', data).then(res => {
  106. this.getdata()
  107. })
  108. }
  109. })
  110. },
  111. // 跳转到详情页
  112. gotoDetail(e) {
  113. let aid = e.currentTarget.dataset.aid;
  114. const value = this.$store.state.user.openid;
  115. if (value == '') return this.goLog()
  116. uni.navigateTo({
  117. url: `/pages/activityDetailNew/activityDetailNew?acId=${aid}`
  118. // url:'/pages/activityDetailNew/activityDetailNew'
  119. // url: `/pages/teachingDetail?acId=${aid}`
  120. });
  121. },
  122. //跳转到第三方链接
  123. gotoLink(e){
  124. const value = this.$store.state.user.openid;
  125. if (value == '') {
  126. uni.navigateTo({
  127. url: "/pages/login_Wechat/login_Wechat",
  128. });
  129. return
  130. }
  131. // return console.log('aaaaaa', e.currentTarget.dataset);
  132. let link = e.currentTarget.dataset.link;
  133. uni.navigateTo({
  134. url: "/pages/skipone/skipone?url=" + encodeURIComponent(link),
  135. });
  136. },
  137. // 获取收藏事件
  138. getdata() {
  139. // 触发收藏事件
  140. console.log('触发收藏事件');
  141. let data = {
  142. oid: this.$store.state.user.openid, //用户id
  143. type: 0
  144. }
  145. this.$request('/selectOperator', 'POST', data).then(res => {
  146. // console.log('获取收藏', res);
  147. // 每次调用前清零,防止push叠加错误
  148. this.collArr = []
  149. // 将acid遍历到collArr中
  150. res[0].forEach(i => {
  151. this.collArr.push(i.acId)
  152. })
  153. // console.log(this.collArr);
  154. })
  155. },
  156. goLog() {
  157. uni.showToast({
  158. title:'请登录',
  159. icon:'none'
  160. })
  161. uni.navigateTo({
  162. url: "/pages/login_Wechat/login_Wechat",
  163. });
  164. },
  165. },
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. .listBlock1 {
  170. display: flex;
  171. justify-content: space-between;
  172. background-color: #ffffff;
  173. padding: 20rpx 30rpx;
  174. width: 750rpx;
  175. .img {
  176. width: 160rpx;
  177. height: 160rpx;
  178. flex-shrink: 0;
  179. position: relative;
  180. .star {
  181. position: absolute;
  182. right: 10rpx;
  183. top: 10rpx;
  184. width: 30rpx;
  185. height: 30rpx;
  186. }
  187. image {
  188. width: 100%;
  189. height: 100%;
  190. border-radius: 10rpx;
  191. }
  192. }
  193. .right {
  194. padding-left: 20rpx;
  195. flex: 1;
  196. display: flex;
  197. flex-direction: column;
  198. justify-content: space-between;
  199. .title {
  200. display: flex;
  201. width: 500rpx;
  202. justify-content: flex-start;
  203. align-items: center;
  204. .titTxt{
  205. flex: 1;
  206. font-weight: bold;
  207. overflow: hidden;
  208. text-overflow: ellipsis;
  209. white-space: nowrap;
  210. }
  211. }
  212. .introduce {
  213. font-size: 24rpx;
  214. display: flex;
  215. justify-content: space-between;
  216. .bri {
  217. width: 250rpx;
  218. color: #a7a7a7;
  219. overflow: hidden;
  220. text-overflow: ellipsis;
  221. white-space: nowrap;
  222. }
  223. .tim {
  224. color: #a7a7a7;
  225. }
  226. }
  227. .operate {
  228. display: flex;
  229. justify-content: space-between;
  230. .left {
  231. display: flex;
  232. align-items: baseline;
  233. position: relative;
  234. width: 60%;
  235. .add {
  236. position: absolute;
  237. bottom: 0;
  238. left: 0;
  239. width: 100%;
  240. padding-left: 3rpx;
  241. color: rgba(0, 0, 0, 0.6) !important;
  242. }
  243. }
  244. .Oright {
  245. // width: 80px;
  246. display: flex;
  247. justify-content: flex-end;
  248. align-items: center;
  249. .mon {
  250. color: rgba(246, 135, 23, 1);
  251. font-weight: 700;
  252. font-size: 34rpx;
  253. }
  254. .text {
  255. font-size: 24rpx;
  256. color: #3081E8;
  257. }
  258. .arrow {
  259. display: flex;
  260. justify-content: center;
  261. margin-top: 5rpx;
  262. image {
  263. width: 32rpx;
  264. height: 32rpx;
  265. }
  266. }
  267. }
  268. }
  269. }
  270. .tag {
  271. border: 1px rgba(0, 178, 182, 1) solid;
  272. flex-shrink: 0;
  273. letter-spacing: 2rpx;
  274. width: 104rpx;
  275. height: 32rpx;
  276. display: flex;
  277. white-space: nowrap;
  278. justify-content: center;
  279. align-items: center;
  280. border-radius: 4rpx;
  281. margin-right: 10rpx;
  282. color:rgba(0, 178, 182, 1);
  283. line-height: 32rpx;
  284. }
  285. .tag1 {
  286. border: 1px rgba(0, 86, 168, 1) solid;
  287. flex-shrink: 0;
  288. letter-spacing: 2rpx;
  289. width: 104rpx;
  290. height: 32rpx;
  291. display: flex;
  292. white-space: nowrap;
  293. justify-content: center;
  294. align-items: center;
  295. border-radius: 4rpx;
  296. margin-right: 10rpx;
  297. color: rgba(0, 86, 168, 1);
  298. line-height: 32rpx;
  299. }
  300. }
  301. </style>