listBlock1.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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) ? pic_coll2 : pic_coll "
  24. style="width: 28rpx; height: 26rpx" mode="aspectFill"></image>
  25. </view>
  26. <text class="fz-font">收藏</text>
  27. </view>
  28. <view class="opr" @click="sub" :data-e="i">
  29. <view class="icon">
  30. <image :src="subArr.includes(i.acId) ? pic_sub2 : pic_sub "
  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. indexId: {
  57. type: Number,
  58. },
  59. },
  60. // props:['classList'],
  61. data() {
  62. return {
  63. collArr:[],
  64. subArr:[],
  65. // 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'
  66. pic_coll:'http://43.139.158.220:5007/img/static/yym/Star 1 (Stroke).png',
  67. pic_coll2:'https://teacherapi.cocorobo.cn/teaching-file/static//mine/Collect_yellow.png',
  68. pic_sub:'http://43.139.158.220:5007/img/static/yym/Vector (Stroke).png',
  69. pic_sub2:'../../static/mine/dingyue_blue.png'
  70. };
  71. },
  72. methods:{
  73. // 收藏事件
  74. coll(event){
  75. // console.log(event.currentTarget.dataset.e);
  76. console.log(this.$store.state.user.openid);
  77. let aId=event.currentTarget.dataset.e.acId
  78. // 先获取用户收藏信息
  79. let data={
  80. oid:this.$store.state.user.openid, //用户id
  81. }
  82. this.$request('/selectColl','POST',data).then(res=>{
  83. // console.log('获取收藏信息',res);
  84. // return console.log('获取收藏信息',res[0][0].coll=='');
  85. let res2
  86. let colls
  87. if(res[0][0].coll!==null && res[0][0].coll !==""){
  88. colls=JSON.parse(res[0][0].coll)
  89. console.log('获取收藏信息',colls);
  90. // 判断收藏表是否包含这个活动
  91. res2 = colls.some((e)=>{
  92. return e == aId
  93. })
  94. // console.log(res2);
  95. }
  96. // return console.log('2',res2);
  97. // 第一次存储返回值为null,然后存储收藏
  98. if(res[0][0].coll==null || res[0][0].coll==""){
  99. // 然后进行存储活动到用户coll字段
  100. let arr={
  101. oid:this.$store.state.user.openid, //用户id
  102. acid:JSON.stringify([aId])
  103. }
  104. this.$request('/updateColl','POST',arr).then(res=>{
  105. this.$request('/selectColl','POST',data).then(res=>{
  106. this.collArr=JSON.parse(res[0][0].coll)
  107. })
  108. })
  109. // 当数组中没有这个收藏活动时添加收藏
  110. }else if(!res2){
  111. colls.push(aId)
  112. let arr2={
  113. oid:this.$store.state.user.openid, //用户id
  114. acid:JSON.stringify(colls)
  115. }
  116. this.$request('/updateColl','POST',arr2).then(res=>{
  117. this.$request('/selectColl','POST',data).then(res=>{
  118. this.collArr=JSON.parse(res[0][0].coll)
  119. })
  120. })
  121. // 取消收藏
  122. }else if(res2){
  123. const newArray = colls.filter(item => item !== aId);
  124. let arr3={
  125. oid:this.$store.state.user.openid, //用户id
  126. acid:JSON.stringify(newArray)
  127. }
  128. this.$request('/updateColl','POST',arr3).then(res=>{
  129. this.$request('/selectColl','POST',data).then(res=>{
  130. this.collArr=JSON.parse(res[0][0].coll)
  131. })
  132. })
  133. }
  134. })
  135. },
  136. // 订阅事件
  137. sub(event){
  138. console.log(this.$store.state.user.openid);
  139. let aId=event.currentTarget.dataset.e.acId
  140. // 先获取用户订阅信息
  141. let data={
  142. oid:this.$store.state.user.openid, //用户id
  143. }
  144. this.$request('/selectSub','POST',data).then(res=>{
  145. // console.log('获取订阅信息',res);
  146. // return console.log('获取订阅信息',res[0][0].coll=='');
  147. let res2
  148. let subs
  149. if(res[0][0].sub!==null && res[0][0].sub !==""){
  150. subs=JSON.parse(res[0][0].sub)
  151. console.log('获取订阅信息',subs);
  152. // 判断订阅表是否包含这个活动
  153. res2 = subs.some((e)=>{
  154. return e == aId
  155. })
  156. // console.log(res2);
  157. }
  158. // return console.log('2',res2);
  159. // 第一次存储返回值为null,然后存储订阅
  160. if(res[0][0].sub==null || res[0][0].sub==""){
  161. // 然后进行存储活动到用户coll字段
  162. let arr={
  163. oid:this.$store.state.user.openid, //用户id
  164. acid:JSON.stringify([aId])
  165. }
  166. this.$request('/updateSub','POST',arr).then(res=>{
  167. this.$request('/selectSub','POST',data).then(res=>{
  168. this.subArr=JSON.parse(res[0][0].sub)
  169. })
  170. })
  171. // 当数组中没有这个订阅活动时添加订阅
  172. }else if(!res2){
  173. subs.push(aId)
  174. let arr2={
  175. oid:this.$store.state.user.openid, //用户id
  176. acid:JSON.stringify(subs)
  177. }
  178. this.$request('/updateSub','POST',arr2).then(res=>{
  179. this.$request('/selectSub','POST',data).then(res=>{
  180. this.subArr=JSON.parse(res[0][0].sub)
  181. })
  182. })
  183. // 取消订阅
  184. }else if(res2){
  185. const newArray = subs.filter(item => item !== aId);
  186. let arr3={
  187. oid:this.$store.state.user.openid, //用户id
  188. acid:JSON.stringify(newArray)
  189. }
  190. this.$request('/updateSub','POST',arr3).then(res=>{
  191. this.$request('/selectSub','POST',data).then(res=>{
  192. this.subArr=JSON.parse(res[0][0].sub)
  193. })
  194. })
  195. }
  196. })
  197. },
  198. join() {
  199. const value = this.$store.state.user.openid;
  200. if (value == '') {
  201. uni.navigateTo({
  202. url: "/pages/login_Wechat/login_Wechat",
  203. });
  204. return 1;
  205. } else {
  206. //推荐课程
  207. const urls = [
  208. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00351166273N",
  209. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00330324841N",
  210. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00231455802N",
  211. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00406339964N",
  212. ];
  213. let index = this.indexId;
  214. if (index >= 0 && index < urls.length) {
  215. const url = urls[index];
  216. uni.navigateTo({
  217. url: "/pages/skipone/skipone?url=" + encodeURIComponent(url),
  218. });
  219. }
  220. }
  221. },
  222. getdata(){
  223. let data={
  224. oid:this.$store.state.user.openid, //用户id
  225. }
  226. this.$request('/selectColl','POST',data).then(res=>{
  227. this.collArr=JSON.parse(res[0][0].coll)
  228. console.log('进来就显示',this.collArr);
  229. })
  230. },
  231. getSub(){
  232. let data={
  233. oid:this.$store.state.user.openid, //用户id
  234. }
  235. this.$request('/selectSub','POST',data).then(res=>{
  236. this.subArr=JSON.parse(res[0][0].sub)
  237. console.log('进来就显示',this.subArr);
  238. })
  239. }
  240. },
  241. // created () {
  242. // this.getdata()
  243. // }
  244. }
  245. </script>
  246. <style lang="scss">
  247. .listBlock1{
  248. display: flex;
  249. justify-content: space-between;
  250. // margin-bottom: 10px;
  251. background-color: #ffffff;
  252. padding: 20rpx 30rpx;
  253. .img {
  254. width: 160rpx;
  255. height: 160rpx;
  256. image {
  257. width: 100%;
  258. height: 100%;
  259. border-radius: 10rpx;
  260. }
  261. }
  262. .right {
  263. padding-left: 20rpx;
  264. flex: 1;
  265. // height: 300px;
  266. width: 100rpx;
  267. display: flex;
  268. flex-direction: column;
  269. // align-content: flex-end ;
  270. justify-content: space-between;
  271. // align-content: space-between;
  272. .title {
  273. display: flex;
  274. justify-content: flex-start;
  275. align-items: center;
  276. margin-bottom: 15rpx;
  277. // margin-bottom: 10rpx;
  278. text {
  279. font-weight: bold;
  280. overflow: hidden;
  281. text-overflow: ellipsis;
  282. white-space: nowrap;
  283. }
  284. }
  285. .introduce {
  286. // font-size: 28rpx;
  287. color: #a7a7a7;
  288. // padding: 20rpx 0;
  289. // width: 560rpx;
  290. height: 40rpx;
  291. overflow: hidden;
  292. text-overflow: ellipsis;
  293. white-space: nowrap;
  294. }
  295. .operate {
  296. display: flex;
  297. justify-content: space-between;
  298. // align-items: baseline;
  299. align-items: flex-end;
  300. .left {
  301. display: flex;
  302. // justify-content: space-between;
  303. // align-items: center;
  304. align-items: baseline;
  305. // width: 200rpx;
  306. .opr {
  307. display: flex;
  308. align-items: center;
  309. .icon {
  310. width: 32rpx;
  311. height: 32rpx;
  312. display: flex;
  313. justify-content: center;
  314. align-items: center;
  315. }
  316. text {
  317. padding-left: 3rpx;
  318. color: #666666;
  319. }
  320. }
  321. }
  322. .btn {
  323. z-index: 5;
  324. border: none;
  325. padding: 0;
  326. text-align: center;
  327. // padding: 8px, 24px, 8px, 24px;
  328. background-color: rgba(48, 129, 232, 1);
  329. color: #fff;
  330. border-radius: 100rpx;
  331. float: right;
  332. width: 144rpx;
  333. height: 48rpx;
  334. line-height: 48rpx;
  335. letter-spacing: 1px;
  336. }
  337. }
  338. }
  339. .tag {
  340. border: 1px #00b2b6 solid;
  341. flex-shrink: 0;
  342. letter-spacing: 2rpx;
  343. width: 64rpx;
  344. height: 32rpx;
  345. display: flex;
  346. white-space: nowrap;
  347. justify-content: center;
  348. align-items: center;
  349. border-radius: 4rpx;
  350. margin-right: 10rpx;
  351. color: #00b2b6;
  352. line-height: 32rpx;
  353. }
  354. }
  355. </style>