<template>
    <view>
        <scroll-view class="scroll-view" :scroll-y="true" @scrolltolower="scrollLower">
            <!-- <block style="height: {{(winHeight)*2}}rpx;"></block> -->
            <view v-if="videoAdmList.length > 0">
                <block v-for="(item, index) in videoAdmList" :key="index">
                    <patAdmRecord :adm-record="item" :serviceTypeVisible="serviceTypeVisible" :serviceTypeCode="serviceTypeCode" @rejectAdm="handleRejectAdm" />
                </block>
            </view>
            <block v-else>
                <nothingData />
            </block>
            <van-toast id="van-toast" />
        </scroll-view>
    </view>
</template>

<script>
import Cache from '../../../../utils/cache';
import patAdmRecord from '@/pages/components/patAdmRecord/patAdmRecord';
import nothingData from '@/pages/components/nothingData/nothingData';
import { $http } from '../../../../config/https.js';
import Toast from '../../../../utils/toast';
const nowDate = new Date();
export default {
    components: {
        patAdmRecord,
        nothingData
    },
    data() {
        return {
            videoAdmList: [],
            winWidth: 0,
            winHeight: 0,
            pageSize: 10,
            // 条数
            currentPage: 1,
            // 页数
            statusCode: 'F',
            //已完成
            hasMoreData: false,
            httpsCode: '',
            serviceTypeVisible: false,
            //是否显示服务类型
            serviceTypeCode: '' //服务类型代码
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        let winWidth = 0;
        let winHeight = 0;
        uni.getSystemInfo({
            success: function (res) {
                winWidth = res.windowWidth;
                winHeight = res.windowHeight;
            }
        });
        console.log('options:', options);
        let { admTypeCode } = options;
        let title = admTypeCode == 'image' ? '图文咨询' : admTypeCode == 'video' ? '视频问诊' : '';
        let httpsCode = admTypeCode == 'image' ? '03100011' : admTypeCode == 'video' ? '03100022' : '';
        that.setData({
            winWidth,
            winHeight,
            httpsCode,
            serviceTypeCode: admTypeCode
        });
        uni.setNavigationBarTitle({
            title: `${title} (已完成)`
        });
    },
    /**   * 生命周期函数--监听页面初次渲染完成   */
    onReady: function () {
        this.findVedioAdmList(false);
    },
    /**   * 生命周期函数--监听页面显示   */
    onShow: function () {
        console.log('pageonShow', this);
        this.findVedioAdmList(false);
    },
    /**   * 生命周期函数--监听页面隐藏   */
    onHide: function () {},
    /**   * 生命周期函数--监听页面卸载   */
    onUnload: function () {},
    /**   * 页面相关事件处理函数--监听用户下拉动作   */
    onPullDownRefresh: function () {},
    /**   * 页面上拉触底事件的处理函数   */
    onReachBottom: function () {},
    /**   * 用户点击右上角分享   */
    onShareAppMessage: function () {},
    methods: {
        /**屏幕下滑至最底部 */
        scrollLower: function () {
            let { hasMoreData, currentPage } = this;
            if (hasMoreData) {
                Toast.loading({
                    mask: true,
                    message: '加载中...'
                });
                this.setData(
                    {
                        currentPage: currentPage + 1
                    },
                    () => {
                        this.findVedioAdmList(true); // 传参标识 表示是滚动加载
                    }
                );
            } else {
                uni.showToast({
                    title: '没有更多数据啦',
                    icon: 'none'
                });
            }
        },

        /**
         * 获取就诊记录
         */
        findVedioAdmList: function (searchType) {
            let { videoAdmList, pageSize, currentPage, statusCode, hasMoreData, httpsCode } = this;
            let userData = Cache.get('userData');
            if (httpsCode == '') {
                uni.showToast({
                    title: '未获取到接口代码',
                    icon: 'none'
                });
                return;
            }
            if (Cache.get('userData') == undefined) {
                uni.showToast({
                    title: '未获取到用户信息',
                    icon: 'none'
                });
                return;
            }
            let data = {
                params: [
                    {
                        locID: userData.locID,
                        hospID: userData.hospID,
                        userID: userData.userID,
                        statusCode,
                        allFlag: 'Y',
                        dateFrom: '',
                        dateTo: ''
                        // "dateFrom": "2020-04-01",
                        // "dateTo": `${nowDate.getFullYear()}-${nowDate.getMonth()+1}-${nowDate.getDate()}`,
                    }
                ],

                pagination: [
                    //页码信息
                    {
                        pageSize: pageSize,
                        currentPage: currentPage
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: httpsCode,
                data: data,
                success: function (res) {
                    if (res.errorCode == '0') {
                        if (res.result.data) {
                            // console.log("res-data", res.result.data)
                            let newHasMoreData = false;
                            if (res.result.data.length === pageSize) {
                                newHasMoreData = true;
                            }
                            let newVideoAdmList = [];
                            if (searchType) {
                                newVideoAdmList = videoAdmList.concat(res.result.data);
                            } else {
                                newVideoAdmList = res.result.data;
                            }
                            this.setData({
                                videoAdmList: newVideoAdmList,
                                hasMoreData: newHasMoreData
                            });
                        } else {
                        }
                    }
                }
            });
        },

        handleRejectAdm() {
            console.log('占位：函数 handleRejectAdm 未声明');
        }
    }
};
</script>
<style>
page {
    background: #f4f7fb;
}

.scroll-view-item {
    display: flex;
    flex-direction: row;
}
.scroll-view {
    height: 100vh;
    background: #f4f7fb;
    box-sizing: border-box;
    padding: 2rpx 0 28rpx;
}
</style>
