home.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. import {
  2. ilogin,
  3. ihome,
  4. iactivity,
  5. icommunity,
  6. imine
  7. } from '../../api/api.js'
  8. const app = getApp()
  9. Page({
  10. loadMyinformation() {
  11. imine.loadMyinformation({reqdata: {id:1}},r => {
  12. this.setData({
  13. user: Object.assign(this.data.user, r.object)
  14. })
  15. wx.setStorage({
  16. key: 'user',
  17. data: this.data.user
  18. })
  19. })
  20. },
  21. loadMyActivities() {
  22. imine.loadMyActivities(this.data.mine.pagination, r => {
  23. this.setData({
  24. ['mine.curNav']: 3,
  25. ['mine.list']: this.data.mine.list.concat(r.list),
  26. ['mine.pagination.page']: r.list.length > 0 ? this.data.mine.pagination.page : --this.data.mine.pagination.page
  27. })
  28. })
  29. },
  30. loadMyComments() {
  31. imine.loadMyComments(this.data.mine.pagination, r => {
  32. for (let c of r.list) {
  33. c.showtime = new Date(c.comment_addtime).getDateName('hh:mm')
  34. }
  35. this.setData({
  36. ['mine.curNav']: 2,
  37. ['mine.list']: this.data.mine.list.concat(r.list),
  38. ['mine.pagination.page']: r.list.length > 0 ? this.data.mine.pagination.page : --this.data.mine.pagination.page
  39. })
  40. })
  41. },
  42. loadMyPubarticles() {
  43. imine.loadMyPubarticles(this.data.mine.pagination, r => {
  44. this.setData({
  45. ['mine.curNav']: 0,
  46. ['mine.list']: this.data.mine.list.concat(r.list),
  47. ['mine.pagination.page']: r.list.length > 0 ? this.data.mine.pagination.page : --this.data.mine.pagination.page
  48. })
  49. })
  50. },
  51. loadMyCollectedarticles() {
  52. imine.loadMyCollectedarticles(this.data.mine.pagination, r => {
  53. this.setData({
  54. ['mine.curNav']: 1,
  55. ['mine.list']: this.data.mine.list.concat(r.list).map(item => {
  56. item.status_attend = Date.now() < new Date(item.applyStartTime).valueOf() ? '未开始' : Date.now() > new Date(item.applyEndTime).valueOf() ? '已结束' :''
  57. return item
  58. }),
  59. ['mine.pagination.page']: r.list.length > 0 ? this.data.mine.pagination.page : --this.data.mine.pagination.page
  60. })
  61. })
  62. },
  63. data: {
  64. showAuthPanel: false,
  65. curNav: 0,
  66. imgUrl: app.globalData.imgUrl,
  67. navs: [{
  68. key: 'home',
  69. name: '首页'
  70. }, {
  71. key: 'activity',
  72. name: '活动动态'
  73. }, {
  74. key: 'community',
  75. name: '社区'
  76. }, {
  77. key: 'mine',
  78. name: '个人中心'
  79. }],
  80. searchOn: false,
  81. home: {},
  82. activity: {
  83. list: [],
  84. pagination: {
  85. page: 1,
  86. rows: 10,
  87. reqdata: {
  88. keyword: ''
  89. }
  90. }
  91. },
  92. community: {
  93. showAddtidings: false,
  94. acts: [{
  95. favorite: true
  96. }],
  97. list: [],
  98. pagination: {
  99. page: 1,
  100. rows: 10,
  101. reqdata: {
  102. keyword: ''
  103. }
  104. }
  105. },
  106. mine: {
  107. list: [],
  108. curNav: 0,
  109. pagination: {
  110. page: 1,
  111. rows: 10
  112. }
  113. }
  114. },
  115. loadArticles() {
  116. icommunity.loadArticles(this.data.community.pagination, r => {
  117. this.setData({
  118. ['community.list']: this.data.community.list.concat(r.list),
  119. ['community.pagination.page']: r.list.length > 0 ? this.data.community.pagination.page : --this.data.community.pagination.page
  120. })
  121. wx.stopPullDownRefresh()
  122. })
  123. },
  124. loadActivities() {
  125. iactivity.loadActivities(this.data.activity.pagination, r => {
  126. this.setData({
  127. ['activity.list']: this.data.activity.list.concat(r.list),
  128. ['activity.pagination.page']: r.list.length > 0 ? this.data.activity.pagination.page : --this.data.activity.pagination.page,
  129. })
  130. wx.stopPullDownRefresh()
  131. })
  132. },
  133. loadHome() {
  134. let count = 3
  135. ihome.loadBanners({},r => {
  136. console.log(r);
  137. this.setData({
  138. ['home.banners']: r.list
  139. })
  140. if (count == 1) {
  141. wx.stopPullDownRefresh()
  142. } else {
  143. count--
  144. }
  145. })
  146. ihome.loadPartners({},r => {
  147. this.setData({
  148. ['home.partners']: r.list
  149. })
  150. if (count == 1) {
  151. wx.stopPullDownRefresh()
  152. } else {
  153. count--
  154. }
  155. })
  156. ihome.loadHotnews({},r => {
  157. this.setData({
  158. ['home.hotnews']: r.list
  159. })
  160. if (count == 1) {
  161. wx.stopPullDownRefresh()
  162. } else {
  163. count--
  164. }
  165. })
  166. },
  167. onLoad(args) {
  168. this.loadHome()
  169. // this.loadConfig()
  170. },
  171. clickRemoveArticle(e) {
  172. console.log(e)
  173. wx.showModal({
  174. title: '确定删除?',
  175. content: '是否删除此动态?',
  176. confirmColor: '#f64f5f',
  177. success: r => {
  178. let {id,minenav,i} = e.currentTarget.dataset
  179. if (r.confirm) {
  180. icommunity[minenav==0?'loadDeleteArticle':'loadDeleteCollect']({
  181. reqdata:{id}
  182. }, r => {
  183. wx.showToast({
  184. title: '删除成功'
  185. })
  186. this.data.mine.list.splice(i, 1)
  187. this.setData({
  188. mine: this.data.mine
  189. })
  190. })
  191. }
  192. }
  193. })
  194. },
  195. clickFavorite(e) {
  196. let {id,isCollect} = e.currentTarget.dataset
  197. let scope = this.data.curNav == 2 ? 'community' : 'mine'
  198. let item = this.data[scope].list[e.currentTarget.dataset.i]
  199. icommunity[isCollect?'loadDeleteCollect':'loadAddArticle']({
  200. reqdata:{
  201. [isCollect?'id':'collectProjectId']:id,
  202. ['collectType']: isCollect?null:1
  203. }
  204. }, r => {
  205. item.isCollect = !item.isCollect
  206. item.collectNumber =item.isCollect? parseInt(item.collectNumber) + 1: parseInt(item.collectNumber) - 1
  207. this.setData({
  208. [scope + '.list[' + e.currentTarget.dataset.i + ']']: item
  209. })
  210. })
  211. },
  212. clickActivity(e) {
  213. app.data.nav.activityDetails = this.data.activity.list[e.currentTarget.dataset.i]
  214. wx.navigateTo({
  215. url: '../activities/activityDetails/activityDetails?id=' + e.currentTarget.dataset.id
  216. })
  217. },
  218. clickArticle(e) {
  219. console.log(e)
  220. app.data.nav.newsDetails = this.data.home.hotnews[e.currentTarget.dataset.i]
  221. wx.navigateTo({
  222. url: '../hotnews/newsDetails/newsDetails?id=' + e.currentTarget.dataset.id
  223. })
  224. },
  225. clickHotnewsMore() {
  226. wx.navigateTo({
  227. url: '../hotnews/hotnews/hotnews'
  228. })
  229. },
  230. clickMyinfo() {
  231. wx.navigateTo({
  232. url: '../mine/myinfo/edit/edit'
  233. })
  234. },
  235. clickCommunityArticle(e) {
  236. app.data.nav.communityArticle = e.currentTarget.dataset.item
  237. wx.navigateTo({
  238. url: e.currentTarget.dataset.item.fileType == 2 ? '../community/videoDetails/videoDetails' : '../community/articleDetails/articleDetails'
  239. })
  240. },
  241. clickUploadpics() {
  242. wx.navigateTo({
  243. url: '../community/uploadPics/uploadPics'
  244. })
  245. this.setData({
  246. ['community.showAddtidings']: false
  247. })
  248. },
  249. clickUploadvideos() {
  250. wx.navigateTo({
  251. url: '../community/uploadVideos/uploadVideos'
  252. })
  253. this.setData({
  254. ['community.showAddtidings']: false
  255. })
  256. },
  257. clickClosetidings() {
  258. this.setData({
  259. ['community.showAddtidings']: false
  260. })
  261. },
  262. clickAddtidings() {
  263. // if (!this.data.user) {
  264. // return this.setData({
  265. // showAuthPanel: true
  266. // })
  267. // }
  268. this.setData({
  269. ['community.showAddtidings']: true
  270. })
  271. },
  272. inputSearch(e) {
  273. if (this.data.curNav == 1) {
  274. this.setData({
  275. ['activity.pagination.reqdata.keyword']: e.detail.value,
  276. ['activity.pagination.page']: 1,
  277. ['activity.list']: [],
  278. })
  279. this.loadActivities()
  280. } else {
  281. this.setData({
  282. ['community.pagination.reqdata.keyword']: e.detail.value,
  283. ['community.pagination.page']: 1,
  284. ['community.list']: []
  285. })
  286. this.loadArticles()
  287. }
  288. },
  289. clickSearch() {
  290. this.setData({
  291. searchOn: true
  292. })
  293. },
  294. blurSearch(e) {
  295. if (!e.detail.value) {
  296. this.setData({
  297. searchOn: false
  298. })
  299. }
  300. },
  301. clickMinenav(e) {
  302. this.data.mine.pagination.page = 1
  303. this.data.mine.list = []
  304. switch (e.currentTarget.dataset.cur) {
  305. case '1':
  306. {
  307. this.loadMyCollectedarticles()
  308. };
  309. break;
  310. case '2':
  311. {
  312. this.loadMyComments()
  313. };
  314. break;
  315. case '3':
  316. {
  317. this.loadMyActivities()
  318. };
  319. break;
  320. default:
  321. {
  322. this.loadMyPubarticles()
  323. }
  324. }
  325. },
  326. clickNav(e) {
  327. switch (e.currentTarget.dataset.cur) {
  328. case '1':
  329. this.data.activity.pagination.page = 1
  330. this.data.activity.list = []
  331. this.loadActivities()
  332. break;
  333. case '2':
  334. this.data.community.pagination.page = 1
  335. this.data.community.list = []
  336. this.loadArticles()
  337. break;
  338. case '3':
  339. // if (!this.data.user || this.data.user.is_finish_reg == 0) {
  340. // return this.setData({
  341. // showAuthPanel: true
  342. // })
  343. // }
  344. this.data.mine.pagination.page = 1
  345. this.data.mine.list = []
  346. this.loadMyinformation()
  347. // if (this.data.config.open_space == 1) {
  348. // this.loadMyPubarticles()
  349. // } else {
  350. // this.loadMyCollectedarticles()
  351. // }
  352. // this.loadMyCollectedarticles()
  353. this.setData({
  354. ['mine.curNav']: 0
  355. },()=>{
  356. this.loadMyPubarticles()
  357. })
  358. break;
  359. }
  360. this.setData({
  361. curNav: e.currentTarget.dataset.cur
  362. })
  363. wx.setNavigationBarTitle({
  364. title: this.data.navs[e.currentTarget.dataset.cur].name
  365. })
  366. },
  367. clickHideAuthPanel() {
  368. this.setData({
  369. showAuthPanel: false
  370. })
  371. },
  372. // getUserinfo(e) {
  373. // let {encryptedData,iv} = e.detail
  374. // console.log(e);
  375. // wx.login({
  376. // success: r => {
  377. // ilogin.loadAT({
  378. // reqdata: {
  379. // code: r.code,
  380. // encryptedData,
  381. // iv
  382. // }
  383. // }, r => {
  384. // console.log(r)
  385. // })
  386. // }
  387. // })
  388. // },
  389. getUserInfo (e) {
  390. wx.login({
  391. success: r => {
  392. wx.getUserInfo({
  393. success: e => {
  394. // let {encryptedData,iv} = e
  395. // ilogin.loadAT({
  396. // reqdata: {
  397. // code: r.code,
  398. // encryptedData,
  399. // iv
  400. // }
  401. // }, r => {
  402. console.log(r)
  403. console.log(e);
  404. // })
  405. },
  406. })
  407. // ilogin.loadAT({
  408. // reqdata: {
  409. // code: r.code,
  410. // encryptedData,
  411. // iv
  412. // }
  413. // }, r => {
  414. // console.log(r)
  415. // })
  416. }
  417. })
  418. },
  419. onShow() {
  420. wx.getStorage({
  421. key: 'user',
  422. complete: r => {
  423. if (r.data) {
  424. this.setData({
  425. user: r.data
  426. })
  427. }
  428. }
  429. })
  430. },
  431. onPullDownRefresh() {
  432. switch (this.data.curNav) {
  433. case 1:
  434. case '1':
  435. this.data.activity.pagination.page = 1
  436. this.data.activity.list = []
  437. this.loadActivities()
  438. break;
  439. case 2:
  440. case '2':
  441. this.data.community.pagination.page = 1
  442. this.data.community.list = []
  443. this.loadArticles()
  444. break;
  445. case 3:
  446. case '3':
  447. wx.stopPullDownRefresh()
  448. break;
  449. default:
  450. this.loadHome()
  451. }
  452. },
  453. onReachBottom() {
  454. if (this.data.curNav == 1) {
  455. this.data.activity.pagination.page += 1
  456. this.loadActivities()
  457. }
  458. if (this.data.curNav == 2) {
  459. this.data.community.pagination.page += 1
  460. this.loadArticles()
  461. }
  462. if (this.data.curNav == 3) {
  463. this.data.mine.pagination.page += 1
  464. switch (this.data.mine.curNav) {
  465. case 1:
  466. case '1':
  467. this.loadMyCollectedarticles();
  468. break;
  469. case 2:
  470. case '2':
  471. this.loadMyComments()
  472. break;
  473. case 3:
  474. case '3':
  475. this.loadMyActivities()
  476. break;
  477. default:
  478. this.loadMyPubarticles()
  479. }
  480. }
  481. },
  482. loadConfig() {
  483. ilogin.loadConfig({},r => {
  484. app.config = r
  485. this.setData({
  486. config: r
  487. })
  488. })
  489. },
  490. onShareAppMessage() {
  491. return {
  492. title: '冰雪小程序',
  493. path: '/pages/home/home',
  494. imageUrl: '../../imgs/share2.jpg',
  495. success: function(res) {},
  496. fail: function(res) {
  497. console.log(res, '失败')    
  498. }
  499. }
  500. }
  501. })