yky-wx-components1
Version:
Taro实现微信小程序红包雨效果
309 lines (276 loc) • 8.7 kB
JavaScript
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import {AtCard,AtIcon} from 'taro-ui'
import './index.less'
import {imgUrl,exportBaseUrl,openPDF} from '../utils/utils'
class Attachment extends Component {
static options = {
addGlobalClass: true
}
config = {
navigationBarTitleText: '审批',
navigationBarBackgroundColor:'#F7F7F7',
navigationBarTextStyle:'black',
navigationStyle: "custom"
}
componentWillReceiveProps (nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount () { }
componentDidShow () { }
componentDidHide () { }
onPullDownRefresh(){
wx.stopPullDownRefresh()
}
// 索引tab栏
constructor () {
super(...arguments)
this.state = {
current: 0,
projectFileObj:'',//项目报告
reportFileObj:'',//尽调报告
showProjectFile:true,
showReportFile:true,
fileHidden:false
}
}
handleClick (value) {
this.setState({
current: value
})
}
handleClick1 (value) {
this.setState({
current1: value
})
}
// nav-bar高度
componentDidMount () {
this.setNavSize()
// this.handleGetAccessoriesName()
}
setNavSize () {
let sysinfo = Taro.getSystemInfoSync();
let statusHeight = sysinfo.statusBarHeight
let isiOS = sysinfo.system.indexOf('iOS') > -1
let navHeight
if (!isiOS) {
navHeight = 48;
} else {
navHeight = 44;
}
this.setState({
status: statusHeight,
navHeight: navHeight
})
}
//返回上一页
handleBack(){
console.log(223)
Taro.navigateBack({
// url:`/pages/lending/lendingDetails/index`
})
}
//获取附件的名称
handleGetAccessoriesName(){
// const {projectReport,reportFile} = this.$router.params;
let params1 = {
token: Taro.getStorageSync('token') ? Taro.getStorageSync('token') : '',
userFlag: Taro.getStorageSync('userFlag') ? Taro.getStorageSync('userFlag') : '',
fileId:projectReport
}
let params2 = {
token: Taro.getStorageSync('token') ? Taro.getStorageSync('token') : '',
userFlag: Taro.getStorageSync('userFlag') ? Taro.getStorageSync('userFlag') : '',
fileId:reportFile
}
try {
if(projectReport && projectReport!=='' && projectReport!==null && projectReport!=='null'){
api.getAccessoriesName(params1).then(res =>{
if(res.success===true){
this.setState({
projectFileObj:res.obj
})
}else{
Taro.showToast(res.msg)
}
}).then(()=>{
if(reportFile && reportFile!=='' && reportFile!==null && reportFile!=='null'){
api.getAccessoriesName(params2).then(res =>{
if(res.success===true){
this.setState({
reportFileObj:res.obj
})
}
})
}
})
}
} catch (error) {
Taro.showToast(error)
}
}
//显示项目报告的文件
handleShowfile(sign){
console.log(sign,'zz')
if(sign==='0'){
this.setState((prevState)=>({
showProjectFile:!prevState.showProjectFile,
}))
}else{
this.setState((prevState)=>({
showReportFile:!prevState.showReportFile,
}))
}
// 附件的显示与隐藏标识
if(this.state.fileHidden==false){
this.setState({
fileHidden:true
})
}else{
this.setState({
fileHidden:false
})
}
}
chakanfujian(receivablesId,desc){
const {pdfFileVoList}=this.props
const baseUrl=getBaseUrl()
console.log(pdfFileVoList,'cc')
const mingxibiao=pdfFileVoList[1].pdfUrl
const tongyishu=pdfFileVoList[0].pdfUrl
let category = 1
let token= Taro.getStorageSync('token') ? Taro.getStorageSync('token') : ''
let userFlag=Taro.getStorageSync('userFlag') ? Taro.getStorageSync('userFlag') : ''
// console.log(baseUrl,'11')
// let params="token="+token+"&userFlag="+userFlag+ "&category=" + category+ "&desc=" + desc;
// let url='/ceMakeLoansConsumer/rebackUrlForApp/' + receivablesId+'?'+params
let params = {
token: Taro.getStorageSync('token') ? Taro.getStorageSync('token') : '',
userFlag: Taro.getStorageSync('userFlag') ? Taro.getStorageSync('userFlag') : '',
category:1,
desc:desc
}
if(desc=='0'){
const PDF=baseUrl+mingxibiao
console.log(PDF,'21')
openPDF(PDF)
}else if(desc=='1'){
const PD1F=baseUrl+tongyishu
openPDF(PD1F)
}
// api.getPdfUrl(params,receivablesId).then(res => {
// if(res.success==true){
// const PDF=baseUrl+res.obj
// openPDF(PDF)
// }else{
// wx.showToast({
// title: res.msg,
// icon: 'none',
// duration: 3000
// })
// }
// })
// this.openPDF(url)
}
// 打开附件
openPDF(PDF) {
let sysinfo = Taro.getSystemInfoSync()
let isiOS = sysinfo.system.indexOf('iOS') > -1
console.log(sysinfo.system,'23')
let isHUAWEI = sysinfo.brand.toUpperCase().indexOf('HUAWEI') > -1
let isXIAOMI = sysinfo.brand.toLowerCase().indexOf('xiaomi') > -1
if (isiOS) { //ios
// if(leixin=='pdf'){
// this.$preload({ url: PDF })
// Taro.navigateTo({
// url: '/pages/pdf/index'
// })
// }else{
Taro.downloadFile({
url: PDF,
success: function(res1) {
let Path = res1.tempFilePath
console.log(res1,'pp')
Taro.openDocument({
filePath: Path,
fileType:leixin!='txt'?leixin:'docx',
success: function() {
console.log('打开文档成功')
}
})
}
})
// }
} else if (isHUAWEI || isXIAOMI) {
Taro.setClipboardData({
data: PDF,
success: function () {
Taro.showModal({
title: '提示',
content: '复制成功,请使用浏览器下载浏览',
showCancel: false
})
}
})
} else { //Android
Taro.downloadFile({
url: PDF,
success: function(res1) {
console.log(res1,'12')
let Path = res1.tempFilePath
Taro.openDocument({
filePath: Path,
fileType:'pdf',
success: function() {
console.log('打开文档成功')
}
})
}
})
}
}
//打开pdf合同
handleOpenPDF(url) {
const {pdfBaseUrl}=this.props
let pdfurl = pdfBaseUrl + url;
openPDF(pdfurl)
}
render () {
const {projectFileObj, reportFileObj, showProjectFile,showReportFile} = this.state;
console.log(showProjectFile,'ppp')
let {pdfFileVoList}=this.props
if(!Array.isArray(pdfFileVoList)){
pdfFileVoList=[]
}
let pdfLength=0
if(pdfFileVoList){
pdfLength=pdfFileVoList.length
}
return (
<View >
<AtCard
className='attachment-card'
>
<View className='report-item' >
<View className='report-header'>
<View><Image src={`${this.props.imgUrl}approvel/xmbg.png`} style="width:48rpx;height:48rpx"/>{this.props.title?this.props.title:'---'}</View>
<View onClick={this.handleShowfile.bind(this,'0')}>{pdfLength}份<AtIcon value={showProjectFile?'chevron-down':'chevron-up'} size='16' color='#317BF2'></AtIcon></View>
</View>
<View className='report-con' hidden={this.state.fileHidden}>
{
pdfFileVoList && pdfFileVoList.map(item => {
return (
// <Text onClick={this.handleOpenPDF.bind(this, item.pdfUrl)} className="checkContract">{item.pdfType}</Text>
<View onClick={this.handleOpenPDF.bind(this, item.pdfUrl)}>{item.pdfType}</View>
)
})
}
</View>
</View>
</AtCard>
</View>
)
}
}
export default Attachment