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.setData({
  47. tempFilePath: tempFilePaths
  48. })
  49. var uploadImgCount = 0;
  50. for (var i = 0, h = tempFilePaths.length; i < h; i++) {
  51. //上传文件
  52. wx.uploadFile({
  53. url: HOST + '/cms/file/upload',
  54. filePath: tempFilePaths[i],
  55. name: 'uploadfile_ant',
  56. header: {
  57. "Content-Type": "multipart/form-data"
  58. },
  59. success: function (res) {
  60. uploadImgCount++;
  61. let data = JSON.parse(res.data);
  62. that.data.imgId.push(data.data.id)
  63. that.setData({
  64. imgId: that.data.imgId,
  65. })
  66. console.log(data);
  67. //如果是最后一张,则隐藏等待中
  68. if (uploadImgCount == tempFilePaths.length) {
  69. wx.hideToast();
  70. }
  71. },
  72. fail: function (res) {
  73. wx.hideToast();
  74. wx.showModal({
  75. title: '错误提示',
  76. content: '上传图片失败',
  77. showCancel: false,
  78. success: function (res) { }
  79. })
  80. }
  81. });
  82. }
  83. }
  84. });
  85. },
  86. //点击发送
  87. send: function() {
  88. const type = utils.getUrl().type;
  89. const columnType = utils.getUrl().columnType;
  90. const columnId = utils.column(columnType).columnId;
  91. const columnName = utils.column(columnType).columnName;
  92. if(this.data.imgId.length == 0 && type == 2){
  93. wx.showModal({
  94. title: '提示',
  95. content: '请上传分享的作品',
  96. success: function(res) {
  97. if (res.confirm) {
  98. console.log('用户点击确定')
  99. } else if (res.cancel) {
  100. console.log('用户点击取消')
  101. }
  102. }
  103. })
  104. return false;
  105. }
  106. let data = {
  107. "title": this.data.textValue,
  108. "type": type,
  109. "columnId": columnId,
  110. "columnType": columnType,
  111. "columnNames": columnName,
  112. };
  113. if(type == 2){
  114. data.imagesStrList = this.data.imgId
  115. }
  116. login.getOpenidSessionKey(function(res) {
  117. //console.log(res.data.data.uid);
  118. APIClient.getSendSchedule({
  119. uid: res.data.data.uid
  120. }, data).success(res => {
  121. console.log(res)
  122. if(res.data.success) {
  123. wx.redirectTo({
  124. url: utils.url(columnType)
  125. })
  126. }
  127. })
  128. }, function() {
  129. wx.showModal({
  130. title: '提示',
  131. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  132. showCancel: false,
  133. success: function (res) {
  134. if (res.confirm) {
  135. console.log('用户点击确定')
  136. } else if (res.cancel) {
  137. console.log('用户点击取消')
  138. }
  139. }
  140. })
  141. });
  142. },
  143. cancel: function() {
  144. wx.navigateBack({ changed: true });
  145. },
  146. /**
  147. * 图片预览
  148. */
  149. listenerButtonPreviewImage: function(e) {
  150. let index = e.target.dataset.index;
  151. let that = this;
  152. wx.previewImage({
  153. current: that.data.tempFilePath[index],
  154. urls: that.data.tempFilePath,
  155. //这根本就不走
  156. success: function(res) {
  157. //console.log(res);
  158. },
  159. //也根本不走
  160. fail: function() {
  161. //console.log('fail')
  162. }
  163. })
  164. },
  165. /**
  166. * 生命周期函数--监听页面加载
  167. */
  168. onLoad: function (options) {
  169. if(options.type == 2) {
  170. wx.setNavigationBarTitle({
  171. title: '作品分享'
  172. })
  173. }
  174. if(options.type == 1) {
  175. wx.setNavigationBarTitle({
  176. title: '答疑讨论'
  177. })
  178. }
  179. this.setData({
  180. type: options.type
  181. })
  182. },
  183. /**
  184. * 生命周期函数--监听页面初次渲染完成
  185. */
  186. onReady: function () {
  187. },
  188. /**
  189. * 生命周期函数--监听页面显示
  190. */
  191. onShow: function () {
  192. },
  193. /**
  194. * 生命周期函数--监听页面隐藏
  195. */
  196. onHide: function () {
  197. },
  198. /**
  199. * 生命周期函数--监听页面卸载
  200. */
  201. onUnload: function () {
  202. },
  203. /**
  204. * 页面相关事件处理函数--监听用户下拉动作
  205. */
  206. onPullDownRefresh: function () {
  207. },
  208. /**
  209. * 页面上拉触底事件的处理函数
  210. */
  211. onReachBottom: function () {
  212. },
  213. /**
  214. * 用户点击右上角分享
  215. */
  216. onShareAppMessage: function () {
  217. }
  218. })