city_card/pages/neighbor/circle/new.js
2023-07-15 14:25:28 +08:00

161 lines
5.4 KiB
JavaScript

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
});
},
submitHelp: function() {
var a = this;
if (!a.data.isLoading) {
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,
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.submitNeighborCircle, [ e.baseUrls.requestUrl ]), i, {
headers: {
token: e.globalData.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 || 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.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() {}
});