<template>
<a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
            <a-descriptions title="">
                <a-descriptions-item label="扫房人">
                    {{model.waiterName}}
                </a-descriptions-item>
                <a-descriptions-item label="房号">
                    {{model.roomNo}}
                </a-descriptions-item>
                <!-- <a-descriptions-item label="脏房类型">
                    {{'脏房'}}
                </a-descriptions-item> -->
            </a-descriptions>

            <a-space direction="vertical" style="width:100%;">
                <a-card title="客房用品统计" style="width: 100%">
                    <div style="display:flex;align-items:center;flex-wrap:wrap">
                        <div class="flex" v-for="(item, index) in (model.useConsumableList || []).filter(item => item.roomConsumable.type == 1)" :key="index" >
                            <div>{{item.roomConsumable.goodName}}({{item.roomConsumable.unit}})</div>
                            <a-input-number v-model="item.num" :min="0" :max="1000" :step="1" />
                        </div>
                    </div>

                </a-card>
                <a-card title="布草统计" style="width: 100%">
                    <div style="display:flex;align-items:center;flex-wrap:wrap">
                        <div class="flex" v-for="(item, index) in (model.useConsumableList || []).filter(item => item.roomConsumable.type == 2)" :key="index" >
                            <div>{{item.roomConsumable.goodName}}({{item.roomConsumable.unit}})</div>
                            <a-input-number v-model="item.num" :min="0" :max="1000" :step="1" />
                        </div>
                    </div>

                </a-card>
                <a-card title="审核意见" style="width: 100%">
                    <a-textarea v-model="model.remark" placeholder="请输入内容" />
                </a-card>
            </a-space>
        </a-form-model>
    </j-form-container>
</a-spin>
</template>

<script>
import {
    httpAction,
    getAction
} from "@/api/manage";
import {
    validateDuplicateValue
} from "@/utils/util";

export default {
    name: "PosTypeForm",
    components: {},
    props: {
        //表单禁用
        disabled: {
            type: Boolean,
            default: false,
            required: false,
        },
    },
    data() {
        return {
            model: {

            },
            labelCol: {
                xs: {
                    span: 24
                },
                sm: {
                    span: 5
                },
            },
            wrapperCol: {
                xs: {
                    span: 24
                },
                sm: {
                    span: 16
                },
            },
            confirmLoading: false,
            validatorRules: {
                goodName: [{
                    required: true,
                    message: "请输入名称!"
                }],
                goodSpe: [{
                    required: true,
                    message: "请输入规格!"
                }],
                type: [{
                    required: true,
                    message: "请选择规格!"
                }],
                unit: [{
                    required: true,
                    message: "请输入单位!"
                }],
                address: [{
                    required: true,
                    message: "请输入地址!"
                }],
            },
            url: {
                // add: "/fw/fwRoomConsumable/add",
                edit: "/fw/fwRoomClean/edit",
                queryById: "/kc/kcSupplier/queryById",
            },
        };
    },
    computed: {
        formDisabled() {
            return this.disabled;
        },
    },
    created() {
        var _info = JSON.parse(localStorage.getItem("storeInfo"));
        if (_info) {
            this.model.hotelId = _info.id;
        }
        //备份model原始值
        this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
        add() {
            this.edit(this.modelDefault);
        },
        edit(record) {
            console.log(record);
            this.model = Object.assign({}, record);
            this.visible = true;
        },

        handlePass() {
            this.model.verifyState = 1;
            this.submitForm();
        },
        handleNoPass() {
            this.model.verifyState = 2;
            this.submitForm();
        },

        submitForm() {
            const that = this;
            // 触发表单验证
            this.$refs.form.validate((valid) => {
                if (valid) {
                    that.confirmLoading = true;
                    let httpurl = "";
                    let method = "";
                    if (!this.model.id) {
                        httpurl += this.url.add;
                        method = "post";
                    } else {
                        httpurl += this.url.edit;
                        method = "put";
                    }
                    httpAction(httpurl, this.model, method)
                        .then((res) => {
                            if (res.success) {
                                that.$message.success(res.message);
                                that.$emit("ok");
                            } else {
                                that.$message.warning(res.message);
                            }
                        })
                        .finally(() => {
                            that.confirmLoading = false;
                        });
                }
            });
        },
    },
};
</script>

<style scoped>
.flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-right: 20px;
    margin-top: 10px;
}
</style>
