listBlock1.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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="subaaa" :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. subaaa(event){
  138. console.log('sub',111111111);
  139. console.log(this.$store.state.user.openid);
  140. let aId=event.currentTarget.dataset.e.acId
  141. // 先获取用户订阅信息
  142. let data={
  143. oid:this.$store.state.user.openid, //用户id
  144. }
  145. this.$request('/selectSub','POST',data).then(res=>{
  146. // console.log('获取订阅信息',res);
  147. // return console.log('获取订阅信息',res[0][0].coll=='');
  148. let res2
  149. let subs
  150. if(res[0][0].sub!==null && res[0][0].sub !==""){
  151. subs=JSON.parse(res[0][0].sub)
  152. console.log('获取订阅信息',subs);
  153. // 判断订阅表是否包含这个活动
  154. res2 = subs.some((e)=>{
  155. return e == aId
  156. })
  157. // console.log(res2);
  158. }
  159. // return console.log('2',res2);
  160. // 第一次存储返回值为null,然后存储订阅
  161. if(res[0][0].sub==null || res[0][0].sub==""){
  162. // 然后进行存储活动到用户coll字段
  163. let arr={
  164. oid:this.$store.state.user.openid, //用户id
  165. acid:JSON.stringify([aId])
  166. }
  167. this.$request('/updateSub','POST',arr).then(res=>{
  168. this.$request('/selectSub','POST',data).then(res=>{
  169. this.subArr=JSON.parse(res[0][0].sub)
  170. })
  171. })
  172. // 当数组中没有这个订阅活动时添加订阅
  173. }else if(!res2){
  174. subs.push(aId)
  175. let arr2={
  176. oid:this.$store.state.user.openid, //用户id
  177. acid:JSON.stringify(subs)
  178. }
  179. this.$request('/updateSub','POST',arr2).then(res=>{
  180. this.$request('/selectSub','POST',data).then(res=>{
  181. this.subArr=JSON.parse(res[0][0].sub)
  182. })
  183. })
  184. // 取消订阅
  185. }else if(res2){
  186. const newArray = subs.filter(item => item !== aId);
  187. let arr3={
  188. oid:this.$store.state.user.openid, //用户id
  189. acid:JSON.stringify(newArray)
  190. }
  191. this.$request('/updateSub','POST',arr3).then(res=>{
  192. this.$request('/selectSub','POST',data).then(res=>{
  193. this.subArr=JSON.parse(res[0][0].sub)
  194. })
  195. })
  196. }
  197. })
  198. },
  199. join() {
  200. const value = this.$store.state.user.openid;
  201. if (value == '') {
  202. uni.navigateTo({
  203. url: "/pages/login_Wechat/login_Wechat",
  204. });
  205. return 1;
  206. } else {
  207. //推荐课程
  208. const urls = [
  209. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00351166273N",
  210. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00330324841N",
  211. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00231455802N",
  212. "https://szptxnjys.yuketang.cn/pro/portal/about/szpt-99Q00406339964N",
  213. ];
  214. let index = this.indexId;
  215. if (index >= 0 && index < urls.length) {
  216. const url = urls[index];
  217. uni.navigateTo({
  218. url: "/pages/skipone/skipone?url=" + encodeURIComponent(url),
  219. });
  220. }
  221. }
  222. },
  223. getdata(){
  224. let data={
  225. oid:this.$store.state.user.openid, //用户id
  226. }
  227. this.$request('/selectColl','POST',data).then(res=>{
  228. let a=JSON.parse(res[0][0].coll)
  229. if(a==null || a=='undefined'){
  230. this.collArr=[]
  231. }else{
  232. this.collArr=JSON.parse(res[0][0].coll)
  233. }
  234. console.log('进来就显示111111',this.collArr);
  235. })
  236. },
  237. getSub(){
  238. let data={
  239. oid:this.$store.state.user.openid, //用户id
  240. }
  241. this.$request('/selectSub','POST',data).then(res=>{
  242. console.log('呵呵呵',res[0][0].sub);
  243. let a=JSON.parse(res[0][0].sub)
  244. if(a==null || a=='undefined'){
  245. this.sub=[]
  246. }else{
  247. this.subArr=JSON.parse(res[0][0].sub)
  248. }
  249. // this.subArr=JSON.parse(res[0][0].sub)
  250. console.log('进来就显示',this.subArr);
  251. })
  252. }
  253. },
  254. // created () {
  255. // this.getdata()
  256. // }
  257. }
  258. </script>
  259. <style lang="scss">
  260. .listBlock1{
  261. display: flex;
  262. justify-content: space-between;
  263. // margin-bottom: 10px;
  264. background-color: #ffffff;
  265. padding: 20rpx 30rpx;
  266. .img {
  267. width: 160rpx;
  268. height: 160rpx;
  269. image {
  270. width: 100%;
  271. height: 100%;
  272. border-radius: 10rpx;
  273. }
  274. }
  275. .right {
  276. padding-left: 20rpx;
  277. flex: 1;
  278. // height: 300px;
  279. width: 100rpx;
  280. display: flex;
  281. flex-direction: column;
  282. // align-content: flex-end ;
  283. justify-content: space-between;
  284. // align-content: space-between;
  285. .title {
  286. display: flex;
  287. justify-content: flex-start;
  288. align-items: center;
  289. margin-bottom: 15rpx;
  290. // margin-bottom: 10rpx;
  291. text {
  292. font-weight: bold;
  293. overflow: hidden;
  294. text-overflow: ellipsis;
  295. white-space: nowrap;
  296. }
  297. }
  298. .introduce {
  299. // font-size: 28rpx;
  300. color: #a7a7a7;
  301. // padding: 20rpx 0;
  302. // width: 560rpx;
  303. height: 40rpx;
  304. overflow: hidden;
  305. text-overflow: ellipsis;
  306. white-space: nowrap;
  307. }
  308. .operate {
  309. display: flex;
  310. justify-content: space-between;
  311. // align-items: baseline;
  312. align-items: flex-end;
  313. .left {
  314. display: flex;
  315. // justify-content: space-between;
  316. // align-items: center;
  317. align-items: baseline;
  318. // width: 200rpx;
  319. .opr {
  320. display: flex;
  321. align-items: center;
  322. .icon {
  323. width: 32rpx;
  324. height: 32rpx;
  325. display: flex;
  326. justify-content: center;
  327. align-items: center;
  328. }
  329. text {
  330. padding-left: 3rpx;
  331. color: #666666;
  332. }
  333. }
  334. }
  335. .btn {
  336. z-index: 5;
  337. border: none;
  338. padding: 0;
  339. text-align: center;
  340. // padding: 8px, 24px, 8px, 24px;
  341. background-color: rgba(48, 129, 232, 1);
  342. color: #fff;
  343. border-radius: 100rpx;
  344. float: right;
  345. width: 144rpx;
  346. height: 48rpx;
  347. line-height: 48rpx;
  348. letter-spacing: 1px;
  349. }
  350. }
  351. }
  352. .tag {
  353. border: 1px #00b2b6 solid;
  354. flex-shrink: 0;
  355. letter-spacing: 2rpx;
  356. width: 64rpx;
  357. height: 32rpx;
  358. display: flex;
  359. white-space: nowrap;
  360. justify-content: center;
  361. align-items: center;
  362. border-radius: 4rpx;
  363. margin-right: 10rpx;
  364. color: #00b2b6;
  365. line-height: 32rpx;
  366. }
  367. }
  368. </style>