You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

552 lines
12 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// pages/myAgentNew/images/index.js
let app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
imageList:[],
imageListJob:[],
deleteShow:false,
deleteI:false,
isEdit:false,
urls:[],
agencyId:'',
checkedImg:'',
isLoading:false,
jobDetail:{},
isStore:true,
},
imgLoad(e){
console.log(e);
// wx.showLoading({
// title: '加载中...',
// })
// if(e.type == 'load'){
// wx.hideLoading();
// }
},
chooseMedia(e){
var that = this;
var num = e.currentTarget.dataset.type;
wx.chooseMedia({
count: 9,
mediaType: ['image','video'],
sizeType: ['original','compressed'],
sourceType: ['album', 'camera'],
success (res) {
// tempFilePath可以作为 img 标签的 src 属性显示图片
wx.showLoading({
title: '上传中...',
})
console.log(res);
var currData = {};
if(num == 1){
currData["fkId"] = that.data.jobDetail.store.id
that.setData({
isStore:true
})
}else{
currData["fkId"] = that.data.jobDetail.storeJob.id
that.setData({
isStore:false
})
}
currData["type"] = num;
const tempFilePaths = res.tempFiles;
tempFilePaths.forEach((item,index)=>{
// let currData = {};
// currData["agencyId"] = that.data.agencyId;
// currData['']
// currData["url"] = tempFilePaths[index];
wx.uploadFile({
url: app.globalData.ip + "/imgs/uploadImage",
method: "post",
// data:currData,
// name: "uploadFile",
filePath: tempFilePaths[index].tempFilePath,
name: "uploadFile",
header: app.globalData.header2,
success: function (res) {
wx.hideLoading()
console.log(res);
console.log(JSON.parse(res.data));
currData.data = JSON.parse(res.data);
if(currData.data.status == 500){
wx.showToast({
title: '上传失败,请重新上传',
duration:1500,
success(){
wx.hideLoading()
}
})
return
}
// currData["url"] = JSON.parse(res.data.data)[0];
// 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.type,currData.fkId,currData.data.data);
// if (idcard.status == 200) {
// } else {
// }
},
fail: function (res) {
console.log(res);
},
});
})
}
})
},
updateImgs(type,fkId,url){
var that = this;
console.log(type);
console.log(fkId);
console.log(url);
let currData = {};
currData["fkId"] = fkId;
currData["type"] = type;
currData["url"] = url;
currData["recordState"] = 3;
wx.request({
url: app.globalData.ip + "/imgs/upload",
header: app.globalData.header,
method: "post",
data:currData,
success: function (res) {
console.log(res.data);
if(res.data.status == 500){
wx.showToast({
title: '上传失败,请重新上传',
duration:1500,
success(){
wx.hideLoading()
}
})
return
}
let obj = {};
obj.id = res.data.data.img.id;
obj.url = res.data.data.img.url;
obj.recordState = 3;
let regs = /\.(jpg|jpeg|png)(\?.*)?$/;
obj.isImg = regs.test(res.data.data.img.url.toLowerCase());
// obj.isImg = true;
obj.checked = false;
if(that.data.isStore){
that.data.imageList.push(obj);
that.setData({
imageList:that.data.imageList
})
}else{
that.data.imageListJob.push(obj);
that.setData({
imageListJob:that.data.imageListJob
})
}
that.pushImg();
// wx.hideLoading();
// 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) {
var that = this;
that.setData({
jobDetail: wx.getStorageSync('jobDetail')
})
console.log(that.data.jobDetail);
},
changeEdit(){
this.setData({
isEdit:true
})
},
closeEdit(){
this.setData({
isEdit:false
})
},
checkboxChange(e){
var that = this;
const items = this.data.imageList;
const itemsJob = this.data.imageListJob
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) {
if (items[i].id - values[j] == 0) {
items[i].checked = true
break
}
}
}
for (let i = 0, lenI = itemsJob.length; i < lenI; ++i) {
itemsJob[i].checked = false
for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
if (itemsJob[i].id - values[j] == 0) {
itemsJob[i].checked = true
break
}
}
}
if(values.length > 0){
this.setData({
deleteShow:true
})
}else{
this.setData({
deleteShow:false
})
}
console.log('items', items)
console.log('itemsJob', itemsJob)
this.setData({
imageList:items,
imageListJob:itemsJob,
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);
that.data.checkedImg.forEach((item,index)=>{
wx.request({
url: app.globalData.ip + "/imgs/del/"+item,
header: app.globalData.header,
// data:currData,
method: "get",
success: function (res) {
console.log(res.data);
var currImg = [];
var currImg2 = [];
that.data.imageList.forEach((item,index)=>{
that.data.checkedImg.forEach((item1,index1)=>{
if(item.id == item1){
currImg.push(item)
}
})
});
that.data.imageListJob.forEach((item,index)=>{
that.data.checkedImg.forEach((item1,index1)=>{
if(item.id == item1){
currImg2.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)
const arrSet2 = new Set(that.data.imageListJob);
for (const o of currImg2) {
arrSet2.delete(o);
}
const newArr2 = [...arrSet2];
console.log(newArr2)
that.setData({
imageList:newArr,
imageListJob:newArr2
});
that.pushImg();
},
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 + "/imgs/list/"+that.data.jobDetail.storeJob.id+"?type=2",
header: app.globalData.header,
method: "GET",
success: function (res) {
console.log(res.data.data);
// console.log(that.convertHtmlToText(res.data.data.articleContent));
var imgs = [];
var imgsJob = [];
// if(app.isNotEmptyCheck(res.data.data.brand)){
// imgs.push({url:res.data.data.brand,id:99999})
// };
if(app.isNotEmptyCheck(res.data.data.store)){
res.data.data.store.forEach((item,index)=>{
item.checked = false
imgs.push({url:item.url,id:item.id,recordState:item.recordState})
});
}
if(app.isNotEmptyCheck(res.data.data.storeJob)){
res.data.data.storeJob.forEach((item,index)=>{
item.checked = false
imgsJob.push({url:item.url,id:item.id,recordState:item.recordState})
});
}
let regs = /\.(jpg|jpeg|png)(\?.*)?$/;
imgs.forEach((item) => {
item.isImg = regs.test(item.url.toLowerCase());
});
imgsJob.forEach((item) => {
item.isImg = regs.test(item.url.toLowerCase());
});
that.setData({
// record: res.data.data,
imageList:imgs,
imageListJob:imgsJob
});
// 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=>{
if(item.isImg){
that.data.urls.push(item.url)
}
})
that.data.imageListJob.forEach(item=>{
if(item.isImg){
that.data.urls.push(item.url)
}
})
that.setData({
urls:that.data.urls
})
// console.log(that.data.imageList);
console.log( that.data.urls);
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
showVideo(e) {
console.log(e);
console.log(wx.getSystemInfo());
var that = this;
this.videoContext = wx.createVideoContext(`${e.target.dataset.id}`, this);
this.videoContext.requestFullScreen();
this.videoContext.hideStatusBar();
this.videoContext.play();
setTimeout(() => {
that.setData({
isShareShow: true,
});
}, 500);
},
fullScreen(e) {
console.log(e);
if (!e.detail.fullScreen) {
this.setData({
isShareShow: false,
});
this.videoContext.stop();
}
},
shareVideo(e) {
console.log(e);
wx.showLoading({
title: "下载中...",
mask: true,
});
wx.downloadFile({
url: e.currentTarget.dataset.src, // 下载url
success(res) {
// 下载完成后转发
wx.hideLoading();
wx.showLoading({
title: "分享中...",
mask: true,
});
wx.shareVideoMessage({
videoPath: res.tempFilePath,
success() {
wx.hideLoading();
},
fail: () => {
wx.hideLoading();
wx.showToast({
title: "分享失败",
});
},
});
},
fail: () => {
wx.hideLoading();
wx.showToast({
title: "下载失败",
});
},
});
},
renderToCanvas() {
const p1 = this.widget.renderToCanvas({ wxml: wxml(that.data.wxml), style });
p1.then((res) => {
console.log("container", res.layoutBox);
this.container = res;
console.log(res);
});
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})