input_content.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. // pages/Input_content/input_content.js
  2. const app = getApp();
  3. const url = require('../../utils/const.js');
  4. const APIClient = require('../../utils/APIClient.js');
  5. const login = require('../../utils/loginSchedule.js');
  6. const utils = require('../../utils/util.js');
  7. const HOST = url.apiUrl;
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. tempFilePath: [],
  14. imgId: [],
  15. textValue: '',
  16. //type: '',
  17. //columnType: ''
  18. },
  19. /**
  20. * 获取输入框内容
  21. */
  22. bindKeyInput: function(e) {
  23. this.setData({
  24. textValue: e.detail.value
  25. })
  26. },
  27. /**
  28. * 图片上传
  29. */
  30. uploading: function () {
  31. var that = this;
  32. wx.chooseImage({
  33. count: 2, //最多可以选择的图片总数
  34. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  35. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  36. success: function (res) {
  37. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  38. var tempFilePaths = res.tempFilePaths;
  39. //启动上传等待中...
  40. wx.showToast({
  41. title: '正在上传...',
  42. icon: 'loading',
  43. mask: true,
  44. duration: 1000
  45. })
  46. that.data.tempFilePath.push(tempFilePaths);
  47. that.setData({
  48. tempFilePath: that.data.tempFilePath
  49. })
  50. var uploadImgCount = 0;
  51. for (var i = 0, h = tempFilePaths.length; i < h; i++) {
  52. //上传文件
  53. wx.uploadFile({
  54. url: HOST + '/cms/file/upload',
  55. filePath: tempFilePaths[i],
  56. name: 'uploadfile_ant',
  57. header: {
  58. "Content-Type": "multipart/form-data"
  59. },
  60. success: function (res) {
  61. uploadImgCount++;
  62. let data = JSON.parse(res.data);
  63. that.data.imgId.push(data.data.id)
  64. that.setData({
  65. imgId: that.data.imgId,
  66. })
  67. console.log(data);
  68. //如果是最后一张,则隐藏等待中
  69. if (uploadImgCount == tempFilePaths.length) {
  70. wx.hideToast();
  71. }
  72. },
  73. fail: function (res) {
  74. wx.hideToast();
  75. wx.showModal({
  76. title: '错误提示',
  77. content: '上传图片失败',
  78. showCancel: false,
  79. success: function (res) { }
  80. })
  81. }
  82. });
  83. }
  84. }
  85. });
  86. },
  87. //点击发送
  88. send: function() {
  89. const type = utils.getUrl().type;
  90. const columnType = utils.getUrl().columnType;
  91. const columnId = utils.column(columnType).columnId;
  92. const columnName = utils.column(columnType).columnName;
  93. if(this.data.imgId.length == 0 && type == 2){
  94. wx.showModal({
  95. title: '提示',
  96. content: '请上传分享的作品',
  97. success: function(res) {
  98. if (res.confirm) {
  99. console.log('用户点击确定')
  100. } else if (res.cancel) {
  101. console.log('用户点击取消')
  102. }
  103. }
  104. })
  105. return false;
  106. }
  107. let data = {
  108. "title": this.data.textValue,
  109. "type": type,
  110. "columnId": columnId,
  111. "columnType": columnType,
  112. "columnNames": columnName,
  113. };
  114. if(type == 2){
  115. data.imagesStrList = this.data.imgId
  116. }
  117. login.getOpenidSessionKey(function(res) {
  118. //console.log(res.data.data.uid);
  119. APIClient.getSendSchedule({
  120. uid: res.data.data.uid
  121. }, data).success(res => {
  122. console.log(res)
  123. if(res.data.success) {
  124. wx.redirectTo({
  125. url: utils.url(columnType)
  126. })
  127. }
  128. })
  129. }, function() {
  130. wx.showModal({
  131. title: '提示',
  132. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  133. showCancel: false,
  134. success: function (res) {
  135. if (res.confirm) {
  136. console.log('用户点击确定')
  137. } else if (res.cancel) {
  138. console.log('用户点击取消')
  139. }
  140. }
  141. })
  142. });
  143. },
  144. cancel: function() {
  145. wx.navigateBack({ changed: true });
  146. },
  147. /**
  148. * 图片预览
  149. */
  150. listenerButtonPreviewImage: function(e) {
  151. let index = e.target.dataset.index;
  152. let that = this;
  153. wx.previewImage({
  154. current: that.data.tempFilePath[index],
  155. urls: that.data.tempFilePath,
  156. //这根本就不走
  157. success: function(res) {
  158. //console.log(res);
  159. },
  160. //也根本不走
  161. fail: function() {
  162. //console.log('fail')
  163. }
  164. })
  165. },
  166. /**
  167. * 生命周期函数--监听页面加载
  168. */
  169. onLoad: function (options) {
  170. if(options.type == 2) {
  171. wx.setNavigationBarTitle({
  172. title: '作品分享'
  173. })
  174. }
  175. if(options.type == 1) {
  176. wx.setNavigationBarTitle({
  177. title: '答疑讨论'
  178. })
  179. }
  180. this.setData({
  181. type: options.type
  182. })
  183. },
  184. /**
  185. * 生命周期函数--监听页面初次渲染完成
  186. */
  187. onReady: function () {
  188. },
  189. /**
  190. * 生命周期函数--监听页面显示
  191. */
  192. onShow: function () {
  193. },
  194. /**
  195. * 生命周期函数--监听页面隐藏
  196. */
  197. onHide: function () {
  198. },
  199. /**
  200. * 生命周期函数--监听页面卸载
  201. */
  202. onUnload: function () {
  203. },
  204. /**
  205. * 页面相关事件处理函数--监听用户下拉动作
  206. */
  207. onPullDownRefresh: function () {
  208. },
  209. /**
  210. * 页面上拉触底事件的处理函数
  211. */
  212. onReachBottom: function () {
  213. },
  214. /**
  215. * 用户点击右上角分享
  216. */
  217. onShareAppMessage: function () {
  218. }
  219. })