//上传图片 多图
choosePhoto: function () {
var that = this;
wx.chooseImage({
count: 9 , // 默认9
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有 'original',
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
//上传图片
var successUp = 0; //成功个数
var failUp = 0; //失败个数
var length = res.tempFilePaths.length; //总共个数
var i = 0; //第几个
that.uploadDIY(res.tempFilePaths, successUp, failUp, i, length);
console.log(that.data.imglist);
},
});
},
uploadDIY(filePaths, successUp, failUp, i, length) {
var that = this;
var uniacid = app.siteInfo.uniacid;
var upload_picture_list = that.data.upload_picture_list;
wx.uploadFile({
url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Upload&m=pinba',
filePath: filePaths[i],
name: 'upfile',
formData: {},
success: (resp) => {
console.log(resp.data);
successUp++;
upload_picture_list.push(resp.data);
that.setData({
upload_picture_list: upload_picture_list
})
},
fail: (res) => {
failUp++;
},
complete: () => {
i++;
if (i == length) {
wx.hideLoading();
console.log('总共' + successUp + '张上传成功,' + failUp + '张上传失败!');
}
else { //递归调用uploadDIY函数
this.uploadDIY(filePaths, successUp, failUp, i, length);
}
},
});
},
// 删除图片
delImg: function(e) {
var index = e.currentTarget.dataset.id;
var pic = this.data.upload_picture_list;
var that = this;
wx.showModal({
title: '提示',
content: '确定删除吗?',
success: function(res) {
if (res.confirm) {
pic.splice(index, 1);
that.setData({
upload_picture_list: pic,
})
}
console.log(pic);
}
})
},
// 发布
formsubmit(e) {
var val = e.detail.value;
var that = this;
var times = new Date();
var pyear = times.getFullYear();
var pmonth = until.formatNumber(times.getMonth() + 1);
var pday = until.formatNumber(times.getDate());
var phour = until.formatNumber(times.getHours());
var pmin = until.formatNumber(times.getMinutes());
var date = that.data.date;
var Da_w = date.split(" ");
var Da = Da_w[0].split("-");
var time = that.data.time;
var Ti = time.split(":");
var xttime = parseInt("" + pyear + pmonth + pday + phour + pmin);
var pictime = parseInt("" + Da[0] + Da[1] + Da[2] + Ti[0] + Ti[1]);
if (val.q_title == "") {
wx.showToast({
title: '请填写主题名称',
image: "../images/error.png"
})
} else if (xttime >= pictime) {
wx.showToast({
title: '不能小于当前时间',
image: "../images/error.png"
})
} else if (val.q_content == "") {
wx.showToast({
title: '请添加活动描述',
image: "../images/error.png"
})
}
else {
var that = this;
wx.showToast({
title: '上传中,请稍后',
icon: "loading"
})
setTimeout(function () {
var upload_picture_list = that.data.upload_picture_list;
console.log(upload_picture_list)
var val = e.detail.value;
console.log(val)
var openid = wx.getStorageSync('openid')
var q_title = val.q_title;
var q_address = val.q_address;
var q_time = val.q_date + ' ' + val.q_time;
var q_content = val.q_content;
var q_fname = val.q_fname;
// var upload_picture_list = val.fujian;
var q_number = val.q_number;
var q_jieshao = val.q_jieshao;
var q_yijian = val.q_yijian;
var q_tel = val.q_tel;
var q_hname = val.q_hname;
var q_sex = val.q_sex;
var q_age = val.q_age;
var q_aname = val.q_aname;
var q_name = val.q_name;
var feiyong = val.feiyong
console.log(upload_picture_list)
app.util.request({
'url': "entry/wxapp/Fabuhuodong",
data: {
openid: openid,
q_title: q_title,
q_address: q_address,
q_time: q_time,
q_content: q_content,
q_fname: q_fname,
q_slide: upload_picture_list,
q_number: q_number,
q_jieshao: q_jieshao,
q_yijian: q_yijian,
q_tel: q_tel,
q_hname: q_hname,
q_sex: q_sex,
q_age: q_age,
q_aname: q_aname,
q_name: q_name,
feiyong: feiyong,
},
header: {
'Content-Type': 'application/json'
},
success: function (res) {
wx.showToast({
title: "发布成功!",
})
wx.redirectTo({
url: '../huodongzq/huodongzq'
})
console.log(res);
},
fail: function (err) {
console.log(err)
}
})
},3000)
}
},