<template>
    <div class="container">
        <md-scroll-view
                ref="scrollView"
                :scrolling-x="false"
                :bouncing="false"
                :auto-reflow="true"
                @end-reached="$_onEndReached">
            <template v-if="this.list.length > 0">
                                <RiskPoint v-for="(item,index) in list" :key="index" :data="item"/>
                <md-scroll-view-more
                        slot="more"
                        :is-finished="isFinished"
                >
                </md-scroll-view-more>
            </template>
            <template v-else>
                <empty-data-page></empty-data-page>
            </template>
        </md-scroll-view>
    </div>
</template>

<script>
    import {
        TabBar,
        Swiper,
        SwiperItem,
        ScrollView,
        ScrollViewRefresh,
        ScrollViewMore,
        Button,
        InputItem,
        Icon,
        Tag,
    } from 'mand-mobile'

    import {HeadBar, EmptyDataPage} from '@/components'

    import {RiskPoint} from './components/index'

    import {mapGetters} from 'vuex'

    import {hazardList,uploadFile} from '@/api/smart_fire'

    export default {
        name: "index",
        components: {
            [TabBar.name]: TabBar,
            [Swiper.name]: Swiper,
            [SwiperItem.name]: SwiperItem,
            [ScrollView.name]: ScrollView,
            [ScrollViewRefresh.name]: ScrollViewRefresh,
            [ScrollViewMore.name]: ScrollViewMore,
            [Button.name]: Button,
            [InputItem.name]: InputItem,
            [Icon.name]: Icon,
            [Tag.name]: Tag,
            [HeadBar.name]: HeadBar,
            [EmptyDataPage.name]: EmptyDataPage,
            RiskPoint
        },
        data() {
            return {
                current: 0,
                items: [
                    {name: 0, label: '无线火灾报警监控系统', notifications: 0, isShowTag: true},
                    {name: 1, label: '电气火灾智能监控系统', notifications: 0, isShowTag: true},
                    {name: 2, label: '消防给水监测系统', notifications: 0, isShowTag: true},
                    {name: 3, label: '火灾自动报警系统', notifications: 0, isShowTag: true},
                ],
                list: [],
                isFinished: false,
                query: {
                    limit: 10,
                    page: 1
                },
                lastPage: 0,
            }
        },
        computed: {
            ...mapGetters([
                'request_config_aId',
                'request_config_cId',
                'request_config_gId',
                'request_config_baseUrl',
            ])
        },
        mounted() {
            // 所以接口传 aId=294，cId=1
            if (this.$route.query.aId && this.$route.query.cId && this.$route.query.fromUrl) {
                this.$store.dispatch('request_config/setReqConfig', {
                    // aId: 294,
                    // aId: 1352,
                    // aId: 48160,
                    // cId: 1
                    aId: this.$route.query.aId,
                    cId: this.$route.query.cId,
                    gId: this.$route.query.cId,
                })
                this.$store.dispatch('request_config/setBaseUrl', this.$route.query.fromUrl)
            } else {
                this.$store.dispatch('request_config/setReqConfig', {
                    aId: '',
                    cId: ''
                })
                this.$store.dispatch('request_config/setBaseUrl', location.host)
            }
            if (this.request_config_aId && this.request_config_cId && this.request_config_gId && this.request_config_baseUrl) {
                this.loadData();

            }
        },
        methods: {
            async loadData() {
                this.query.aId = this.request_config_aId
                this.query.cId = this.request_config_cId
                this.query.gId = this.request_config_gId

                await hazardList(this.request_config_baseUrl, this.query).then(response => {
                    const {code, count, data} = response
                    if (code === 0) {
                        this.list = this.list.concat(data);
                        this.lastPage = Math.ceil(count / this.query.limit);
                    }

                    if (this.query.page >= this.lastPage) {
                        this.isFinished = true
                    }
                }).catch(error => {
                    console.log(error)
                })

            },
            $_onEndReached() {
                if (this.isFinished) {
                    return
                }
                if (this.query.page < this.lastPage) {
                    this.isFinished = false
                    this.query.page = ++this.query.page;
                    this.loadData();
                } else {
                    this.isFinished = true
                }
                this.$refs.scrollView.finishLoadMore()
            },
        }
    }
</script>

<style lang="scss" scoped>
    .container {
        height: 100vh;
        background: #F2F2F2;

        /*.search-input-wrap {*/
        /*padding: 15px;*/
        /*.search-input {*/
        /*border-radius: 10px;*/
        /*background: #FFF;*/
        /*padding: 0 15px;*/
        /*}*/
        /*}*/

        /*.md-swiper {*/
        /*height: calc(100vh - 230px);*/
        /*font-size: 14px;*/
        /*}*/

        .md-swiper {
            height: calc(100vh - 130px);
            font-size: 14px;
        }

        .md-scroll-view {
            height: 100%;
        }

        .md-tab-bar {
            padding: 0;

            .tab-bar-item {
                position: relative;

                .md-tag {
                    position: absolute;
                    top: -35px;
                    right: -35px;
                }
            }

        }

        // 审批类型
        .approval-type {
            overflow: hidden;
            padding: 15px;
            background: #FFF;
            margin-bottom: 20px;

            .left, .center, .right {
                float: left;
                height: 150px;
            }

            .left {
                .type-img {
                    width: 100px;
                    height: 100px;
                    border-radius: 50%;
                    position: relative;
                    top: 50%;
                    transform: translateY(-50%);
                }
            }

            .center {
                width: calc(500px - 30px);
                margin: 0 15px;

                .title {
                    color: #222222;
                    font-size: 36px;
                    font-weight: bold;
                    margin: 15px 0;
                }

                .info {
                    font-size: 28px;
                    color: #999999;
                    height: 70px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    line-height: 1.4em;
                }
            }

            .right {
                .btn {
                    background: #15CD85;
                    box-shadow: 3px 3px 10px #0ABC88;
                    color: #FFF;
                    padding: 0;
                    height: 50px;
                    line-height: 50px;
                    margin: 0 auto;
                    display: block;
                    align-items: center;
                    position: relative;
                    top: 50%;
                    transform: translateY(-50%);
                    padding: 0 10px;
                    border-radius: 30px;
                    border: none;
                    width: 120px;
                    font-size: 28px;
                }

                .btn:after {
                    border: none;
                }
            }

        }

        // 任务信息
        .task-info {
            background: #FFF;
            padding: 20px 30px;

            .task-info-content {
                font-size: 28px;

                &:after {
                    content: "";
                    display: block;
                    height: 1px;
                    width: 100%;
                    background: #CECECE;
                    margin-top: 20px;
                }

                .head {
                    padding-bottom: 15px;

                    .title {
                        font-size: 36px;
                        font-weight: bold;
                        color: #222222;
                        display: inline-block;
                        margin-right: 15px;
                        border: 1px;
                    }

                    .tag {
                        position: relative;
                        top: 50%;
                        transform: translateY(-15%);
                        display: inline-block;
                        padding: 8px 15px 5px;
                        border-radius: 30px;
                        color: #FFF;
                        margin: 0 5px;
                    }

                    .tag-green {
                        background: #0DC187;
                        box-shadow: 3px 3px 10px #2FDCA4;
                    }

                    .tag-gray {
                        background: #B1BABC;
                        box-shadow: 3px 3px 10px #84898A;
                    }

                    .tag-red {
                        background: #FF5252;
                        box-shadow: 3px 3px 10px #FF4D4D;
                    }
                }

                .content {
                    font-size: 28px;
                    color: #555555;
                    line-height: 1.4em;
                    height: 70px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    margin-bottom: 30px;
                }

                .info {
                    &:after {
                        content: "";
                        display: block;
                        clear: both;
                    }

                    .left {
                        float: left;

                        p {
                            margin: 10px 0 0;
                            color: #909090;
                        }
                    }

                    .right {
                        float: right;
                        padding-top: 10px;

                        .btn {
                            background: #15CD85;
                            box-shadow: 3px 3px 10px #0ABC88;
                            color: #FFF;
                            padding: 0;
                            height: 50px;
                            line-height: 50px;
                            margin: 0 auto;
                            display: block;
                            align-items: center;
                            padding: 0 10px;
                            border-radius: 30px;
                            border: none;
                            width: 120px;
                            font-size: 28px;
                        }

                        .btn:after {
                            border: none;
                        }
                    }
                }
            }

        }

    }
</style>