123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- // compontents/discuss/discuss.js
- const APIClient = require('../../utils/APIClient.js');
- const login = require('../../utils/loginSchedule.js');
- Component({
- /**
- * 组件的属性列表
- * 暂时放弃了原本是评论框
- */
- properties: {
- discussData: {
- type: Array,
- value: []
- },
- uid: {
- type: String,
- value: ''
- },
- type: {
- type: String,
- value: ''
- },
- postsId: {
- type: String,
- value: ''
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- flag: false,
- text: '',
- discussDatas: [],
- animationData: {},
- messageLength: '',
- downUp: '展开'
- },
- /**
- * 组件的方法列表
- */
- methods: {
- onTap (e) {
- let flage = e.target.dataset.flag;
- if(flage){
- this.util(flage, '0rpx');
- this.setData({
- 'flag': false,
- 'downUp': '展开'
- })
- } else {
- this.util(flage, '800rpx');
- this.setData({
- 'flag': true,
- 'downUp': '收起'
- })
- }
- },
- /* 创建动画并执行 */
- util (flag, height) {
- // 创建动画实例
- var animation = wx.createAnimation({
- duration: 200, //动画时长
- timingFunction: "linear", //线性
- delay: 0 //0则不延迟
- });
-
- this.animation = animation;
- animation.height(height).step();
- this.setData({
- animationData: animation.export()
- })
- },
- /* 获取输入内容 */
- bindKeyInput (e) {
- this.setData({
- text: e.detail.value
- })
- },
- /* 发送评论 */
- sendText () {
- //console.log(this.data.text.trim())
- let text = this.data.text.trim();
- let postsId = this.properties.postsId;
- let _this = this;
- if(text == ''){
- wx.showModal({
- title: '提示',
- content: '请输入评论内容',
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- return false;
- }
- this.data.text = "";
- let data = {
- "postsId": postsId,
- "content": text
- };
- login.getOpenidSessionKey(function(res) {
- //console.log(res.data.data.uid);
- APIClient.getDiscussSchedule({
- uid: res.data.data.uid
- }, data).success(function (res) {
- console.log(res.data)
- if(res.data.success) {
- _this.properties.discussData.push(res.data.data);
- _this.setData({
- discussDatas: _this.properties.discussData,
- messageLength: _this.properties.discussData.length
- });
- };
- });
- }, function() {
- wx.showModal({
- title: '提示',
- content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除勋章战士后再次扫码进入,允许授权后可正常使用',
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- });
- this.setData({
- text: ''
- })
- }
- },
- ready () {
- this.setData({
- discussDatas: this.properties.discussData
- })
- }
- })
|