forBack.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // pages/forBack/forBack.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. radioList: [
  11. { name: '学校不满意', type: 'school', value: '8df20e39d0e94a95bc35f020cc2e4b84' },
  12. { name: '课程不满意', type: 'school', value: '00901101530549789799899a113d46e8' },
  13. { name: '产品建议/功能优化', type: 'select', value: '325ef70d708a46d094ef3eaefebaf254' },
  14. { name: '其他问题', type: 'select', value: 'f9b1ecb1bd1943739082552dc68af535' },
  15. ],
  16. curRadioIndex: '-1',
  17. plateList: [],
  18. plateIndex: 0,
  19. radioType: '',
  20. curStu: null,
  21. content: '',
  22. imgList: []
  23. },
  24. getRadio:function(e){
  25. const type = this.data.radioList[e.currentTarget.dataset.index].type
  26. this.setData({
  27. curRadioIndex: e.currentTarget.dataset.index,
  28. radioType: type
  29. })
  30. },
  31. bindPickerChange: function(e) {
  32. this.setData({
  33. plateIndex: e.detail.value
  34. })
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. let stu = wx.getStorageSync('student');
  41. this.setData({ curStu: stu })
  42. let urls = urlDef.urls;
  43. util.apiPost(urls.get_suggest_moudles).then((rs) => {
  44. let list = []
  45. rs.forEach(v => {
  46. list.push({ id: v.id, name: v.detailName })
  47. });
  48. this.setData({ plateList: list })
  49. });
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面显示
  58. */
  59. onShow: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面卸载
  68. */
  69. onUnload: function () {
  70. },
  71. /**
  72. * 页面相关事件处理函数--监听用户下拉动作
  73. */
  74. onPullDownRefresh: function () {
  75. },
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom: function () {
  80. },
  81. /**
  82. * 用户点击右上角分享
  83. */
  84. onShareAppMessage: function () {
  85. },
  86. doInput: function (e) {
  87. this.setData({ content: e.detail.value })
  88. },
  89. len: function(s) {
  90. return (s == null ? 0 : s.length);
  91. },
  92. doSave: function () {
  93. let urls = urlDef.urls
  94. if (this.len(this.data.content) === 0) {
  95. wx.showToast({ title: '请输入建议或投诉内容', icon: 'none' });
  96. return;
  97. }
  98. let t = this.data.radioList[this.data.curRadioIndex]
  99. let typeId = t ? t.value : '';
  100. let moduleId = this.data.plateList[this.data.plateIndex].id
  101. if ((typeId !== '8df20e39d0e94a95bc35f020cc2e4b84' && typeId !== '00901101530549789799899a113d46e8')
  102. && (this.len(moduleId) === 0)) {
  103. wx.showToast({ title: '请选择模块', icon: 'none' });
  104. return;
  105. }
  106. let entity = {}
  107. entity.studentId = this.data.curStu.studentId
  108. entity.submitDate = new Date();
  109. entity.status = 1;
  110. entity.orgId = this.data.curStu.orgId
  111. entity.remarks = this.data.content
  112. entity.telephone = wx.getStorageSync('phone')
  113. entity.typeId = typeId
  114. entity.moduleId = moduleId
  115. util.apiPost(urls.suggest_save, entity, 'application/json').then((rs) => {
  116. wx.showToast({ title: '提交成功', icon: 'success' });
  117. entity.id = rs.id;
  118. const body = { 'id': rs.id, 'orgId': this.data.curStu.orgId, 'studentId': this.data.curStu.studentId }
  119. util.apiPost(urls.suggest_send_message, body, 'application/json').then((rs) => {
  120. console.log('发送通知 ' + JSON.stringify(rs));
  121. });
  122. // 保存图片
  123. let imgs = [];
  124. let delList = []
  125. this.data.imgList.forEach(r => {
  126. if (r.delete && r.delete == 1) {
  127. delList.push(r.url.substring(r.url.lastIndexOf('/') + 1))
  128. } else {
  129. imgs.push({ feedbackId: rs.id, feedbackImageUrl: r.url })
  130. }
  131. });
  132. // 删除文件
  133. if (delList.length > 0) {
  134. const params = { 'keys': delList }
  135. util.apiPost(urls.file_delete, params).then((rs) => {
  136. console.log('删除文件 ... ');
  137. });
  138. }
  139. if (imgs.length > 0) {
  140. console.log('保存关联图片 ... ');
  141. util.apiPost(urls.suggest_image_save, imgs, 'application/json').then((rs) => {
  142. })
  143. }
  144. setTimeout(() => {
  145. wx.navigateBack({
  146. delta: 1, // 返回上一级页面。
  147. success: function () {
  148. console.log('成功!')
  149. }
  150. })
  151. }, 1000)
  152. })
  153. },
  154. uploadTap: function () {
  155. const that = this
  156. const urls = urlDef.urls;
  157. wx.chooseImage({
  158. count: 6,
  159. sourceType: ['album', 'camera'],
  160. success(res) {
  161. wx.showLoading({
  162. title: '上传中...',
  163. })
  164. for (var i in res.tempFilePaths) {
  165. wx.uploadFile({
  166. filePath: res.tempFilePaths[i],
  167. name: 'name',
  168. url: urls.file_upload,
  169. header: util.getHeaders(),
  170. success(res) {
  171. wx.showToast({
  172. title: '上传成功',
  173. })
  174. const rs = JSON.parse(JSON.parse(JSON.stringify(res.data)))
  175. const list = [{ url: rs.data[0].url }]
  176. that.setData({
  177. imgList: that.data.imgList.concat(list)
  178. })
  179. },
  180. fail(res) {
  181. wx.showToast({
  182. title: '上传失败',
  183. icon: none
  184. })
  185. },
  186. complete(res) {
  187. wx.hideLoading({
  188. success: (res) => { },
  189. })
  190. }
  191. })
  192. }
  193. }
  194. })
  195. },
  196. showImg: function (e) {
  197. const index = e.currentTarget.dataset.index
  198. let images = this.data.imgList;
  199. let imgs = []
  200. images.map(i => {
  201. imgs.push(i.url)
  202. })
  203. wx.previewImage({
  204. current: images[index].url,
  205. urls: imgs,
  206. })
  207. },
  208. delImg: function (e) {
  209. const index = e.currentTarget.dataset.index
  210. let images = this.data.imgList;
  211. let image = images[index]
  212. image.delete = 1
  213. this.setData({
  214. imgList: images
  215. })
  216. },
  217. })