<template>
    <a-spin :spinning="confirmLoading">
        <j-form-container :disabled="formDisabled">
            <a-form-model ref="form" :rules="validatorRules" slot="detail">
                <a-row>
                    <a-col :span="24">
                        <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batchType">
                            <a-radio-group v-model="batchType" @change="onChange">
                                <a-radio :value="1" :style="radioStyle">
                                    关联号与房间号相同
                                </a-radio>
                                <a-radio :value="2" :style="radioStyle">
                                    关联号 =
                                    <a-input style="width: 80px" @change="(e)=>handleFront(e)" ></a-input>
                                    +房间号+
                                    <a-input style="width: 80px" @change="(e)=>handleAfter(e)"></a-input>
                                </a-radio>
                                <a-radio :value="3" :style="radioStyle">
                                    关联号 =
                                    <a-input style="width: 80px" @change="(e)=>handleFront(e)"></a-input>
                                    +缺少首位的房间号+
                                    <a-input style="width: 80px" @change="(e)=>handleAfter(e)" ></a-input>
                                </a-radio>
                                <a-radio :value="4" :style="radioStyle">
                                    关联号 = 由
                                    <a-input style="width: 80px" @change="(e)=>handleFront(e)"></a-input>
                                    +开始随房间号递增一位
                                </a-radio>
                            </a-radio-group>
                        </a-form-model-item>
                    </a-col>
                </a-row>
            </a-form-model>
        </j-form-container>
    </a-spin>
</template>

<script>
    import { httpAction, getAction } from '@/api/manage'
    import { validateDuplicateValue } from '@/utils/util'
    import { buildingTree, queryFloorByParentId,queryRoomByFloorId } from "@/api/roomBuildingApi";

    export default {
        name: 'doorLockBatchForm',
        components: {},
        props: {
            //表单禁用
            disabled: {
                type: Boolean,
                default: false,
                required: false
            }
        },
        data() {
            return {
                batchType: '',
                front:'',
                after:'',
                labelCol: {
                    xs: {span: 24},
                    sm: {span: 5},
                },
                wrapperCol: {
                    xs: {span: 24},
                    sm: {span: 16},
                },
                confirmLoading: false,
                validatorRules: {
                    batchType: [
                        // {required: true, message: '请选择!'},
                    ],
                },
                url: {
                    batchAdd: "/business/busDoorLock/batchAdd"
                },
                radioStyle: {
                    display: 'block',
                    height: '50px',
                    lineHeight: '50px',
                },
            }
        },
        computed: {
            formDisabled() {
                return this.disabled
            },
        },
        created() {
            //备份model原始值
        },
        methods: {
            add() {
                this.visible = true;
            },
            submitForm() {
                console.log(this.batchType)
                const that = this;
                if (this.batchType == ''){
                    that.$message.error('请选择');
                }

                that.confirmLoading = true;
                let httpurl = this.url.batchAdd;
                let method = 'post';
                var info = JSON.parse(localStorage.getItem("storeInfo"));
                var data = {
                    hotelId: info.id,
                    radioType: this.batchType,
                    front: this.front,
                    after: this.after
                }
                httpAction(httpurl, data, method).then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        that.$emit('ok');
                    } else {
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                })
            },
            onChange(e) {
                console.log('radio checked', e.target.value);
            },
            handleFront(e){
                console.log(e)
                this.front = e.target.value
            },
            handleAfter(e){
                console.log(e)
                this.after = e.target.value
            }
        }
    }
</script>

<style scoped>

</style>
