pushArticle.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // pages/pushArticle/pushArticle.js
  2. var app = getApp();
  3. const request = require("../../utils/request.js");
  4. const uploadImage = require('../../utils/uploadFile.js');
  5. const login = require("../../utils/login.js");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. productId: null,
  12. uploadURL: request._debug ? 'test/toktok/cont/content/' : 'toktok/cont/content/',
  13. content: '',
  14. imgList: [],
  15. selectedTagList: [],
  16. },
  17. pushContent() {
  18. let that = this;
  19. let tagIds_list = that.data.selectedTagList.map((item,index)=>{
  20. return item.contTagId
  21. })
  22. let parmas = {
  23. productId: that.data.productId,
  24. imgUrls: that.data.imgList.join(';'),
  25. tagIds: tagIds_list.join(';'),
  26. content: that.data.content
  27. }
  28. request.postData(
  29. 'app/cont/content/pub',
  30. parmas,
  31. res => {
  32. app.globalData.content = ''
  33. app.globalData.imgList = []
  34. app.globalData.selectedTagList = []
  35. wx.redirectTo({
  36. url: '../circlesDetail/circlesDetail?contentId=' + res.data.data
  37. })
  38. }
  39. )
  40. },
  41. delFun(event) {
  42. let index = event.currentTarget.dataset.idx;
  43. this.data.imgList.splice(index,1)
  44. this.setData({
  45. imgList: this.data.imgList
  46. })
  47. },
  48. getbindinput(event) {
  49. app.globalData.content = event.detail.value;
  50. this.setData({
  51. content: event.detail.value
  52. })
  53. },
  54. uploadImg() {
  55. let that = this;
  56. let count = Number(9 - that.data.imgList.length);
  57. wx.chooseMedia({
  58. count: count,
  59. mediaType: ['image'],
  60. sourceType: ['album', 'camera'],
  61. success(res) {
  62. console.log(res)
  63. const tempFiles = res.tempFiles;
  64. tempFiles.forEach(function(value, index) {
  65. uploadImage(value.tempFilePath, that.data.uploadURL,
  66. function(res) {
  67. that.data.imgList.push(res)
  68. that.setData({
  69. imgList: that.data.imgList
  70. })
  71. },
  72. function(res) {
  73. console.log(res)
  74. })
  75. })
  76. }
  77. })
  78. },
  79. addTags() {
  80. app.globalData.content = this.data.content;
  81. app.globalData.imgList = this.data.imgList;
  82. let tagObject = JSON.stringify(this.data.selectedTagList);
  83. wx.navigateTo({
  84. url: '../addTags/addTags?tagObject='+tagObject
  85. })
  86. },
  87. /**
  88. * 生命周期函数--监听页面加载
  89. */
  90. onLoad(options) {
  91. login.getAssumeRole()
  92. if(options.productId) {
  93. this.setData({
  94. productId: options.productId
  95. })
  96. }
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady() {
  102. },
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow() {
  107. this.setData({
  108. content: app.globalData.content,
  109. imgList: app.globalData.imgList,
  110. selectedTagList: app.globalData.selectedTagList
  111. })
  112. },
  113. /**
  114. * 生命周期函数--监听页面隐藏
  115. */
  116. onHide() {
  117. },
  118. /**
  119. * 生命周期函数--监听页面卸载
  120. */
  121. onUnload() {
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh() {
  127. },
  128. /**
  129. * 页面上拉触底事件的处理函数
  130. */
  131. onReachBottom() {
  132. },
  133. /**
  134. * 用户点击右上角分享
  135. */
  136. onShareAppMessage() {
  137. }
  138. })