listBlock1.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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.showToast({title: '未登录,请登录',icon: 'none'})
  79. setTimeout(this.goLog,1000)
  80. return
  81. }
  82. // return console.log(event);
  83. let aId = event.currentTarget.dataset.e.acId
  84. // let type= event.currentTarget.dataset.e.type
  85. //判断是否收藏
  86. let iscoll = null
  87. // 查询是否收藏过
  88. let data = {
  89. acid: aId,
  90. oid: this.$store.state.user.openid, //用户id
  91. ty: 0
  92. }
  93. this.$request('/selectOneOperator', 'POST', data).then(res => {
  94. // console.log('查询是否收藏过',res);
  95. res[0].length ? iscoll = true : iscoll = false;
  96. // iscoll为true表示已经收藏过,执行删除 为true则收藏
  97. if (iscoll) {
  98. console.log('执行删除');
  99. this.$request('/deleteOperator', 'POST', data).then(res => {
  100. this.getdata()
  101. })
  102. } else {
  103. console.log('执行添加');
  104. this.$request('/insertOperator', 'POST', data).then(res => {
  105. this.getdata()
  106. })
  107. }
  108. })
  109. },
  110. // 跳转到详情页
  111. gotoDetail(e) {
  112. const value = this.$store.state.user.openid;
  113. if(!value){
  114. uni.showToast({title: '未登录,请登录',icon: 'none'})
  115. setTimeout(this.goLog,1000)
  116. return
  117. }
  118. let aid = e.currentTarget.dataset.aid;
  119. uni.navigateTo({
  120. url: `/pages/activityDetailNew/activityDetailNew?acId=${aid}`
  121. });
  122. },
  123. //跳转到第三方链接
  124. gotoLink(e) {
  125. const value = this.$store.state.user.openid;
  126. if(!value){
  127. uni.showToast({title: '未登录,请登录',icon: 'none'})
  128. setTimeout(this.goLog,1000)
  129. return
  130. }
  131. let link = e.currentTarget.dataset.link;
  132. uni.navigateTo({
  133. url: "/pages/skipone/skipone?url=" + encodeURIComponent(link),
  134. });
  135. },
  136. // 获取收藏事件
  137. getdata() {
  138. const value = this.$store.state.user.openid;
  139. if(!value) return this.collArr = []
  140. // 触发收藏事件
  141. console.log('触发收藏事件');
  142. // this.collArr: [],
  143. let data = {
  144. oid: this.$store.state.user.openid, //用户id
  145. type: 0
  146. }
  147. this.$request('/selectOperator', 'POST', data).then(res => {
  148. // console.log('获取收藏', res);
  149. // 每次调用前清零,防止push叠加错误
  150. this.collArr = []
  151. // 将acid遍历到collArr中
  152. res[0].forEach(i => {
  153. this.collArr.push(i.acId)
  154. })
  155. // console.log(this.collArr);
  156. })
  157. },
  158. goLog() {
  159. uni.navigateTo({
  160. url: "/pages/login_Wechat/login_Wechat",
  161. });
  162. },
  163. },
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .listBlock1 {
  168. display: flex;
  169. justify-content: space-between;
  170. background-color: #ffffff;
  171. padding: 20rpx 30rpx;
  172. width: 750rpx;
  173. .img {
  174. width: 160rpx;
  175. height: 160rpx;
  176. flex-shrink: 0;
  177. position: relative;
  178. .star {
  179. position: absolute;
  180. right: 10rpx;
  181. top: 10rpx;
  182. width: 30rpx;
  183. height: 30rpx;
  184. }
  185. image {
  186. width: 100%;
  187. height: 100%;
  188. border-radius: 10rpx;
  189. }
  190. }
  191. .right {
  192. padding-left: 20rpx;
  193. flex: 1;
  194. display: flex;
  195. flex-direction: column;
  196. justify-content: space-between;
  197. .title {
  198. display: flex;
  199. width: 500rpx;
  200. justify-content: flex-start;
  201. align-items: center;
  202. .titTxt {
  203. flex: 1;
  204. font-weight: bold;
  205. overflow: hidden;
  206. text-overflow: ellipsis;
  207. white-space: nowrap;
  208. }
  209. }
  210. .introduce {
  211. font-size: 24rpx;
  212. display: flex;
  213. justify-content: space-between;
  214. .bri {
  215. width: 250rpx;
  216. color: #a7a7a7;
  217. overflow: hidden;
  218. text-overflow: ellipsis;
  219. white-space: nowrap;
  220. }
  221. .tim {
  222. color: #a7a7a7;
  223. }
  224. }
  225. .operate {
  226. display: flex;
  227. justify-content: space-between;
  228. .left {
  229. display: flex;
  230. align-items: baseline;
  231. position: relative;
  232. width: 60%;
  233. .add {
  234. position: absolute;
  235. bottom: 0;
  236. left: 0;
  237. width: 100%;
  238. padding-left: 3rpx;
  239. color: rgba(0, 0, 0, 0.6) !important;
  240. }
  241. }
  242. .Oright {
  243. // width: 80px;
  244. display: flex;
  245. justify-content: flex-end;
  246. align-items: center;
  247. .mon {
  248. color: rgba(246, 135, 23, 1);
  249. font-weight: 700;
  250. font-size: 34rpx;
  251. }
  252. .text {
  253. font-size: 24rpx;
  254. color: #3081E8;
  255. }
  256. .arrow {
  257. display: flex;
  258. justify-content: center;
  259. margin-top: 5rpx;
  260. image {
  261. width: 32rpx;
  262. height: 32rpx;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. .tag {
  269. border: 1px rgba(0, 178, 182, 1) solid;
  270. flex-shrink: 0;
  271. letter-spacing: 2rpx;
  272. width: 104rpx;
  273. height: 32rpx;
  274. display: flex;
  275. white-space: nowrap;
  276. justify-content: center;
  277. align-items: center;
  278. border-radius: 4rpx;
  279. margin-right: 10rpx;
  280. color: rgba(0, 178, 182, 1);
  281. line-height: 32rpx;
  282. }
  283. .tag1 {
  284. border: 1px rgba(0, 86, 168, 1) solid;
  285. flex-shrink: 0;
  286. letter-spacing: 2rpx;
  287. width: 104rpx;
  288. height: 32rpx;
  289. display: flex;
  290. white-space: nowrap;
  291. justify-content: center;
  292. align-items: center;
  293. border-radius: 4rpx;
  294. margin-right: 10rpx;
  295. color: rgba(0, 86, 168, 1);
  296. line-height: 32rpx;
  297. }
  298. }
  299. </style>