// customer/pages/screenshot/screenshot.js var app = getApp(); var utils = require("../../../utils/http"); var page = 1; Page({ /** * 页面的初始数据 */ data: { imageArr: [], nowimagearr: [], uploadlist: [], remark: '', loading: false, showMask: false, datashow: false, shareArticleNew: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { page = 1; wx.showLoading({ title: '加载中...', }) wx.hideHomeButton(); this.getUploadImglist(); }, /** * 获取上传分享截图列表 */ getUploadImglist() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/agents_work/uploadlog_list', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { page: page, limit: 10, }, success: function (res) { wx.hideLoading(); if (res.data.code == '0') { that.setData({ datashow: true, uploadlist: res.data.data }) } } }) }, /** * 分享内容 */ getNewShareArticleNum() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/agentsWork/newShareArticle', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == '0') { that.setData({ shareArticleNew: res.data.new }) } } }) }, /** * 预览图片 */ previewImage(e) { let index = e.currentTarget.dataset.index; let idx = e.currentTarget.dataset.idx; wx.previewImage({ urls: this.data.uploadlist[index]['img'], current: this.data.uploadlist[index]['img'][idx] }) }, /** * 输入备注信息 */ getRemarkVal(e) { this.setData({ remark: e.detail.value }) }, /** * 提交分享截图内容 */ submit() { if (!this.data.imageArr.length) { wx.showToast({ title: '请选择要上传的截图!', icon: "none" }) return false; } if (!this.data.remark) { wx.showToast({ title: '请输入备注信息!', icon: "none" }) return false; } this.setData({ loading: true }) this.ossuploadimg(); }, requestUploadImageApi() { let that = this; let imgs = that.data.nowimagearr.filter((item,index,itemArr) => { return itemArr.indexOf(item) == index; }).map(v => { return {serverId: "", img: v,}; }); utils.$post({ url: app.globalData.webUrl + 'api/agentsWork/upload_share_log', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { file_media_id: imgs, remarks: that.data.remark }, success: function (res) { that.setData({ loading: false }) if (res.data.code == '0') { wx.showToast({ title: '上传成功', icon: "success", duration: 1500, success: function() { that.setData({ showMask: false }) page = 1; wx.showLoading({ title: '加载中...', }) that.getUploadImglist(); } }) } } }) }, /** * 弹出分享截图上传 */ uploadClick() { this.setData({ showMask: true }) }, /** * 关闭分享截图上传 */ closeMask() { this.setData({ showMask: false }) }, dothis() { }, jumpMinePage: function () { wx.reLaunch({ url: '/customer/pages/broker/broker', }) }, jumpSharePage: function () { wx.reLaunch({ url: '/customer/pages/brokershare/brokershare', }) }, jumpRankPage: function () { wx.reLaunch({ url: '/customer/pages/brokerindex/brokerindex?type=rank', }) }, jumpIndexPage: function () { wx.reLaunch({ url: '/customer/pages/brokerindex/brokerindex', }) }, /** * 选择上传的图片 */ chooseImage() { let _this = this; wx.chooseMedia({ count: 9, mediaType: ["image"], sourceType: ["album", "camera"], sizeType: ['original', 'compressed'], success: function (res) { if (res.errMsg == "chooseMedia:ok") { _this.data.imageArr = _this.data.imageArr.concat(res.tempFiles); _this.setData({ imageArr: _this.data.imageArr }) } } }) }, /** * 删除图片 */ imagedel(e) { let index = parseInt(e.currentTarget.dataset.index); this.data.imageArr.splice(index, 1); this.setData({ imageArr: this.data.imageArr }) }, /** * 上传图片到OSS */ ossuploadimg: function (e) { let that = this; let trackimgarr = that.data.imageArr; var arr = []; for (let i = 0; i < trackimgarr.length; i++) { // 随机生成文件名称 var fileRandName = Date.now() + "" + parseInt(Math.random() * 10000) + i; var imgName = fileRandName + '.' + 'png'; var date = new Date(); var time = date.getFullYear() + '' + (date.getMonth() * 1 + 1) + '' + date.getDate(); var imgstr = 'broker/' + time + '/' + imgName; var nowimagearr = that.data.nowimagearr; nowimagearr.push(imgstr); that.setData({ nowimagearr: nowimagearr }) wx.uploadFile({ url: 'https://wzh-zqxg.oss-cn-hangzhou.aliyuncs.com', filePath: trackimgarr[i].tempFilePath, name: 'file', formData: { key: 'broker/' + time + '/' + imgName, policy: "eyJleHBpcmF0aW9uIjoiMjA0MC0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF1dfQ==", OSSAccessKeyId: "LTAI5tHjWupJSCAycy2yVbQZ", success_action_status: "200", signature: "GPu5wBYVzdhICS/hdJH6rKG0kos=", }, header: { "Content-Type": "multipart/form-data", 'accept': 'application/json', }, success: function (rs) { if (rs.errMsg == 'uploadFile:ok') { arr.push('0'); if (arr.length == trackimgarr.length) { that.requestUploadImageApi(); } } }, fail(res) { wx.hideLoading() } }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { setTimeout(() => { wx.stopPullDownRefresh(); }, 1500); page = 1; wx.showLoading({ title: '加载中...', }) this.getUploadImglist(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { wx.showLoading({ title: '加载中...', }) page = page * 1 + 1; let that = this; utils.$post({ url: app.globalData.webUrl + 'api/agents_work/uploadlog_list', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { page: page, limit: 10, }, success: function (res) { wx.hideLoading(); if (res.data.code == '0') { that.data.uploadlist = that.data.uploadlist.concat(res.data.data); that.setData({ datashow: true, uploadlist: that.data.uploadlist }) } } }) }, })