123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- // compontents/chat/chat.js
- const util = require('../../utils/util.js');
- const APIClient = require('../../utils/APIClient.js');
- const login = require('../../utils/loginSchedule.js');
- Component({
- /**
- * 组件的属性列表
- * productionData 传过来的数据
- * title 头部标题
- * query 看是上传还是分享图片
- * type 主要是判断答疑和分享
- * columnType 主要是课程的编号 底下会用到
- * more是否显示展开更多
- */
- properties: {
- productionData: {
- type: Object,
- value: {}
- },
- title: {
- type: String,
- value: ''
- },
- query: {
- type: String,
- value: ''
- },
- type: {
- type: String,
- value: ''
- },
- columnType: {
- type: String,
- value: ''
- },
- more: {
- type: String,
- value: ''
- },
- ind: {
- type: String,
- value: ''
- },
- timeList: {
- type: Array,
- value: ''
- },
- teacher: {
- type: String,
- value: ''
- },
- isTopFlagList: {
- type: Array,
- value: ''
- }
- },
- /**
- * 组件的初始数据
- * animationData 主要是定义一个展开的动画
- */
- data: {
- animationData: {},
- ratio: '',
- canvasHeight: ''
- },
- /**
- * 组件的方法列表
- */
- methods: {
- uploadImage (e) {
- const type = this.properties.type;
- const columnType = this.properties.columnType;
- wx.navigateTo({
- url: '../input_content/input_content?type=' + type + '&columnType=' + columnType
- })
- },
- listenerButtonPreviewImage: function(e) {
- const imgUrl = [...e.target.dataset.img];
- const index = e.target.dataset.index;
- wx.previewImage({
- current: imgUrl[index], // 当前显示图片的http链接
- urls: imgUrl, // 需要预览的图片http链接列表
- //成功时候调用
- success: function(res) {
- //console.log(res);
- },
- //失败时候调用
- fail: function() {
- //console.log('fail')
- }
- })
- },
- //分享
- shareImage: function(e){
- this.triggerEvent('getHeight');
- //分享查询单条的时候会用到这个值
- const postId = e.currentTarget.dataset.postsid;
- //获取分享的图片
- const imgUrl = e.currentTarget.dataset.imgurl;
- //获取分享的个人信息
- const featureMap = e.currentTarget.dataset.featuremap;
- //获取输入内容
- const title = e.currentTarget.dataset.title;
- //获取宽高比例
- const ratio = this.data.ratio;
- //分享组件弹窗调用里边方法,在底下会获取
- this.share.showPopup(postId, imgUrl, featureMap, title, ratio);
- },
- //跳转详情页
- particulars: function (e) {
- const postId = e.currentTarget.dataset.postsid;
- const type = e.currentTarget.dataset.type;
- //取消小点
- login.getOpenidSessionKey(function(res) {
- APIClient.cancelDian({
- uid: res.data.data.uid
- }, {
- "postsId":postId
- }).success((res) => {
- console.log(res);
- })
- }, function() {
- wx.showModal({
- title: '提示',
- content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- });
- wx.navigateTo({
- url: '../../pages/particulars/particulars?postId=' + postId + '&type=' + type
- })
- },
- //查看更多
- examine: function () {
- //组件间方法的调用
- var myEventDetail = {} // detail对象,提供给事件监听函数
- var myEventOption = {} // 触发事件的选项
- this.triggerEvent('myevent', myEventDetail, myEventOption)
- },
- //获取image宽高
- imageLoad: function(e) {
- let height = e.detail.height;
- let width = e.detail.width;
- //获取屏幕宽度
- const windowWidth = wx.getSystemInfoSync().windowWidth;
- //获取图片高度
- const imgHeight = windowWidth*(height/width);
- this.setData({
- ratio: height/width,
- canvasHeight: imgHeight + 300
- })
- },
- //修改留言
- setMessage: function ({currentTarget}) {
- const id = currentTarget.dataset.id;
- const type = currentTarget.dataset.type;
- const ind = currentTarget.dataset.ind;
- const top = currentTarget.dataset.top == 1 ? '0' : '1';
- if(type == 'isTop') {
- const str = top == 1 ? '确定置顶吗' : '确定取消置顶吗';
- //置顶
- wx.showModal({
- title: '提示',
- content: str,
- success: (res) => {
- if (res.confirm) {
- APIClient.setMessage({
- id,
- isTop: top,
- }).success(res => {
- this.data.productionData.list[ind].isTop = top;
- if(top == '1') {
- this.data.productionData.list.unshift(this.data.productionData.list[ind]);
- this.data.productionData.list.splice(ind + 1, 1);
- }else {
- let arr = [];
- //取消置顶排序 isTop 然后uid 然后时间
- this.data.productionData.list.sort(function(a,b){
- return b.gmtCreated - a.gmtCreated
- });
- }
- this.setData({
- productionData: this.data.productionData
- })
- })
- }
- }
- })
- }else {
- //删除
- wx.showModal({
- title: '提示',
- content: '确定删除吗',
- success: (res) => {
- if (res.confirm) {
- APIClient.setMessage({
- id,
- status: 'DEL'
- }).success(res => {
- console.log('删除成功');
- this.data.productionData.list.splice(ind,1);
- this.setData({
- productionData: this.data.productionData
- })
- })
- }
- }
- })
- }
- }
- },
- ready: function(){
- //获取分享弹窗组件
- this.share = this.selectComponent("#share");
- }
- })
|