//上传标识
var i=0
//imglist为要上传图片的路径数组
uploadImg: function () {
var that = this
if (i == imglist.length) {
//清空还原
news = ""
city = ""
i=0
wait = true
imglist = []
serverImg = []
retrunList = []
that.setData({
loding: false,
src: [],
disabled: false
})
return;
}
var imgcount = imglist.length;
wx.uploadFile({
url: config.serverUrl('index.php/user/uploadtu'),
filePath: imglist[i],
name: 'file',
formData: { 'user': 'test' },
success: function (res) {
serverImg.push(res.data)
if (imgcount == serverImg.length) {
var serverImgStr = serverImg.join("|")
wx.request({
url: config.serverUrl('index.php/user/baobeiadd'),
method: 'POST',
data: Util.json2Form({
imglist: serverImgStr,
userId: userId,
news: news,
city: city,
latitude: latitude,
longitude: longitude
}),
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res2) {
if (res2.data.state == "ok") {
that.setData({
loding: false,
butTxt: "发布",
disabled: false
})
Util.mesUrl("发布成功!", "../index/index")
}
else {
Util.mes("描述至少10人字以上哦,还有图片也要选哦!")
}
}
})
}else
{
//这里直接递归
i++;
that.uploadImg();
}
},
fail: function (e) {
console.log(e)
Util.mes("图片上传失败,请重新发布!" + i)
}
})
},
var i=0
//imglist为要上传图片的路径数组
uploadImg: function () {
var that = this
if (i == imglist.length) {
//清空还原
news = ""
city = ""
i=0
wait = true
imglist = []
serverImg = []
retrunList = []
that.setData({
loding: false,
src: [],
disabled: false
})
return;
}
var imgcount = imglist.length;
wx.uploadFile({
url: config.serverUrl('index.php/user/uploadtu'),
filePath: imglist[i],
name: 'file',
formData: { 'user': 'test' },
success: function (res) {
serverImg.push(res.data)
if (imgcount == serverImg.length) {
var serverImgStr = serverImg.join("|")
wx.request({
url: config.serverUrl('index.php/user/baobeiadd'),
method: 'POST',
data: Util.json2Form({
imglist: serverImgStr,
userId: userId,
news: news,
city: city,
latitude: latitude,
longitude: longitude
}),
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res2) {
if (res2.data.state == "ok") {
that.setData({
loding: false,
butTxt: "发布",
disabled: false
})
Util.mesUrl("发布成功!", "../index/index")
}
else {
Util.mes("描述至少10人字以上哦,还有图片也要选哦!")
}
}
})
}else
{
//这里直接递归
i++;
that.uploadImg();
}
},
fail: function (e) {
console.log(e)
Util.mes("图片上传失败,请重新发布!" + i)
}
})
},