|
|
|
|
|
// pages/myAgentNew/images/index.js
|
|
|
|
|
|
let app = getApp();
|
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
data: {
|
|
|
|
|
|
imageList:[],
|
|
|
|
|
|
deleteShow:false,
|
|
|
|
|
|
deleteI:false,
|
|
|
|
|
|
isEdit:false,
|
|
|
|
|
|
urls:[],
|
|
|
|
|
|
agencyId:'',
|
|
|
|
|
|
checkedImg:'',
|
|
|
|
|
|
isLoading:false
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
chooseMedia(){
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
wx.chooseImage({
|
|
|
|
|
|
count: 9,
|
|
|
|
|
|
sizeType: ['original', 'compressed'],
|
|
|
|
|
|
sourceType: ['album', 'camera'],
|
|
|
|
|
|
success (res) {
|
|
|
|
|
|
// tempFilePath可以作为 img 标签的 src 属性显示图片
|
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
|
title: '上传中...',
|
|
|
|
|
|
})
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
const tempFilePaths = res.tempFilePaths;
|
|
|
|
|
|
tempFilePaths.forEach((item,index)=>{
|
|
|
|
|
|
// let currData = {};
|
|
|
|
|
|
// currData["agencyId"] = that.data.agencyId;
|
|
|
|
|
|
|
|
|
|
|
|
wx.uploadFile({
|
|
|
|
|
|
url: app.globalData.ip + "/agency/uploadImage?agencyId="+that.data.agencyId,
|
|
|
|
|
|
method: "post",
|
|
|
|
|
|
// data:currData,
|
|
|
|
|
|
name: "uploadFile",
|
|
|
|
|
|
filePath: tempFilePaths[index],
|
|
|
|
|
|
header: app.globalData.header2,
|
|
|
|
|
|
success: function (res) {
|
|
|
|
|
|
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
|
|
|
|
|
|
let currData = JSON.parse(res.data);
|
|
|
|
|
|
let obj = {};
|
|
|
|
|
|
obj.id = currData.data.id;
|
|
|
|
|
|
obj.url = currData.data.url;
|
|
|
|
|
|
obj.checked = false;
|
|
|
|
|
|
that.data.imageList.push(obj);
|
|
|
|
|
|
that.setData({
|
|
|
|
|
|
imageList:that.data.imageList
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
that.pushImg();
|
|
|
|
|
|
console.log(that.data.imageList);
|
|
|
|
|
|
|
|
|
|
|
|
// that.updateImgs(currData.data.url);
|
|
|
|
|
|
// if (idcard.status == 200) {
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// }
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: function (res) {
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
updateImgs(url){
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
|
|
|
|
let currData = {};
|
|
|
|
|
|
currData["agencyId"] = that.data.agencyId;
|
|
|
|
|
|
currData["images"] = url;
|
|
|
|
|
|
|
|
|
|
|
|
wx.request({
|
|
|
|
|
|
url: app.globalData.ip + "/agency/updateImgs",
|
|
|
|
|
|
header: app.globalData.header,
|
|
|
|
|
|
method: "post",
|
|
|
|
|
|
data:currData,
|
|
|
|
|
|
success: function (res) {
|
|
|
|
|
|
console.log(res.data);
|
|
|
|
|
|
// debugger;
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: function (res) {
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
showImgs(e){
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
console.log(that.data.urls);
|
|
|
|
|
|
|
|
|
|
|
|
wx.previewImage({
|
|
|
|
|
|
current: e.mark.url, // 当前显示图片的 http 链接
|
|
|
|
|
|
urls: that.data.urls // 需要预览的图片 http 链接列表
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
|
*/
|
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
|
console.log(options.agencyId);
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
agencyId: options.agencyId
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
changeEdit(){
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
isEdit:true
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
closeEdit(){
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
isEdit:false
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
checkboxChange(e){
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
const items = this.data.imageList
|
|
|
|
|
|
const values = e.detail.value
|
|
|
|
|
|
console.log('checkbox发生change事件,携带value值为:', e.detail.value)
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0, lenI = items.length; i < lenI; ++i) {
|
|
|
|
|
|
items[i].checked = false
|
|
|
|
|
|
|
|
|
|
|
|
for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
|
|
|
|
|
|
// console.log(items[i], values[j])
|
|
|
|
|
|
if (items[i].id - values[j] == 0) {
|
|
|
|
|
|
items[i].checked = true
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(values.length > 0){
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
deleteShow:true
|
|
|
|
|
|
})
|
|
|
|
|
|
}else{
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
deleteShow:false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//console.log('items:', items)
|
|
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
imageList:items,
|
|
|
|
|
|
checkedImg:e.detail.value
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
deleteImg(){
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
deleteI:true
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
sureDelete(){
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
|
|
|
|
let currData = {};
|
|
|
|
|
|
|
|
|
|
|
|
currData["images"] = that.data.checkedImg.join(",");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(that.data.imageList);
|
|
|
|
|
|
console.log(that.data.checkedImg);
|
|
|
|
|
|
|
|
|
|
|
|
wx.request({
|
|
|
|
|
|
url: app.globalData.ip + "/agency/delImgs",
|
|
|
|
|
|
header: app.globalData.header,
|
|
|
|
|
|
data:currData,
|
|
|
|
|
|
method: "post",
|
|
|
|
|
|
success: function (res) {
|
|
|
|
|
|
console.log(res.data);
|
|
|
|
|
|
|
|
|
|
|
|
var currImg = [];
|
|
|
|
|
|
|
|
|
|
|
|
that.data.imageList.forEach((item,index)=>{
|
|
|
|
|
|
that.data.checkedImg.forEach((item1,index1)=>{
|
|
|
|
|
|
if(item.id == item1){
|
|
|
|
|
|
currImg.push(item)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
console.log(currImg)
|
|
|
|
|
|
|
|
|
|
|
|
const arrSet = new Set(that.data.imageList);
|
|
|
|
|
|
for (const o of currImg) {
|
|
|
|
|
|
arrSet.delete(o);
|
|
|
|
|
|
}
|
|
|
|
|
|
const newArr = [...arrSet];
|
|
|
|
|
|
|
|
|
|
|
|
console.log(newArr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
that.setData({
|
|
|
|
|
|
imageList:newArr
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
that.pushImg();
|
|
|
|
|
|
// debugger;
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: function (res) {
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
deleteI:false
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
close(){
|
|
|
|
|
|
this.setData({
|
|
|
|
|
|
deleteI:false
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
|
*/
|
|
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
|
*/
|
|
|
|
|
|
onShow() {
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
// wx.showLoading({
|
|
|
|
|
|
// title: '加载中...',
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
that.getList().then(() => {
|
|
|
|
|
|
that.pushImg();
|
|
|
|
|
|
that.setData({
|
|
|
|
|
|
isLoading:true
|
|
|
|
|
|
})
|
|
|
|
|
|
// wx.hideLoading({
|
|
|
|
|
|
// success: (res) => {},
|
|
|
|
|
|
// })
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
getList() {
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
|
wx.request({
|
|
|
|
|
|
url: app.globalData.ip + "/agency/getDetailById?id=" + that.data.agencyId,
|
|
|
|
|
|
header: app.globalData.header,
|
|
|
|
|
|
method: "GET",
|
|
|
|
|
|
success: function (res) {
|
|
|
|
|
|
console.log(res.data);
|
|
|
|
|
|
// console.log(that.convertHtmlToText(res.data.data.articleContent));
|
|
|
|
|
|
res.data.data.imageList.forEach((item,index)=>{
|
|
|
|
|
|
item.checked = false
|
|
|
|
|
|
});
|
|
|
|
|
|
that.setData({
|
|
|
|
|
|
record: res.data.data,
|
|
|
|
|
|
imageList:res.data.data.imageList
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// await that.pushImg();
|
|
|
|
|
|
|
|
|
|
|
|
console.log(that.data.imageList);
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: function (res) {
|
|
|
|
|
|
console.log(res);
|
|
|
|
|
|
reject();
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
pushImg(){
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
that.data.urls = [];
|
|
|
|
|
|
that.data.imageList.forEach(item=>{
|
|
|
|
|
|
that.data.urls.push(item.url)
|
|
|
|
|
|
})
|
|
|
|
|
|
that.setData({
|
|
|
|
|
|
urls:that.data.urls
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
console.log(that.data.imageList);
|
|
|
|
|
|
console.log( that.data.urls);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
|
*/
|
|
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
|
*/
|
|
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
|
*/
|
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
|
*/
|
|
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
|
*/
|
|
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|