friendcircle.js 24 KB

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