<template>
<a-spin :spinning="confirmLoading">
    <j-form-container>
        <a-table :dataSource="dataSource" :columns="columns" :pagination="false">
            <template slot="action" slot-scope="text, record">
                <a @click="handleLookRoom()">申请查房</a>
            </template>
        </a-table>
    </j-form-container>

    <a-modal :title="'申请查房'" :visible="visibleLook" @cancel="visibleLook = false" @ok="submitOK">
        <!-- <j-form-container :disabled="false"> -->
            <a-form-model-item label="请输入备注">
                <a-input v-model="model.remarks" placeholder="请输入备注"></a-input>
            </a-form-model-item>
        <!-- </j-form-container> -->
    </a-modal>
</a-spin>
</template>

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

export default {
    // mixins: [JeecgListMixin],
    name: "PosTableForm",
    components: {},
    props: {
        //表单禁用
        disabled: {
            type: Boolean,
            default: true,
            required: false,
        },
    },
    data() {
        return {
            visibleLook: false,
            queryParam: {
                hotelId: null,
                livingOrderId: null,
            },
            dataSource: [],
            columns: [{
                title: '房号',
                align: "center",
                dataIndex: 'roomName'
            }, {
                title: '客人姓名',
                align: "center",
                dataIndex: 'contactName'
            }, {
                title: '房间状态',
                align: "center",
                dataIndex: 'roomStatus',
            }, {
                title: '入住状态',
                align: "center",
                dataIndex: 'createBy'
            }, {
                title: '查房状态',
                align: "center",
                dataIndex: 'state',
                //   sorter: true
            }, {
                title: '操作',
                key: 'operation',
                align: "center",
                width: 130,
                scopedSlots: {
                    customRender: 'action'
                },
            }],
            model: {
                hotelId: null,
                remarks:'',
            },
            labelCol: {
                xs: {
                    span: 24
                },
                sm: {
                    span: 5
                },
            },
            wrapperCol: {
                xs: {
                    span: 24
                },
                sm: {
                    span: 16
                },
            },
            confirmLoading: false,
            validatorRules: {
                tenantId: [{
                    required: true,
                    message: "请输入关联租户!"
                }],
                qz: [{
                    required: true,
                    message: "请输入餐桌名前缀!"
                }],
                hotelId: [{
                    required: true,
                    message: "请输入关联酒店!"
                }],
                name: [{
                    required: true,
                    message: "请输入餐桌名称!"
                }],
                posTypeId: [{
                    required: true,
                    message: "请输入pos类型id!"
                }],
                posTableTypeId: [{
                    required: true,
                    message: "请输入pos桌型id!"
                }],
                posRegionId: [{
                    required: true,
                    message: "请输入pos餐桌区域id!"
                }],
                num: [{
                    required: true,
                    message: "请输入座位数!"
                }],
                tableNo: [{
                    required: true,
                    message: "请输入餐桌序号!"
                }],
                state: [{
                    required: true,
                    message: "请输入状态!"
                }],
            },
            url: {
                list: "",
                edit: "/pos/posTable/edit",
                queryById: "/pos/posTable/queryById",
            },
            posTypeList: [],
            tableTypeList: [],
            regionList: []
        };
    },
    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));
        getAction("/pos/posType/list", {
            hotelId: _info.id,
            pageNo: 1,
            pageSize: 100,
        }).then((res) => {
            if (res.success) {
                this.posTypeList = res.result.records;
                // this.model.posTypeId = this.posTypeList[0].id;
            }
        });
        getAction("/pos/posTableType/list", {
            hotelId: _info.id,
            pageNo: 1,
            pageSize: 100,
        }).then((res) => {
            if (res.success) {
                this.tableTypeList = res.result.records;
            }
        });
        getAction("/pos/posRegion/list", {
            hotelId: _info.id,
            pageNo: 1,
            pageSize: 100,
        }).then((res) => {
            if (res.success) {
                this.regionList = res.result.records;
            }
        });
    },
    methods: {
        add() {
            this.edit(this.modelDefault);
        },
        loadData() {
            getAction(`/fw/fwRoomExamine/list?livingOrderId=${this.model.roomInfo.livingOrderId}`).then(res => {
                console.log(res);
                if (res.success) {
                    this.dataSource = res.result.records;
                } else {
                    this.$message.warning(res.message);
                }
            })
        },
        edit(record) {
            this.model = Object.assign({}, record);
            this.queryParam.livingOrderId = record.roomInfo.livingOrderId;
            this.loadData()

            this.visible = true;
        },
        submitOK(){
            this.confirmLoading = true;
            console.log(this.model);
            httpAction("/fw/fwRoomExamine/edit", {
                livingOrderId: this.model.roomInfo.livingOrderId,
                remark: this.model.remarks
            },'post').then(res => {
                this.confirmLoading = false;
                if (res.success) {
                    this.$message.success("申请成功");
                    this.visibleLook = false;
                } else {
                    this.$message.warning(res.message);
                }
            })
        },
        handleLookRoom(record) {
            this.visibleLook = true;
        },
    },
};
</script>
