You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
271 lines
5.8 KiB
271 lines
5.8 KiB
3 years ago
|
var Api = require('../../../utils/common.js');
|
||
|
var re = require('../../../utils/request.js');
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
photolist:[],
|
||
|
id:'',
|
||
|
uploaderList: [],//fengmian
|
||
|
showList: [],
|
||
|
uploaderNum: 0,
|
||
|
showUpload: true,
|
||
|
ifremove:true,
|
||
|
remooveList:[]
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function (options) {
|
||
|
var that = this;
|
||
|
that.setData({
|
||
|
id:options.id
|
||
|
})
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
*/
|
||
|
onReady: function () {
|
||
|
|
||
|
},
|
||
|
toedit:function(){
|
||
|
this.setData({
|
||
|
ifremove:false,
|
||
|
remooveList:[]
|
||
|
})
|
||
|
},
|
||
|
getAlbumOne:function(){
|
||
|
var that = this;
|
||
|
const imgUrl = wx.getStorageSync('imgUrl')
|
||
|
var header = {
|
||
|
token:wx.getStorageSync('token'),
|
||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||
|
};
|
||
|
var postData={
|
||
|
albumId:that.data.id,
|
||
|
param:'1',
|
||
|
sort:'desc'
|
||
|
};
|
||
|
re.request(Api.getAlbumOne(), postData, header).then((res) => {
|
||
|
let datas = res.data.data;
|
||
|
console.log(datas)
|
||
|
for(let i=0;i<datas.length;i++){
|
||
|
if(datas[i].photoUrl){
|
||
|
datas[i].photoUrl = imgUrl + datas[i].photoUrl
|
||
|
}
|
||
|
}
|
||
|
that.setData({
|
||
|
photolist:datas
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
/**
|
||
|
* 生命周期函数--监听页面显示
|
||
|
*/
|
||
|
onShow: function () {
|
||
|
this.getAlbumOne();
|
||
|
},
|
||
|
// 删除图片
|
||
|
clearImg: function (e) {
|
||
|
var nowList = []; //新数据
|
||
|
var nowListshow = []; //新数据
|
||
|
var uploaderList = this.data.uploaderList; //原数据
|
||
|
var showList = this.data.showList; //原数据
|
||
|
|
||
|
for (let i = 0; i < uploaderList.length; i++) {
|
||
|
if (i == e.currentTarget.dataset.index) {
|
||
|
continue;
|
||
|
} else {
|
||
|
nowList.push(uploaderList[i]);
|
||
|
nowListshow.push(showList[i]);
|
||
|
}
|
||
|
}
|
||
|
this.setData({
|
||
|
uploaderNum: this.data.uploaderNum - 1,
|
||
|
uploaderList: nowList,
|
||
|
showUpload: true,
|
||
|
showList: nowListshow
|
||
|
})
|
||
|
},
|
||
|
//展示图片
|
||
|
showImg: function (e) {
|
||
|
var that = this;
|
||
|
wx.previewImage({
|
||
|
urls: that.data.uploaderList,
|
||
|
current: that.data.uploaderList[e.currentTarget.dataset.index]
|
||
|
})
|
||
|
},
|
||
|
//上传图片
|
||
|
upload: function (e) {
|
||
|
var that = this;
|
||
|
wx.chooseImage({
|
||
|
count: 9 - that.data.uploaderNum, // 默认3
|
||
|
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
||
|
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
||
|
success: function (res) {
|
||
|
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
|
||
|
let tempFilePaths = res.tempFilePaths;
|
||
|
let uploaderList = that.data.uploaderList.concat(tempFilePaths);
|
||
|
if (uploaderList.length == 9) {
|
||
|
that.setData({
|
||
|
showUpload: false
|
||
|
})
|
||
|
}
|
||
|
that.setData({
|
||
|
uploaderList: uploaderList,
|
||
|
uploaderNum: uploaderList.length,
|
||
|
})
|
||
|
for (var i = 0; i < tempFilePaths.length; i++) {
|
||
|
wx.uploadFile({
|
||
|
url: Api.uploadImg(),
|
||
|
filePath: res.tempFilePaths[i],
|
||
|
name: 'file',
|
||
|
formData: {
|
||
|
},
|
||
|
success: function (res) {
|
||
|
var sss = JSON.parse(res.data);
|
||
|
let showList = that.data.showList.concat(sss.msg);
|
||
|
that.setData({
|
||
|
showList: showList
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
clubPhotoadd:function(){
|
||
|
var that = this;
|
||
|
const imgUrl = wx.getStorageSync('imgUrl')
|
||
|
var header = {
|
||
|
token:wx.getStorageSync('token'),
|
||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||
|
};
|
||
|
var postData={
|
||
|
albumId:that.data.id,
|
||
|
photos:that.data.showList
|
||
|
};
|
||
|
re.request(Api.clubPhotoadd(), postData, header).then((res) => {
|
||
|
wx.showToast({
|
||
|
title: '上传成功',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
wx.navigateBack({
|
||
|
delta: 1
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
deletephoto:function(){
|
||
|
var that = this;
|
||
|
var header = {
|
||
|
token:wx.getStorageSync('token'),
|
||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||
|
};
|
||
|
let list = that.data.remooveList;
|
||
|
let ids = '';
|
||
|
ids = list.join(',')
|
||
|
var postData={
|
||
|
ids:ids,
|
||
|
};
|
||
|
if(ids){
|
||
|
re.request(Api.removephoto(), postData, header).then((res) => {
|
||
|
wx.showToast({
|
||
|
title: '删除成功',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
that.setData({
|
||
|
ifremove:true
|
||
|
})
|
||
|
that.getAlbumOne();
|
||
|
})
|
||
|
}else{
|
||
|
wx.showToast({
|
||
|
title: '请选择你要删除的图片',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
}
|
||
|
|
||
|
},
|
||
|
tonoenjoy:function(e){
|
||
|
var that = this;
|
||
|
var header = {
|
||
|
token:wx.getStorageSync('token'),
|
||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||
|
};
|
||
|
var postData={
|
||
|
mode:'sub',
|
||
|
photoId:e.currentTarget.dataset.id
|
||
|
};
|
||
|
re.request(Api.photoenjoy(), postData, header).then((res) => {
|
||
|
wx.showToast({
|
||
|
title: '取消点赞',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
that.getAlbumOne();
|
||
|
})
|
||
|
},
|
||
|
toenjoy:function(e){
|
||
|
var that = this;
|
||
|
var header = {
|
||
|
token:wx.getStorageSync('token'),
|
||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||
|
};
|
||
|
var postData={
|
||
|
mode:'add',
|
||
|
photoId:e.currentTarget.dataset.id
|
||
|
};
|
||
|
re.request(Api.photoenjoy(), postData, header).then((res) => {
|
||
|
wx.showToast({
|
||
|
title: '点赞成功',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
that.getAlbumOne();
|
||
|
})
|
||
|
},
|
||
|
checkboxChange:function(e){
|
||
|
const values = e.detail.value;
|
||
|
this.setData({
|
||
|
remooveList:values
|
||
|
|
||
|
})
|
||
|
},
|
||
|
//
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 用户点击右上角分享
|
||
|
*/
|
||
|
onShareAppMessage: function () {
|
||
|
|
||
|
}
|
||
|
})
|