123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520 |
- const Parse = getApp().Parse;
- const company = getApp().globalData.company;
- Component({
-
- properties: {
- objectId: '',
- type: '',
- permission: ''
- },
-
- data: {
-
- images: [],
- imageclass: '',
-
- isgood: false,
- isclick: false,
-
- cicleList: [],
- time: '',
-
- chickList: '',
- show: false,
-
- inputValue: '',
- textareaHeight: 52,
- bottomNavHeight: 0,
-
- commentList: [],
-
- poptype: '',
- userobject: '',
-
- commenttext: "评论",
- focusedCommentId: null,
- isCommentFocused: false
- },
- lifetimes: {
- detached: function () {
-
- },
- attached: async function () {
-
- this.getcircle()
- this.showischick()
- this.getbottomheight()
- this.getComment()
- },
- },
-
- methods: {
- onImageLoad: function (e) {
- const {
- width,
- height
- } = e.detail;
- const imageClass = width > height ? 'image-landscape' : 'image-portrait';
- this.setData({
- imageclass: imageClass
- });
- },
- previewImage: function (e) {
- const index = e.currentTarget.dataset.index;
- const images = this.data.images;
- wx.previewImage({
- current: images[index],
- urls: images
- });
- },
- gourl(e) {
- const url = e.currentTarget.dataset.url
- const objectId = e.currentTarget.dataset.id
- wx.navigateTo({
- url: `${url}?id=` + objectId
- });
- },
- showgood() {
- this.setData({
- isgood: !this.data.isgood
- })
- },
- isclick() {
- this.chickin()
- setTimeout(() => {
- this.showchick()
- this.showgood()
- }, 400)
- },
- async getcircle() {
- 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.find();
- let AIMoment1List = P.map(item => item.toJSON());
- this.setData({
- cicleList: AIMoment1List,
- })
- this.setData({
- images: this.data.cicleList[0].images
- })
-
- 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) {
- return '刚刚';
- } else if (diff < 3600000) {
- return Math.floor(diff / 60000) + '分钟前';
- } else if (diff < 86400000) {
- return Math.floor(diff / 3600000) + '小时前';
- } else if (diff < 172800000) {
- return '昨天';
- } else {
- const date = new Date(timestamp);
- return date.toLocaleDateString();
- }
- },
-
- async chickin() {
- this.setData({
- isclick: !this.data.isclick
- })
- 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();
- const currentUser = Parse.User.current();
- let AIMomentCommentquery = new Parse.Query('AIMomentLike');
- AIMomentCommentquery.equalTo('company', company);
- AIMomentCommentquery.equalTo('type', 'chickin');
- AIMomentCommentquery.equalTo('moment', P.toPointer());
- AIMomentCommentquery.equalTo('user', currentUser.id);
- let moment = await AIMomentCommentquery.first()
- if (moment) {
- moment.set('isLiked', this.data.isclick)
- try {
- let saveDate = await moment.save();
- this.showchick()
- 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('AIMomentLike');
- Comment.set('moment', P.toPointer())
- Comment.set('company', companyPointer);
- Comment.set('type', 'chickin');
- Comment.set('user', user.toPointer());
- Comment.set('isLiked', true);
- try {
- let saveDate2 = await Comment.save();
- this.showchick()
- console.log(saveDate2);
- console.log("新数据保存成功");
- } catch (error) {
- console.error("保存数据时出现错误:", error);
- }
- }
- },
-
- async showischick() {
- const currentUser = Parse.User.current();
- let AIMomentCommentquery2 = new Parse.Query('AIMomentLike');
- AIMomentCommentquery2.equalTo('company', company);
- AIMomentCommentquery2.equalTo('type', 'chickin');
- AIMomentCommentquery2.equalTo('moment', this.data.objectId);
- AIMomentCommentquery2.equalTo('user', currentUser.id);
- let moment2 = await AIMomentCommentquery2.find()
- let AIMoment1List2 = moment2.map(item => item.toJSON());
- if (AIMoment1List2.length != 0) {
- this.setData({
- isclick: AIMoment1List2[0].isLiked
- })
- } else {
- this.setData({
- isclick: false
- })
- }
- console.log('isclick', AIMoment1List2);
- },
-
- async showchick() {
- let Momentquery = new Parse.Query('AIMomentLike');
- Momentquery.equalTo('company', company);
- Momentquery.equalTo('type', 'chickin');
- Momentquery.equalTo('moment', this.data.objectId);
- Momentquery.notEqualTo('isDeleted', true)
- Momentquery.include('user')
- Momentquery.equalTo('isLiked', true);
- let r = await Momentquery.find();
- let chickList = r.map(item => item.toJSON());
- console.log('chickList',chickList);
- this.setData({
- chickList
- })
- },
-
- showPopup() {
- this.setData({
- show: true,
- poptype: 'one',
- commenttext: '评论'
- });
- this.showgood()
- },
- onClose() {
- this.setData({
- show: false
- });
- },
-
- onInput: function (event) {
- const value = event.detail.value;
- this.setData({
- inputValue: value,
- textareaHeight: this.calculateHeight(value)
- });
- },
- calculateHeight: function (value) {
-
-
- const lineHeight = 40;
- const lines = Math.ceil(value.length / 30);
- return Math.max(52, lines * lineHeight);
- },
-
- async sendComment() {
-
- if (this.data.poptype == 'one') {
- let AIMomentquery = new Parse.Query('AIMoment');
- AIMomentquery.equalTo('company', company);
- AIMomentquery.equalTo('objectId', this.data.objectId);
- AIMomentquery.equalTo('isVisible', true);
- AIMomentquery.notEqualTo('isDeleted', true)
- let P = await AIMomentquery.first();
- 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('type', 'coment');
- Comment.set('isDeleted', false);
- Comment.set('content', this.data.inputValue);
- Comment.set('user', user.toPointer());
- try {
- let saveDate2 = await Comment.save();
- console.log(saveDate2);
- console.log("新数据保存成功");
- this.getComment()
- } catch (error) {
- console.error("保存数据时出现错误:", error);
- }
-
- console.log(this.data.inputValue);
-
- this.setData({
- inputValue: '',
- textareaHeight: 52
- });
- }
-
- if (this.data.poptype == 'two') {
- console.log('id', this.data.userobject);
- this.rebackmoment()
- }
- },
-
- async getComment() {
- let Momentquery = new Parse.Query('AIMomentComment');
- Momentquery.equalTo('company', company);
- Momentquery.equalTo('type', 'coment');
- Momentquery.equalTo('moment', this.data.objectId);
- Momentquery.notEqualTo('isDeleted', true);
- Momentquery.include('user');
- Momentquery.include('comment');
- Momentquery.include('comment.user');
-
- Momentquery.ascending('createdAt');
- let r = await Momentquery.find();
- let commentList = r.map(item => {
- let comment = item.toJSON();
-
- comment.showdeletid = false;
- return comment;
- });
- const filteredCommentList = commentList.filter(item => !item.comment || (item.comment && !item.comment.isDeleted));
- console.log('评论', filteredCommentList);
- this.setData({
- commentList: filteredCommentList
- });
- },
-
- async showpop(e) {
- const objectId = e.currentTarget.dataset.id;
- let AIMomentCommentquery = new Parse.Query('AIMomentComment');
- AIMomentCommentquery.equalTo('company', company);
- AIMomentCommentquery.equalTo('objectId', objectId);
- AIMomentCommentquery.notEqualTo('isDeleted', true);
- AIMomentCommentquery.include('user');
- let r = await AIMomentCommentquery.find();
- let commentList = r.map(item => item.toJSON());
- 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 R = await userquery.find();
- let user = R.map(item => item.toJSON());
-
- if (user[0].objectId != commentList[0].user.objectId) {
- this.setData({
- show: true,
- poptype: 'two',
- userobject: objectId,
- commenttext: `回复${commentList[0].user.nickname}`
- });
- } else {
-
- const updatedCommentList = this.data.commentList.map(comment => {
- if (comment.objectId === objectId) {
- return {
- ...comment,
- showdeletid: true
- };
- }
- return comment;
- });
- this.setData({
- commentList: updatedCommentList
- });
- console.log('点击了自己');
- }
- console.log(this.data.commentList);
- },
-
- onTapOutside() {
- if (!this.data.isCommentFocused) {
- const updatedCommentList = this.data.commentList.map(comment => ({
- ...comment,
- showdeletid: false ,
- }));
- this.setData({
- commentList: updatedCommentList,
- focusedCommentId: null
- });
- }
- },
-
- onTouchStart() {
- this.onTapOutside();
- },
-
- async rebackmoment() {
-
- let AIMomentCommentquery = new Parse.Query('AIMomentComment');
- AIMomentCommentquery.equalTo('company', company);
- AIMomentCommentquery.equalTo('objectId', this.data.userobject);
- AIMomentCommentquery.notEqualTo('isDeleted', true)
- let Puser = await AIMomentCommentquery.first();
-
- let AIMomentquery = new Parse.Query('AIMoment');
- AIMomentquery.equalTo('company', company);
- AIMomentquery.equalTo('objectId', this.data.objectId);
- AIMomentquery.equalTo('isVisible', true);
- AIMomentquery.notEqualTo('isDeleted', true)
- let P = await AIMomentquery.first();
-
- 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('comment', Puser.toPointer());
- Comment.set('type', 'coment');
- Comment.set('isDeleted', false);
- Comment.set('content', this.data.inputValue);
- Comment.set('user', user.toPointer());
- try {
- let saveDate2 = await Comment.save();
- console.log(saveDate2);
- console.log("新数据保存成功");
- this.getComment()
- } catch (error) {
- console.error("保存数据时出现错误:", error);
- }
-
- console.log(this.data.inputValue);
-
- this.setData({
- inputValue: '',
- textareaHeight: 52
- });
- },
-
- getbottomheight() {
- const systemInfo = wx.getSystemInfoSync();
- const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
- this.setData({
- bottomNavHeight,
- });
- },
-
- async deletecomment(e) {
- const objectId = e.currentTarget.dataset.id
- let Momentquery = new Parse.Query('AIMomentComment');
- Momentquery.equalTo('company', company);
- Momentquery.equalTo('objectId', objectId);
- Momentquery.notEqualTo('isDeleted', true);
- let d = await Momentquery.first();
- d.set('isDeleted', true)
- try {
- let saveDate2 = await d.save();
- console.log(saveDate2);
- console.log("删除成功");
- this.getComment()
- } catch (error) {
- console.error("保存数据时出现错误:", error);
- }
- console.log(objectId);
- },
-
- async deletecircle() {
- let Profilequery = new Parse.Query('AIMoment');
- Profilequery.equalTo('company', company);
- Profilequery.equalTo('isVisible', true);
- Profilequery.notEqualTo('isDeleted', true)
- Profilequery.equalTo('objectId', this.data.objectId);
- let P = await Profilequery.first();
- P.set('isDeleted', true)
- try {
- let saveDate2 = await P.save();
- console.log(saveDate2);
- this.setData({
- objectId: ''
- })
- console.log("删除数据成功");
- } catch (error) {
- console.error("保存数据时出现错误:", error);
- }
- },
- }
- })
|