index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const app = getApp();
  2. const util = require("../../../util/util.js")
  3. Page({
  4. data: {
  5. StatusBar: app.globalData.StatusBar,
  6. CustomBar: app.globalData.CustomBar,
  7. content: '',
  8. img_list:[],
  9. submit: false,
  10. img: ''
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. this.setData({submit:false})
  17. },
  18. confirm: function (e) {
  19. let img = this.data.img_list.join(",");
  20. let { content } = e.detail.value;
  21. let param = { img, content };
  22. if( this.data.submit) return;
  23. util.http("User.Suggest", param, (errCode, res) => {
  24. util.showToast(errCode, "提交成功", res);
  25. if( errCode == 200){
  26. this.setData({submit: true})
  27. }
  28. });
  29. },
  30. ChooseImage() {
  31. let that = this
  32. wx.chooseImage({
  33. count: 3, //默认9
  34. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  35. sourceType: ['album', 'camera'], //从相册选择
  36. success: (res) => {
  37. for( let i in res.tempFilePaths ){
  38. that.doUpload(res.tempFilePaths[i] );
  39. }
  40. }
  41. });
  42. },
  43. doUpload(imgPath) {
  44. this.setData({ loadModal: true });
  45. let img_list = this.data.img_list;
  46. if( img_list.length >3 ){
  47. this.setData({loadModal: false });
  48. return;
  49. }
  50. util.uploadFile(1, imgPath, (newPath) => {
  51. img_list.push( newPath )
  52. this.setData({ img_list, loadModal: false });
  53. })
  54. },
  55. DelImg(e) {
  56. var index = e.currentTarget.dataset.index;//获取data-src
  57. let img_list = this.data.img_list;
  58. wx.showModal({
  59. title: '确认',
  60. content: '你确认要删除么?',
  61. cancelText: '再想想',
  62. confirmText: '确认',
  63. success: res => {
  64. if (res.confirm) {
  65. img_list.splice( index, 1)
  66. this.setData({img_list })
  67. }
  68. }
  69. })
  70. },
  71. /**
  72. * 用户点击右上角分享
  73. */
  74. onShareAppMessage: function () {
  75. },
  76. goBack(){
  77. wx.navigateBack({
  78. delta:1
  79. })
  80. }
  81. })