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.
109 lines
2.9 KiB
109 lines
2.9 KiB
// pages/preview-list/preview-list.js |
|
const $api = require('../../utils/api').API; |
|
Page({ |
|
|
|
/** |
|
* 页面的初始数据 |
|
*/ |
|
data: { |
|
previewFileList: [], |
|
images: [], |
|
loadingHidden: true |
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面加载 |
|
*/ |
|
onLoad: function (options) { |
|
if (options.transactionStatus == "toBeListed") { |
|
$api.AJAX('GET', 'applets/landToListAttachment', { |
|
fileType: options.fileType, |
|
proposedseriaId: options.id, |
|
}, true).then(res => { |
|
if (res.data.length > 0) { |
|
let images = res.data.filter(item => { |
|
let src = item.filePath; |
|
let startIndex = src.lastIndexOf("."); |
|
let fileType; |
|
if (startIndex != -1) { |
|
fileType = src.substring(startIndex + 1, src.length).toLowerCase(); |
|
} |
|
let imgTypes = ['png', 'bmp', 'gif', 'jpg', 'jpeg']; |
|
return imgTypes.indexOf(fileType) != -1; |
|
}).map(item => { |
|
return item.filePath |
|
}) |
|
this.setData({ |
|
previewFileList: res.data, |
|
images |
|
}) |
|
} |
|
}) |
|
} else { |
|
$api.AJAX('GET', 'applets/landAttachment', { |
|
fileType: options.fileType, |
|
landListedId: options.id, |
|
}, true).then(res => { |
|
if (res.data.length > 0) { |
|
let images = res.data.filter(item => { |
|
let src = item.filePath; |
|
let startIndex = src.lastIndexOf("."); |
|
let fileType; |
|
if (startIndex != -1) { |
|
fileType = src.substring(startIndex + 1, src.length).toLowerCase(); |
|
} |
|
let imgTypes = ['png', 'bmp', 'gif', 'jpg', 'jpeg']; |
|
return imgTypes.indexOf(fileType) != -1; |
|
}).map(item => { |
|
return item.filePath |
|
}) |
|
this.setData({ |
|
previewFileList: res.data, |
|
images |
|
}) |
|
} |
|
}) |
|
} |
|
}, |
|
preview: function (e) { |
|
let src = e.target.dataset.type; |
|
let startIndex = src.lastIndexOf("."); |
|
let fileType; |
|
let { |
|
images |
|
} = this.data |
|
if (startIndex != -1) { |
|
fileType = src.substring(startIndex + 1, src.length).toLowerCase(); |
|
} |
|
let imgTypes = ['png', 'bmp', 'gif', 'jpg', 'jpeg']; |
|
if (imgTypes.indexOf(fileType) != -1) { |
|
//图片 |
|
wx.previewImage({ |
|
current: src, |
|
urls: images |
|
}) |
|
} else { |
|
this.setData({ |
|
loadingHidden: false |
|
}); |
|
let that = this; |
|
wx.downloadFile({ |
|
url: src, |
|
success: function (res) { |
|
if (res.statusCode === 200) { |
|
let filePath = res.tempFilePath |
|
wx.openDocument({ |
|
fileType: fileType, |
|
filePath: filePath, |
|
success: function () { |
|
that.setData({ |
|
loadingHidden: true |
|
}); |
|
} |
|
}) |
|
} |
|
} |
|
}) |
|
} |
|
} |
|
}) |