<template>
    <a-card :bordered="false" :schemeId="schemeId">
        <a-radio-group v-model="tablemode" :style="{ marginBottom: '8px' }">
            <a-radio-button value="ordinaryDays">平日房价</a-radio-button>
            <a-radio-button value="weekend">周末房价</a-radio-button>
        </a-radio-group>
        <div>
            <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"
                :rowKey="(record, index) => index + 1">
                <template slot="openSlot" slot-scope="text, record, index">
                    <a-switch checked-children="开" un-checked-children="关" default-checked :checked="record.open == 1"
                              @change="e=>changeOpenState(e,record)" />
                </template>
                <template slot="moneySlot" slot-scope="text, record">
                    <div>
                        <a-input-number v-model="record.money" :step="1" :min="0" :precision="2"
                                        @blur="onMoneyChange(record)" />
                    </div>
                </template>
                <template slot="breakfastNumberSlot" slot-scope="text, record">
                    <div>
                        <a-input-number v-model="record.breakfastNumber" :step="1" :min="0" :precision="0"
                                        @blur="onNumberChange(record)" />
                    </div>
                </template>
                <template slot="departureTimeSlot" slot-scope="text, record">
                    <div>
                        <a-time-picker :default-value="moment(record.departureTime, 'HH:mm')" format="HH:mm"
                                       @change="e=>onDepartureTimeChange(e,record)">
                        </a-time-picker>
                    </div>
                </template>
                <template slot="imgSlot" slot-scope="text, record">
                    <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
                    <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
                         style="max-width: 80px; font-size: 12px; font-style: italic" />
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
                    <a-button v-else :ghost="true" type="primary" icon="download" size="small"
                              @click="downloadFile(text)">
                        下载
                    </a-button>
                </template>

                <span slot="action" slot-scope="text, record">
                    <a @click="handleReset(record)">重置</a>
                    <a @click="handleMoney(record)">房价日历</a>
                </span>
            </a-table>
        </div>
        <house-price-scheme-layout-modal ref="modalForm" @ok="modalFormOk"></house-price-scheme-layout-modal>
    </a-card>
</template>

<script>
    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import moment from 'moment';
    import { httpAction } from '@/api/manage'
    import HousePriceSchemeLayoutModal from "./housePriceSchemeLayout/housePriceSchemeLayoutModal";

    export default {
        name: 'housePriceSchemeDetailList',
        mixins:[JeecgListMixin, mixinDevice],
        components: {
            HousePriceSchemeLayoutModal
        },
        props: {
            schemeId: {
                type: String,
                default: () => {
                    return ""
                }
            }
        },
        data () {
            return {
                description: '房价方案-房型关联表管理页面',
                // 表头
                columns: [
                    {
                        title: "序号",
                        align: 'center',
                        customRender: (text, record, index) => index + 1,
                    },
                    {
                        title:'房型',
                        align:"center",
                        dataIndex: 'layoutName'
                    },
                    {
                        title:'间数（间）1',
                        align:"center",
                        dataIndex: 'layoutName'
                    },
                    // {
                    //     title:'门市价',
                    //     align:"center",
                    //     dataIndex: 'layoutPrice'
                    // },
                    {
                        title:'挂牌价(元)1',
                        align:"center",
                        dataIndex: 'layoutPrice'
                    },
                    {
                        title:'前台价(散客)1',
                        align:"center",
                        dataIndex: 'layoutPrice'
                    },
                    {
                        title:'微信小程序(散客)1',
                        align:"center",
                        dataIndex: 'layoutPrice'
                    },
                    {
                        title:'钟点房间(元/小时)1',
                        align:"center",
                        dataIndex: 'layoutPrice'
                    },
                    // {
                    //     title:'执行房价',
                    //     align:"center",
                    //     dataIndex: 'money',
                    //     scopedSlots: {customRender: "moneySlot"},
                    // },
                    // {
                    //     title:'早餐数量',
                    //     align:"center",
                    //     dataIndex: 'breakfastNumber',
                    //     scopedSlots: {customRender: "breakfastNumberSlot"},
                    // },
                    // {
                    //     title:'默认离店时间',
                    //     align:"center",
                    //     dataIndex: 'departureTime',
                    //     // customRender:function (text) {
                    //     //     return !text?"":(text.length>10?text.substr(0,10):text)
                    //     // },
                    //     scopedSlots: {customRender: "departureTimeSlot"},
                    // },
                    {
                        title: '查看每日房价',
                        dataIndex: 'action',
                        align:"center",
                        fixed:"right",
                        width:147,
                        scopedSlots: { customRender: 'action' }
                    }
                ],
                url: {
                    list: "/business/busHousePriceSchemeLayout/list",
                    delete: "/business/busHousePriceSchemeLayout/delete",
                    deleteBatch: "/business/busHousePriceSchemeLayout/deleteBatch",
                    exportXlsUrl: "/business/busHousePriceSchemeLayout/exportXls",
                    importExcelUrl: "business/busHousePriceSchemeLayout/importExcel",
                    editMoney: "/business/busHousePriceSchemeLayout/editMoney",
                    editNumber: "/business/busHousePriceSchemeLayout/editNumber",
                    editTime: "/business/busHousePriceSchemeLayout/editTime",
                },
                dictOptions:{},
                superFieldList:[],
                queryParam: {
                  schemeId: this.schemeId
                },
                tablemode: 'ordinaryDays'
            }
        },
        created() {
            this.getSuperFieldList();
        },
        computed: {
            importExcelUrl: function(){
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
            },
        },
        methods: {
            moment,
            initDictConfig(){
            },
            getSuperFieldList(){
                let fieldList=[];
                fieldList.push({type:'string',value:'tenantId',text:'关联租户'})
                fieldList.push({type:'string',value:'hotelId',text:'关联酒店'})
                fieldList.push({type:'string',value:'schemeId',text:'关联房价方案'})
                fieldList.push({type:'string',value:'layoutId',text:'关联房型'})
                fieldList.push({type:'number',value:'money',text:'执行房价'})
                fieldList.push({type:'date',value:'departureTime',text:'默认离店时间'})
                fieldList.push({type:'int',value:'breakfastNumber',text:'早餐数量'})
                fieldList.push({type:'int',value:'lunchNumber',text:'中餐数量'})
                fieldList.push({type:'int',value:'dinnerNumber',text:'晚餐数量'})
                fieldList.push({type:'int',value:'delFlag',text:'删除状态'})
                this.superFieldList = fieldList
            },
            onMoneyChange(record){
                var that = this;
                //修改执行房价
                var param = {
                    money: record.money,
                    id: record.id
                }
                console.log(param)

                httpAction(this.url.editMoney, param, 'post').then((res) => {
                    if (res.success) {
                        that.$message.success('操作成功')
                        that.$emit('ok')
                    } else {
                        that.$message.warning(res.message)
                    }
                }).finally(() => {
                    that.confirmLoading = false
                })
            },
            onNumberChange(record){
                //修改早餐数量
                var that = this;
                var param = {
                    breakfastNumber: record.breakfastNumber,
                    id: record.id
                }
                console.log(param)
                httpAction(this.url.editNumber, param, 'post').then((res) => {
                    if (res.success) {
                        that.$message.success('操作成功')
                        that.$emit('ok')
                    } else {
                        that.$message.warning(res.message)
                    }
                }).finally(() => {
                    that.confirmLoading = false
                })
            },
            onDepartureTimeChange(e,record){
                var _time = moment(new Date(e)).format('HH:mm:ss')
                console.log(_time)
                //修改时间
                var that = this;
                var param = {
                    departureTime: _time,
                    id: record.id
                }
                console.log(param)
                httpAction(this.url.editTime, param, 'post').then((res) => {
                    if (res.success) {
                        that.$message.success('操作成功')
                        that.$emit('ok')
                    } else {
                        that.$message.warning(res.message)
                    }
                }).finally(() => {
                    that.confirmLoading = false
                })
            },
            handleMoney(record){
                this.$refs.modalForm.title="每日房价"
                this.$refs.modalForm.visible = true
                this.$refs.modalForm.edit(record);
            },
            // 重置按钮
            handleReset() {
                
            }

        }
    }
</script>

<style scoped>

</style>
