chat.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // compontents/chat/chat.js
  2. const util = require('../../utils/util.js');
  3. const APIClient = require('../../utils/APIClient.js');
  4. const login = require('../../utils/loginSchedule.js');
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. * productionData 传过来的数据
  9. * title 头部标题
  10. * query 看是上传还是分享图片
  11. * type 主要是判断答疑和分享
  12. * columnType 主要是课程的编号 底下会用到
  13. * more是否显示展开更多
  14. */
  15. properties: {
  16. productionData: {
  17. type: Object,
  18. value: {}
  19. },
  20. title: {
  21. type: String,
  22. value: ''
  23. },
  24. query: {
  25. type: String,
  26. value: ''
  27. },
  28. type: {
  29. type: String,
  30. value: ''
  31. },
  32. columnType: {
  33. type: String,
  34. value: ''
  35. },
  36. more: {
  37. type: String,
  38. value: ''
  39. },
  40. ind: {
  41. type: String,
  42. value: ''
  43. },
  44. timeList: {
  45. type: Array,
  46. value: ''
  47. },
  48. teacher: {
  49. type: String,
  50. value: ''
  51. },
  52. isTopFlagList: {
  53. type: Array,
  54. value: ''
  55. }
  56. },
  57. /**
  58. * 组件的初始数据
  59. * animationData 主要是定义一个展开的动画
  60. */
  61. data: {
  62. animationData: {},
  63. ratio: '',
  64. canvasHeight: ''
  65. },
  66. /**
  67. * 组件的方法列表
  68. */
  69. methods: {
  70. uploadImage (e) {
  71. const type = this.properties.type;
  72. const columnType = this.properties.columnType;
  73. wx.navigateTo({
  74. url: '../input_content/input_content?type=' + type + '&columnType=' + columnType
  75. })
  76. },
  77. listenerButtonPreviewImage: function(e) {
  78. const imgUrl = [...e.target.dataset.img];
  79. const index = e.target.dataset.index;
  80. wx.previewImage({
  81. current: imgUrl[index], // 当前显示图片的http链接
  82. urls: imgUrl, // 需要预览的图片http链接列表
  83. //成功时候调用
  84. success: function(res) {
  85. //console.log(res);
  86. },
  87. //失败时候调用
  88. fail: function() {
  89. //console.log('fail')
  90. }
  91. })
  92. },
  93. //分享
  94. shareImage: function(e){
  95. this.triggerEvent('getHeight');
  96. //分享查询单条的时候会用到这个值
  97. const postId = e.currentTarget.dataset.postsid;
  98. //获取分享的图片
  99. const imgUrl = e.currentTarget.dataset.imgurl;
  100. //获取分享的个人信息
  101. const featureMap = e.currentTarget.dataset.featuremap;
  102. //获取输入内容
  103. const title = e.currentTarget.dataset.title;
  104. //获取宽高比例
  105. const ratio = this.data.ratio;
  106. //分享组件弹窗调用里边方法,在底下会获取
  107. this.share.showPopup(postId, imgUrl, featureMap, title, ratio);
  108. },
  109. //跳转详情页
  110. particulars: function (e) {
  111. const postId = e.currentTarget.dataset.postsid;
  112. const type = e.currentTarget.dataset.type;
  113. //取消小点
  114. login.getOpenidSessionKey(function(res) {
  115. APIClient.cancelDian({
  116. uid: res.data.data.uid
  117. }, {
  118. "postsId":postId
  119. }).success((res) => {
  120. console.log(res);
  121. })
  122. }, function() {
  123. wx.showModal({
  124. title: '提示',
  125. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  126. showCancel: false,
  127. success: function (res) {
  128. if (res.confirm) {
  129. console.log('用户点击确定')
  130. } else if (res.cancel) {
  131. console.log('用户点击取消')
  132. }
  133. }
  134. })
  135. });
  136. wx.navigateTo({
  137. url: '../../pages/particulars/particulars?postId=' + postId + '&type=' + type
  138. })
  139. },
  140. //查看更多
  141. examine: function () {
  142. //组件间方法的调用
  143. var myEventDetail = {} // detail对象,提供给事件监听函数
  144. var myEventOption = {} // 触发事件的选项
  145. this.triggerEvent('myevent', myEventDetail, myEventOption)
  146. },
  147. //获取image宽高
  148. imageLoad: function(e) {
  149. let height = e.detail.height;
  150. let width = e.detail.width;
  151. //获取屏幕宽度
  152. const windowWidth = wx.getSystemInfoSync().windowWidth;
  153. //获取图片高度
  154. const imgHeight = windowWidth*(height/width);
  155. this.setData({
  156. ratio: height/width,
  157. canvasHeight: imgHeight + 300
  158. })
  159. },
  160. //修改留言
  161. setMessage: function ({currentTarget}) {
  162. const id = currentTarget.dataset.id;
  163. const type = currentTarget.dataset.type;
  164. const ind = currentTarget.dataset.ind;
  165. const top = currentTarget.dataset.top == 1 ? '0' : '1';
  166. if(type == 'isTop') {
  167. const str = top == 1 ? '确定置顶吗' : '确定取消置顶吗';
  168. //置顶
  169. wx.showModal({
  170. title: '提示',
  171. content: str,
  172. success: (res) => {
  173. if (res.confirm) {
  174. APIClient.setMessage({
  175. id,
  176. isTop: top,
  177. }).success(res => {
  178. this.data.productionData.list[ind].isTop = top;
  179. if(top == '1') {
  180. this.data.productionData.list.unshift(this.data.productionData.list[ind]);
  181. this.data.productionData.list.splice(ind + 1, 1);
  182. }else {
  183. let arr = [];
  184. //取消置顶排序 isTop 然后uid 然后时间
  185. this.data.productionData.list.sort(function(a,b){
  186. return b.gmtCreated - a.gmtCreated
  187. });
  188. }
  189. this.setData({
  190. productionData: this.data.productionData
  191. })
  192. })
  193. }
  194. }
  195. })
  196. }else {
  197. //删除
  198. wx.showModal({
  199. title: '提示',
  200. content: '确定删除吗',
  201. success: (res) => {
  202. if (res.confirm) {
  203. APIClient.setMessage({
  204. id,
  205. status: 'DEL'
  206. }).success(res => {
  207. console.log('删除成功');
  208. this.data.productionData.list.splice(ind,1);
  209. this.setData({
  210. productionData: this.data.productionData
  211. })
  212. })
  213. }
  214. }
  215. })
  216. }
  217. }
  218. },
  219. ready: function(){
  220. //获取分享弹窗组件
  221. this.share = this.selectComponent("#share");
  222. }
  223. })