<template>
    <view class="container">
        <!-- 供销社列表 -->
        <view class="rnwdList" v-for="(item, index) in list" :key="index">
            <view @tap="goDetails(item.id)" class="cooperativeImgBox">
                <image :src="loadImgSrc('/snbj.png')" class="cooperativeImg"></image>
                <!--<image :src="loadImgSrc(item.imgUrl)" class="cooperativeImg"></image>-->
            </view>
            <view @tap="goDetails(item.id)" class="cooperativeBox">
                <view class="list">
                    <span class="listTitle">{{ item.name }}</span>
                    <view class="jlSj">
                        <span class="jf">
                            {{ item.address?item.address:'' }}
                        </span>
                    </view>
                </view>
            </view>
            <em class="iconfont icon-xiangyoujiantou"></em>
        </view>
        <uni-load-more :status="status" :content-text="contentText"/>
        <uni-fab ref="fab" horizontal="right" vertical="bottom"
                 @fabClick="handleAdd()"/>
    </view>
</template>

<script>
import { getList, getDetails } from '@/api/cooperative/cooperative';
export default {
    data() {
        return {
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 15,
                id: null,
                status:"1",
            },
            // 加载更多
            status: 'more',
            contentText: {
                contentdown: '查看更多',
                contentrefresh: '加载中',
                contentnomore: '------------------我是有底线的------------------'
            },
            // 列表数据
            list: [
                {
                    name:"-",
                    address:"-",
                    chargePeople:"-",
                    chargePhone:"-",
                    imgUrl:"-"
                }
            ],
        };
    },
    onPullDownRefresh() {
        this.queryParams.pageNum = 1;
        this.list = [];
        this.getList()
    },
    //上拉加载
    onReachBottom(){
        let pageNum = this.queryParams.pageNum;
        let pageSize = this.queryParams.pageSize;
        let total = this.total;
        if(pageNum*pageSize >= total){
            uni.showToast({
                title:'暂无更多数据'
            });
            return;
        } else {
            this.queryParams.pageNum += 1;
            this.getList()
        }
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        this.getList();
    },
    methods: {
        /** 新增按钮操作 */
        handleAdd(){
            uni.navigateTo({
                url: '../cooperative/addCooperative'
            });
        },
        /** 查询列表 */
        getList(type) {
            this.loading = true;
            getList().then(response => {
                if (this.queryParams.pageNum === 1) {
                    this.list = response.rows;
                } else {
                    this.list = this.list.concat(response.rows);
                }
                // 判断是否还有更多数据
                if (response.rows.length < this.queryParams.pageSize) {
                    this.status = 'noMore'; // 没有更多数据
                } else {
                    this.status = 'more'; // 还有更多数据
                }
            });
        },
        /** 查询详情 */
        goDetails(id) {
            uni.navigateTo({
                url: '/pages/cooperative/details?id='+id
            });
        }
    }
};
</script>
<style>
@import './cooperative.css';
</style>
