friendcircle.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. const app=getApp();
  2. var utils=require("../../../utils/http");
  3. const util=require("../../../utils/util");
  4. let nowfid='',copytextarr=[],copyimgarr=[];
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. storeflag:false,
  11. wxfriendlist:[],
  12. imgUrl:app.globalData.imgUrl,
  13. friendpage:1,
  14. wxlabel:'',
  15. friendkeytext:'',
  16. companylabel:[],
  17. videoid:[],
  18. nowlabel:'',
  19. text:'养成良好的发圈习惯^.^',
  20. fromtype:'',
  21. filterId: '',
  22. tab: [{
  23. name: '全部',
  24. type: ''
  25. },{
  26. name: '分类',
  27. type: '3'
  28. }]
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. let that = this;
  35. if (options.id) {
  36. that.setData({
  37. filterId: options.id
  38. })
  39. }
  40. this.friendtitfun();
  41. this.wxfriendfun();
  42. },
  43. dothis(){},
  44. /**
  45. * 生命周期函数--监听页面初次渲染完成
  46. */
  47. onReady: function () {
  48. },
  49. closetitleTap(){
  50. this.setData({
  51. storeflag:false
  52. })
  53. },
  54. setfromtap(e){
  55. this.setData({
  56. fromtype: e.currentTarget.dataset.type,
  57. storeflag:false,
  58. allfiltrate:false
  59. })
  60. if(this.data.fromtype===''){
  61. this.data.tab[1].name = '分类';
  62. this.setData({
  63. wxlabel:'',
  64. nowlabel:'',
  65. festival_id:'',
  66. tab: this.data.tab
  67. })
  68. } else {
  69. this.setData({
  70. allfiltrate:true
  71. })
  72. }
  73. if (this.data.fromtype) {
  74. return false;
  75. }
  76. this.wxfriendfun();
  77. },
  78. opentitleTap(){
  79. this.setData({
  80. storeflag:true
  81. })
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. // var that=this;
  88. // const query = wx.createSelectorQuery()
  89. // query.select('.pagetop').boundingClientRect()
  90. // query.selectViewport().scrollOffset()
  91. // query.exec(function(res){
  92. // that.setData({
  93. // dayght:res[0].height
  94. // })
  95. // })
  96. },
  97. titleTap:function(e){
  98. this.data.tab[1].name = e.currentTarget.dataset.text;
  99. this.setData({
  100. wxlabel:e.currentTarget.dataset.tid,
  101. tab: this.data.tab,
  102. allfiltrate:false,
  103. fromtype: '3'
  104. })
  105. this.wxfriendfun();
  106. },
  107. friendtitfun:function(){
  108. var that=this;
  109. utils.$post({
  110. url: app.globalData.webUrl + 'api/daily_wechat/label_list',
  111. header: {
  112. 'Authorization':'bearer '+app.globalData.token
  113. },
  114. data:{},
  115. success: function (res) {
  116. that.setData({
  117. companylabel:res.data
  118. })
  119. }
  120. })
  121. },
  122. wxfriendfun:function(e){
  123. var that=this;
  124. this.setData({
  125. friendpage:1
  126. })
  127. wx.showLoading({
  128. title: '加载中...',
  129. })
  130. utils.$get({
  131. url: app.globalData.webUrl + 'api/daily_wechat/list',
  132. header: {
  133. 'Authorization':'bearer '+app.globalData.token
  134. },
  135. data:{
  136. page:1,
  137. limit:10,
  138. festival_id:that.data.wxlabel,
  139. keyword:that.data.friendkeytext,
  140. from_type:that.data.fromtype=='3'?'':'',
  141. id: that.data.filterId
  142. },
  143. success: function (res) {
  144. setTimeout(function(){
  145. wx.hideLoading()
  146. },500)
  147. if(res.data.code=='0'){
  148. // var arr=[ 'png','PNG','jpg','JPG', 'jpeg','JPEG', 'bmp','BMP', 'gif',"GIF","WEBP", 'webp', 'psd',"PSD", 'svg', 'tiff'];
  149. for(let i=0;i<res.data.data.length;i++){
  150. res.data.data[i].textflag=0;
  151. // if(res.data.data[i].type==2){
  152. // res.data.data[i].picture=res.data.data[i].picture.split(',');
  153. // }
  154. if(res.data.data[i].content.length>62){
  155. res.data.data[i].othercontent=res.data.data[i].content.substring(0,60)+'...';
  156. res.data.data[i].textflag=0;
  157. }else{
  158. res.data.data[i].othercontent=res.data.data[i].content;
  159. res.data.data[i].textflag=1;
  160. }
  161. }
  162. that.setData({
  163. wxfriendlist:res.data.data,
  164. datashow:true
  165. })
  166. }
  167. },
  168. fail(){
  169. wx.hideLoading()
  170. }
  171. })
  172. },
  173. previewImg:function(e){
  174. var that=this;
  175. var idx = e.target.dataset.src,current;
  176. var imglist=[];
  177. for(var i=0;i<that.data.wxfriendlist.length;i++){
  178. if(that.data.wxfriendlist[i].id==idx){
  179. imglist=that.data.wxfriendlist[i].picture;
  180. }
  181. }
  182. current=e.target.dataset.vsrc;
  183. wx.previewImage({
  184. current:current, // 当前显示图片的http链接
  185. urls: imglist, // 需要预览的图片http链接列表
  186. fail(res){
  187. console.log(res)
  188. }
  189. })
  190. },
  191. copy:function(e){
  192. var that=this;
  193. wx.setClipboardData({
  194. data: e.currentTarget.dataset.text,
  195. success (res) {
  196. let nowcopy=false;
  197. let friendArr=that.data.wxfriendlist;
  198. nowfid=e.currentTarget.dataset.fid;
  199. for(let i in copyimgarr){
  200. if(nowfid==copyimgarr[i]){
  201. that.addusenumfun();
  202. nowcopy=true;
  203. }
  204. }
  205. if(!friendArr[e.currentTarget.dataset.idx].picture){
  206. that.addusenumfun();
  207. }else if(!nowcopy){
  208. nowfid=e.currentTarget.dataset.fid;
  209. let flag=false;
  210. for(let i in copytextarr){
  211. if(nowfid==copytextarr[i]){
  212. flag=true;
  213. }
  214. }
  215. if(!flag){
  216. copytextarr.push(nowfid);
  217. }
  218. }
  219. }
  220. })
  221. },
  222. saveVideo:function(e){
  223. var that=this;
  224. wx.showLoading({
  225. title: '加载中',
  226. })
  227. let str1=e.currentTarget.dataset.vsrc;
  228. var str=str1.replace('http',"https");
  229. wx.getSetting({
  230. success(res) {
  231. if (!!res.authSetting['scope.writePhotosAlbum']) {
  232. that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
  233. }else{
  234. wx.hideLoading()
  235. wx.showModal({
  236. title: '提示',
  237. content: '您好,请先授权,再保存此图片。',
  238. showCancel: false,
  239. success(res) {
  240. if (res.confirm) {//重新授权弹框用户点击了确定
  241. wx.openSetting({//进入小程序授权设置页面
  242. success(settingdata) {
  243. if (!settingdata.authSetting['scope.writePhotosAlbum']) {
  244. wx.authorize({
  245. scope: 'scope.writePhotosAlbum',
  246. success() {
  247. //这里是用户同意授权后的回调
  248. that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
  249. },
  250. fail(rs){
  251. console.log(rs)
  252. }
  253. })
  254. }else{
  255. wx.authorize({
  256. scope: 'scope.writePhotosAlbum',
  257. success() {
  258. //这里是用户同意授权后的回调
  259. that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
  260. },
  261. fail(rs){
  262. console.log(rs)
  263. }
  264. })
  265. }
  266. },
  267. fail(res){
  268. wx.authorize({
  269. scope: 'scope.writePhotosAlbum',
  270. success() {
  271. //这里是用户同意授权后的回调
  272. that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
  273. },
  274. })
  275. }
  276. })
  277. }
  278. },
  279. fail(res){
  280. that.savevideoToLocal(e.currentTarget.dataset.vsrc,e);
  281. }
  282. })
  283. }
  284. }
  285. })
  286. },
  287. savevideoToLocal:function(vsrc,e){
  288. let that=this;
  289. var friendArr=that.data.wxfriendlist;
  290. wx.showLoading({
  291. title: '加载中',
  292. })
  293. var str=vsrc.replace('http',"https");
  294. var num=0;
  295. wx.downloadFile({
  296. url: str, //仅为示例,并非真实的资源
  297. success (res) {
  298. if (res.statusCode === 200) {
  299. wx.saveVideoToPhotosAlbum({
  300. filePath: res.tempFilePath,
  301. success (res) {
  302. wx.hideLoading()
  303. num++;
  304. that.setData({
  305. num:num
  306. })
  307. that.setData({
  308. downloaded:true
  309. })
  310. setTimeout(function(){
  311. that.setData({
  312. downflag:false
  313. })
  314. },1200)
  315. let nowcopy=false;
  316. for(let i in copytextarr){
  317. if(nowfid==copytextarr[i]){
  318. that.addusenumfun();
  319. nowcopy=true;
  320. }
  321. }
  322. if(!nowcopy){
  323. nowfid=e.currentTarget.dataset.fid;
  324. let flag=false;
  325. for(let i in copyimgarr){
  326. if(nowfid==copyimgarr[i]){
  327. flag=true;
  328. }
  329. }
  330. if(!flag){
  331. copyimgarr.push(nowfid);
  332. }
  333. }
  334. wx.hideLoading()
  335. },
  336. fail(r){
  337. wx.hideLoading()
  338. that.setData({
  339. downflag:false
  340. })
  341. }
  342. })
  343. }else{
  344. wx.hideLoading()
  345. wx.showModal({
  346. title: '下载失败',
  347. content: '下载失败,重新下载!',
  348. showCancel: false,
  349. })
  350. that.setData({
  351. downflag:false
  352. })
  353. }
  354. },
  355. fail(r){
  356. wx.hideLoading();
  357. wx.showModal({
  358. title: '下载失败',
  359. content: '下载失败,重新下载!',
  360. showCancel: false,
  361. })
  362. that.setData({
  363. downflag:false
  364. })
  365. }
  366. })
  367. },
  368. saveImg:function(e){
  369. var that=this;
  370. wx.getSetting({
  371. success(res) {
  372. if (!!res.authSetting['scope.writePhotosAlbum']) {
  373. that.saveImgToLocal(e.currentTarget.dataset.img,e);
  374. }else{
  375. wx.hideLoading()
  376. wx.showModal({
  377. title: '提示',
  378. content: '您好,请先授权,再保存此图片。',
  379. showCancel: false,
  380. success(res) {
  381. if (res.confirm) {//重新授权弹框用户点击了确定
  382. wx.openSetting({//进入小程序授权设置页面
  383. success(settingdata) {
  384. if (!settingdata.authSetting['scope.writePhotosAlbum']) {
  385. wx.authorize({
  386. scope: 'scope.writePhotosAlbum',
  387. success() {
  388. //这里是用户同意授权后的回调
  389. that.saveImgToLocal(e.currentTarget.dataset.img,e);
  390. },
  391. fail(rs){
  392. console.log(rs)
  393. }
  394. })
  395. }else{
  396. wx.authorize({
  397. scope: 'scope.writePhotosAlbum',
  398. success() {
  399. //这里是用户同意授权后的回调
  400. that.saveImgToLocal(e.currentTarget.dataset.img,e);
  401. },
  402. fail(rs){
  403. console.log(rs)
  404. }
  405. })
  406. }
  407. },
  408. fail(res){
  409. wx.authorize({
  410. scope: 'scope.writePhotosAlbum',
  411. success() {
  412. //这里是用户同意授权后的回调
  413. that.saveImgToLocal(e.currentTarget.dataset.img,e);
  414. },
  415. })
  416. }
  417. })
  418. }
  419. },
  420. fail(res){
  421. that.saveImgToLocal(e.currentTarget.dataset.img,e);
  422. }
  423. })
  424. }
  425. }
  426. })
  427. },
  428. saveImgToLocal:function(eimg,e){
  429. let that=this;
  430. var friendArr=that.data.wxfriendlist;
  431. wx.showLoading({
  432. title: '加载中',
  433. })
  434. for(var i=0;i<friendArr.length;i++){
  435. if(friendArr[i].id==eimg){
  436. that.setData({
  437. downlen:friendArr[i].picture.length,
  438. num:0,
  439. downflag:true,
  440. downloaded:false
  441. })
  442. var num=that.data.num;
  443. for(var j=0;j<friendArr[i].picture.length;j++){
  444. var str=friendArr[i].picture[j].replace('http',"https");
  445. wx.downloadFile({
  446. url: str, //仅为示例,并非真实的资源
  447. success (res) {
  448. if (res.statusCode === 200) {
  449. wx.saveImageToPhotosAlbum({
  450. filePath: res.tempFilePath,
  451. success (res) {
  452. num++;
  453. that.setData({
  454. num:num
  455. })
  456. if(num==that.data.downlen){
  457. let nowcopy=false;
  458. for(let i in copytextarr){
  459. if(nowfid==copytextarr[i]){
  460. that.addusenumfun();
  461. nowcopy=true;
  462. }
  463. }
  464. if(!nowcopy){
  465. nowfid=e.currentTarget.dataset.fid;
  466. let flag=false;
  467. for(let i in copyimgarr){
  468. if(nowfid==copyimgarr[i]){
  469. flag=true;
  470. }
  471. }
  472. if(!flag){
  473. copyimgarr.push(nowfid);
  474. }
  475. }
  476. that.setData({
  477. downloaded:true
  478. })
  479. setTimeout(function(){
  480. that.setData({
  481. downflag:false
  482. })
  483. },1200)
  484. }
  485. wx.hideLoading()
  486. },
  487. fail(r){
  488. wx.hideLoading()
  489. that.setData({
  490. downflag:false
  491. })
  492. }
  493. })
  494. }else{
  495. wx.hideLoading()
  496. wx.showModal({
  497. title: '下载失败',
  498. content: '下载失败,重新下载!',
  499. showCancel: false,
  500. })
  501. that.setData({
  502. downflag:false
  503. })
  504. }
  505. },
  506. fail(r){
  507. wx.hideLoading();
  508. wx.showModal({
  509. title: '下载失败',
  510. content: '下载失败,重新下载!',
  511. showCancel: false,
  512. })
  513. that.setData({
  514. downflag:false
  515. })
  516. }
  517. })
  518. }
  519. }
  520. }
  521. },
  522. addusenumfun(){
  523. const that=this;
  524. utils.$post({
  525. url: app.globalData.webUrl + 'api/daily_wechat/use_count',
  526. header: {
  527. 'Authorization':'bearer '+app.globalData.token
  528. },
  529. data:{
  530. id:nowfid,
  531. },
  532. success: function (res) {
  533. if(res.data.code==0){
  534. let arr=that.data.wxfriendlist;
  535. for(let i in arr){
  536. if(arr[i].id==nowfid){
  537. arr[i].use_count=arr[i].use_count*1+1;
  538. that.setData({
  539. wxfriendlist:arr
  540. })
  541. }
  542. }
  543. copyimgarr=[];
  544. copytextarr=[];
  545. nowfid='';
  546. }
  547. }
  548. })
  549. },
  550. filtratetap:function(){
  551. this.setData({
  552. allfiltrate:true
  553. })
  554. },
  555. closetap:function(){
  556. this.setData({
  557. allfiltrate:false
  558. })
  559. },
  560. bindplay:function(e){
  561. var that=this;
  562. var videoid=that.data.videoid;
  563. var flag=false;
  564. videoid.push(e.currentTarget.dataset.vid);
  565. for(var i=0;i<videoid.length;i++){
  566. if(videoid[i]!=e.currentTarget.dataset.vid){
  567. const videoContext = that.selectComponent('#'+videoid[i]);
  568. videoContext.pause();
  569. videoid.splice(i, 1);
  570. flag=true;
  571. }
  572. }
  573. that.setData({
  574. videoid:videoid
  575. })
  576. },
  577. bindpause:function(e){
  578. var that=this;
  579. var videoid=that.data.videoid;
  580. const videoContext = that.selectComponent('#video'+e.currentTarget.dataset.vid);
  581. videoContext.pause();
  582. for(var i=0;i<videoid.length;i++){
  583. if(videoid[i]==e.currentTarget.dataset.vid){
  584. videoid.splice(i, 1);
  585. }
  586. }
  587. that.setData({
  588. videoid:videoid
  589. })
  590. },
  591. bindended:function(e){
  592. var that=this;
  593. var videoid=that.data.videoid;
  594. const videoContext = that.selectComponent('#video'+e.target.dataset.vid);
  595. videoContext.stop();
  596. for(var i=0;i<videoid.length;i++){
  597. if(videoid[i]==e.currentTarget.dataset.vid){
  598. videoid.splice(i, 1);
  599. }
  600. }
  601. videoid=[];
  602. that.setData({
  603. videoid:videoid
  604. })
  605. },
  606. onPageScroll: function (e) {
  607. var that=this;
  608. let screenHeight = wx.getSystemInfoSync().windowHeight
  609. let topBottomPadding = (screenHeight - 175) / 2
  610. const videoObserve = wx.createIntersectionObserver()
  611. videoObserve.relativeToViewport({
  612. bottom: -topBottomPadding,
  613. top: -topBottomPadding
  614. })
  615. .observe("#video"+that.data.videoid[0], (res) => {
  616. // console.log(res)
  617. var videoContext = that.selectComponent('#video'+that.data.videoid[0])
  618. let {
  619. intersectionRatio
  620. } = res
  621. if (intersectionRatio === 0) {
  622. //离开视界,因为视窗占比为0,停止播放
  623. if(videoContext){
  624. videoContext.pause()
  625. }
  626. }
  627. })
  628. },
  629. /**
  630. * 生命周期函数--监听页面隐藏
  631. */
  632. onHide: function () {
  633. },
  634. /**
  635. * 生命周期函数--监听页面卸载
  636. */
  637. onUnload: function () {
  638. },
  639. /**
  640. * 页面相关事件处理函数--监听用户下拉动作
  641. */
  642. onPullDownRefresh: function () {
  643. var that=this;
  644. this.setData({
  645. friendpage:1
  646. })
  647. if (!that.data.wxlabel) {
  648. console.log(that.data.wxlabel)
  649. that.setData({
  650. fromtype: ''
  651. })
  652. }
  653. wx.showLoading({
  654. title: '加载中...',
  655. })
  656. utils.$get({
  657. url: app.globalData.webUrl + 'api/daily_wechat/list',
  658. header: {
  659. 'Authorization':'bearer '+app.globalData.token
  660. },
  661. data:{
  662. page:1,
  663. limit:10,
  664. festival_id:that.data.wxlabel,
  665. keyword:that.data.friendkeytext,
  666. from_type: that.data.fromtype=='3'?'':'',
  667. },
  668. success: function (res) {
  669. wx.hideLoading();
  670. wx.stopPullDownRefresh();
  671. if(res.data.code=='0'){
  672. // var arr=[ 'png','PNG','jpg','JPG', 'jpeg','JPEG', 'bmp','BMP', 'gif',"GIF","WEBP", 'webp', 'psd',"PSD", 'svg', 'tiff'];
  673. for(let i=0;i<res.data.data.length;i++){
  674. res.data.data[i].textflag=0;
  675. // if(res.data.data[i].type==2){
  676. // res.data.data[i].picture=res.data.data[i].picture.split(',');
  677. // }
  678. if(res.data.data[i].content.length>62){
  679. res.data.data[i].othercontent=res.data.data[i].content.substring(0,60)+'...';
  680. res.data.data[i].textflag=0;
  681. }else{
  682. res.data.data[i].othercontent=res.data.data[i].content;
  683. res.data.data[i].textflag=1;
  684. }
  685. }
  686. that.setData({
  687. wxfriendlist:res.data.data,
  688. datashow:true
  689. })
  690. }
  691. },
  692. fail(){
  693. wx.hideLoading()
  694. }
  695. })
  696. },
  697. opentap(e){
  698. const that=this;
  699. let wxfriendlist=that.data.wxfriendlist;
  700. wxfriendlist[e.currentTarget.dataset.idx].textflag=wxfriendlist[e.currentTarget.dataset.idx].textflag==1?0:1;
  701. this.setData({
  702. wxfriendlist:wxfriendlist
  703. })
  704. },
  705. /**
  706. * 页面上拉触底事件的处理函数
  707. */
  708. onReachBottom: function () {
  709. var that=this;
  710. let friendpage=that.data.friendpage;
  711. friendpage=friendpage*1+1;
  712. this.setData({
  713. friendpage:friendpage
  714. })
  715. wx.showLoading({
  716. title: '加载中...',
  717. })
  718. utils.$get({
  719. url: app.globalData.webUrl + 'api/daily_wechat/list',
  720. header: {
  721. 'Authorization':'bearer '+app.globalData.token
  722. },
  723. data:{
  724. page:friendpage,
  725. limit:10,
  726. festival_id:that.data.wxlabel,
  727. keyword:that.data.friendkeytext,
  728. from_type:that.data.fromtype=='3'?'':'',
  729. },
  730. success: function (res) {
  731. wx.hideLoading();
  732. if(res.data.code=='0'){
  733. for(let i=0;i<res.data.data.length;i++){
  734. if(res.data.data[i].content.length>62){
  735. res.data.data[i].othercontent=res.data.data[i].content.substring(0,60)+'...';
  736. res.data.data[i].textflag=0;
  737. }else{
  738. res.data.data[i].othercontent=res.data.data[i].content;
  739. res.data.data[i].textflag=1;
  740. }
  741. }
  742. let wxfriendlist=that.data.wxfriendlist;
  743. wxfriendlist=wxfriendlist.concat(res.data.data);
  744. that.setData({
  745. wxfriendlist:wxfriendlist
  746. })
  747. }
  748. },
  749. fail(){
  750. wx.hideLoading()
  751. }
  752. })
  753. },
  754. /**
  755. * 用户点击右上角分享
  756. */
  757. })