<template>
    <div class="proportion">
        <!-- 详情 -->
        <el-dialog title="修改自付比例" :visible="visible"  @update:visible="updateVisible" width="30%"
            :close-on-press-escape="false" :close-on-click-modal="false">
            <el-form ref="form" style="padding: 0 20px;" v-loading="loadingEdit" element-loading-text="加载中" 
                element-loading-spinner="el-icon-loading">
                <el-radio-group v-model="proportion" >
                    <div v-for="(item) in infor" :key="item.id" style="margin-bottom:10px;">
                        <el-radio :label="item.zfbl">
                           <span class="_break"> 名称： {{ item.sm }}<br>
                            自付比例：{{ item.zfbl }}</span>
                        </el-radio>
                    </div>
                </el-radio-group>

                <div style="text-align:right;">
                    <el-button @click="updateVisible(false)">取消</el-button>
                    <el-button type="primary" @click="editPropFun">确定</el-button>
                </div>

            </el-form>
        </el-dialog>
        <!-- 详情 -->


    </div>
</template>

<script>
import { editProp } from '@/api/jiesuan'
export default {
    components: {
    },
    props: {
        infor: Array,
        visible: Boolean,
        data: Object,
        his_patient_id: String, //门诊
        his_patient_no: String, //住院
        isHospital: String, //1住院
    },
    data() {
        return {
            loadingEdit: false,
            propArr: [{
                name: '0.1000',
                hint: '说明说明说明1'
            }, {
                name: '0.2000',
                hint: '说明说明说明2'
            }], //数据
            proportion: 'x', //比例

        }
    },
    created() {
    },
    methods: {
        /* 更新visible */
        updateVisible(val) {
            this.$emit('update:visible', val);
        },
        //修改比例
        editPropFun() {
            var that = this
            if (that.proportion=='x') {
                that.$message({
                    message: '请选择自付比例',
                    type: 'error',
                })
                return false
            }
            if(this.isHospital && this.isHospital == 1){
                this.zhuyuan() //住院
            }else{
                this.menzhen() //门诊
            }

        },
        //修改门诊比例
        menzhen(){
            var that = this
            var obj = {
                is_zy: '0', //1住院 0门诊
                his_patient_id: that.his_patient_id, //
                column: 'sxzfbl', //his_patient_type结算类型 sxzfbl自付比例
                value: String(that.proportion), //
                med_cost_id: that.data.id,
            }
            that.loadingEdit = true,
                editProp(obj)
                    .then(response => {
                        that.loadingEdit = false,
                            // that.$message({
                            //     message: '修改自付比例成功',
                            //     type: 'success',
                            // })
                        that.updateVisible(false)
                        that.$emit('proportion', that.data.id, that.proportion);
                    })
                    .finally(() => {
                        that.loadingEdit = false
                    })
        },
        //修改住院比例
        zhuyuan(){
            var that = this
            var obj = {
                is_zy: '1', //1住院 0门诊
                column: 'sxzfbl', //his_patient_type结算类型 sxzfbl自付比例
                value: String(that.proportion), //
                med_cost_id: that.data.id,
                his_patient_no: that.his_patient_no
            }
            that.loadingEdit = true,
                editProp(obj)
                    .then(response => {
                        that.loadingEdit = false,
                            // that.$message({
                            //     message: '修改自付比例成功',
                            //     type: 'success',
                            // })
                        that.updateVisible(false)
                        that.$emit('proportion', that.data.id, that.proportion);
                    })
                    .finally(() => {
                        that.loadingEdit = false
                    })
        },

    },
    watch: {
        visible(visible) {
            console.log(visible)
        },
        data(data) {
            console.log(data)
        }
    }
}
</script>

<style lang="scss" scoped>
.proportion {
    .el-radio__inner {
        width: 22px;
        height: 22px
    }
    ::v-deep.el-radio{
        word-break: break-word;
        display: inline-block;
        white-space: break-spaces;
        display: flex;
    }
    .el-radio__inner::after {
        width: 8px;
        height: 8px;
    }
    ._break{
        word-break: break-word;
        display: inline-block;
    }
}
</style>
