$(function () {


    new Vue({
        el: "#main",
        data: {
            YiYuan: {
                hosName: '',
                hospitalId: ''
            },
            YiYuanArr: [],
            KeShi: {
                deptName: '',
                hosDeptId: ''
            },
            KeShiArr: [],
            YiSheng: {
                doctorName: '',
                doctorSn: ''
            },
            YiShengArr: [],
        },
        mounted() {
            $("#myCarousel").carousel('cycle');
            this.getYiYuan();
            //从缓存获取前一个页面缓存的信息
            var dateInfo = window.localStorage.getItem("dateInfo"),
                numberInfo = window.localStorage.getItem("numberInfo"),
                patientInfo = window.sessionStorage.getItem("oauthInfo");

            if (patientInfo) {
                patientInfo = JSON.parse(patientInfo);
                this.patientInfo = patientInfo;
            }
            if (numberInfo) {
                numberInfo = JSON.parse(numberInfo);
                this.numberInfo = numberInfo;
            }
        },
        methods: {
            setYiYuan(value) {
                console.log(value);
                this.YiYuan.hosName = value.hosName;
                this.YiYuan.hospitalId = value.hospitalId;
                var vm = this;
                var params = {
                    pageIndex: 1,
                    pageSize: 99,
                    hospitalId: this.YiYuan.hospitalId
                }
                appointmentAPI.querySimpleHosDeptList(params).then(function (res) {
                    console.log(res);
                    if (res.successFlg && res.obj.Code == "10000") {
                        vm.KeShiArr = res.obj.Result;
                        vm.KeShi.deptName = '';
                        vm.KeShi.hosDeptId = '';
                        vm.YiShengArr = [];
                        vm.YiSheng.doctorName = '';
                        vm.YiSheng.doctorUid = '';
                    }
                }).catch(function (err) {
                    consolel.log(err)
                })
            },
            setKeShi(value) {
                console.log(value);
                if (!this.YiYuan.hospitalId) {
                    toastr.warning('请先选择医院')
                    return
                }
                this.KeShi.deptName = value.deptName;
                this.KeShi.hosDeptId = value.hosDeptId;
                //查询医生总数
                var vm = this;
                var params = {
                    pageIndex: 1,
                    pageSize: 99,
                    hospitalId: vm.YiYuan.hospitalId,
                    hosDeptId: vm.KeShi.hosDeptId
                }
                appointmentAPI.querySimpleDoctorList(params).then(function (res) {
                    console.log(res);
                    if (res.successFlg && res.obj.Code == "10000") {
                        if (!res.obj.Result) {
                            res.obj.Message && toastr.warning(res.obj.Message)
                        } else {
                            vm.YiShengArr = res.obj.Result;
                            vm.YiSheng.doctorName = '';
                            vm.YiSheng.doctorUid = '';
                        }

                        //获取医生排班数据

                    }
                })
            },
            setYiSheng(value) {
                console.log(value);
                if (!this.KeShi.hosDeptId) {
                    toastr.warning('请先选择科室')
                    return
                }
                this.YiSheng.doctorName = value.doctorName;
                this.YiSheng.doctorSn = value.doctorSn;
            },
            goMyJiuZhen() {
                window.location.href = '../../mineJiuZhen/html/mineJiuZhen.html'
            },
            getYiYuan() {
                var params = {
                        pageIndex: 1,
                        pageSize: 99,
                        provinceCode: 360000,
                        cityCode: 361100
                    },
                    vm = this;
                appointmentAPI.querySimpleHospitalList(params).then(function (res) {
                    console.log(res);
                    if (res.successFlg && res.obj.Code == "10000") {
                        vm.YiYuanArr = res.obj.Result;
                    }
                }).catch(function (err) {
                    console.error(err)
                })
            },
            save() {
                if (!this.YiYuan.hospitalId) {
                    toastr.warning('请选择医院')
                    return
                } else if (!this.KeShi.hosDeptId) {
                    toastr.warning('请选择科室')
                    return
                } else if (!this.YiSheng.doctorSn) {
                    toastr.warning('请选择医生')
                    return
                }
                window.location.href = "../../appointment/html/select-time.html?doctorSn="+Base64.encode(this.YiSheng.doctorSn);
            }
        }
    })
})