<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="患者姓名" prop="patientName">
                <el-input v-model="queryParams.patientName" placeholder="请输入患者姓名" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-tabs type="card" v-model="queryParams.type" @tab-click="handleClickX">
            <el-tab-pane label="全部" name="0"></el-tab-pane>
            <el-tab-pane label="我的" name="1"></el-tab-pane>
        </el-tabs>
        <el-table v-loading="loading" border :data="list" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="患者姓名" align="center" prop="patientName" width="120px" />
            <el-table-column label="性别" align="center" prop="gender" width="120px">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.gender == 0">未知</el-tag>
                    <el-tag v-if="scope.row.gender == 1">男</el-tag>
                    <el-tag v-if="scope.row.gender == 2">女</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="患者年龄" align="center" prop="age" width="120px" />
            <el-table-column label="患者电话" align="center" prop="phone" width="120px" />
            <el-table-column label="日期" align="center" prop="dateTime" width="120px" />
            <el-table-column label="身体状况" align="center" prop="physicalCondition" :show-overflow-tooltip="true" />
            <el-table-column label="患者是否答复" align="center" prop="userStatus" width="120px">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.userStatus == 0">未答复</el-tag>
                    <el-tag type="success" v-if="scope.row.userStatus == 1">已答复</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px">
                <template slot-scope="scope">
                    <el-button :disabled="scope.row.userStatus == 1" size="mini" type="text"
                        @click="handleFill(scope.row)">填写初诊单</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />

        <el-dialog title="填写初诊单" :visible.sync="open" width="1000px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="110px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="患者姓名" prop="patientName">
                            <el-input disabled v-model="form.patientName" placeholder="请输入患者姓名" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="年龄" prop="age">
                            <el-input disabled v-model="form.age" label="年龄"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="患者电话" prop="phone">
                            <el-input disabled v-model="form.phone" placeholder="请输入电话" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="性别" prop="gender">
                            <el-select disabled v-model="form.gender">
                                <el-option label="未知" :value="0"></el-option>
                                <el-option label="男性" :value="1"></el-option>
                                <el-option label="女性" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item label="身体状况" prop="physicalCondition">
                    <el-input v-model="form.physicalCondition" type="textarea" placeholder="请输入内容" />
                </el-form-item>

                <el-form-item label="初步诊断" prop="firstDiagnosis">
                    <el-input v-model="form.firstDiagnosis" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="日期" prop="dateTime">
                            <el-date-picker clearable size="small" v-model="form.dateTime" type="date"
                                value-format="yyyy-MM-dd" placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { getDiagnosisList, fill, detail } from "@/api/diagnosis.js";
export default {
    name: "diagnosis",
    data() {
        return {
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            // 遮罩层
            loading: true,
            // 导出遮罩层
            exportLoading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            list: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                type: "0",
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {


            }
        }
    },
    created() {
        this.getList();
    },

    methods: {
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    fill(this.form).then(res => {
                        this.msgSuccess("填写成功");
                        this.open = false;
                        this.getList();
                    })
                }
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
        },
        handleFill(row) {
            detail(row.id).then(res => {
                this.form = res.data
            })
            this.open = true;
        },
        getList() {
            this.loading = true;
            getDiagnosisList(this.queryParams).then(response => {
                this.list = response.data.list;
                this.total = response.data.total;
                this.loading = false;
            });
        },
        //切换
        handleClickX(tab, event) {
            this.queryParams.type = tab.name;
            this.handleQuery();
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.patientId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        }
    }

};
</script>