var e = getApp(); Page({ data: { token: e.globalData.token, sourceUrl: e.baseUrls.sourceUrl, helpType: [], index: 0, helpTypeAll: [], helpSelected: "", content: "", contentSupplement: "", userIcon: wx.getStorageSync("userIcon"), userName: wx.getStorageSync("name"), imageList: [], serviceUrl: e.baseUrls.serviceUrl, baseImgUrl: e.baseUrls.baseImgUrl, videoId: "", communityId: "", areaCode: "", isLoading: !1 }, bindPickerChange: function(e) { this.setData({ index: e.detail.value, helpSelected: this.data.helpTypeAll[e.detail.value - 1].dataId }); }, getHelpType: function() { var a = this; e.restAjax.get(e.restAjax.path(e.apis.getDictionary, [ e.baseUrls.serviceUrl, "4fcf52f9-2e05-4cca-8966-83f0232f22e8" ]), { areaCode: a.data.locationCode }, { headers: { token: a.data.token } }, function(e, t) { for (var o = [ "请选择互助类型" ], i = 0; i < t.length; i++) o.push(t[i].dataName); a.setData({ helpType: o, helpTypeAll: t }), console.log(t); }, function(e, a) { console.log(a); }); }, submitHelp: function() { var a = this; if (!a.data.isLoading) { if (0 == a.data.index) return void wx.showToast({ title: "请选择发布类型", icon: "error" }); var t = ""; if (a.data.imageList.length > 0) for (var o = 0; o < a.data.imageList.length; o++) o != a.data.imageList.length - 1 ? t += a.data.imageList[o] + "," : t += a.data.imageList[o]; var i = { content: a.data.content, contentSupplement: a.data.contentSupplement, photo: t, problemTypeId: a.data.helpSelected, problemTypeName: a.data.helpTypeAll[a.data.index - 1].dataName, video: a.data.videoId, videoCover: "", headPortrait: a.data.userIcon, nickName: a.data.userName, communityId: a.data.communityId, areaCode: a.data.areaCode }; a.setData({ isLoading: !0 }), e.restAjax.post(e.restAjax.path(e.apis.submitHelp, [ e.baseUrls.requestUrl ]), i, { headers: { token: a.data.token } }, function(e, t) { "200" == e && (wx.showToast({ title: "发布成功!", icon: "success" }), setTimeout(function() { a.setData({ isLoading: !1 }), wx.navigateBack({ delta: 1 }); }, 1500)), console.log(e); }, function(e, t) { console.log(t), a.setData({ isLoading: !1 }); }); } }, uploadImage: function() { var a = this; a.data.isLoading || (a.setData({ isLoading: !0 }), wx.chooseImage({ count: 9 - a.data.imageList.length, sourceType: [ "album", "camera" ], success: function(t) { wx.showToast({ title: "上传中", icon: "loading" }); for (var o = function(o) { n = t.tempFiles[o].path, e.restAjax.file(e.restAjax.path(e.apis.uploadImg, [ e.baseUrls.serviceUrl ]), n, "image", { headers: { token: e.globalData.token } }, function(e, i) { if ("200" == e) { var n = JSON.parse(i).data, s = a.data.imageList; s.push(n), a.setData({ imageList: s }), o == t.tempFiles.length - 1 && a.setData({ isLoading: !1 }), wx.hideToast(); } }, function(e, t) { console.log(t), a.setData({ isLoading: !1 }); }); }, i = 0; i < t.tempFiles.length; i++) { var n; o(i); } } })); }, uploadVideo: function() { var a = this; a.data.isLoading || (a.setData({ isLoading: !0 }), wx.chooseVideo({ sourceType: [ "album", "camera" ], success: function(t) { e.restAjax.file(e.restAjax.path(e.apis.uploadVideo, [ e.baseUrls.serviceUrl ]), t.tempFilePath, "video", { headers: { token: e.globalData.token } }, function(e, t) { if ("200" == e) { a.setData({ isLoading: !1 }); var o = JSON.parse(t).data; a.setData({ videoId: o }); } }, function(e, t) { console.log(t), a.setData({ isLoading: !1 }); }); } })); }, deleteImg: function(e) { var a = e.currentTarget.dataset.cur, t = this.data.imageList; t.splice(a, 1), this.setData({ imageList: t }); }, deleteVideo: function() { this.setData({ videoId: "" }); }, onLoad: function(a) { this.getHelpType(), this.setData({ communityId: a.communityId, areaCode: a.areaCode, userIcon: wx.getStorageSync("userIcon"), userName: wx.getStorageSync("name"), token: e.globalData.token }); }, onReady: function() {}, onShow: function() {}, onHide: function() {}, onUnload: function() {}, onPullDownRefresh: function() {}, onReachBottom: function() {}, onShareAppMessage: function() {} });