<template>
    <div class="all">
        <!-- 详情 -->
        <el-dialog title="详情" :visible="visible" width="70%" @update:visible="updateVisible">
            <el-table :data="detailArr" v-loading="loading" element-loading-text="拼命加载中">
                <el-table-column align="center" property="name" label="患者姓名"></el-table-column>
                <el-table-column align="left" property="yyxmbm" label="医院项目编码"></el-table-column>
                <el-table-column align="left" property="yyxmmc" label="医院项目名称"></el-table-column>
                <el-table-column align="center" property="sfryxm" label="收费人员姓名"></el-table-column>
                <!-- <el-table-column align="center" property="sxzfbl" label="自付比例"></el-table-column> -->
                <el-table-column align="center" property="fysfsj" label="发生时间"></el-table-column>
                <el-table-column align="center" label="自付比例" width="150">
                    <template slot-scope="scope">
                        <div>
                            <el-input v-model="scope.row.sxzfbl" type="number" ref="zifu" @focus="savefocus(scope.row)" @blur="biliBlur(scope.row)"></el-input>
                            <el-button size="mini" type="primary" v-if="seemodel == scope.row.id" @click.stop="savebtn(scope.row)">保存</el-button>
                        </div>
                    </template>
                </el-table-column>
               
                <!-- <el-table-column fixed="right" align="center" label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" @click="getProp(scope.row)" size="small">比例</el-button>
                    </template>
                </el-table-column> -->
                <!-- <el-table-column align="center" property="" label="操作">
                    <template>
                        <div>
                            <el-button type="danger" size="mini" @click="edit(data)">修改自付比例</el-button>
                        </div>
                    </template>
                </el-table-column> -->
            </el-table>
            <div style="display: flex; justify-content: space-between">
                <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getListDetail()" style="position: relative; !important" />
                <div>
                    <el-button type="primary" size="mini" @click.stop="uploadToday">上传</el-button>
                    <el-button type="primary" size="mini" @click.stop="withdrawToday">撤销</el-button>
                </div>
            </div>
        </el-dialog>
        <!-- 详情 -->
        <!-- <edit-prop1 :visible.sync="showEditProp" :data="currentData" isHospital="1" @proportion="proportion" :infor="infor"
            :his_patient_no="patientform.his_patient_no"></edit-prop1> -->
    </div>
</template>

<script>
import {editProp, zfbl} from '@/api/jiesuan'
import editProp1 from '../../jiesuan/components/editProp.vue' //修改自付比例
import { settleDetail } from '@/api/inned'
export default {
    components: {
        editProp1,
    },
    props: {
        visible: Boolean,
        data: Array,
    },
    data() {
        return {
            showEditProp: false, //详情蒙层
            seemodel: '', // 是否显示按钮
            total: 0,
            pageInfo: {
                page: 1,
                limit: 10,
            },
            loading: false,
            detailArr: [], //数据
        }
    },
    created() {},
    methods: {
        uploadToday(){
            let int={
                his_inpatient_no: this.data[0].his_inpatient_no,

            }
            
            this.$emit('uploadToday','1')
        },
        withdrawToday(){
            this.$emit('withdrawToday')
        },
        //保存显示按钮
        savefocus(e) {
            this.seemodel = e.id
        },
        biliBlur(row) {
            if (row.sxzfbl > 1) {
                this.$message({
                    message: '自付比例最大值为1',
                    type: 'warning',
                })
                row.sxzfbl = 1
                return false
            }
        },
        savebtn(e) {

            this.resave(e.id, e.sxzfbl)
            this.seemodel = ''
        },
        //获取自付比例
        getProp(row) {
            zfbl({
                is_zy: '1',
                yyxmbm: row.yyxmbm,
                rqlb: this.patientform.p_rqlb,
                fyfssj: row.fysfsj,
                channel: this.patientform.channel,
            })
                .then(response => {
                    if (response.data.length > 1) {
                        // TODO: 接口修改完毕那参数
                        this.infor = response.data
                        if (response.data.length > 1) {
                            row.many = '1'
                            var min = response.data[0].zfbl
                            for (let i = 0; i < response.data.length; i++) {
                                if (min > response.data[i].zfbl) {
                                    min = response.data[i].zfbl
                                }
                            }
                            row.sxzfbl = min
                            this.$forceUpdate()
                        } else {
                            row.sxzfbl = response.data[0].zfbl
                            this.$forceUpdate()
                        }
                        this.showEditProp = true
                        this.currentData = row
                    } else {
                        // TODO: 接口修改完毕那参数
                        this.resave(row.id, row.sxzfbl)
                    }
                    //     element.sxzfbl=response.data.sxzfbl
                    //    this.resave(element.id,response.data.sxzfbl)
                })
                .finally(() => {
                    this.loading = false
                })
        },
         //保存自付比例
         resave(e, x) {
            editProp({
                is_zy: '1', //1住院 0门诊
                his_patient_no: this.data[0].his_inpatient_no,
                column: 'sxzfbl', //his_patient_type结算类型 sxzfbl自付比例
                value: x * 1,
                med_cost_id: e,
            })
                .then(response => {
                   this. getList2()
                })
                .finally(() => {
                    this.loading = false
                })
        },
        //保存显示按钮
        savefocus(e) {
            this.seemodel = e.id
        },
        edit() {
            this.$emit('editSelfPay')
        },
        //获取详情列表
        getListDetail() {
            this.loading = true
            this.list = []
            const qyparams = {
                ...this.pageInfo,
                his_inpatient_no: this.data[0].his_inpatient_no,
                fysfsj_date: this.data[0].fysfsj_date,
                // dw_fyid: this.data[0].dw_fyid?this.data[0].dw_fyid.toString():'',
            }
            settleDetail(qyparams)
                .then(response => {
                    this.detailArr = response.data
                    this.total = response.meta.total
                })
                .finally(() => {
                    this.loading = false
                })
        },
        /* 更新visible */
        updateVisible(val) {
            this.$emit('update:visible', val)
        },
    },
    watch: {
        visible(visible) {},
        data(data) {
            this.getListDetail()
        },
    },
}
</script>

<style lang="scss" scoped>
::v-deep .pagination-container .el-pagination {
    position: relative;
}
</style>
