1
0

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