<template>
    <div>
        <a-form-model ref="form" :model="model" :rules="validatorRules">
            <a-form-model-item label="房型大图" >
                <j-image-upload class="avatar-uploader" text="上传" v-model="model.cover" ></j-image-upload>
              </a-form-model-item>
              <a-form-model-item label="图片" >
                <j-image-upload class="avatar-uploader" text="上传" v-model="model.picture" :isMultiple="true"></j-image-upload>
              </a-form-model-item>
              <a-button :disabled="submitLoading" :loading="submitLoading" @click="submitForm"
                type="primary">保存</a-button>
        </a-form-model>
    </div>
</template>

<script>
import { modify } from '@/api/roomLayout'
import { editGood } from '@/api/good'
export default {
    name: 'HotelSaasTenantFrontendRoomLayoutImage',

    data() {
        return {
            submitLoading: false,
            model: {
                id: 0,
                cover: null,
                picture: null
            },
            validatorRules: {

            }
        };
    },

    mounted() {
        
    },

    methods: {
        setData(data) {
            this.model = JSON.parse(JSON.stringify(data))
            if (!data.picture) {
                this.model.picture = data.images
            }
        },
        submitForm() {
            const that = this;
            // 触发表单验证
            this.$refs.form.validate((valid) => {
                if (valid) {
                    let data = JSON.parse(JSON.stringify(this.model))
                    that.confirmLoading = true;
                    // debugger
                    console.log('datadatadatadata',data);
                    if (data.url) {
                        editGood({
                            id: data.id,
                            hotelId: data.hotelId,
                            name: data.name,
                            images: data.picture,
                            goodUnit: data.goodUnit,
                            goodType: data.goodType,
                            barCode: data.barCode,
                            bid: data.bid,
                            sellingPrice: data.sellingPrice,
                            purchases: data.purchases,
                            salesVolume: data.salesVolume,
                            marketPrice: data.marketPrice,
                            inventory: data.inventory,
                            appState: data.appState,
                            // canLivePersonNum: data.canLivePersonNum,
                            // breakfastNum: data.breakfastNum,
                            // lunchNum: data.lunchNum,
                            // dinnerNum: data.dinnerNum,
                            cover: data.cover,
                            picture: data.picture
                        })
                        .then(res => {
                            if (res.code == 200) {
                                this.$emit('saveOk')
                                this.$message.success("保存成功")
                            }
                        }).finally(_ => {
                            that.confirmLoading = false;
                        })
                        return
                    }
                    modify({
                        id: data.id,
                        hotelId: data.hotelId,
                        name: data.name,
                        marketPrice: data.marketPrice,
                        canLivePersonNum: data.canLivePersonNum,
                        breakfastNum: data.breakfastNum,
                        lunchNum: data.lunchNum,
                        dinnerNum: data.dinnerNum,
                        cover: data.cover,
                        picture: data.picture
                    }).then(res => {
                        if (res.code == 200) {
                            this.$emit('saveOk')
                            this.$message.success("保存成功")
                        }
                    }).finally(_ => {
                        that.confirmLoading = false;
                    })
                }
            });

        },
    },
};
</script>

<style lang="stylus" scoped>

</style>