js 文件
// commercial/pages/message/message.js
var app = getApp();
Page({
data: {
shopid: '',
vipower: true, //二维码中的图片框是否显示
tempFilePathsArr: [], //轮播图数组
tempFilePaths: [], //二维码
textarea: '', //会员权益
shopunia: '',
oldPiclist: [],//旧图片列表
chooseFlag: false, //旧图片列表显示标志
// newPiclist: []
},
onLoad: function (options) {
var that = this;
},
onShow: function () {
},
//选择轮播图片
carouselFigure: function () {
var that = this
var evimg = that.data.tempFilePathsArr;
var count = 9 - evimg.length;
if (count == 0) {
wx.showToast({
title: '最多可上传9张',
icon: "none"
})
return;
}
wx.chooseImage({
count: count, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
console.log(res)
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
var tempFilePathsArr = res.tempFilePaths
var hearr = evimg.concat(tempFilePathsArr);
console.log(hearr)
that.setData({
tempFilePathsArr: hearr,
})
}
})
},
oldimgdelete: function (e) { //删除原始照片
var that = this;
var val = e.currentTarget.dataset.src;
var arr = that.data.oldPiclist;
for (var i = 0; i < arr.length; i++) {
if (arr[i] == val) {
arr.splice(i, 1);
break;
}
}
that.setData({
oldPiclist: arr
})
},
formSubmit: function (e) {
var that = this;
var newPiclist = new Array();
var token = e.currentTarget.dataset.token;
if (that.data.tempFilePathsArr.length > 0) { //如果选择照片数组修改了就上传图片
for (var i = 0; i < that.data.tempFilePathsArr.length; i++) {
console.log(i);
// if (that.data.tempFilePathsArr[i] != that.data.oldPiclist[i]) { //判断选择图片数组里的值是否与旧数组里的一样
wx.uploadFile({ //不一样就将新的一一上传
url: app.wechatUrl('entry/wxapp/UploadImg/yyt_vipcard_plugin_boos') + '&shopunia=' + that.data.shopunia,
filePath: that.data.tempFilePathsArr[i],
name: 'file',
success: function (res) {
console.log(res)
var imgpath = res.data;
newPiclist.push(imgpath);
if (newPiclist.length == that.data.tempFilePathsArr.length) {
that.onloadData(newPiclist, token);
}
}
})
// } else { //如果不一样就将旧的上传
// }
}
// console.log(newPiclist)
} else {
that.onloadData(newPiclist, token);
}
},
details: function (shopid) {
var that = this;
app.util.request({
url: 'entry/wxapp/EditShop',
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: {
m: 'yyt_vipcard_plugin_boos',
op: 'setting',
shopid: shopid
},
success: function (res) {
console.log(res)
that.setData({
details: res.data.data,
// tempFilePathsArr: res.data.data.swiper_pic,
oldPiclist: res.data.data.swiper_pic,
shopunia: res.data.data.shopunia,
textarea: res.data.data.userrights
})
},
fail: function (res) {
// console.log(res)
}
});
},
//上传
onloadData: function (newPiclist, token) {
var that = this;
console.log(typeof (that.data.oldPiclist))
console.log(typeof (newPiclist))
app.util.request({ //如未修改
url: 'entry/wxapp/EditShop',
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: {
m: 'yyt_vipcard_plugin_boos',
op: 'setting',
shopid: that.data.shopid,
oldPiclist: that.data.oldPiclist,
newPiclist: newPiclist,
textarea: that.data.textarea,
token: token
},
success: function (res) {
console.log(res)
var text = res.data.message;
wx.showToast({
title: text,
icon: 'none',
duration: 3000,
mask: true,
success: function (res) {
setTimeout(function () {
wx.switchTab({
url: '../store/store'
})
}, 3000)
},
})
},
fail: function (res) {
var text = res.data.message;
wx.showToast({
title: text,
icon: 'none',
duration: 3000,
mask: true,
success: function (res) {
setTimeout(function () {
wx.switchTab({
url: '../store/store'
})
}, 3000)
},
})
}
});
}
})