<template>
    <div class="container">
        <md-tab-bar
                v-model="current"
                :items="items"
                @change="onTabChange"
        >
            <template slot="item" slot-scope="{ item }">
                <div class="tab-bar-item">
                    <md-tag
                            size="large"
                            shape="bubble"
                            fill-color="linear-gradient(90deg, #FF5B60 0%, #F98472 100%)"
                            type="fill"
                            v-show="item.isShowTag && item.notifications !== 0"
                    >{{item.notifications}}
                    </md-tag>
                    <div class="text">
                        <span v-text="item.label"></span>
                    </div>
                </div>
            </template>
        </md-tab-bar>

        <md-swiper
                ref="swiper"
                :autoplay="0"
                :is-prevent="false"
                :is-loop="false"
                :has-dots="false"
                @before-change="onSwiperChange"
        >
            <md-swiper-item>
                <md-scroll-view
                        ref="typeFormList"
                        :scrolling-x="false"
                        :bouncing="false"
                        :auto-reflow="true"
                >
                    <template v-if="this.alarmMoData &&  this.alarmMoData.fireData">
                        <AlarmMo v-for="(item,index) in this.alarmMoData.fireData[0]" :key="index" :data="item"/>
                        <!--                        <md-scroll-view-more-->
                        <!--                                slot="more"-->
                        <!--                                :is-finished="typeFormListQuery.isFinished"-->
                        <!--                        >-->
                        <!--                        </md-scroll-view-more>-->
                        <md-scroll-view-more
                                slot="more"
                                :is-finished="true"
                        >
                        </md-scroll-view-more>
                    </template>
                    <template v-else>
                        <empty-data-page></empty-data-page>
                    </template>
                </md-scroll-view>
            </md-swiper-item>
            <md-swiper-item>
                <md-scroll-view
                        ref="applyList"
                        :scrolling-x="false"
                        :bouncing="false"
                        :auto-reflow="true">
                    <template v-if="this.eleFireData &&  this.eleFireData.fireData">
                        <EleFire v-for="(item,index) in this.eleFireData.fireData[0]" :key="index" :data="item"/>
                        <!--                        <md-scroll-view-more-->
                        <!--                                slot="more"-->
                        <!--                                :is-finished="applyListQuery.isFinished"-->
                        <!--                        >-->
                        <!--                        </md-scroll-view-more>-->
                        <md-scroll-view-more
                                slot="more"
                                :is-finished="true"
                        >
                        </md-scroll-view-more>
                    </template>
                    <template v-else>
                        <empty-data-page></empty-data-page>
                    </template>
                </md-scroll-view>
            </md-swiper-item>
            <md-swiper-item>
                <md-scroll-view
                        ref="applyList"
                        :scrolling-x="false"
                        :bouncing="false"
                        :auto-reflow="true">
                    <template v-if="this.fireWaterData && this.fireWaterData.fireData3 || this.fireWaterData.fireData4">
                        <template v-if="this.fireWaterData &&  this.fireWaterData.fireData3">
                            <FireWater v-for="(item,index) in fireWaterData.fireData3.fireData[0]"
                                       :key="'fireData3' + index" :el="index" :data="item" :chart1Type="2"></FireWater>

                        </template>
                        <template v-if="this.fireWaterData &&  this.fireWaterData.fireData4">
                            <FireWater v-for="(item,index) in fireWaterData.fireData4.fireData[0]"
                                       :key="'fireData4' + index" :el="fireWaterData.fireData3.fireData[0].length + index" :data="item" :chart1Type="1"></FireWater>


                        </template>
                        <!--                        <md-scroll-view-more-->
                        <!--                                slot="more"-->
                        <!--                                :is-finished="applyListQuery.isFinished"-->
                        <!--                        >-->
                        <!--                        </md-scroll-view-more>-->
                        <md-scroll-view-more
                                slot="more"
                                :is-finished="true"
                        >
                        </md-scroll-view-more>
                    </template>
                    <template v-else>
                        <empty-data-page></empty-data-page>
                    </template>
                </md-scroll-view>
            </md-swiper-item>
            <md-swiper-item>
                <md-scroll-view
                        ref="applyList"
                        :scrolling-x="false"
                        :bouncing="false"
                        :auto-reflow="true">
                    <template v-if="true">
                        <FireAlarm v-for="(item,index) in 10" :key="index" :data="item"/>
                        <!--                        <md-scroll-view-more-->
                        <!--                                slot="more"-->
                        <!--                                :is-finished="applyListQuery.isFinished"-->
                        <!--                        >-->
                        <!--                        </md-scroll-view-more>-->
                        <md-scroll-view-more
                                slot="more"
                                :is-finished="true"
                        >
                        </md-scroll-view-more>
                    </template>
                    <template v-else>
                        <empty-data-page></empty-data-page>
                    </template>
                </md-scroll-view>
            </md-swiper-item>
        </md-swiper>
    </div>
</template>

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

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

    import {AlarmMo, EleFire, FireWater,FireAlarm} from './components/index'

    import {mapGetters} from 'vuex'

    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,
            AlarmMo,
            EleFire,
            FireWater,
            FireAlarm
        },
        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: 10,
                isFinished: false,

                typeFormList: [],   // 表单列表
                typeFormListQuery: {
                    page: 0,
                    limit: 10,
                    isFinished: false,
                },
                applyList: [], // 申请列表
                applyListQuery: {
                    page: 0,
                    limit: 10,
                    isFinished: false,
                },
                approvalList: [], // 审批列表
                approvalListQuery: {
                    page: 0,
                    limit: 10,
                    isFinished: false,
                },
                approvedList: [], // 已审批列表
                approvedListQuery: {
                    page: 0,
                    limit: 10,
                    isFinished: false,
                },
            }
        },
        computed: {
            ...mapGetters([
                'request_config_aId',
                'request_config_cId',
                'request_config_gId',
                'request_config_baseUrl',
                'eleFireData',
                'alarmMoData',
                'fireWaterData',
            ])
        },
        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.initData();
                this.current = 0;

            }
        },
        methods: {
            async initData() {
                let reqParams = {
                    aId: this.request_config_aId,
                    cId: this.request_config_cId,
                    gId: this.request_config_gId,
                    baseUrl: this.request_config_baseUrl,
                };
                // await this.$store.dispatch("smart_fire/getFireAlarmData",reqParams).then(()=>{
                //     // console.log("数据请求成功")
                // }).catch(error=>{
                //     console.log(error)
                // })
                await this.$store.dispatch("smart_fire/getFireWaterData", reqParams).then(() => {
                    // console.log("数据请求成功")
                }).catch(error => {
                    console.log(error)
                })
                await this.$store.dispatch("smart_fire/getEleFireData", reqParams).then(() => {
                    // console.log("数据请求成功")
                }).catch(error => {
                    console.log(error)
                })
                // await this.$store.dispatch("smart_fire/getGasMoData",reqParams).then(()=>{
                //     // console.log("数据请求成功")
                // }).catch(error=>{
                //     console.log(error)
                // })
                await this.$store.dispatch("smart_fire/getAlarmMoData", reqParams).then(() => {
                    // console.log("数据请求成功")
                }).catch(error => {
                    console.log(error)
                })
            },
            /**
             * @Author: NanKeYang
             * @Description: 重新加载标签下标
             * @Data: 2020/1/9 10:22
             */
            reloadTabBarIndex(index) {
                this.current = index
                this.$nextTick(() => {
                    this.$refs.swiper.goto(index)
                })
            },
            /**
             * @Author: NanKeYang
             * @Description: 滑动区域切换
             * @Data: 2020/1/9 10:21
             */
            onSwiperChange(from, to) {
                this.current = to
            },
            /**
             * @Author: NanKeYang
             * @Description: 标签切换
             * @Data: 2020/1/9 10:21
             */
            onTabChange(item, index) {
                this.$refs.swiper.goto(index)
            },
        }
    }
</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>