index.js 10.7 KB
/**
 * Created by DEV005 on 2017/11/13.
 */

/**
 * Created by tdzl2003 on 12/18/16.
 */
import React, {Component} from "react";
import {
    Image,
    ListView,
    NativeModules,
    StyleSheet,
    Text,
    TextInput,
    TouchableOpacity,
    View,
    Platform,
    RefreshControl,
    ActivityIndicator,
    ScrollView,
    Dimensions,
    Modal,
    FlatList,
    Button
} from "react-native";

import { observable, useStrict, action } from 'mobx';
import { observer } from 'mobx-react';
import {xnToast} from "../utils/utils";
import AppService from "../service/AppService";
import Orientation from 'react-native-orientation';
import moment from "moment";
import {timeShow} from "../utils/utils";
import Video from 'react-native-video'
import SearchBar from 'react-native-search-bar'
const play = require('../img/play.png');
export default class DEMO extends Component {

    static navigationOptions = ({ navigation, screenProps })=>({
        title: '收藏',
        headerLeft:(<View style={{flexDirection: 'row',flex:1}}>
            <TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:15}} onPress={navigation.state.params?navigation.state.params._close:null}>
                <Image style={{  width:16,height:16}}  source={require('../img/backB.png')}  resizeMode="contain"/>
            </TouchableOpacity>
        </View>)
    });

    constructor(props) {
        super(props);
        this.state = {
            dataSoure:[
                // {objectType:'picture'},
                // {objectType:'video'},
                // {objectType:'text'},
                // {objectType:'audio'},
                // {objectType:'url'}
            ],
            pause:false,
            nodata:false,//搜索无结果
            loading:false,
            allList:[]
        };
    }
    componentWillMount(){
        this.getData();
    }

    getData=()=>{
        let vm={
            pageSize:0,
            unionId:global.unionId
        };
        this.setState({
            loading:true
        })
        AppService.findCollectList(vm).then(data=>{
            this.setState({
                loading:false
            })
            if (data.errors == null || data.errors.length > 0) {
                xnToast(data.errors[0].message);
                return
            }
            this.setState({
                dataSoure:data.result,
                allList:data.result
            });

        })
    }

    setTime=(e)=>{
        if (!this.state.pause){
            this.setState({
                pause:true
            })
        }else {
            this.setState({
                pause:false
            })
        }
    }

    componentDidMount(){
        let  _this=this;
        //设置头部
        this.props.navigation.setParams({
            _goBack:()=>{
                this.props.navigation.goBack();
            },
            _close:()=>{
                NativeModules.system.navTo("BACK")
            }
        });
    };
    _toPage=(page,item)=>{
        let that = this;
        this.props.navigation.navigate(page, {item:item,callBack:()=>{
            that.getData();
        }})
    };
    //渲染item
    keyExtractor = (item,index) => index;
    rowRender =(item,i)=>{

        if (item.objectType == 'IMAGE') {
            return (
                <TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
                    <View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
                        <Image resizeMode="cover" source={{uri:item.objectContent+'?x-oss-process=image/resize,w_100'}} style={{backgroundColor:'#ececf1',height:90,width:90}}></Image>
                        <Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName}
                            <Text style={{color:'#999',fontSize:14}}>{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text></Text>
                    </View>
                </TouchableOpacity>

            )
        }else if (item.objectType == 'VIDEO') {
            return (
                <TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
                    <View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
                        <View style={{backgroundColor:'#ececf1',height:90,width:90,justifyContent:'center',alignItems:'center'}}>
                            <Image resizeMode="cover" source={{uri:item.thumbUrl ==null? "":item.thumbUrl+'?x-oss-process=image/resize,w_100'}}
                                   style={{width:'100%',height:'100%'}}></Image>
                            <View style={{position:'absolute',justifyContent:'center',alignItems:'center'}}>
                                <Image resizeMode="cover" source={play}
                                       style={{width:20,height:20}}></Image>
                            </View>
                        </View>

                        <Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName}<Text style={{color:'#999',fontSize:14}}>{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text></Text>
                    </View>
                </TouchableOpacity>
            )
        }else if (item.objectType == 'TEXT') {
            return (
                <TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
                    <View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
                        <Text style={{fontSize:16,color:'#333'}}>{item.objectContent}</Text>
                        <Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName}
                        <Text style={{color:'#999',fontSize:14}}>{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text></Text>
                    </View>
                </TouchableOpacity>
            )
        }else if (item.objectType == 'AUDIO') {
            return (
                <TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
                    <View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
                        <View style={{flexDirection:'row',alignItems:'center'}}>
                            <Image source={require('../img/sound.png')}  style={{height:50,width:50}}></Image>
                            <Text style={{marginLeft:15}}></Text>
                        </View>
                        <Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName}  <Text style={{color:'#999',fontSize:14}}>{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text></Text>
                    </View>
                </TouchableOpacity>
            )
        }else if (item.objectType == 'url') {
            return (
                <TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
                    <View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
                        <View style={{flexDirection:'row',alignItems:'flex-start'}}>
                            <Image style={{backgroundColor:'yellow',height:50,width:50}}></Image>
                            <Text style={{marginLeft:15}}>此处显示文章标题</Text>
                        </View>
                        <Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName}  <Text style={{color:'#999',fontSize:14}}>{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text></Text>
                    </View>
                </TouchableOpacity>

            )
        }

    }

    search = (text) =>{
        let contain=[];
        for (let i =0;i<this.state.allList.length;i++){
            let aaa = this.state.allList[i].objectContent;

            if (aaa == null){
                continue;
            }
            let bbb = aaa.indexOf(text);
            if (bbb >-1 ){
                contain.push(this.state.allList[i]);
            }
        }

        if(contain.length==0){
            this.setState({
                nodata:true
            })
        }else {
            this.setState({
                nodata:false
            })
        }
        this.setState({
            dataSoure:contain
        })
    }

    render() {
        return (
            <View style={styles.body}>
                <View style={{width:"100%",height:50,flexDirection:'row',justifyContent:'flex-end',backgroundColor:'#efeff4'}}>
                    <View style={{flex:1,marginLeft:10,marginRight:10,justifyContent:'center',
                        marginBottom:9,marginTop:9,backgroundColor:'#ffffff',borderWidth:1,
                        borderColor:'#dddddd',borderRadius:4}}>
                        <TextInput placeholder={"搜索"}
                                   returnKeyType="search"
                                   onSubmitEditing={()=>this.search(this.state.search)}
                                   onChangeText={(text)=>{
                                       this.state.search=text
                                   }}
                                   underlineColorAndroid="transparent"
                                   style={{flex:1,marginLeft:10,fontSize:12,padding:0}}></TextInput>
                    </View>
                </View>

                {this.state.nodata &&  <View style = {{flex:1,padding:10,alignItems:'center'}}>
                    <Text style={{fontSize:14}}>无结果</Text>
                </View> }

                <FlatList
                    style={styles.list}
                    data={this.state.dataSoure}
                    renderItem={({item,i}) => this.rowRender(item,i)}
                    keyExtractor={this.keyExtractor}
                    ItemSeparatorComponent={()=><View style={{height:10,backgroundColor:'#f0eff5'}}/>}
                    showsVerticalScrollIndicator={false}
                />

            </View>
        );
    }
}

const styles = StyleSheet.create({

    body:{
        flex:1,
        flexDirection:"column",
        backgroundColor:"#f0eff5",

    },
    list:{
        flex:1,
        marginLeft:10,
        marginRight:10,
        marginBottom:10

    },
    item:{
        flexDirection:"row",
        alignItems:"center",
        backgroundColor:"#fff",
        borderBottomWidth:0.5,
        borderBottomColor:"#ddd",
        padding:8,
    },

    itemInfo:{
        flex:1,
        justifyContent:"center",
        height:30,
    },
    itemInfoText:{
        color:"#333",
        fontSize:14,
    },
    link:{
        width:10,
        height:10,
        borderTopWidth:0.5,
        borderTopColor:"#666",
        borderRightWidth:0.5,
        borderRightColor:"#666",
        transform:[
            {rotate:'45deg'},
        ],
    },
    loadingBox: {
        width: (100),
        height: (120),
        backgroundColor: 'rgba(0,0,0,.5)',
        borderRadius: 8,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center'
    }

});