<template>
<a-card :bordered="false">

    <a-tabs default-active-key="1">
        <a-tab-pane key="1" tab="待查房">
            <!-- 查询区域 -->
            <div class="table-page-search-wrapper">
                <a-form layout="inline" @keyup.enter.native="searchQuery">
                    <a-row :gutter="24">

                        <a-col :span="15">
                            <a-button @click="cancelRoom" :disabled="setBtnsDisable(4)" type="danger">设置取消查房</a-button>
                            <a-button @click="setWaitRoom" :disabled="setBtnsDisable(1)" style="margin-left: 8px">设置等待查房</a-button>
                            <a-button @click="setInRoom" :disabled="setBtnsDisable(2)" style="margin-left: 8px">设置正在查房</a-button>
                            <a-button @click="setFinishRoom" :disabled="setBtnsDisable(3)" style="margin-left: 8px">设置查房完毕</a-button>
                            <a-button type="primary" @click="searchQuery" icon="reload" style="margin-left: 8px">刷新</a-button>
                        </a-col>

                        <a-col :span="3">
                            <a-form-item label="">
                                <a-input placeholder="房号" v-model="queryParam.roomName"></a-input>
                            </a-form-item>
                        </a-col>
                        <a-col :span="3">
                            <a-form-item label="">
                                <a-select v-model="queryParam.state" style="width: 100%" placeholder="请选择" allowClear>
                                    <a-select-option :value="4">取消查房</a-select-option>
                                    <a-select-option :value="0">待查房</a-select-option>
                                    <a-select-option :value="1">等待查房</a-select-option>
                                    <a-select-option :value="2">正在查房</a-select-option>
                                    <a-select-option :value="3">查房完毕</a-select-option>
                                </a-select>
                            </a-form-item>
                        </a-col>
                        <a-col :span="3">
                            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                            </span>
                        </a-col>
                    </a-row>
                </a-form>
            </div>
            <!-- 查询区域-END -->
            <!-- table区域-begin -->
            <div>
                <!-- type:'radio' -->
                <a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading" :rowSelection="{
                selectedRowKeys: selectedRowKeys,
                onChange: onSelectChange,
                }" class="j-table-force-nowrap" @change="handleTableChange">
                    <!-- <template slot="name" slot-scope="text, record">
                        <a @click="handleBillInfo(record)">{{record.contactName}}</a>
                    </template> -->
                </a-table>
            </div>
        </a-tab-pane>
        <a-tab-pane key="2" tab="历史查房">
            <historyLookRoom />
        </a-tab-pane>
    </a-tabs>

    <a-modal :title="title" :visible="visibleLook" @cancel="changeCancel" @ok="submitOK">
        <!-- <j-form-container :disabled="false"> -->
        <a-form-model-item label="服务员" :labelCol="labelCol" :wrapperCol="wrapperCol" v-if="status==2">
            <a-select placeholder="服务员" v-model="waiterId" style="width:40%">
                <a-select-option :value="item.id" v-for="(item, index) in busWaiterList" :key="item.id">
                    {{ item.name }}
                </a-select-option>
            </a-select>
        </a-form-model-item>
        <a-form-model-item label="请输入备注" :labelCol="labelCol" :wrapperCol="wrapperCol" v-else>
            <a-input v-model="remarks" placeholder="请输入备注"></a-input>
        </a-form-model-item>
        <!-- </j-form-container> -->
    </a-modal>
</a-card>
</template>

<script>
import "@/assets/less/TableExpand.less";
import {
    mixinDevice
} from "@/utils/mixin";
import {
    JeecgListMixin
} from "@/mixins/JeecgListMixin";
// import BillRoomInfoModal from "./modules/checkIn/BillRoomInfoModal.vue";
import {
    httpAction,
    postAction,
    getAction
} from "@/api/manage";
import historyLookRoom from './historyLookRoom.vue';
export default {
    name: "CesOrderMessageList",
    mixins: [JeecgListMixin, mixinDevice],
    components: {
        // BillRoomInfoModal,
        historyLookRoom
    },
    data() {
        return {
            title: "",
            busWaiterList: [],
            labelCol: {
                xs: {
                    span: 24
                },
                sm: {
                    span: 5
                },
            },
            wrapperCol: {
                xs: {
                    span: 24
                },
                sm: {
                    span: 16
                },
            },
            waiterId: '',
            visibleLook: false,
            status: null,
            // 表头
            columns: [{
                    title: "查房状态",
                    align: "center",
                    dataIndex: 'state',
                    customRender: function (text) {
                        let txt = "";
                        switch (text) {
                            case 0:
                                txt = "待查房";
                                break;
                            case 1:
                                txt = "等待查房";
                                break;
                            case 2:
                                txt = "正在查房";
                                break;
                            case 3:
                                txt = "查房完毕";
                                break;
                            case 4:
                                txt = "取消查房";
                                break;
                            default:
                                break;
                        }
                        return txt;
                    },
                },
                {
                    title: "房号",
                    align: "center",
                    dataIndex: "roomName",
                },
                {
                    title: "客人姓名",
                    align: "center",
                    dataIndex: "contactName",
                    scopedSlots: { customRender: 'name' }
                },
                {
                    title: "查房发起人",
                    align: "center",
                    dataIndex: "promoterBy",
                },
                {
                    title: "查房发起时间",
                    align: "center",
                    dataIndex: "promoterTime",
                },
                {
                    title: "查房备注",
                    align: "center",
                    dataIndex: "remark",
                },
                {
                    title: "查房人",
                    align: "center",
                    dataIndex: "cfWaiterName",
                },
                {
                    title: "查房时间",
                    align: "center",
                    dataIndex: "cfTime",
                },
                {
                    title: "查房反馈",
                    align: "center",
                    dataIndex: "feedback",
                },
                {
                    title: "查房完成人",
                    align: "center",
                    dataIndex: "completedBy",
                },
                {
                    title: "查房完成时间",
                    align: "center",
                    dataIndex: "completedTime",
                },
                {
                    title: "房间状态",
                    align: "center",
                    dataIndex: "roomStatus",
                }
            ],
            url: {
                list: "/fw/fwRoomExamine/list",
                delete: "/order/cesOrderMessage/delete",
                deleteBatch: "/order/cesOrderMessage/deleteBatch",
                exportXlsUrl: "/order/cesOrderMessage/exportXls",
                importExcelUrl: "order/cesOrderMessage/importExcel",
            },
            dictOptions: {},
            superFieldList: [],
            hotelList: [],
            queryParam: {
                // type: 1,
                // livingStatus: -1,
                // bookingStatus: 1
            },
            remarks: "",
        };
    },
    created() {
        getAction("/business/busWaiter/list", {
            // hotelId: _info.id,
            pageNo: 1,
            pageSize: 99999,
        }).then((res) => {
            if (res.success) {
                this.busWaiterList = res.result.records;
            }
        });
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG["domianURL"]}/${this.url.importExcelUrl}`;
        },
    },
    methods: {
        /**
         * 根据选中数据设置按钮是否可用
         */
        setBtnsDisable(type) {
            if (this.selectedRowKeys.length === 0) {
                return true
            }
            if (type == 4 && this.selectionRows.some(item => item.state == 1 || item.state == 2)) {
                return false
            }
            if (type == 1 && this.selectionRows.some(item => item.state == 0 || item.state == 4)) {
                return false
            }
            if (type == 2 && this.selectionRows.some(item => item.state == 1)) {
                return false
            }
            if (type == 3 && this.selectionRows.some(item => item.state == 2)) {
                return false
            }
            return true
        },
        /**
         * 设置取消查房
         */
        cancelRoom() {
            // console.log(this.selectionRows);
            this.status = 4
            this.selectionRows.forEach(item => {
                this.editLookRoom(item, 4)
            })
            // this.editLookRoom(this.selectionRows.livingOrderId, 4)
        },

        changeCancel(){
            this.remarks = ''
            this.waiterId = ''
            this.visibleLook = false
        },

        editLookRoom(data, state, remark = '') {

            // let obj = {
            //     id: id,
            //     livingOrderId: livingOrderId,
            //     state: state,
            //     remark: remark,
            //     waiterId: this.waiterId,
            //     cfTime: this.waiterId?new Date().toLocaleString().replaceAll('/','-'):''
            // }
            data.state = state*1
            if (remark && this.status !=3) {
                data.remark = remark
            }
            if (this.status == 2) {
                data.waiterId = this.waiterId
                data.cfTime = new Date().toLocaleString().replaceAll('/', '-')
            }
            if (this.status == 3) {
                // data.remark = ''
                data.feedback = this.remarks
            }
            console.log(typeof data.state);
            console.log(data);
            // return
            httpAction("/fw/fwRoomExamine/checkRoom", data, 'post').then(res => {
                    this.confirmLoading = false;
                    if (res.success) {
                        this.$message.success("成功");
                        this.onClearSelected()
                        this.visibleLook = false
                        this.loadData()
                    } else {
                        this.$message.warning(res.message);
                    }
                })
                .finally(() => {
                    this.remarks = ''
                    this.waiterId = ''
                    this.confirmLoading = false;
                });
            console.log('3333333333333333333333333333', this.waiterId, this.remarks);
        },

        /**
         * 设置等待查房
         */
        setWaitRoom() {
            this.title = '申请查房'
            this.status = 1
            this.visibleLook = true
        },

        /**
         * 设置正在查房
         */
        setInRoom() {
            this.title = '设置正在查房'
            this.waiterId = ''
            this.status = 2
            this.visibleLook = true
        },

        /**
         * 设置查房完毕
         */
        setFinishRoom() {
            this.title = '查房完毕'
            this.status = 3
            this.visibleLook = true
        },

        /**
         * 表单提交
         */
        submitOK() {
            if (this.status == 2 && !this.waiterId) {
                this.$message.warning('请选择查房人')
                return                
            }
            this.confirmLoading = true;
            this.selectionRows.forEach(item => {
                this.editLookRoom(item, this.status, this.remarks)
            })
        },
        handleBillInfo(data){
            console.log(data);
        }
    },
};
</script>

<style scoped>
@import "~@assets/less/common.less";
</style>
