<template>
    <view>
        <view>
            <mp-searchbar :placeholder="searchPlaceholder" @input="selectPatAdm" @cancel="searchCancel"></mp-searchbar>
        </view>
        <view v-if="videoAdmList.length > 0">
            <block v-for="(item, index) in videoAdmList" :key="index">
                <view class="scroll-view-item">
                    <patAdmRecord :adm-record="item" @rejectAdm="handleRejectAdm" @cancelAdm="findAdmRecordList" />
                </view>
            </block>
        </view>
        <block v-else><nothingData /></block>
        <view v-if="showRefusal">
            <refusal @colseRefuse="colseRefuse" :showRefusal="showRefusal" @selectData="findAdmRecordList" :admID="admID"></refusal>
        </view>
    </view>
</template>

<script>
import Cache from '../../../../utils/cache';
import patAdmRecord from '@/pages/components/patAdmRecord/patAdmRecord';
import nothingData from '@/pages/components/nothingData/nothingData';
import refusal from '../refusal/refusal';
// pages/myConsultRoom/page/searchPatient/searchPatient.js
import { $http } from '../../../../config/https.js';
const userData = Cache.get('userData');
const nowDate = new Date();
export default {
    components: {
        patAdmRecord,
        nothingData,
        refusal
    },
    data() {
        return {
            patName: '',
            videoAdmList: [],
            searchPlaceholder: '输入患者姓名查找',
            showRefusal: false,
            dateRangeCode: '',
            dateFrom: '',
            dateTo: '',
            admID: ''
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options);
        const eventChannel = this.getOpenerEventChannel();
        // eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});
        // eventChannel.emit('someEvent', {data: 'test'});
        // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
        eventChannel.on('acceptDataFromOpenerPage', function (data) {
            console.log(data);
        });
        this.setData({
            dateRangeCode: options.dateRangeCode,
            dateFrom: options.dateFrom,
            dateTo: options.dateTo
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        uni.setNavigationBarTitle({
            title: '搜索患者'
        });
    },
    /**   * 生命周期函数--监听页面显示   */
    onShow: function () {},
    /**   * 生命周期函数--监听页面隐藏   */
    onHide: function () {},
    /**   * 生命周期函数--监听页面卸载   */
    onUnload: function () {},
    /**  * 页面相关事件处理函数--监听用户下拉动作  */
    onPullDownRefresh: function () {},
    /**   * 页面上拉触底事件的处理函数   */
    onReachBottom: function () {},
    /**   * 用户点击右上角分享   */
    onShareAppMessage: function () {},
    methods: {
        /**搜索框输入内容 */
        selectPatAdm: function (event) {
            this.setData(
                {
                    patName: event.detail.value
                },
                () => {
                    this.findAdmRecordList();
                }
            );
        },

        /**
         * 点击取消接诊
         */
        handleRejectAdm: function (event) {
            console.log('就诊ID:', event);
            let { admID, patientData } = event.detail;
            if (admID == '') {
                uni.showToast({
                    title: '请选择患者操作',
                    icon: 'none'
                });
                return;
            }
            this.setData({
                showRefusal: true,
                admID: event.detail.admID
            });
            Cache.set('patientData', {
                patID: patientData.patID,
                admID: admID
            });
        },

        /**取消搜索 */
        searchCancel: function (e) {
            this.setData({
                patName: ''
            });
        },

        /**
         * 根据条件查询患者所有视频就诊记录
         */
        findAdmRecordList: function () {
            let { patName, dateRangeCode, dateFrom, dateTo } = this;
            let user = Cache.get('userData');
            let data = {
                params: [
                    {
                        locID: user.locID,
                        hospID: user.hospID,
                        userID: user.userID,
                        statusCode: '',
                        dateRangeCode,
                        dateFrom,
                        dateTo,
                        patName
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: '03100022',
                data: data,
                success: function (res) {
                    if (res.errorCode == '0') {
                        if (res.result.data) {
                            // console.log("res-data",res.result.data)
                            this.setData({
                                videoAdmList: res.result.data
                            });
                        } else {
                        }
                    }
                }
            });
        },

        colseRefuse() {
            console.log('占位：函数 colseRefuse 未声明');
        }
    }
};
</script>
<style>
/* pages/graphicConsult/graphicConsult.wxss */
Page {
    background-color: #f1f1f1;
}
.scroll-view-item {
}
</style>
