Browse Source

circle page

邹能昇 4 months ago
parent
commit
e73f6dc23c
2 changed files with 120 additions and 12 deletions
  1. 110 8
      nova-werun/components/circle-card/index.js
  2. 10 4
      nova-werun/components/circle-card/index.wxml

+ 110 - 8
nova-werun/components/circle-card/index.js

@@ -21,7 +21,10 @@ Component({
         isgood: false,
         isclick: false,
         //朋友圈
-        cicleList: []
+        cicleList: [],
+        time: '',
+        //点赞人
+        chickList:''
     },
     lifetimes: {
 
@@ -74,16 +77,16 @@ Component({
             console.log(this.data.isgood);
         },
         isclick() {
-            this.setData({
-                isclick: !this.data.isclick
-            })
+            // this.setData({
+            //     isclick: !this.data.isclick
+            // })
+            this.chickin()
             setTimeout(() => {
+                this.showchick()
                 this.showgood()
             }, 400)
-            console.log(this.data.isclick);
         },
         async getcircle() {
-            console.log('数据',this.data.objectId,this.data.type);
             let AIMomentquery = new Parse.Query('AIMoment');
             AIMomentquery.equalTo('company', company);
             AIMomentquery.equalTo('objectId', this.data.objectId);
@@ -99,8 +102,107 @@ Component({
             this.setData({
                 images: this.data.cicleList[0].images
             })
-            console.log('动态', this.data.cicleList);
-            console.log('动态', this.data.type);
+            // 将 ISO 字符串转换为时间戳并传递给 formatTime
+            const createdAt = new Date(this.data.cicleList[0].createdAt).getTime();
+            const time = this.formatTime(createdAt);
+            this.setData({
+                time
+            })
+            this.showchick()
+        },
+        formatTime(timestamp) {
+            const now = Date.now();
+            const diff = now - timestamp;
+            if (diff < 60000) { // 小于1分钟
+                return '刚刚';
+            } else if (diff < 3600000) { // 小于1小时
+                return Math.floor(diff / 60000) + '分钟前';
+            } else if (diff < 86400000) { // 小于24小时
+                return Math.floor(diff / 3600000) + '小时前';
+            } else if (diff < 172800000) { // 小于48小时
+                return '昨天';
+            } else {
+                const date = new Date(timestamp);
+                return date.toLocaleDateString(); // 显示具体日期
+            }
+        },
+        //点击点赞按钮
+        async chickin() {
+            let AIMomentquery = new Parse.Query('AIMoment');
+            AIMomentquery.equalTo('company', company);
+            AIMomentquery.equalTo('objectId', this.data.objectId);
+            AIMomentquery.equalTo('isVisible', true);
+            AIMomentquery.include('profile.user');
+            AIMomentquery.include('profile');
+            AIMomentquery.notEqualTo('isDeleted', true)
+            let P = await AIMomentquery.first();
+              //点赞成功
+            this.setData({
+                isclick: !this.data.isclick
+            })
+            const currentUser = Parse.User.current();
+            let AIMomentCommentquery = new Parse.Query('AIMomentComment');
+            AIMomentCommentquery.equalTo('company', company);
+            AIMomentCommentquery.equalTo('moment', P.toPointer());
+            AIMomentCommentquery.equalTo('user', currentUser.id);
+            let moment = await AIMomentCommentquery.first()
+            if (moment) {
+                moment.set('isDeleted', this.data.isclick)
+                try {
+                    let saveDate = await moment.save();
+                    console.log(saveDate);
+                    console.log("新数据保存成功");
+                } catch (error) {
+                    console.error("保存数据时出现错误:", error);
+                }
+            } else {
+                const currentUser = Parse.User.current();
+                let userquery = new Parse.Query('_User');
+                userquery.equalTo('company', company);
+                userquery.equalTo('objectId', currentUser.id);
+                userquery.notEqualTo('isDeleted', true)
+                let user = await userquery.first();
+
+                let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
+                let Comment = new Parse.Object('AIMomentComment');
+                Comment.set('moment', P.toPointer())
+                Comment.set('company', companyPointer);
+                Comment.set('user', user.toPointer());
+                Comment.set('isDeleted', false);
+                try {
+                    let saveDate2 = await Comment.save();
+                    console.log(saveDate2);
+                    console.log("新数据保存成功");
+                } catch (error) {
+                    console.error("保存数据时出现错误:", error);
+                }
+               
+            }
+        },
+        //显示点赞人
+        async showchick() {
+            const currentUser = Parse.User.current();
+            let AIMomentCommentquery2 = new Parse.Query('AIMomentComment');
+            AIMomentCommentquery2.equalTo('company', company);
+            AIMomentCommentquery2.equalTo('moment', this.data.objectId);
+            AIMomentCommentquery2.equalTo('user', currentUser.id);
+            let moment2 = await AIMomentCommentquery2.find()
+            let AIMoment1List2 = moment2.map(item => item.toJSON());
+            console.log('AIMoment1List2',AIMoment1List2);
+            this.setData({
+                isclick:AIMoment1List2[0].isDeleted
+            })
+            let Momentquery = new Parse.Query('AIMomentComment');
+            Momentquery.equalTo('company', company);
+            Momentquery.equalTo('moment', this.data.cicleList[0].objectId);
+            Momentquery.notEqualTo('isDeleted', true)
+            Momentquery.include('user')
+            let r = await Momentquery.find();
+            let chickList = r.map(item => item.toJSON());
+            console.log(chickList);
+            this.setData({
+                chickList
+            })
         }
     }
 })

+ 10 - 4
nova-werun/components/circle-card/index.wxml

@@ -51,17 +51,17 @@
     <!--  -->
     <view class="timebox">
         <view class="time-box">
-            <view class="time">3个月前</view>
-            <van-icon name="delete-o" size='20' />
+            <view class="time">{{time}}</view>
+            <!-- <van-icon name="delete-o" size='20' /> -->
         </view>
         <!-- 点赞评论 -->
         <view class="functionbox" wx:if="{{isgood}}">
             <view class="function">
-                <view class="function1" wx:if="{{!isclick}}" bindtap="isclick">
+                <view class="function1" wx:if="{{isclick}}" bindtap="isclick" data-id="{{cicleList[0].objectId}}">
                     <van-icon name="like-o" />
                     <view class="text2">赞</view>
                 </view>
-                <view class="function1" wx:if="{{isclick}}" bindtap="isclick">
+                <view class="function1" wx:if="{{!isclick}}" bindtap="isclick">
                     <van-icon name="like" color='red' />
                     <view class="text2">取消</view>
                 </view>
@@ -75,4 +75,10 @@
         <view class="point" bindtap="showgood"> ·· </view>
 
     </view>
+    <view>
+        <block wx:for="{{chickList}}">
+            <view>{{item.user.nickname}}</view>
+        </block>
+
+    </view>
 </view>