<template>
    <view style="display: flex; height: 100%; flex-direction: column">
        <view style="flex: 1; overflow: scroll">
            <view class="user-wrap">
                <view class="user-flex">
                    <view class="user-lab">
                        <text space="ensp">姓 名：</text>
                        {{ userObj.patName }}
                    </view>
                    <view class="user-lab">
                        <text>性别：</text>
                        {{ userObj.patSexDesc }}
                    </view>
                    <view class="user-lab">
                        <text>年龄：</text>
                        {{ userObj.patAge }}
                    </view>
                </view>
                <view class="user-flex">
                    <view class="user-lab">
                        <text>登记号：</text>
                        {{ userObj.patNo }}
                    </view>
                </view>
            </view>
            <view class="content-item margin15">
                <view>工作单位（住址）：</view>
                <textarea @blur="bindTextAreaBlur" auto-height style="line-height: 20rpx" :value="userObj.patAddress" @input="onInput" data-key="patAddress" />
            </view>
            <view class="content-item">
                <view class="item-go" @tap="addDiag">
                    <view>临床诊断：</view>
                    <view style="margin-right: 10rpx">></view>
                </view>
                <textarea @blur="bindTextAreaBlur" style="height: 100rpx; line-height: 20rpx; background-color: #f8f8f8" :value="userObj.admDiagnosis" :disabled="true" />
            </view>
            <view class="content-item">
                <view>建议：</view>
                <textarea @blur="bindTextAreaBlur" auto-height style="line-height: 20rpx" :value="userObj.admAdvise" @input="onInput" data-key="admAdvise" />
            </view>
            <view class="user-wrap margin5" style="font-size: 26rpx">
                <view class="user-flex">
                    <view class="user-lab">
                        <text>科室：</text>
                        {{ userObj.admLocDesc }}
                    </view>
                    <view class="user-lab">
                        <text>医生：</text>
                        {{ userObj.doctorName }}
                    </view>
                    <view class="user-lab">
                        <text>日期：</text>
                        {{ userObj.receiveDate }}
                    </view>
                </view>
            </view>
        </view>
        <view style="height: 100rpx" class="save-btn" @tap="onSave">保存</view>
    </view>
</template>

<script>
import Cache from '../../../../../utils/cache';
import { $http } from '../../../../../config/https.js';
export default {
    data() {
        return {
            userObj: {
                patAddress: '',
                admDiagnosis: '',
                admAdvise: ''
            }
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        this.queryInfo();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        onSave: function () {
            const patientData = Cache.get('patientData');
            const userData = Cache.get('userData');
            let userObj = this.userObj;
            let data = {
                params: [
                    {
                        userID: userData.userID,
                        admID: patientData.admID,
                        patAddress: userObj.patAddress,
                        admDiagnosis: userObj.admDiagnosis,
                        admAdvise: userObj.admAdvise,
                        certificateID: userObj.certificateID
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: '03050230',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        uni.showToast({
                            title: '保存成功',
                            icon: 'success',
                            duration: 1000
                        });
                    }
                }
            });
        },

        queryInfo: function () {
            const patientData = Cache.get('patientData');
            const userData = Cache.get('userData');
            let data = {
                params: [
                    {
                        hospID: userData.hospID,
                        userID: userData.userID,
                        locID: userData.locID,
                        admID: patientData.admID
                    }
                ]
            };
            $http.post('urlDeault', this, {
                code: '03050231',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setData({
                            userObj: res.result
                        });
                    }
                }
            });
        },

        onInput: function (e) {
            let value = e.detail.value;
            let key = e.currentTarget.dataset.key;
            this.userObj[key] = value;
            this.setData({
                userObj: this.userObj
            });
        },

        addDiag: function (e) {
            uni.navigateTo({
                // url: '/pages/Entry/Entry?select=0',
                url: '../../../../entryWrite/page/Entry/Entry?select=1&addText=添加诊断'
            });
        },

        bindTextAreaBlur() {
            console.log('占位：函数 bindTextAreaBlur 未声明');
        }
    }
};
</script>
<style>
page {
    background-color: #f8f8f8;
    height: 100%;
    font-size: 32rpx;
    line-height: 1.6;
}
.user-wrap {
    padding: 20rpx;
    background-color: #ffffff;
}
.user-flex {
    display: flex;
    padding: 10rpx 0;
}
.user-lab {
    flex: 1;
}
.user-lab text {
    color: #666666;
}
.content-item {
    padding: 20rpx;
    background-color: #ffffff;
    margin-top: 4rpx;
}
.margin15 {
    margin-top: 15rpx;
}
.margin5 {
    margin-top: 5rpx;
}
.save-btn {
    height: 100rpx;
    line-height: 100rpx;
    text-align: center;
    color: #ffffff;
    font-size: 30rpx;
    background-color: #0079fe;
}
textarea {
    padding: 25rpx 0;
}
.item-go {
    padding-bottom: 10rpx;
    display: flex;
    justify-content: space-between;
}
</style>
